From 2a4fdeeb96699995b42182c3f4499232d6d1450d Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Mon, 9 Feb 2015 20:19:47 -0500 Subject: [PATCH] further ui improvements --- client/app/app.scss | 19 +++++- client/app/document/document.js | 64 +++++++++++++++++++ client/app/document/document.scss | 3 - client/app/document/index/index.controller.js | 8 +-- client/app/document/index/index.jade | 62 ++++++++++-------- .../revision-new/revision-new.controller.js | 13 +--- .../document/revision-new/revision-new.jade | 2 +- .../document/revision/revision.controller.js | 10 +-- client/app/document/revision/revision.jade | 14 +++- client/app/document/show/show.controller.js | 16 ++++- client/app/document/show/show.jade | 28 +++++--- client/app/document/wdiff/wdiff.controller.js | 20 +----- server/api/document/document.controller.js | 1 + server/components/wdiff/index.js | 2 +- 14 files changed, 178 insertions(+), 84 deletions(-) diff --git a/client/app/app.scss b/client/app/app.scss index aa9f0bf..cd4d2a0 100644 --- a/client/app/app.scss +++ b/client/app/app.scss @@ -15,15 +15,30 @@ $fa-font-path: "/bower_components/font-awesome/fonts"; padding: 0.2em 0; } +.indent { + margin-left: 2em; +} table.revisions th, table.revisions td{ - padding-left: 1em; padding-right: 1em; } - +table.revisions td.content { + max-height: 30em; +} table.revisions .state { width: 7em; } +form.controls { + margin-top: 1em; +} + +form.form-inline.controls > * { + margin-right: 1em; +} +form.form-inline.controls > .form-group > label, { + margin-right: 0.5em; +} + // Component styles are injected through grunt // injector @import 'account/login/login.scss'; diff --git a/client/app/document/document.js b/client/app/document/document.js index 2ac1417..e4802d1 100644 --- a/client/app/document/document.js +++ b/client/app/document/document.js @@ -28,4 +28,68 @@ angular.module('markdownFormatWdiffApp') controller: 'DocumentWdiffCtrl' }); + }) + .factory('App', function ($window, Auth) { + var root = {}; + + root.json = function (object) { + return JSON.stringify(object, null, " "); + }; + + //returns true if this revision is the current revision in its document + root.isCurrent = function (revision) { + if (!revision) + return false; + + return revision._id == revision.document.currentRevision; + }; + + //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) { + if (!revision) + return false; + + if (revision.document.revisions.length <= 1) + return true; + + return revision._id == revision.document.revisions[1]; + }; + + //returns true if the current user is logged in and is the owner of this document / revision + root.isOwner = function (document) { + var currentUser = Auth.getCurrentUser(); + if (!currentUser || !document || !document.owner) + return false; + + return document.owner._id == currentUser._id; + } + + //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.previousRevision = function (document, revision) { + //find the index of the revision in documents + var index = _.findIndex(document.revisions, '_id'); + var prevIndex = index-1; + if (prevIndex < 0) + prevIndex = 0; + + return document.revisions[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; + + return document.revisions[prevIndex]; + } + + + return root; }); \ No newline at end of file diff --git a/client/app/document/document.scss b/client/app/document/document.scss index 871c6a1..e69de29 100644 --- a/client/app/document/document.scss +++ b/client/app/document/document.scss @@ -1,3 +0,0 @@ -table.revisions { - column-gap: 2em; -} \ No newline at end of file diff --git a/client/app/document/index/index.controller.js b/client/app/document/index/index.controller.js index 0b0cbef..c556bfd 100644 --- a/client/app/document/index/index.controller.js +++ b/client/app/document/index/index.controller.js @@ -1,7 +1,8 @@ 'use strict'; angular.module('markdownFormatWdiffApp') - .controller('DocumentIndexCtrl', function ($scope, $routeParams, $http, Auth, $location) { + .controller('DocumentIndexCtrl', function ($scope, $routeParams, $http, Auth, $location, App) { + $scope.App = App; $scope.title = 'Documents'; $scope.documents = []; @@ -25,11 +26,10 @@ angular.module('markdownFormatWdiffApp') $http.post('/api/documents', {title: $scope.newDocumentTitle}) .success(function(newDocument) { $scope.documents.push(newDocument); - //and document view page - $location.path('/'+newDocument._id); + //skip redirecting to document view page + //$location.path('/'+newDocument._id); }); }; - $scope.json = function (object) { return JSON.stringify(object, null, " "); }; }) diff --git a/client/app/document/index/index.jade b/client/app/document/index/index.jade index 9f9784b..131b2fc 100644 --- a/client/app/document/index/index.jade +++ b/client/app/document/index/index.jade @@ -4,8 +4,8 @@ nav(ng-include='"components/elements/header.html"') .container .row(ng-show='isLoggedIn()') - .col-lg-9.col-md-12 - form.form-inline + .col-lg-0.col-md-12 + form.form-inline.controls.well .form-group label(for='title-input') | New Document @@ -14,29 +14,39 @@ nav(ng-include='"components/elements/header.html"') | Create .row - .col-lg-6.col-md-12(ng-repeat='document in documents | orderBy:"currentRevision.created":true' ) - h1 - a(href='/{{document._id}}') - {{document.title}} - table.revisions - tr - th.state State - th.created revision - tr(ng-repeat='revision in document.revisions | orderBy:"created":true | limitTo:5' ) - td.state {{revision.state}} - td.created - h4 - a(href='/{{document._id}}/revision/{{revision._id}}') - {{revision.created}} - //div - p - | State: - {{document.currentRevision.state}} - p - | Updated: - {{document.currentRevision.created}} - //pre - {{json(document)}} - + .col-md-6.col-sm-12(ng-repeat='document in documents | orderBy:"currentRevision.created":true' ) + .center-block + h1 + a(href='/{{document._id}}') + | {{document.title}} + a.btn.btn-default.pull-right(href='/{{document._id}}/revision/new') + | New rev + a.btn.btn-default.pull-right(ng-hide='document.revisions.length<=1', href='/wdiff/{{document.revisions[1]._id}}/{{document.currentRevision._id}}') + | Wdiff all + div.indent + p(ng-hide='App.isOwner(document)') + span + | Owner: + span + | {{document.owner.name}} + table.revisions + tr + th.state State + th.created Revision + //th.wdiff(colspan='2') Wdiff With + tr(ng-repeat='revision in document.revisions | orderBy:"created":true | limitTo:5' ng-hide='$last') + td.state {{revision.state}} + td.created + h4 + a(href='/{{document._id}}/revision/{{revision._id}}') + {{revision.created}} + //these aren't working great + //td.wdiff.prev + a.btn.btn-default(ng-hide='$last', href='/wdiff/{{App.previousRevision(document, revision)._id}}/{{revision._id}}') Prev + //td.wdiff.curr + a.btn.btn-default(ng-hide='$first', href='/wdiff/{{revision._id}}/{{document.currentRevision._id}}') Current + //pre + {{App.json(document)}} + footer(ng-include='"components/elements/footer.html"') \ No newline at end of file diff --git a/client/app/document/revision-new/revision-new.controller.js b/client/app/document/revision-new/revision-new.controller.js index b45e90d..be57322 100644 --- a/client/app/document/revision-new/revision-new.controller.js +++ b/client/app/document/revision-new/revision-new.controller.js @@ -1,7 +1,8 @@ 'use strict'; angular.module('markdownFormatWdiffApp') - .controller('DocumentRevisionNewCtrl', function ($scope, $routeParams, $http, Auth, $location) { + .controller('DocumentRevisionNewCtrl', function ($scope, $routeParams, $http, Auth, $location, App) { + $scope.App = App; $scope.title = ''; $scope.subtitle = ''; @@ -12,14 +13,6 @@ angular.module('markdownFormatWdiffApp') $scope.getCurrentUser = Auth.getCurrentUser; $scope.isLoggedIn = Auth.isLoggedIn; - $scope.isOwner = function () { - var currentUser = Auth.getCurrentUser(); - if (!currentUser || !$scope.revision || !$scope.revision.owner) - return false; - - return $scope.revision.owner._id == currentUser._id; - }; - var path = '/api/documents/' + $routeParams.id; $http.get(path).success(function(document) { $scope.document = document; @@ -30,7 +23,6 @@ angular.module('markdownFormatWdiffApp') $scope.saveRevision = function() { - alert(JSON.stringify($scope.revision)) //save the revision to the document $http.post('/api/documents/'+$routeParams.id+'/revisions', $scope.revision) .success(function(newRevision) { @@ -39,5 +31,4 @@ angular.module('markdownFormatWdiffApp') }); }; - $scope.json = function (object) { return JSON.stringify(object, null, " "); }; }) diff --git a/client/app/document/revision-new/revision-new.jade b/client/app/document/revision-new/revision-new.jade index e327622..65be9bd 100644 --- a/client/app/document/revision-new/revision-new.jade +++ b/client/app/document/revision-new/revision-new.jade @@ -5,7 +5,7 @@ nav(ng-include='"components/elements/header.html"') .container .row .col-lg-6.col-md-12 - form + form.controls h4 {{document.title}} - {{revision.created}} .form-group diff --git a/client/app/document/revision/revision.controller.js b/client/app/document/revision/revision.controller.js index 7f6855d..634ae6a 100644 --- a/client/app/document/revision/revision.controller.js +++ b/client/app/document/revision/revision.controller.js @@ -1,7 +1,8 @@ 'use strict'; angular.module('markdownFormatWdiffApp') - .controller('DocumentRevisionCtrl', function ($scope, $routeParams, $http, Auth) { + .controller('DocumentRevisionCtrl', function ($scope, $routeParams, $http, Auth, App) { + $scope.App = App; $scope.revision = {}; $scope.title = ''; @@ -20,11 +21,11 @@ angular.module('markdownFormatWdiffApp') } //returns true if this revision is the current revision in its document - $scope.isCurrent = function () { - if (!$scope.revision) + $scope.isCurrent = function (revision) { + if (!revision) return false; - return $scope.revision._id == $scope.revision.document.currentRevision; + return revision._id == revision.document.currentRevision; } var path = '/api/documents/'+$routeParams.id+'/revisions/' + $routeParams.revisionid; @@ -34,6 +35,5 @@ angular.module('markdownFormatWdiffApp') $scope.subtitle = $scope.isCurrent() ? " (current)":(" ("+$scope.revision.created+")"); }); - $scope.json = function (object) { return JSON.stringify(object, null, " "); }; }) diff --git a/client/app/document/revision/revision.jade b/client/app/document/revision/revision.jade index d8b119c..5288a3a 100644 --- a/client/app/document/revision/revision.jade +++ b/client/app/document/revision/revision.jade @@ -6,8 +6,18 @@ nav(ng-include='"components/elements/header.html"') .row //span(ng-show='isCurrent()') | Current revision - a.btn.btn-primary(ng-hide='isCurrent()' href='/wdiff/{{revision._id}}/{{revision.document.currentRevision}}') - | wdiff current + 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}}') + | 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}}') + | View Next + a.btn.btn-primary.pull-right(ng-hide='App.isCurrent(revision)' href='/wdiff/{{revision._id}}/{{revision.document.currentRevision}}') + | Wdiff to Current .row .col-lg-6.col-md-9 diff --git a/client/app/document/show/show.controller.js b/client/app/document/show/show.controller.js index bc053c1..9925c82 100644 --- a/client/app/document/show/show.controller.js +++ b/client/app/document/show/show.controller.js @@ -1,7 +1,8 @@ 'use strict'; angular.module('markdownFormatWdiffApp') - .controller('DocumentShowCtrl', function ($scope, $routeParams, $http, Auth) { + .controller('DocumentShowCtrl', function ($scope, $routeParams, $http, Auth, App) { + $scope.App = App; $scope.document = {}; $scope.title = ''; @@ -23,6 +24,17 @@ angular.module('markdownFormatWdiffApp') $scope.title = document.title; }); - $scope.json = function (object) { return JSON.stringify(object, null, " "); }; + //looks up this revision in the document revisions list + //and returns the previous revision + //if this is the oldest revision, then just return itself + $scope.previousRevision = function (revision) { + //find the index of the revision in documents + var index = _.findIndex($scope.document.revisions, '_id'); + var prevIndex = index-1; + if (prevIndex < 0) + prevIndex = 0; + + return $scope.document.revisions[prevIndex]; + } }) diff --git a/client/app/document/show/show.jade b/client/app/document/show/show.jade index 56e5683..35601de 100644 --- a/client/app/document/show/show.jade +++ b/client/app/document/show/show.jade @@ -3,27 +3,37 @@ nav(ng-include='"components/navbar/navbar.html"') nav(ng-include='"components/elements/header.html"') .container - .row(ng-show='isOwner()') + .row .col-lg-12 - form + + + .row + .col-lg-6.col-sm-12 + form.form-inline.controls.well(ng-show='App.isOwner(document)') a.btn.btn-primary(href='/{{document._id}}/revision/new') | New Revision - .row - .col-lg-6.col-md-9.center-block - table.revisions tr th.state State - th.created revision - tr(ng-repeat='revision in document.revisions | orderBy:"created":true | limitTo:5' ) + th.created Revision + tr(ng-repeat='revision in document.revisions | orderBy:"created":true' ng-hide='$last' ) td.state {{revision.state}} td.created h4 a(href='/{{document._id}}/revision/{{revision._id}}') {{revision.created}} - //pre - | {{json(revision)}} + //these aren't working great + //td.wdiff.prev + a.btn.btn-default(ng-hide='$last', href='/wdiff/{{App.previousRevision(document, revision)._id}}/{{revision._id}}') Prev + //td.wdiff.curr + a.btn.btn-default(ng-hide='$first', href='/wdiff/{{revision._id}}/{{document.currentRevision._id}}') Current + + .col-lg-6.col-sm-12 + div(btf-markdown='document.currentRevision.content') + + //pre.col-lg-6 + | {{json(document)}} footer(ng-include='"components/elements/footer.html"') \ No newline at end of file diff --git a/client/app/document/wdiff/wdiff.controller.js b/client/app/document/wdiff/wdiff.controller.js index 979090c..16d484e 100644 --- a/client/app/document/wdiff/wdiff.controller.js +++ b/client/app/document/wdiff/wdiff.controller.js @@ -1,7 +1,8 @@ 'use strict'; angular.module('markdownFormatWdiffApp') - .controller('DocumentWdiffCtrl', function ($scope, $routeParams, $http, Auth) { + .controller('DocumentWdiffCtrl', function ($scope, $routeParams, $http, Auth, App) { + $scope.App = App; $scope.wdiff = ''; $scope.title = ''; $scope.same = false; @@ -10,24 +11,8 @@ angular.module('markdownFormatWdiffApp') $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 - $scope.isCurrent = function () { - if (!$scope.revision) - return false; - - return $scope.revision._id == $scope.revision.document.currentRevision._id; - } -*/ var path = '/api/documents/wdiff/'+$routeParams.revisionida+'/'+$routeParams.revisionidb; $http.get(path).success(function(result) { $scope.result = result; @@ -39,6 +24,5 @@ angular.module('markdownFormatWdiffApp') $scope.subtitle = "wdiff: "+result.a.created + " / " + result.b.created; }); - $scope.json = function (object) { return JSON.stringify(object, null, " "); }; }) diff --git a/server/api/document/document.controller.js b/server/api/document/document.controller.js index e551fa8..769eaee 100644 --- a/server/api/document/document.controller.js +++ b/server/api/document/document.controller.js @@ -161,6 +161,7 @@ exports.showRevision = function(req, res) { .findById(req.params.revisionid) .populate('owner', '_id name') .populate('document', '_id title currentRevision') + .populate('document.revisions', '_id') .exec(function (err, revision) { if(err) { return handleError(res, err); } if(!revision) { return res.send(404); } diff --git a/server/components/wdiff/index.js b/server/components/wdiff/index.js index e878b81..b4a5b7e 100644 --- a/server/components/wdiff/index.js +++ b/server/components/wdiff/index.js @@ -205,7 +205,7 @@ function rewriteWdiffMarkdown(source) { // |([ \t]+[0-9]+\.) - numeric lists // )? // [ \t]+ - trailing whitespace - var PREFIX = /^([ \t]*\>)*(([ \t]*#*)|([ \t]+[\*\+-])|([ \t]+[0-9]+\.))?[ \t]+/ + var PREFIX = /^([ \t]*\>)*(([ \t]*#*)|([ \t]*[\*\+-])|([ \t]*[\d]+\.))?[ \t]+/ //var PREFIX = /^#*/