[Persistence] Show user, modification time

Show user name and modification time in dialog when revision-checking
detects modifications. WTD-1033.
This commit is contained in:
Victor Woeltjen 2015-03-25 12:19:45 -07:00
parent 5e20c2199d
commit 9eeb68ddd0
6 changed files with 76 additions and 1 deletions

View File

@ -31,6 +31,12 @@
"key": "persistence-failure-dialog",
"templateUrl": "templates/persistence-failure-dialog.html"
}
],
"controllers": [
{
"key": "PersistenceFailureController",
"implementation": "PersistenceFailureController.js"
}
]
}
}

View File

@ -1,3 +1,5 @@
<span ng-controller="PersistenceFailureController as controller">
<div ng-if="ngModel.revised.length > 0">
External changes have been made to the following objects:
<ul>
@ -5,6 +7,10 @@
<mct-representation key="'label'"
mct-object="failure.domainObject">
</mct-representation>
was modified at
<b>{{controller.formatTimestamp(failure.error.model.modified)}}</b>
by
<i>{{controller.formatUsername(failure.error.model.modifier)}}</i>
</li>
</ul>
You may overwrite these objects, or discard your changes to keep
@ -22,3 +28,4 @@
</ul>
</div>
</span>

View File

@ -2,5 +2,7 @@
define({
REVISION_ERROR_KEY: "revision",
OVERWRITE_KEY: "overwrite"
OVERWRITE_KEY: "overwrite",
TIMESTAMP_FORMAT: "YYYY-MM-DD HH:mm:ss\\Z",
UNKNOWN_USER: "unknown user"
});

View File

@ -0,0 +1,32 @@
/*global define*/
define(
['moment', './PersistenceFailureConstants'],
function (moment, Constants) {
"use strict";
/**
* Controller to support the template to be shown in the
* dialog shown for persistence failures.
*/
function PersistenceFailureController() {
return {
/**
* Format a timestamp for display in the dialog.
*/
formatTimestamp: function (timestamp) {
return moment.utc(timestamp)
.format(Constants.TIMESTAMP_FORMAT);
},
/**
* Format a user name for display in the dialog.
*/
formatUsername: function (username) {
return username || Constants.UNKNOWN_USER;
}
};
}
return PersistenceFailureController;
}
);

View File

@ -0,0 +1,27 @@
/*global define,Promise,describe,it,expect,beforeEach,waitsFor,jasmine*/
define(
["../src/PersistenceFailureController"],
function (PersistenceFailureController) {
"use strict";
describe("The persistence failure controller", function () {
var controller;
beforeEach(function () {
controller = new PersistenceFailureController();
});
it("converts timestamps to human-readable dates", function () {
expect(controller.formatTimestamp(402514331000))
.toEqual("1982-10-03 17:32:11Z");
});
it("provides default user names", function () {
expect(controller.formatUsername(undefined))
.toEqual(jasmine.any(String));
});
});
}
);

View File

@ -1,5 +1,6 @@
[
"PersistenceFailureConstants",
"PersistenceFailureController",
"PersistenceFailureDialog",
"PersistenceFailureHandler",
"PersistenceQueue",