fix up the buttons\n stabilize ui\n add wdiff panes
This commit is contained in:
parent
2a4fdeeb96
commit
b414f9f181
@ -37,23 +37,27 @@ angular.module('markdownFormatWdiffApp')
|
|||||||
};
|
};
|
||||||
|
|
||||||
//returns true if this revision is the current revision in its document
|
//returns true if this revision is the current revision in its document
|
||||||
root.isCurrent = function (revision) {
|
root.isCurrent = function (document, revision) {
|
||||||
if (!revision)
|
if (!revision)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return revision._id == revision.document.currentRevision;
|
var cr = document.currentRevision;
|
||||||
|
var compareId = (cr.hasOwnProperty('_id') ? cr._id : cr);
|
||||||
|
return revision._id == compareId;
|
||||||
};
|
};
|
||||||
|
|
||||||
//returns true if this revision is the first revision in its document
|
//returns true if this revision is the first revision in its document
|
||||||
// Note: documents have an initial empty sentinel revision - that is the zeroth revision
|
// Note: documents have an initial empty sentinel revision - that is the zeroth revision
|
||||||
root.isFirst = function (revision) {
|
root.isFirst = function (document, revision) {
|
||||||
if (!revision)
|
if (!revision)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (revision.document.revisions.length <= 1)
|
if (document.revisions.length <= 1)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return revision._id == revision.document.revisions[1];
|
var fr = document.revisions[1];
|
||||||
|
var compareId = (fr.hasOwnProperty('_id') ? fr._id : fr);
|
||||||
|
return revision._id == compareId;
|
||||||
};
|
};
|
||||||
|
|
||||||
//returns true if the current user is logged in and is the owner of this document / revision
|
//returns true if the current user is logged in and is the owner of this document / revision
|
||||||
@ -69,25 +73,35 @@ angular.module('markdownFormatWdiffApp')
|
|||||||
//and returns the previous revision
|
//and returns the previous revision
|
||||||
//if this is the oldest revision, then just return itself
|
//if this is the oldest revision, then just return itself
|
||||||
root.previousRevision = function (document, revision) {
|
root.previousRevision = function (document, revision) {
|
||||||
|
//sometimes the document will have revision ids as a separate field and sometimes it wont
|
||||||
|
var revisionIds = document.revisions;
|
||||||
|
if (revisionIds[0].hasOwnProperty('_id'))
|
||||||
|
revisionIds = _.pluck(revisionIds, '_id');
|
||||||
|
|
||||||
//find the index of the revision in documents
|
//find the index of the revision in documents
|
||||||
var index = _.findIndex(document.revisions, '_id');
|
var index = _.findIndex(revisionIds);
|
||||||
var prevIndex = index-1;
|
var prevIndex = index-1;
|
||||||
if (prevIndex < 0)
|
if (prevIndex < 0)
|
||||||
prevIndex = 0;
|
prevIndex = 0;
|
||||||
|
|
||||||
return document.revisions[prevIndex];
|
return {_id: revisionIds[prevIndex]};
|
||||||
}
|
}
|
||||||
//looks up this revision in the document revisions list
|
//looks up this revision in the document revisions list
|
||||||
//and returns the previous revision
|
//and returns the previous revision
|
||||||
//if this is the oldest revision, then just return itself
|
//if this is the oldest revision, then just return itself
|
||||||
root.nextRevision = function (document, revision) {
|
root.nextRevision = function (document, revision) {
|
||||||
//find the index of the revision in documents
|
//sometimes the document will have revision ids as a separate field and sometimes it wont
|
||||||
var index = _.findIndex(document.revisions, '_id');
|
var revisionIds = document.revisions;
|
||||||
var prevIndex = index+1;
|
if (revisionIds[0].hasOwnProperty('_id'))
|
||||||
if (prevIndex >= document.revisions.size())
|
revisionIds = _.pluck(revisionIds, '_id');
|
||||||
prevIndex = document.revisions.size()-1;
|
|
||||||
|
|
||||||
return document.revisions[prevIndex];
|
//find the index of the revision in documents
|
||||||
|
var index = _.findIndex(revisionIds);
|
||||||
|
var nextIndex = index+1;
|
||||||
|
if (nextIndex >= document.revisions.size())
|
||||||
|
nextIndex = document.revisions.size()-1;
|
||||||
|
|
||||||
|
return {_id: revisionIds[nextIndex]};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -8,15 +8,15 @@ nav(ng-include='"components/elements/header.html"')
|
|||||||
| Current revision
|
| Current revision
|
||||||
form.form-inline.controls.well
|
form.form-inline.controls.well
|
||||||
|
|
||||||
a.btn.btn-primary(ng-hide='App.isFirst(revision)' href='/{{revision.document._id}}/revision/{{App.previousRevision(revision.document, revision)._id}}')
|
//a.btn.btn-primary(ng-hide='App.isFirst(revision.document, revision)' href='/{{revision.document._id}}/revision/{{App.previousRevision(revision.document, revision)._id}}')
|
||||||
| View Previous
|
| View Previous
|
||||||
//a.btn.btn-primary(ng-hide='App.isFirst()' href='/wdiff/{{App.previousRevision(revision.document, revision)._id}}/{{revision._id}}')
|
//a.btn.btn-primary(ng-hide='App.isFirst()' href='/wdiff/{{App.previousRevision(revision.document, revision)._id}}/{{revision._id}}')
|
||||||
| Wdiff from Previous
|
| Wdiff from Previous
|
||||||
//a.btn.btn-primary(ng-hide='App.isCurrent()' href='/wdiff/{{revision._id}}/{{App.nextRevision(revision.document, revision)._id}}')
|
//a.btn.btn-primary(ng-hide='App.isCurrent()' href='/wdiff/{{revision._id}}/{{App.nextRevision(revision.document, revision)._id}}')
|
||||||
| Wdiff to Next
|
| Wdiff to Next
|
||||||
a.btn.btn-primary(ng-hide='App.isCurrent(revision)' href='/{{revision.document._id}}/revision/{{App.nextRevision(revision.document, revision)._id}}')
|
//a.btn.btn-primary(ng-hide='App.isCurrent(revision.document, revision)' href='/{{revision.document._id}}/revision/{{App.nextRevision(revision.document, revision)._id}}')
|
||||||
| View Next
|
| View Next
|
||||||
a.btn.btn-primary.pull-right(ng-hide='App.isCurrent(revision)' href='/wdiff/{{revision._id}}/{{revision.document.currentRevision}}')
|
a.btn.btn-primary.pull-right(ng-hide='App.isCurrent(revision.document, revision)' href='/wdiff/{{revision._id}}/{{revision.document.currentRevision}}')
|
||||||
| Wdiff to Current
|
| Wdiff to Current
|
||||||
|
|
||||||
.row
|
.row
|
||||||
|
@ -8,6 +8,8 @@ angular.module('markdownFormatWdiffApp')
|
|||||||
$scope.same = false;
|
$scope.same = false;
|
||||||
$scope.revisionA = {};
|
$scope.revisionA = {};
|
||||||
$scope.revisionB = {};
|
$scope.revisionB = {};
|
||||||
|
$scope.isShowBefore = true;
|
||||||
|
$scope.isShowAfter = false;
|
||||||
|
|
||||||
$scope.getCurrentUser = Auth.getCurrentUser;
|
$scope.getCurrentUser = Auth.getCurrentUser;
|
||||||
$scope.isLoggedIn = Auth.isLoggedIn;
|
$scope.isLoggedIn = Auth.isLoggedIn;
|
||||||
@ -24,5 +26,13 @@ angular.module('markdownFormatWdiffApp')
|
|||||||
$scope.subtitle = "wdiff: "+result.a.created + " / " + result.b.created;
|
$scope.subtitle = "wdiff: "+result.a.created + " / " + result.b.created;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$scope.showBefore = function() {
|
||||||
|
$scope.isShowBefore = true;
|
||||||
|
$scope.isShowAfter = false;
|
||||||
|
}
|
||||||
|
$scope.showAfter = function() {
|
||||||
|
$scope.isShowBefore = false;
|
||||||
|
$scope.isShowAfter = true;
|
||||||
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
|
@ -4,11 +4,18 @@ nav(ng-include='"components/elements/header.html"')
|
|||||||
|
|
||||||
.container
|
.container
|
||||||
.row
|
.row
|
||||||
//!!! add controls to view a and b
|
.col-md-6.col-sm-12.well(ng-show='isShowBefore')
|
||||||
|
div(btf-markdown='revisionA.content')
|
||||||
|
.col-md-6.col-sm-12
|
||||||
|
.controls.well
|
||||||
|
a.btn.btn-default.pull-left(ng-hide='isShowBefore', type='submit', ng-click='showBefore()')
|
||||||
|
| Show Before
|
||||||
|
a.btn.btn-default.pull-right(ng-hide='isShowAfter', type='submit', ng-click='showAfter()')
|
||||||
|
| Show After
|
||||||
|
|
||||||
.row
|
|
||||||
.col-lg-6.col-md-9.center-block
|
|
||||||
div(btf-markdown='wdiff')
|
div(btf-markdown='wdiff')
|
||||||
|
.col-md-6.col-sm-12.well(ng-show='isShowAfter')
|
||||||
|
div(btf-markdown='revisionB.content')
|
||||||
//pre
|
//pre
|
||||||
{{json(result)}}
|
{{json(result)}}
|
||||||
|
|
||||||
|
@ -146,7 +146,8 @@ exports.indexRevisionsForDocument = function(req, res) {
|
|||||||
Revision
|
Revision
|
||||||
.find({document: req.params.id})
|
.find({document: req.params.id})
|
||||||
.populate('owner', '_id name')
|
.populate('owner', '_id name')
|
||||||
.populate('document', '_id title currentRevision')
|
.populate('document', '_id title currentRevision revisions')
|
||||||
|
.populate('document.revisions', '_id')
|
||||||
.exec(function (err, revisions) {
|
.exec(function (err, revisions) {
|
||||||
if(err) { return handleError(res, err); }
|
if(err) { return handleError(res, err); }
|
||||||
if(!revisions) { return res.send(404); }
|
if(!revisions) { return res.send(404); }
|
||||||
@ -160,7 +161,7 @@ exports.showRevision = function(req, res) {
|
|||||||
Revision
|
Revision
|
||||||
.findById(req.params.revisionid)
|
.findById(req.params.revisionid)
|
||||||
.populate('owner', '_id name')
|
.populate('owner', '_id name')
|
||||||
.populate('document', '_id title currentRevision')
|
.populate('document', '_id title currentRevision revisions')
|
||||||
.populate('document.revisions', '_id')
|
.populate('document.revisions', '_id')
|
||||||
.exec(function (err, revision) {
|
.exec(function (err, revision) {
|
||||||
if(err) { return handleError(res, err); }
|
if(err) { return handleError(res, err); }
|
||||||
|
Loading…
Reference in New Issue
Block a user