2015-02-07 19:49:04 +01:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
angular.module('markdownFormatWdiffApp')
|
2015-02-10 02:19:47 +01:00
|
|
|
.controller('DocumentRevisionCtrl', function ($scope, $routeParams, $http, Auth, App) {
|
|
|
|
$scope.App = App;
|
2015-02-07 19:49:04 +01:00
|
|
|
$scope.revision = {};
|
|
|
|
|
2015-02-09 02:42:31 +01:00
|
|
|
$scope.title = '';
|
|
|
|
$scope.subtitle = '';
|
|
|
|
|
2015-02-07 19:49:04 +01:00
|
|
|
$scope.getCurrentUser = Auth.getCurrentUser;
|
|
|
|
$scope.isLoggedIn = Auth.isLoggedIn;
|
|
|
|
|
|
|
|
//returns true if the current user is logged in and is the owner of this document / revision
|
|
|
|
$scope.isOwner = function () {
|
|
|
|
var currentUser = Auth.getCurrentUser();
|
|
|
|
if (!currentUser || !$scope.revision || !$scope.revision.owner)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return $scope.revision.owner._id == currentUser._id;
|
|
|
|
}
|
|
|
|
|
|
|
|
//returns true if this revision is the current revision in its document
|
2015-02-10 02:19:47 +01:00
|
|
|
$scope.isCurrent = function (revision) {
|
|
|
|
if (!revision)
|
2015-02-07 19:49:04 +01:00
|
|
|
return false;
|
|
|
|
|
2015-02-10 02:19:47 +01:00
|
|
|
return revision._id == revision.document.currentRevision;
|
2015-02-07 19:49:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
var path = '/api/documents/'+$routeParams.id+'/revisions/' + $routeParams.revisionid;
|
|
|
|
$http.get(path).success(function(revision) {
|
|
|
|
$scope.revision = revision;
|
2015-02-09 02:42:31 +01:00
|
|
|
$scope.title = revision.document.title;
|
|
|
|
$scope.subtitle = $scope.isCurrent() ? " (current)":(" ("+$scope.revision.created+")");
|
2015-02-07 19:49:04 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
})
|