Merge pull request #754 from nasa/tree-status-styling-749

[Tree] Add status classes during editing
This commit is contained in:
Andrew Henry 2016-03-16 15:26:40 -07:00
commit 4a1ca25e17
2 changed files with 50 additions and 2 deletions

View File

@ -32,6 +32,8 @@ define([
function TreeNodeView(gestureService, subtreeFactory, selectFn) {
this.li = $('<li>');
this.statusClasses = [];
this.toggleView = new ToggleView(false);
this.toggleView.observe(function (state) {
if (state) {
@ -61,6 +63,20 @@ define([
this.model(undefined);
}
TreeNodeView.prototype.updateStatusClasses = function (statuses) {
this.statusClasses.forEach(function (statusClass) {
this.li.removeClass(statusClass);
}.bind(this));
this.statusClasses = statuses.map(function (status) {
return 's-status-' + status;
});
this.statusClasses.forEach(function (statusClass) {
this.li.addClass(statusClass);
}.bind(this));
};
TreeNodeView.prototype.model = function (domainObject) {
if (this.unlisten) {
this.unlisten();
@ -74,6 +90,14 @@ define([
$(this.toggleView.elements()).removeClass('has-children');
}
if (domainObject && domainObject.hasCapability('status')) {
this.unlisten = domainObject.getCapability('status')
.listen(this.updateStatusClasses.bind(this));
this.updateStatusClasses(
domainObject.getCapability('status').list()
);
}
this.labelView.model(domainObject);
if (this.subtreeView) {
this.subtreeView.model(domainObject);

View File

@ -107,12 +107,18 @@ define([
mockLocation =
jasmine.createSpyObj('location', [ 'isLink' ]),
mockMutation =
jasmine.createSpyObj('mutation', [ 'listen' ]);
jasmine.createSpyObj('mutation', [ 'listen' ]),
mockStatus =
jasmine.createSpyObj('status', [ 'listen', 'list' ]);
mockStatus.list.andReturn([]);
return {
context: mockContext,
type: mockType,
mutation: mockMutation,
location: mockLocation
location: mockLocation,
status: mockStatus
};
}
@ -247,6 +253,24 @@ define([
.toEqual(1);
});
});
describe("when status changes", function () {
var testStatuses;
beforeEach(function () {
var mockStatus = mockComposition[1].getCapability('status');
testStatuses = [ 'foo' ];
mockStatus.list.andReturn(testStatuses);
mockStatus.listen.mostRecentCall.args[0](testStatuses);
});
it("reflects the status change in the tree", function () {
expect($(treeView.elements()).find('.s-status-foo').length)
.toEqual(1);
});
});
});
describe("observe", function () {