|
8 | 8 | var subParamKey = null; |
9 | 9 | var subMsgKey = null; |
10 | 10 |
|
| 11 | + var tableBodyVar = null; |
| 12 | + |
| 13 | + var parameterMap = null; |
| 14 | + |
11 | 15 | var subIntervalId = null; |
12 | 16 |
|
| 17 | + function createTable(divToAttach, thTextArray) { |
| 18 | + // Table and header |
| 19 | + var tableNode = document.createElement('table'); |
| 20 | + divToAttach.appendChild(tableNode); |
| 21 | + var theadNode = document.createElement('thead'); |
| 22 | + tableNode.appendChild(theadNode); |
| 23 | + var trNode = document.createElement('tr'); |
| 24 | + theadNode.appendChild(trNode); |
| 25 | + |
| 26 | + for(var colname of thTextArray) { |
| 27 | + var thNode = document.createElement('th'); |
| 28 | + thNode.textContent = colname; |
| 29 | + trNode.appendChild(thNode); |
| 30 | + } |
| 31 | + |
| 32 | + // Create tbody |
| 33 | + var tbodyNode = document.createElement('tbody'); |
| 34 | + tableNode.appendChild(tbodyNode); |
| 35 | + return tbodyNode; |
| 36 | + } |
| 37 | + |
| 38 | + function addRow(tbodyNode, obj, tdTextArrayKeys) { |
| 39 | + var addedTds = new Object(); |
| 40 | + var pTrNode = document.createElement('tr'); |
| 41 | + for(var tdkey of tdTextArrayKeys) { |
| 42 | + var tdNode = document.createElement('td'); |
| 43 | + tdNode.textContent = obj[tdkey]; |
| 44 | + pTrNode.appendChild(tdNode); |
| 45 | + addedTds[tdkey] = tdNode; |
| 46 | + } |
| 47 | + tbodyNode.appendChild(pTrNode); |
| 48 | + return addedTds; |
| 49 | + } |
| 50 | + |
13 | 51 | async function showParameters() { |
14 | 52 | var divToAttach = document.getElementById('div1'); |
15 | 53 | divToAttach.textContent = ''; |
| 54 | + |
| 55 | + var thTextArray = ['Path', 'External ID', 'Description', 'Unit']; |
| 56 | + var tdTextArrayKeys = ['path', 'externalId', 'description', 'unit']; |
| 57 | + |
16 | 58 | var params = await reatmetric.listParameters(); |
17 | 59 | if(params != null) { |
| 60 | + // Create table node |
| 61 | + var tbodyNode = createTable(divToAttach, thTextArray) |
18 | 62 | for(var i = 0; i < params.length; ++i) { |
19 | 63 | var param = params[i]; |
20 | | - var pNode = document.createElement('p'); |
21 | | - pNode.textContent = param.path + " (" + param.externalId + "): " + param.description + " - Unit: " + param.unit; |
22 | | - divToAttach.appendChild(pNode); |
| 64 | + addRow(tbodyNode, param, tdTextArrayKeys); |
23 | 65 | } |
24 | 66 | } |
25 | 67 | } |
26 | 68 |
|
27 | 69 | async function showEvents() { |
28 | 70 | var divToAttach = document.getElementById('div1'); |
29 | 71 | divToAttach.textContent = ''; |
| 72 | + |
| 73 | + var thTextArray = ['Path', 'External ID', 'Description', 'Severity']; |
| 74 | + var tdTextArrayKeys = ['path', 'externalId', 'description', 'severity']; |
| 75 | + |
30 | 76 | var events = await reatmetric.listEvents(); |
31 | 77 | if(events != null) { |
| 78 | + // Create table node |
| 79 | + var tbodyNode = createTable(divToAttach, thTextArray) |
32 | 80 | for(var i = 0; i < events.length; ++i) { |
33 | 81 | var event = events[i]; |
34 | | - var pNode = document.createElement('p'); |
35 | | - pNode.textContent = event.path + " (" + event.externalId + "): " + event.description + " - Severity: " + event.severity; |
36 | | - divToAttach.appendChild(pNode); |
| 82 | + addRow(tbodyNode, event, tdTextArrayKeys); |
37 | 83 | } |
38 | 84 | } |
39 | 85 | } |
|
48 | 94 | var divToAttach = document.getElementById('div1'); |
49 | 95 | divToAttach.textContent = ''; |
50 | 96 |
|
| 97 | + // Create table node |
| 98 | + var thTextArray = ['Severity', 'Gen. Time', 'Path', 'Route', 'Source']; |
| 99 | + tableBodyVar = createTable(divToAttach, thTextArray) |
| 100 | + |
51 | 101 | var filter = reatmetric.eventFilter('STATION', null, null, null, null, null, null); |
52 | 102 |
|
53 | 103 | subEvtKey = await reatmetric.registerToEvents(filter); |
|
64 | 114 | if(subEvtKey != null) { |
65 | 115 | currentEvents = await reatmetric.getEvents(subEvtKey) |
66 | 116 | } |
| 117 | + var tdTextArrayKeys = ['severity', 'gentime', 'path', 'route', 'source']; |
| 118 | + |
67 | 119 | if(currentEvents != null) { |
68 | 120 | console.log("Retrieved " + currentEvents.length + " events"); |
69 | | - var divToAttach = document.getElementById('div1'); |
70 | 121 | for(var i = 0; i < currentEvents.length; ++i) { |
71 | 122 | var event = currentEvents[i]; |
72 | | - var pNode = document.createElement('p'); |
73 | | - pNode.textContent = event.severity + " (" + event.gentime + "): " + event.path + " - Route: " + event.route + ", Source: " + event.source; |
74 | | - divToAttach.appendChild(pNode); |
| 123 | + addRow(tableBodyVar, event, tdTextArrayKeys); |
75 | 124 | } |
76 | 125 | } |
77 | 126 | } |
|
98 | 147 |
|
99 | 148 | var filter = reatmetric.parameterFilter('STATION', null, null, null, null, null); |
100 | 149 |
|
| 150 | + // Create table node |
| 151 | + var thTextArray = ['Path', 'Gen. Time', 'Raw Value', 'Eng. Value', 'Validity', 'Alarm State']; |
| 152 | + tableBodyVar = createTable(divToAttach, thTextArray) |
| 153 | + parameterMap = []; |
| 154 | + |
101 | 155 | subParamKey = await reatmetric.registerToStateParameters(filter); |
102 | 156 | console.log("Parameter subscription key: " + subParamKey); |
103 | 157 | if(subParamKey != null) { |
|
107 | 161 | } |
108 | 162 |
|
109 | 163 | async function paramRetrieve() { |
110 | | - console.log("Retrieving parameters on key " + subParamKey); |
111 | 164 | var currentParameters = null; |
112 | 165 | if(subParamKey != null) { |
113 | 166 | currentParameters = await reatmetric.getStateParameters(subParamKey) |
114 | 167 | } |
115 | 168 | if(currentParameters != null) { |
116 | | - console.log("Retrieved " + currentParameters.length + " parameters"); |
117 | | - var divToAttach = document.getElementById('div1'); |
| 169 | + var paramKeys = ['path', 'gentime', 'raw', 'eng', 'validity', 'alarm']; |
118 | 170 | for(var i = 0; i < currentParameters.length; ++i) { |
119 | 171 | var param = currentParameters[i]; |
120 | | - var pNode = document.createElement('p'); |
121 | | - pNode.textContent = param.alarm + " (" + param.gentime + "): " + param.path + " - Raw Value: " + param.raw + ", Eng. Value: " + param.eng; |
122 | | - divToAttach.appendChild(pNode); |
| 172 | + if(parameterMap[param['path']] != null) { |
| 173 | + for(var tdkey of paramKeys) { |
| 174 | + var theTdArray = parameterMap[param['path']]; |
| 175 | + theTdArray[tdkey].textContent = param[tdkey]; |
| 176 | + } |
| 177 | + } else { |
| 178 | + parameterMap[param['path']] = addRow(tableBodyVar, param, paramKeys); |
| 179 | + } |
123 | 180 | } |
124 | 181 | } |
125 | 182 | } |
|
132 | 189 | subIntervalId = null; |
133 | 190 | await reatmetric.deregisterFromStateParameters(subParamKey); |
134 | 191 | subParamKey = null; |
| 192 | + parameterMap = null; |
135 | 193 | } |
136 | 194 |
|
137 | 195 | async function subscribeToMessages() { |
|
144 | 202 | var divToAttach = document.getElementById('div1'); |
145 | 203 | divToAttach.textContent = ''; |
146 | 204 |
|
| 205 | + // Create table node |
| 206 | + var thTextArray = ['Severity', 'Gen. Time', 'Source', 'Message']; |
| 207 | + tableBodyVar = createTable(divToAttach, thTextArray) |
| 208 | + |
147 | 209 | var filter = reatmetric.messageFilter(null, null, null, null); |
148 | 210 |
|
149 | 211 | subMsgKey = await reatmetric.registerToMessages(filter); |
150 | | - console.log("Parameter subscription key: " + subMsgKey); |
| 212 | + console.log("Message subscription key: " + subMsgKey); |
151 | 213 | if(subMsgKey != null) { |
152 | 214 | subIntervalId = setInterval(msgRetrieve, 1000); |
153 | 215 | console.log("Parameter subscription interval: " + subIntervalId); |
154 | 216 | } |
155 | 217 | } |
156 | 218 |
|
157 | 219 | async function msgRetrieve() { |
158 | | - console.log("Retrieving parameters on key " + subParamKey); |
159 | 220 | var currentMessages = null; |
160 | 221 | if(subMsgKey != null) { |
161 | 222 | currentMessages = await reatmetric.getMessages(subMsgKey) |
162 | 223 | } |
163 | 224 | if(currentMessages != null) { |
164 | | - console.log("Retrieved " + currentMessages.length + " parameters"); |
165 | | - var divToAttach = document.getElementById('div1'); |
| 225 | + var tdTextArrayKeys = ['severity', 'gentime', 'source', 'message']; |
166 | 226 | for(var i = 0; i < currentMessages.length; ++i) { |
167 | 227 | var messg = currentMessages[i]; |
168 | | - var pNode = document.createElement('p'); |
169 | | - pNode.textContent = messg.severity + " (" + messg.gentime + "): " + messg.text + " - Source: " + messg.source; |
170 | | - divToAttach.appendChild(pNode); |
| 228 | + addRow(tableBodyVar, messg, tdTextArrayKeys); |
171 | 229 | } |
172 | 230 | } |
173 | 231 | } |
|
183 | 241 | } |
184 | 242 |
|
185 | 243 | </script> |
| 244 | + <style> |
| 245 | + .tableFixHead { |
| 246 | + overflow-y: auto; |
| 247 | + height: 85%; |
| 248 | + font-size: 9px; |
| 249 | + } |
| 250 | + .tableFixHead thead th { |
| 251 | + position: sticky; |
| 252 | + top: 0; |
| 253 | + font-size: 9px; |
| 254 | + } |
| 255 | + table { |
| 256 | + border-collapse: collapse; |
| 257 | + width: 100%; |
| 258 | + } |
| 259 | + th, |
| 260 | + td { |
| 261 | + padding: 8px 16px; |
| 262 | + border: 1px solid #ccc; |
| 263 | + font-size: 9px; |
| 264 | + } |
| 265 | + th { |
| 266 | + background: #eee; |
| 267 | + } |
| 268 | + </style> |
186 | 269 | </head> |
187 | 270 | <body> |
188 | 271 | <button type="button" onclick="showParameters()">Show Parameters</button> |
189 | 272 | <button type="button" onclick="showEvents()">Show Events</button> |
190 | 273 | <button type="button" onclick="subscribeToEvents()">Subscribe to events</button> |
191 | | - <button type="button" onclick="unsubscribeFromEvents()">Unsubscribe to events</button> |
| 274 | + <button type="button" onclick="unsubscribeFromEvents()">Unsubscribe from events</button> |
192 | 275 | <button type="button" onclick="subscribeToParameters()">Subscribe to parameters</button> |
193 | | - <button type="button" onclick="unsubscribeFromParameters()">Unsubscribe to events</button> |
| 276 | + <button type="button" onclick="unsubscribeFromParameters()">Unsubscribe from parameters</button> |
194 | 277 | <button type="button" onclick="subscribeToMessages()">Subscribe to messages</button> |
195 | | - <button type="button" onclick="unsubscribeFromMessages()">Unsubscribe to messages</button> |
| 278 | + <button type="button" onclick="unsubscribeFromMessages()">Unsubscribe from messages</button> |
196 | 279 | <hr/> |
197 | 280 | <br/> |
198 | | - <div id="div1"> |
| 281 | + <div id="div1" class="tableFixHead"> |
199 | 282 | </div> |
200 | 283 | <br/> |
201 | 284 | </body> |
|
0 commit comments