-
Notifications
You must be signed in to change notification settings - Fork 14
/
dictionary-plugin.js
75 lines (69 loc) · 2.25 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
72
73
74
75
function getDictionary(name) {
return http.get('/dictionary/' + name + '.json')
.then(function (result) {
return result.data;
});
}
var objectProvider = function (config) {
return {
get: function (identifier) {
return getDictionary(config.key).then(function (dictionary) {
if (identifier.key === config.key) {
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: config.type,
telemetry: {
values: measurement.values
},
location: config.namespace + ':' + config.key
};
}
});
}
}
};
var compositionProvider = function (config ) {
return {
appliesTo: function (domainObject) {
return domainObject.identifier.namespace === config.namespace &&
domainObject.type === 'folder';
},
load: function (domainObject) {
return getDictionary(config.key)
.then(function (dictionary) {
return dictionary.measurements.map(function (m) {
return {
namespace: config.namespace,
key: m.key
};
});
});
}
}
};
var DictionaryPlugin = function (dictionary) {
return function install(openmct) {
openmct.objects.addRoot({
namespace: dictionary.namespace,
key: dictionary.key
});
openmct.objects.addProvider(dictionary.namespace, objectProvider(dictionary));
openmct.composition.addProvider(compositionProvider(dictionary));
openmct.types.addType(dictionary.type, {
name: dictionary.name,
description: dictionary.description,
cssClass: 'icon-telemetry'
});
};
};