[List] Use standard format for modified/persisted times (#1737)

* [List] Use standard format for modified/persisted times

This provides consistency with other times and dates in the user interface,
and also provides a meaningful sort order due to the use of ISO formats for
standard date/time presentation. Fixes #1730.

* Remove unused dependency
This commit is contained in:
Victor Woeltjen 2017-10-20 18:25:49 -07:00 committed by Pete Richards
parent 77c7bdfdec
commit 7442768ced
3 changed files with 32 additions and 13 deletions

View File

@ -49,7 +49,7 @@
{ {
"key": "ListViewController", "key": "ListViewController",
"implementation": ListViewController, "implementation": ListViewController,
"depends": ["$scope"] "depends": ["$scope", "formatService"]
} }
], ],
"directives": [ "directives": [

View File

@ -21,7 +21,7 @@
*****************************************************************************/ *****************************************************************************/
define(function () { define(function () {
function ListViewController($scope) { function ListViewController($scope, formatService) {
this.$scope = $scope; this.$scope = $scope;
$scope.orderByField = 'title'; $scope.orderByField = 'title';
$scope.reverseSort = false; $scope.reverseSort = false;
@ -30,6 +30,8 @@ define(function () {
var unlisten = $scope.domainObject.getCapability('mutation') var unlisten = $scope.domainObject.getCapability('mutation')
.listen(this.updateView.bind(this)); .listen(this.updateView.bind(this));
this.utc = formatService.getFormat('utc');
$scope.$on('$destroy', function () { $scope.$on('$destroy', function () {
unlisten(); unlisten();
}); });
@ -50,17 +52,13 @@ define(function () {
icon: child.getCapability('type').getCssClass(), icon: child.getCapability('type').getCssClass(),
title: child.getModel().name, title: child.getModel().name,
type: child.getCapability('type').getName(), type: child.getCapability('type').getName(),
persisted: new Date( persisted: this.utc.format(child.getModel().persisted),
child.getModel().persisted modified: this.utc.format(child.getModel().modified),
).toUTCString(),
modified: new Date(
child.getModel().modified
).toUTCString(),
asDomainObject: child, asDomainObject: child,
location: child.getCapability('location'), location: child.getCapability('location'),
action: child.getCapability('action') action: child.getCapability('action')
}; };
}); }, this);
}; };
return ListViewController; return ListViewController;

View File

@ -31,7 +31,9 @@ define(
controller, controller,
childModel, childModel,
typeCapability, typeCapability,
mutationCapability; mutationCapability,
formatService;
beforeEach(function () { beforeEach(function () {
unlistenFunc = jasmine.createSpy("unlisten"); unlistenFunc = jasmine.createSpy("unlisten");
@ -41,6 +43,18 @@ define(
); );
mutationCapability.listen.andReturn(unlistenFunc); mutationCapability.listen.andReturn(unlistenFunc);
formatService = jasmine.createSpyObj(
"formatService",
["getFormat"]
);
formatService.getFormat.andReturn(jasmine.createSpyObj(
'utc',
["format"]
));
formatService.getFormat().format.andCallFake(function (v) {
return "formatted " + v;
});
typeCapability = jasmine.createSpyObj( typeCapability = jasmine.createSpyObj(
"typeCapability", "typeCapability",
["getCssClass", "getName"] ["getCssClass", "getName"]
@ -94,20 +108,27 @@ define(
); );
scope.domainObject = domainObject; scope.domainObject = domainObject;
controller = new ListViewController(scope); controller = new ListViewController(scope, formatService);
waitsFor(function () { waitsFor(function () {
return scope.children; return scope.children;
}); });
}); });
it("uses the UTC time format", function () {
expect(formatService.getFormat).toHaveBeenCalledWith('utc');
});
it("updates the view", function () { it("updates the view", function () {
expect(scope.children[0]).toEqual( expect(scope.children[0]).toEqual(
{ {
icon: "icon-folder", icon: "icon-folder",
title: "Battery Charge Status", title: "Battery Charge Status",
type: "Folder", type: "Folder",
persisted: "Wed, 07 Jun 2017 20:34:57 GMT", persisted: formatService.getFormat('utc')
modified: "Wed, 07 Jun 2017 20:34:57 GMT", .format(childModel.persisted),
modified: formatService.getFormat('utc')
.format(childModel.modified),
asDomainObject: childObject, asDomainObject: childObject,
location: '' location: ''
} }