mirror of
https://github.com/nasa/openmct.git
synced 2025-03-21 11:35:59 +00:00
* allow re-ordering of default indicators * emit setPriority event set keys for indicators * add warning for duplicate key unit tests * remove debugging statement * improve add indicator test
This commit is contained in:
parent
4b6f59fdd3
commit
f7f06931fc
@ -37,8 +37,8 @@ class IndicatorAPI extends EventEmitter {
|
||||
return sortedIndicators;
|
||||
}
|
||||
|
||||
simpleIndicator() {
|
||||
return new SimpleIndicator(this.openmct);
|
||||
simpleIndicator(key) {
|
||||
return new SimpleIndicator(this.openmct, key);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -63,6 +63,13 @@ class IndicatorAPI extends EventEmitter {
|
||||
*
|
||||
*/
|
||||
add(indicator) {
|
||||
const keyExists = indicator.key !== undefined
|
||||
&& this.indicatorObjects.some(installedIndicator => indicator.key === installedIndicator.key);
|
||||
|
||||
if (keyExists) {
|
||||
console.warn(`An Indicator with key { ${indicator.key} } has already been installed.`);
|
||||
}
|
||||
|
||||
if (!indicator.priority) {
|
||||
indicator.priority = this.openmct.priority.DEFAULT;
|
||||
}
|
||||
@ -72,6 +79,22 @@ class IndicatorAPI extends EventEmitter {
|
||||
this.emit('addIndicator', indicator);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} key the key of the indicator
|
||||
* @param {number} priority the priority to set
|
||||
*/
|
||||
setPriority(key, priority) {
|
||||
const indicatorToPrioritize = this.indicatorObjects
|
||||
.find(indicator => indicator.key === key);
|
||||
|
||||
if (indicatorToPrioritize !== undefined) {
|
||||
indicatorToPrioritize.priority = priority;
|
||||
|
||||
this.emit('setPriority', indicatorToPrioritize);
|
||||
} else {
|
||||
console.warn(`Could not find an installed indicator: ${key}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default IndicatorAPI;
|
||||
|
@ -22,6 +22,8 @@
|
||||
import { createOpenMct, resetApplicationState } from '../../utils/testing';
|
||||
import SimpleIndicator from './SimpleIndicator';
|
||||
|
||||
const NOTIFICATIONS_INDICATOR_KEY = 'notifications-indicator';
|
||||
|
||||
describe("The Indicator API", () => {
|
||||
let openmct;
|
||||
|
||||
@ -39,6 +41,7 @@ describe("The Indicator API", () => {
|
||||
const textNode = document.createTextNode(label);
|
||||
element.appendChild(textNode);
|
||||
const testIndicator = {
|
||||
key: className,
|
||||
element,
|
||||
priority
|
||||
};
|
||||
@ -46,12 +49,22 @@ describe("The Indicator API", () => {
|
||||
return testIndicator;
|
||||
}
|
||||
|
||||
it("installs the notifications indicator by default", () => {
|
||||
let indicators = openmct.indicators.getIndicatorObjectsByPriority();
|
||||
const notificationIndicator = indicators.find(indicator => indicator.key === NOTIFICATIONS_INDICATOR_KEY);
|
||||
|
||||
expect(notificationIndicator.key).toEqual(NOTIFICATIONS_INDICATOR_KEY);
|
||||
});
|
||||
|
||||
it("can register an indicator", () => {
|
||||
let indicators = openmct.indicators.getIndicatorObjectsByPriority();
|
||||
const defaultIndicatorsLength = indicators.length;
|
||||
const testIndicator = generateIndicator('test-indicator', 'This is a test indicator', 2);
|
||||
|
||||
openmct.indicators.add(testIndicator);
|
||||
expect(openmct.indicators.indicatorObjects).toBeDefined();
|
||||
// notifier indicator is installed by default
|
||||
expect(openmct.indicators.indicatorObjects.length).toBe(2);
|
||||
indicators = openmct.indicators.getIndicatorObjectsByPriority();
|
||||
|
||||
expect(indicators.length).toBe(defaultIndicatorsLength + 1);
|
||||
});
|
||||
|
||||
it("can order indicators based on priority", () => {
|
||||
@ -67,10 +80,32 @@ describe("The Indicator API", () => {
|
||||
const testIndicator4 = generateIndicator('test-indicator-4', 'This is yet another test indicator', openmct.priority.HIGH);
|
||||
openmct.indicators.add(testIndicator4);
|
||||
|
||||
expect(openmct.indicators.indicatorObjects.length).toBe(5);
|
||||
const indicatorObjectsByPriority = openmct.indicators.getIndicatorObjectsByPriority();
|
||||
expect(indicatorObjectsByPriority.length).toBe(5);
|
||||
expect(indicatorObjectsByPriority[2].priority).toBe(openmct.priority.DEFAULT);
|
||||
let indicators = openmct.indicators.getIndicatorObjectsByPriority();
|
||||
|
||||
expect(indicators.length).toBe(5);
|
||||
expect(indicators[2].priority).toBe(openmct.priority.DEFAULT);
|
||||
});
|
||||
|
||||
it("can change priority of an installed indicator", () => {
|
||||
const testIndicator1 = generateIndicator('test-indicator-1', 'This is a test indicator', openmct.priority.LOW);
|
||||
openmct.indicators.add(testIndicator1);
|
||||
|
||||
const testIndicator2 = generateIndicator('test-indicator-2', 'This is another test indicator', openmct.priority.DEFAULT);
|
||||
openmct.indicators.add(testIndicator2);
|
||||
|
||||
const testIndicator3 = generateIndicator('test-indicator-3', 'This is yet another test indicator', openmct.priority.LOW);
|
||||
openmct.indicators.add(testIndicator3);
|
||||
|
||||
const testIndicator4 = generateIndicator('test-indicator-4', 'This is yet another test indicator', openmct.priority.HIGH);
|
||||
openmct.indicators.add(testIndicator4);
|
||||
|
||||
let indicators = openmct.indicators.getIndicatorObjectsByPriority();
|
||||
|
||||
expect(indicators[0].key).toEqual('test-indicator-4');
|
||||
openmct.indicators.setPriority('test-indicator-2', openmct.priority.HIGH + 1);
|
||||
indicators = openmct.indicators.getIndicatorObjectsByPriority();
|
||||
|
||||
expect(indicators[0].key).toEqual('test-indicator-2');
|
||||
});
|
||||
|
||||
it("the simple indicator can be added", () => {
|
||||
|
@ -27,10 +27,11 @@ import { convertTemplateToHTML } from '@/utils/template/templateHelpers';
|
||||
const DEFAULT_ICON_CLASS = 'icon-info';
|
||||
|
||||
class SimpleIndicator extends EventEmitter {
|
||||
constructor(openmct) {
|
||||
constructor(openmct, key) {
|
||||
super();
|
||||
|
||||
this.openmct = openmct;
|
||||
this.key = key;
|
||||
this.element = convertTemplateToHTML(indicatorTemplate)[0];
|
||||
this.priority = openmct.priority.DEFAULT;
|
||||
|
||||
|
@ -23,7 +23,7 @@ define(['./URLIndicator'],
|
||||
function URLIndicatorPlugin(URLIndicator) {
|
||||
return function (opts) {
|
||||
return function install(openmct) {
|
||||
const simpleIndicator = openmct.indicators.simpleIndicator();
|
||||
const simpleIndicator = openmct.indicators.simpleIndicator('url-indicator');
|
||||
const urlIndicator = new URLIndicator(opts, simpleIndicator);
|
||||
|
||||
openmct.indicators.add(simpleIndicator);
|
||||
|
@ -49,7 +49,7 @@ export default class OperatorStatusIndicator extends AbstractStatusIndicator {
|
||||
}
|
||||
|
||||
createIndicator() {
|
||||
const operatorIndicator = this.openmct.indicators.simpleIndicator();
|
||||
const operatorIndicator = this.openmct.indicators.simpleIndicator('operator-indicator');
|
||||
|
||||
operatorIndicator.text("My Operator Status");
|
||||
operatorIndicator.description("Set my operator status");
|
||||
|
@ -49,7 +49,7 @@ export default class PollQuestionIndicator extends AbstractStatusIndicator {
|
||||
}
|
||||
|
||||
createIndicator() {
|
||||
const pollQuestionIndicator = this.openmct.indicators.simpleIndicator();
|
||||
const pollQuestionIndicator = this.openmct.indicators.simpleIndicator('poll-question-indicator');
|
||||
|
||||
pollQuestionIndicator.text("Poll Question");
|
||||
pollQuestionIndicator.description("Set the current poll question");
|
||||
|
@ -23,7 +23,7 @@ export default function PerformanceIndicator() {
|
||||
return function install(openmct) {
|
||||
let frames = 0;
|
||||
let lastCalculated = performance.now();
|
||||
const indicator = openmct.indicators.simpleIndicator();
|
||||
const indicator = openmct.indicators.simpleIndicator('performance-indicator');
|
||||
|
||||
indicator.text('~ fps');
|
||||
indicator.statusClass('s-status-info');
|
||||
|
@ -30,7 +30,7 @@ const COUCH_SEARCH_ONLY_NAMESPACE = `COUCH_SEARCH_${Date.now()}`;
|
||||
|
||||
export default function CouchPlugin(options) {
|
||||
return function install(openmct) {
|
||||
const simpleIndicator = openmct.indicators.simpleIndicator();
|
||||
const simpleIndicator = openmct.indicators.simpleIndicator('couch-indicator');
|
||||
openmct.indicators.add(simpleIndicator);
|
||||
const couchStatusIndicator = new CouchStatusIndicator(simpleIndicator);
|
||||
install.couchProvider = new CouchObjectProvider(openmct, options, NAMESPACE, couchStatusIndicator);
|
||||
|
Loading…
x
Reference in New Issue
Block a user