From b5d1118a3ff8f7d1f36db846bf9270cd21571ba7 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Thu, 19 Nov 2015 15:12:03 -0800 Subject: [PATCH 1/2] [Status] Document status capability ...in the developer guide. Includes a table for listing status names and classes, per code review feedback, nasa/openmctweb#319. --- docs/src/guide/index.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/docs/src/guide/index.md b/docs/src/guide/index.md index a0159ec672..6271337792 100644 --- a/docs/src/guide/index.md +++ b/docs/src/guide/index.md @@ -2056,6 +2056,31 @@ objects which has a `relationships` property in their model, whose value is an object containing key-value pairs, where keys are strings identifying relationship types, and values are arrays of domain object identifiers. +## Status Capability + +The `status` capability provides a way to flag domain objects as possessing +certain states, represented as simple strings. These states, in turn, are +reflected on `mct-representation` elements as classes (prefixed with +`s-status-`.) The `status` capability has the following interface: + +* `get()`: Returns an array of all status strings that currently apply + to this object. +* `set(status, state)`: Adds or removes a status flag to this domain object. + The `status` argument is the string to set; `state` is a boolean + indicating whether this status should be included (true) or removed (false). +* `listen(callback)`: Listen for changes in status. The provided `callback` + will be invoked with an array of all current status strings whenever status + changes. + +Plug-ins may add and/or recognize arbitrary status flags. Flags defined +and/or supported by the platform are: + + Status | CSS Class | Meaning +-----------|--------------------|----------------------------------- +`editing` | `s-status-editing` | Domain object is being edited. +`pending` | `s-status-pending` | Domain object is partially loaded. + + ## Telemetry Capability The telemetry capability provides a means for accessing telemetry data From 400b992ec36b4572175b160549ea31d6771f96ac Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Fri, 20 Nov 2015 09:46:08 -0800 Subject: [PATCH 2/2] [Status] Revise API Change method names, add a getter to status capability; per code review feedback, nasa/openmctweb#319. --- platform/status/src/StatusCapability.js | 15 ++++++++++++--- platform/status/src/StatusRepresenter.js | 2 +- platform/status/src/StatusService.js | 2 +- platform/status/test/StatusCapabilitySpec.js | 11 ++++++++--- platform/status/test/StatusRepresenterSpec.js | 4 ++-- platform/status/test/StatusServiceSpec.js | 6 +++--- 6 files changed, 27 insertions(+), 13 deletions(-) diff --git a/platform/status/src/StatusCapability.js b/platform/status/src/StatusCapability.js index 2751c198a9..6b0221d188 100644 --- a/platform/status/src/StatusCapability.js +++ b/platform/status/src/StatusCapability.js @@ -49,11 +49,20 @@ define( } /** - * Get all status flags currently set for this domain object. + * List all status flags currently set for this domain object. * @returns {string[]} all current status flags. */ - StatusCapability.prototype.get = function () { - return this.statusService.getStatus(this.domainObject.getId()); + StatusCapability.prototype.list = function () { + return this.statusService.listStatuses(this.domainObject.getId()); + }; + + /** + * Check if a status flag is currently set for this domain object. + * @param {string} status the status to get + * @returns {boolean} true if the flag is present, otherwise false + */ + StatusCapability.prototype.get = function (status) { + return this.list().indexOf(status) !== -1; }; /** diff --git a/platform/status/src/StatusRepresenter.js b/platform/status/src/StatusRepresenter.js index 0808688c02..550fec3e6d 100644 --- a/platform/status/src/StatusRepresenter.js +++ b/platform/status/src/StatusRepresenter.js @@ -77,7 +77,7 @@ define( self.lastClasses = newClasses; } - updateStatus(statusCapability.get()); + updateStatus(statusCapability.list()); this.unlisten = statusCapability.listen(updateStatus); }; diff --git a/platform/status/src/StatusService.js b/platform/status/src/StatusService.js index 6fff6f49d8..d75e935429 100644 --- a/platform/status/src/StatusService.js +++ b/platform/status/src/StatusService.js @@ -51,7 +51,7 @@ define( * @returns {string[]} an array containing all status flags currently * applicable to the object with this identifier */ - StatusService.prototype.getStatus = function (id) { + StatusService.prototype.listStatuses = function (id) { return this.statusTable[id] || []; }; diff --git a/platform/status/test/StatusCapabilitySpec.js b/platform/status/test/StatusCapabilitySpec.js index 481abf6a53..1bd3326c4e 100644 --- a/platform/status/test/StatusCapabilitySpec.js +++ b/platform/status/test/StatusCapabilitySpec.js @@ -40,7 +40,7 @@ define( mockStatusService = jasmine.createSpyObj( 'statusService', - [ 'listen', 'setStatus', 'getStatus' ] + [ 'listen', 'setStatus', 'listStatuses' ] ); mockDomainObject = jasmine.createSpyObj( 'domainObject', @@ -49,7 +49,7 @@ define( mockUnlisten = jasmine.createSpy('unlisten'); mockStatusService.listen.andReturn(mockUnlisten); - mockStatusService.getStatus.andReturn(testStatusFlags); + mockStatusService.listStatuses.andReturn(testStatusFlags); mockDomainObject.getId.andReturn(testId); capability = new StatusCapability( @@ -69,7 +69,7 @@ define( }); it("gets status from the statusService", function () { - expect(capability.get()).toBe(testStatusFlags); + expect(capability.list()).toBe(testStatusFlags); }); it("listens to changes from the statusService", function () { @@ -79,6 +79,11 @@ define( expect(mockStatusService.listen) .toHaveBeenCalledWith(testId, mockCallback); }); + + it("allows statuses to be checked individually", function () { + expect(capability.get('some-unset-status')).toBe(false); + expect(capability.get(testStatusFlags[0])).toBe(true); + }); }); } ); diff --git a/platform/status/test/StatusRepresenterSpec.js b/platform/status/test/StatusRepresenterSpec.js index e9191587a7..1d305ea983 100644 --- a/platform/status/test/StatusRepresenterSpec.js +++ b/platform/status/test/StatusRepresenterSpec.js @@ -66,7 +66,7 @@ define( ); mockStatusCapability = jasmine.createSpyObj( 'status', - [ 'get', 'set', 'listen' ] + [ 'list', 'get', 'set', 'listen' ] ); mockUnlisten = jasmine.createSpy(); @@ -79,7 +79,7 @@ define( delete elementClasses[c]; }); - mockStatusCapability.get.andReturn(testStatusFlags); + mockStatusCapability.list.andReturn(testStatusFlags); mockStatusCapability.listen.andReturn(mockUnlisten); mockDomainObject.getCapability.andCallFake(function (c) { diff --git a/platform/status/test/StatusServiceSpec.js b/platform/status/test/StatusServiceSpec.js index 1f85cd70a1..c064af6bc8 100644 --- a/platform/status/test/StatusServiceSpec.js +++ b/platform/status/test/StatusServiceSpec.js @@ -54,14 +54,14 @@ define( }); it("initially contains no flags for an object", function () { - expect(statusService.getStatus(testId)).toEqual([]); + expect(statusService.listStatuses(testId)).toEqual([]); }); it("stores and clears status flags", function () { statusService.setStatus(testId, testStatus, true); - expect(statusService.getStatus(testId)).toEqual([testStatus]); + expect(statusService.listStatuses(testId)).toEqual([testStatus]); statusService.setStatus(testId, testStatus, false); - expect(statusService.getStatus(testId)).toEqual([]); + expect(statusService.listStatuses(testId)).toEqual([]); }); it("uses topic to listen for changes", function () {