From b414f9f181c583933b9937a70468475006371643 Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Mon, 9 Feb 2015 20:47:35 -0500 Subject: [PATCH] fix up the buttons\n stabilize ui\n add wdiff panes --- client/app/document/document.js | 40 +++++++++++++------ client/app/document/revision/revision.jade | 6 +-- client/app/document/wdiff/wdiff.controller.js | 10 +++++ client/app/document/wdiff/wdiff.jade | 13 ++++-- server/api/document/document.controller.js | 5 ++- 5 files changed, 53 insertions(+), 21 deletions(-) diff --git a/client/app/document/document.js b/client/app/document/document.js index e4802d1..8b2c52f 100644 --- a/client/app/document/document.js +++ b/client/app/document/document.js @@ -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]}; } diff --git a/client/app/document/revision/revision.jade b/client/app/document/revision/revision.jade index 5288a3a..2a59ca8 100644 --- a/client/app/document/revision/revision.jade +++ b/client/app/document/revision/revision.jade @@ -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 diff --git a/client/app/document/wdiff/wdiff.controller.js b/client/app/document/wdiff/wdiff.controller.js index 16d484e..5999ef3 100644 --- a/client/app/document/wdiff/wdiff.controller.js +++ b/client/app/document/wdiff/wdiff.controller.js @@ -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; + } }) diff --git a/client/app/document/wdiff/wdiff.jade b/client/app/document/wdiff/wdiff.jade index 244b897..795b0af 100644 --- a/client/app/document/wdiff/wdiff.jade +++ b/client/app/document/wdiff/wdiff.jade @@ -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)}} diff --git a/server/api/document/document.controller.js b/server/api/document/document.controller.js index 769eaee..d02ab33 100644 --- a/server/api/document/document.controller.js +++ b/server/api/document/document.controller.js @@ -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); }