1
1
var PORT = 60000 ;
2
2
var HOST = "http://dataweb.isis.rl.ac.uk"
3
+ var DEFAULT_PV_VALUE = "UNKNOWN" ;
3
4
4
5
var instrument = getURLParameter ( "Instrument" ) ;
5
6
var nodeInstTitle = document . createElement ( "H2" ) ;
6
7
var nodeConfigTitle = document . createElement ( "H2" ) ;
8
+ var nodeErrorStatus = document . createElement ( "H3" ) ;
9
+ nodeErrorStatus . style . color = "RED" ;
7
10
var instrumentState ;
8
11
var showHidden ;
9
12
var timeout = 4000 ;
@@ -143,6 +146,40 @@ function refresh() {
143
146
} ) ;
144
147
}
145
148
149
+ /**
150
+ * Build the error status list from the given error statuses.
151
+ */
152
+ function buildErrorStatusList ( errorStatuses ) {
153
+ nodeErrorStatusList = document . createElement ( "UL" ) ;
154
+ for ( var statusIndex in errorStatuses ) {
155
+ var status = errorStatuses [ statusIndex ] ;
156
+ buildErrorStatusListElement ( status , nodeErrorStatusList )
157
+ }
158
+ nodeErrorStatus . appendChild ( nodeErrorStatusList ) ;
159
+ }
160
+
161
+ /**
162
+ * Build an error status list element and add it to the node given.
163
+ */
164
+ function buildErrorStatusListElement ( errorStatus , nodeErrorStatusList ) {
165
+ nodeErrorStatusListELement = document . createElement ( "LI" ) ;
166
+ nodeErrorStatusListELement . appendChild ( document . createTextNode ( errorStatus ) ) ;
167
+ nodeErrorStatusList . appendChild ( nodeErrorStatusListELement ) ;
168
+ }
169
+
170
+ /**
171
+ * Parses error statuses and displays them.
172
+ */
173
+ function setErrorStatus ( instrumentState ) {
174
+ clear ( nodeErrorStatus ) ;
175
+ if ( instrumentState . error_statuses . length > 0 ) {
176
+ var textNode = "Problems were encountered when retrieving data from the instrument:" ;
177
+ nodeErrorStatus . appendChild ( document . createTextNode ( textNode ) ) ;
178
+ buildErrorStatusList ( instrumentState . error_statuses ) ;
179
+ document . getElementById ( "error_status" ) . appendChild ( nodeErrorStatus ) ;
180
+ }
181
+ }
182
+
146
183
/**
147
184
* Parses fetched instrument data into a human-readable html page.
148
185
*/
@@ -170,21 +207,32 @@ function parseObject(obj) {
170
207
document . getElementById ( "config_name" ) . appendChild ( nodeConfigTitle ) ;
171
208
172
209
setVisibilityMode ( 'block' ) ;
210
+
211
+ // Write error status
212
+ setErrorStatus ( instrumentState ) ;
173
213
}
174
214
175
215
176
216
function clearBox ( elementID ) {
177
217
document . getElementById ( elementID ) . innerHTML = "" ;
178
218
}
179
219
220
+ function get_inst_pv_value ( inst_details , pv ) {
221
+ try {
222
+ return inst_details [ "inst_pvs" ] [ pv ] [ "value" ] || DEFAULT_PV_VALUE ;
223
+ } catch ( err ) {
224
+ return DEFAULT_PV_VALUE ;
225
+ }
226
+ }
227
+
180
228
/**
181
229
* creates a Title at the top looking similar to the IBEX GUI
182
230
*/
183
231
function createTitle ( inst_details ) {
184
232
clearBox ( "top_bar" ) ;
185
233
document . body . style . padding = '20px'
186
234
document . getElementById ( "top_bar" ) . innerHTML = "<div id = \"inst_name\"></div><table style=\"width:100%\"><tr id = table_part><th id = \"next_part\" style = \"padding: 10px; width:33%; background-color:lightgrey ; border: black 2px solid\";></th></tr></table>" ;
187
- runStatus = inst_details [ "inst_pvs" ] [ " RUNSTATE"] [ "value" ] ;
235
+ runStatus = get_inst_pv_value ( inst_details , " RUNSTATE") ;
188
236
189
237
colour = getColourFromRunState ( runStatus ) ;
190
238
@@ -197,33 +245,33 @@ function createTitle(inst_details){
197
245
blockListClass . value = "text-center" ;
198
246
title . setAttributeNode ( blockListClass ) ;
199
247
document . getElementById ( "inst_name" ) . appendChild ( title ) ;
200
- addItemToTable ( "Title" , inst_details [ "inst_pvs" ] [ " TITLE"] [ "value" ] ) ;
201
- addItemToTable ( "Users" , inst_details [ "inst_pvs" ] [ " _USERNAME"] [ "value" ] ) ;
248
+ addItemToTable ( "Title" , get_inst_pv_value ( inst_details , " TITLE") ) ;
249
+ addItemToTable ( "Users" , get_inst_pv_value ( inst_details , " _USERNAME") ) ;
202
250
203
251
newPartOfTable ( ) ;
204
252
try {
205
253
// after upgrade script
206
- addItemToTable ( inst_details [ "inst_pvs" ] [ " 1:1:LABEL"] [ "value" ] , inst_details [ "inst_pvs" ] [ " 1:1:VALUE"] [ "value" ] ) ;
207
- addItemToTable ( inst_details [ "inst_pvs" ] [ " 2:1:LABEL"] [ "value" ] , inst_details [ "inst_pvs" ] [ " 2:1:VALUE"] [ "value" ] ) ;
208
- addItemToTable ( inst_details [ "inst_pvs" ] [ " 3:1:LABEL"] [ "value" ] , inst_details [ "inst_pvs" ] [ " 3:1:VALUE"] [ "value" ] ) ;
254
+ addItemToTable ( get_inst_pv_value ( inst_details , " 1:1:LABEL") , get_inst_pv_value ( inst_details , " 1:1:VALUE") ) ;
255
+ addItemToTable ( get_inst_pv_value ( inst_details , " 2:1:LABEL") , get_inst_pv_value ( inst_details , " 2:1:VALUE") ) ;
256
+ addItemToTable ( get_inst_pv_value ( inst_details , " 3:1:LABEL") , get_inst_pv_value ( inst_details , " 3:1:VALUE") ) ;
209
257
210
258
newPartOfTable ( ) ;
211
259
212
- addItemToTable ( inst_details [ "inst_pvs" ] [ " 2:2:LABEL"] [ "value" ] , inst_details [ "inst_pvs" ] [ " 2:2:VALUE"] [ "value" ] ) ;
213
- addItemToTable ( inst_details [ "inst_pvs" ] [ " 1:2:LABEL"] [ "value" ] , inst_details [ "inst_pvs" ] [ " 1:2:VALUE"] [ "value" ] ) ;
214
- addItemToTable ( inst_details [ "inst_pvs" ] [ " 3:2:LABEL"] [ "value" ] , inst_details [ "inst_pvs" ] [ " 3:2:VALUE"] [ "value" ] ) ;
260
+ addItemToTable ( get_inst_pv_value ( inst_details , " 2:2:LABEL") , get_inst_pv_value ( inst_details , " 2:2:VALUE") ) ;
261
+ addItemToTable ( get_inst_pv_value ( inst_details , " 1:2:LABEL") , get_inst_pv_value ( inst_details , " 1:2:VALUE") ) ;
262
+ addItemToTable ( get_inst_pv_value ( inst_details , " 3:2:LABEL") , get_inst_pv_value ( inst_details , " 3:2:VALUE") ) ;
215
263
} catch ( err ) {
216
264
// before upgrade script
217
265
218
- addItemToTable ( "Good / Raw Frames" , inst_details [ "inst_pvs" ] [ " GOODFRAMES"] [ "value" ] + "/" + inst_details [ "inst_pvs" ] [ " RAWFRAMES"] [ "value" ] ) ;
219
- addItemToTable ( "Current / Total" , inst_details [ "inst_pvs" ] [ " BEAMCURRENT"] [ "value" ] + "/" + inst_details [ "inst_pvs" ] [ " TOTALUAMPS"] [ "value" ] ) ;
220
- addItemToTable ( "Monitor Counts" , inst_details [ "inst_pvs" ] [ " MONITORCOUNTS"] [ "value" ] ) ;
266
+ addItemToTable ( "Good / Raw Frames" , get_inst_pv_value ( inst_details , " GOODFRAMES") + "/" + get_inst_pv_value ( inst_details , " RAWFRAMES") ) ;
267
+ addItemToTable ( "Current / Total" , get_inst_pv_value ( inst_details , " BEAMCURRENT") + "/" + get_inst_pv_value ( inst_details , " TOTALUAMPS") ) ;
268
+ addItemToTable ( "Monitor Counts" , get_inst_pv_value ( inst_details , " MONITORCOUNTS") ) ;
221
269
222
270
newPartOfTable ( ) ;
223
271
224
- addItemToTable ( "Start Time" , inst_details [ "inst_pvs" ] [ " STARTTIME"] [ "value" ] ) ;
225
- addItemToTable ( "Run Time" , inst_details [ "inst_pvs" ] [ " RUNDURATION_PD"] [ "value" ] ) ;
226
- addItemToTable ( "Period" , inst_details [ "inst_pvs" ] [ " PERIOD"] [ "value" ] + "/" + inst_details [ "inst_pvs" ] [ " NUMPERIODS"] [ "value" ] ) ;
272
+ addItemToTable ( "Start Time" , get_inst_pv_value ( inst_details , " STARTTIME") ) ;
273
+ addItemToTable ( "Run Time" , get_inst_pv_value ( inst_details , " RUNDURATION_PD") ) ;
274
+ addItemToTable ( "Period" , get_inst_pv_value ( inst_details , " PERIOD") + "/" + get_inst_pv_value ( inst_details , " NUMPERIODS") ) ;
227
275
228
276
}
229
277
0 commit comments