further ui improvements

This commit is contained in:
Adam Brown 2015-02-09 20:19:47 -05:00
parent ee3bd40ef7
commit 2a4fdeeb96
14 changed files with 178 additions and 84 deletions

View File

@ -15,15 +15,30 @@ $fa-font-path: "/bower_components/font-awesome/fonts";
padding: 0.2em 0; padding: 0.2em 0;
} }
.indent {
margin-left: 2em;
}
table.revisions th, table.revisions td{ table.revisions th, table.revisions td{
padding-left: 1em;
padding-right: 1em; padding-right: 1em;
} }
table.revisions td.content {
max-height: 30em;
}
table.revisions .state { table.revisions .state {
width: 7em; 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 // Component styles are injected through grunt
// injector // injector
@import 'account/login/login.scss'; @import 'account/login/login.scss';

View File

@ -28,4 +28,68 @@ angular.module('markdownFormatWdiffApp')
controller: 'DocumentWdiffCtrl' 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;
}); });

View File

@ -1,3 +0,0 @@
table.revisions {
column-gap: 2em;
}

View File

@ -1,7 +1,8 @@
'use strict'; 'use strict';
angular.module('markdownFormatWdiffApp') 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.title = 'Documents';
$scope.documents = []; $scope.documents = [];
@ -25,11 +26,10 @@ angular.module('markdownFormatWdiffApp')
$http.post('/api/documents', {title: $scope.newDocumentTitle}) $http.post('/api/documents', {title: $scope.newDocumentTitle})
.success(function(newDocument) { .success(function(newDocument) {
$scope.documents.push(newDocument); $scope.documents.push(newDocument);
//and document view page //skip redirecting to document view page
$location.path('/'+newDocument._id); //$location.path('/'+newDocument._id);
}); });
}; };
$scope.json = function (object) { return JSON.stringify(object, null, " "); };
}) })

View File

@ -4,8 +4,8 @@ nav(ng-include='"components/elements/header.html"')
.container .container
.row(ng-show='isLoggedIn()') .row(ng-show='isLoggedIn()')
.col-lg-9.col-md-12 .col-lg-0.col-md-12
form.form-inline form.form-inline.controls.well
.form-group .form-group
label(for='title-input') label(for='title-input')
| New Document | New Document
@ -14,29 +14,39 @@ nav(ng-include='"components/elements/header.html"')
| Create | Create
.row .row
.col-lg-6.col-md-12(ng-repeat='document in documents | orderBy:"currentRevision.created":true' ) .col-md-6.col-sm-12(ng-repeat='document in documents | orderBy:"currentRevision.created":true' )
h1 .center-block
a(href='/{{document._id}}') h1
{{document.title}} a(href='/{{document._id}}')
table.revisions | {{document.title}}
tr a.btn.btn-default.pull-right(href='/{{document._id}}/revision/new')
th.state State | New rev
th.created revision a.btn.btn-default.pull-right(ng-hide='document.revisions.length<=1', href='/wdiff/{{document.revisions[1]._id}}/{{document.currentRevision._id}}')
tr(ng-repeat='revision in document.revisions | orderBy:"created":true | limitTo:5' ) | Wdiff all
td.state {{revision.state}} div.indent
td.created p(ng-hide='App.isOwner(document)')
h4 span
a(href='/{{document._id}}/revision/{{revision._id}}') | Owner:
{{revision.created}} span
//div | {{document.owner.name}}
p table.revisions
| State: tr
{{document.currentRevision.state}} th.state State
p th.created Revision
| Updated: //th.wdiff(colspan='2') Wdiff With
{{document.currentRevision.created}} tr(ng-repeat='revision in document.revisions | orderBy:"created":true | limitTo:5' ng-hide='$last')
//pre td.state {{revision.state}}
{{json(document)}} 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"') footer(ng-include='"components/elements/footer.html"')

View File

@ -1,7 +1,8 @@
'use strict'; 'use strict';
angular.module('markdownFormatWdiffApp') 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.title = '';
$scope.subtitle = ''; $scope.subtitle = '';
@ -12,14 +13,6 @@ angular.module('markdownFormatWdiffApp')
$scope.getCurrentUser = Auth.getCurrentUser; $scope.getCurrentUser = Auth.getCurrentUser;
$scope.isLoggedIn = Auth.isLoggedIn; $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; var path = '/api/documents/' + $routeParams.id;
$http.get(path).success(function(document) { $http.get(path).success(function(document) {
$scope.document = document; $scope.document = document;
@ -30,7 +23,6 @@ angular.module('markdownFormatWdiffApp')
$scope.saveRevision = function() { $scope.saveRevision = function() {
alert(JSON.stringify($scope.revision))
//save the revision to the document //save the revision to the document
$http.post('/api/documents/'+$routeParams.id+'/revisions', $scope.revision) $http.post('/api/documents/'+$routeParams.id+'/revisions', $scope.revision)
.success(function(newRevision) { .success(function(newRevision) {
@ -39,5 +31,4 @@ angular.module('markdownFormatWdiffApp')
}); });
}; };
$scope.json = function (object) { return JSON.stringify(object, null, " "); };
}) })

View File

@ -5,7 +5,7 @@ nav(ng-include='"components/elements/header.html"')
.container .container
.row .row
.col-lg-6.col-md-12 .col-lg-6.col-md-12
form form.controls
h4 h4
{{document.title}} - {{revision.created}} {{document.title}} - {{revision.created}}
.form-group .form-group

View File

@ -1,7 +1,8 @@
'use strict'; 'use strict';
angular.module('markdownFormatWdiffApp') angular.module('markdownFormatWdiffApp')
.controller('DocumentRevisionCtrl', function ($scope, $routeParams, $http, Auth) { .controller('DocumentRevisionCtrl', function ($scope, $routeParams, $http, Auth, App) {
$scope.App = App;
$scope.revision = {}; $scope.revision = {};
$scope.title = ''; $scope.title = '';
@ -20,11 +21,11 @@ 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
$scope.isCurrent = function () { $scope.isCurrent = function (revision) {
if (!$scope.revision) if (!revision)
return false; 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; 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.subtitle = $scope.isCurrent() ? " (current)":(" ("+$scope.revision.created+")");
}); });
$scope.json = function (object) { return JSON.stringify(object, null, " "); };
}) })

View File

@ -6,8 +6,18 @@ nav(ng-include='"components/elements/header.html"')
.row .row
//span(ng-show='isCurrent()') //span(ng-show='isCurrent()')
| Current revision | Current revision
a.btn.btn-primary(ng-hide='isCurrent()' href='/wdiff/{{revision._id}}/{{revision.document.currentRevision}}') form.form-inline.controls.well
| wdiff current
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 .row
.col-lg-6.col-md-9 .col-lg-6.col-md-9

View File

@ -1,7 +1,8 @@
'use strict'; 'use strict';
angular.module('markdownFormatWdiffApp') angular.module('markdownFormatWdiffApp')
.controller('DocumentShowCtrl', function ($scope, $routeParams, $http, Auth) { .controller('DocumentShowCtrl', function ($scope, $routeParams, $http, Auth, App) {
$scope.App = App;
$scope.document = {}; $scope.document = {};
$scope.title = ''; $scope.title = '';
@ -23,6 +24,17 @@ angular.module('markdownFormatWdiffApp')
$scope.title = document.title; $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];
}
}) })

View File

@ -3,27 +3,37 @@ nav(ng-include='"components/navbar/navbar.html"')
nav(ng-include='"components/elements/header.html"') nav(ng-include='"components/elements/header.html"')
.container .container
.row(ng-show='isOwner()') .row
.col-lg-12 .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') a.btn.btn-primary(href='/{{document._id}}/revision/new')
| New Revision | New Revision
.row
.col-lg-6.col-md-9.center-block
table.revisions table.revisions
tr tr
th.state State th.state State
th.created revision th.created Revision
tr(ng-repeat='revision in document.revisions | orderBy:"created":true | limitTo:5' ) tr(ng-repeat='revision in document.revisions | orderBy:"created":true' ng-hide='$last' )
td.state {{revision.state}} td.state {{revision.state}}
td.created td.created
h4 h4
a(href='/{{document._id}}/revision/{{revision._id}}') a(href='/{{document._id}}/revision/{{revision._id}}')
{{revision.created}} {{revision.created}}
//pre //these aren't working great
| {{json(revision)}} //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"') footer(ng-include='"components/elements/footer.html"')

View File

@ -1,7 +1,8 @@
'use strict'; 'use strict';
angular.module('markdownFormatWdiffApp') angular.module('markdownFormatWdiffApp')
.controller('DocumentWdiffCtrl', function ($scope, $routeParams, $http, Auth) { .controller('DocumentWdiffCtrl', function ($scope, $routeParams, $http, Auth, App) {
$scope.App = App;
$scope.wdiff = ''; $scope.wdiff = '';
$scope.title = ''; $scope.title = '';
$scope.same = false; $scope.same = false;
@ -10,24 +11,8 @@ angular.module('markdownFormatWdiffApp')
$scope.getCurrentUser = Auth.getCurrentUser; $scope.getCurrentUser = Auth.getCurrentUser;
$scope.isLoggedIn = Auth.isLoggedIn; $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; var path = '/api/documents/wdiff/'+$routeParams.revisionida+'/'+$routeParams.revisionidb;
$http.get(path).success(function(result) { $http.get(path).success(function(result) {
$scope.result = result; $scope.result = result;
@ -39,6 +24,5 @@ angular.module('markdownFormatWdiffApp')
$scope.subtitle = "wdiff: "+result.a.created + " / " + result.b.created; $scope.subtitle = "wdiff: "+result.a.created + " / " + result.b.created;
}); });
$scope.json = function (object) { return JSON.stringify(object, null, " "); };
}) })

View File

@ -161,6 +161,7 @@ exports.showRevision = function(req, res) {
.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')
.populate('document.revisions', '_id')
.exec(function (err, revision) { .exec(function (err, revision) {
if(err) { return handleError(res, err); } if(err) { return handleError(res, err); }
if(!revision) { return res.send(404); } if(!revision) { return res.send(404); }

View File

@ -205,7 +205,7 @@ function rewriteWdiffMarkdown(source) {
// |([ \t]+[0-9]+\.) - numeric lists // |([ \t]+[0-9]+\.) - numeric lists
// )? // )?
// [ \t]+ - trailing whitespace // [ \t]+ - trailing whitespace
var PREFIX = /^([ \t]*\>)*(([ \t]*#*)|([ \t]+[\*\+-])|([ \t]+[0-9]+\.))?[ \t]+/ var PREFIX = /^([ \t]*\>)*(([ \t]*#*)|([ \t]*[\*\+-])|([ \t]*[\d]+\.))?[ \t]+/
//var PREFIX = /^#*/ //var PREFIX = /^#*/