fix up the buttons\n stabilize ui\n add wdiff panes

This commit is contained in:
Adam Brown 2015-02-09 20:47:35 -05:00
parent 2a4fdeeb96
commit b414f9f181
5 changed files with 53 additions and 21 deletions

View File

@ -37,23 +37,27 @@ angular.module('markdownFormatWdiffApp')
};
//returns true if this revision is the current revision in its document
root.isCurrent = function (revision) {
root.isCurrent = function (document, revision) {
if (!revision)
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
// Note: documents have an initial empty sentinel revision - that is the zeroth revision
root.isFirst = function (revision) {
root.isFirst = function (document, revision) {
if (!revision)
return false;
if (revision.document.revisions.length <= 1)
if (document.revisions.length <= 1)
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
@ -69,25 +73,35 @@ angular.module('markdownFormatWdiffApp')
//and returns the previous revision
//if this is the oldest revision, then just return itself
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
var index = _.findIndex(document.revisions, '_id');
var index = _.findIndex(revisionIds);
var prevIndex = index-1;
if (prevIndex < 0)
prevIndex = 0;
return document.revisions[prevIndex];
return {_id: revisionIds[prevIndex]};
}
//looks up this revision in the document revisions list
//and returns the previous revision
//if this is the oldest revision, then just return itself
root.nextRevision = function (document, revision) {
//find the index of the revision in documents
var index = _.findIndex(document.revisions, '_id');
var prevIndex = index+1;
if (prevIndex >= document.revisions.size())
prevIndex = document.revisions.size()-1;
//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');
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]};
}

View File

@ -8,15 +8,15 @@ nav(ng-include='"components/elements/header.html"')
| Current revision
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
//a.btn.btn-primary(ng-hide='App.isFirst()' href='/wdiff/{{App.previousRevision(revision.document, revision)._id}}/{{revision._id}}')
| Wdiff from Previous
//a.btn.btn-primary(ng-hide='App.isCurrent()' href='/wdiff/{{revision._id}}/{{App.nextRevision(revision.document, revision)._id}}')
| 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
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
.row

View File

@ -8,6 +8,8 @@ angular.module('markdownFormatWdiffApp')
$scope.same = false;
$scope.revisionA = {};
$scope.revisionB = {};
$scope.isShowBefore = true;
$scope.isShowAfter = false;
$scope.getCurrentUser = Auth.getCurrentUser;
$scope.isLoggedIn = Auth.isLoggedIn;
@ -24,5 +26,13 @@ angular.module('markdownFormatWdiffApp')
$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;
}
})

View File

@ -4,11 +4,18 @@ nav(ng-include='"components/elements/header.html"')
.container
.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')
.col-md-6.col-sm-12.well(ng-show='isShowAfter')
div(btf-markdown='revisionB.content')
//pre
{{json(result)}}

View File

@ -146,7 +146,8 @@ exports.indexRevisionsForDocument = function(req, res) {
Revision
.find({document: req.params.id})
.populate('owner', '_id name')
.populate('document', '_id title currentRevision')
.populate('document', '_id title currentRevision revisions')
.populate('document.revisions', '_id')
.exec(function (err, revisions) {
if(err) { return handleError(res, err); }
if(!revisions) { return res.send(404); }
@ -160,7 +161,7 @@ exports.showRevision = function(req, res) {
Revision
.findById(req.params.revisionid)
.populate('owner', '_id name')
.populate('document', '_id title currentRevision')
.populate('document', '_id title currentRevision revisions')
.populate('document.revisions', '_id')
.exec(function (err, revision) {
if(err) { return handleError(res, err); }