-
Notifications
You must be signed in to change notification settings - Fork 0
/
misc.js
42 lines (39 loc) · 1.05 KB
/
misc.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
import appConfig from "./config.js"
const topicSeparator = "/"
// acmeResources/veh_trak/gps/v2/{route}/{vehType}/{vehID}/{lat}/{lng}/{dir}/{status}
const topicLevels = {
// start with ZERO
2: "app",
3: "ver",
4: "route",
5: "vehType",
6: "vehID",
7: "lat",
8: "lng",
9: "dir",
10: "status",
}
// input: topic string
// output: topic in multiple <span> element with different css class
function colorTopic(topic) {
const levels = topic.split(topicSeparator);
const levelSpans = levels.map((field, idx) => {
if (idx in topicLevels)
return `<span class="topic-${topicLevels[idx]}">${field}</span>`
else
return field
})
return levelSpans.join(topicSeparator)
}
function buildSubscriptionTopic(filter) {
const topicList = []
for (let i = 4; i <= 10; i++) {
if (topicLevels[i] in filter) {
topicList.push(filter[topicLevels[i]])
} else {
topicList.push(appConfig.singleLevelWildCard)
}
}
return appConfig.topicPrefix + topicList.join(topicSeparator)
}
export { colorTopic, buildSubscriptionTopic }