forked from nasa/openmct-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dictionary-plugin.js
71 lines (65 loc) · 2.16 KB
/
dictionary-plugin.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
function getDictionary() {
return http.get('/dictionary.json')
.then(function (result) {
return result.data;
});
}
var objectProvider = {
get: function (identifier) {
return getDictionary().then(function (dictionary) {
if (identifier.key === 'spacecraft') {
return {
identifier: identifier,
name: dictionary.name,
type: 'folder',
location: 'ROOT'
};
} else {
var measurement = dictionary.measurements.filter(function (m) {
return m.key === identifier.key;
})[0];
return {
identifier: identifier,
name: measurement.name,
type: 'example.telemetry',
telemetry: {
values: measurement.values
},
location: 'example.taxonomy:spacecraft'
};
}
});
}
};
var compositionProvider = {
appliesTo: function (domainObject) {
return domainObject.identifier.namespace === 'example.taxonomy' &&
domainObject.type === 'folder';
},
load: function (domainObject) {
return getDictionary()
.then(function (dictionary) {
return dictionary.measurements.map(function (m) {
return {
namespace: 'example.taxonomy',
key: m.key
};
});
});
}
};
var DictionaryPlugin = function (openmct) {
return function install(openmct) {
openmct.objects.addRoot({
namespace: 'example.taxonomy',
key: 'spacecraft'
});
openmct.objects.addProvider('example.taxonomy', objectProvider);
openmct.composition.addProvider(compositionProvider);
openmct.types.addType('example.telemetry', {
name: 'Example Telemetry Point',
description: 'Example telemetry point from our happy tutorial.',
cssClass: 'icon-telemetry'
});
};
};