mirror of
https://github.com/nasa/openmct.git
synced 2025-04-19 00:27:03 +00:00
Merge branch 'open-status-tracking' into open278
This commit is contained in:
commit
4f0f9e4104
@ -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
|
||||
|
@ -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;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -77,7 +77,7 @@ define(
|
||||
self.lastClasses = newClasses;
|
||||
}
|
||||
|
||||
updateStatus(statusCapability.get());
|
||||
updateStatus(statusCapability.list());
|
||||
this.unlisten = statusCapability.listen(updateStatus);
|
||||
};
|
||||
|
||||
|
@ -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] || [];
|
||||
};
|
||||
|
||||
|
@ -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);
|
||||
});
|
||||
});
|
||||
}
|
||||
);
|
||||
|
@ -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) {
|
||||
|
@ -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 () {
|
||||
|
Loading…
x
Reference in New Issue
Block a user