4 var _allContextNames = {};
5 var _allClassNames = {};
6 var _allHostNames = {};
7 var _arrayOnDisplayTable =
new Array();
9 var _updateAppsTimeout = 0;
11 var _displayingFilters =
false;
13 var _statusDivElement, _filtersDivElement, _toggleFiltersLinkElement;
39 var windowTooltip =
"To verify Status Monitoring is enabled, check the Gateway Supervisor parameter that " +
40 "controls it. To check app status, set this field to YES in your Context Group Configuration Tree: \n\n" +
41 "<b>XDAQApplicationTable --> \nGatewaySupervisor (record in XDAQApplicationTable) --> \nLinkToSuperivorTable --> \nEnableApplicationStatusMonitoring</b>" +
43 "Remember, to restart ots after a Context group configuration change.";
51 Debug.log(
"App status init");
54 DesktopContent.setWindowTooltip(windowTooltip);
57 _statusDivElement = document.getElementById(
"appStatusDiv");
58 _filtersDivElement = document.getElementById(
"filtersDiv");
59 _toggleFiltersLinkElement = document.getElementById(
"toggleFiltersLink");
63 window.onresize = paint;
73 then(
function(result){
87 var w = window.innerWidth;
88 var h = window.innerHeight;
90 Debug.log(
"paint to " + w +
" - " + h);
92 if(_displayingFilters)
94 _filtersDivElement.style.display =
"block";
95 _toggleFiltersLinkElement.innerHTML =
"Hide Filters";
99 _filtersDivElement.style.display =
"none";
100 _toggleFiltersLinkElement.innerHTML =
"Show Filters";
103 h -= _MARGIN*2 + _OFFSET_Y;
109 _filtersDivElement.style.width = w +
"px";
110 _filtersDivElement.style.height = h +
"px";
112 w = _filtersDivElement.scrollWidth;
113 Debug.log(
"Resize filters " + _filtersDivElement.scrollWidth);
115 var filterEls = document.getElementsByClassName(
"filterList");
116 var filterBtns = document.getElementsByClassName(
"collapsible");
117 for(var i=0;i<filterEls.length;++i)
119 filterEls[i].style.width = (w-30) +
"px";
120 filterBtns[i].style.width = w +
"px";
127 function toggleFilters()
129 Debug.log(
"toggleFilters()");
130 _displayingFilters = !_displayingFilters;
136 function getContextNames()
138 return new Promise(
function(resolve, reject)
141 DesktopContent.XMLHttpRequest(
"Request?RequestType=getContextMemberNames",
"",
144 var memberNames = req.responseXML.getElementsByTagName(
"ContextMember");
146 _allContextNames = {};
148 for(var i=0;i<memberNames.length;++i)
149 if(_allContextNames[memberNames[i].getAttribute(
"value")])
150 ++_allContextNames[memberNames[i].getAttribute(
"value")];
152 _allContextNames[memberNames[i].getAttribute(
"value")] = 1;
154 console.log(
"_allContextNames",Object.keys(_allContextNames).length,_allContextNames);
156 if(Object.keys(_allContextNames).length == 0)
158 Debug.log(
"Empty context member list found!",Debug.HIGH_PRIORITY);
159 reject(
"Empty context member list found!");
162 resolve(_allContextNames);
173 function getAppsArray()
175 return new Promise(
function(resolve, reject)
177 DesktopContent.XMLHttpRequest(
"Request?RequestType=getAppStatus",
"",
178 function (req,param,err)
183 Debug.log(
"Error received updating status: " + err);
187 if(_updateAppsTimeout) window.clearTimeout(_updateAppsTimeout);
188 _updateAppsTimeout = window.setTimeout(updateAppsArray, 5000 );
192 var appNames, appUrls, appIds, appStatus, appTime,
193 appStale, appClasses, appProgress, appDetail, appContexts;
195 appNames = req.responseXML.getElementsByTagName(
"name");
196 appIds = req.responseXML.getElementsByTagName(
"id");
197 appStatus = req.responseXML.getElementsByTagName(
"status");
198 appTime = req.responseXML.getElementsByTagName(
"time");
199 appStale = req.responseXML.getElementsByTagName(
"stale");
200 appProgress = req.responseXML.getElementsByTagName(
"progress");
201 appDetail = req.responseXML.getElementsByTagName(
"detail");
202 appClasses = req.responseXML.getElementsByTagName(
"class");
203 appUrls = req.responseXML.getElementsByTagName(
"url");
204 appContexts = req.responseXML.getElementsByTagName(
"context");
206 if(_allAppsArray === undefined && appTime.length > 1)
212 for(var i=1;i<appTime.length;++i)
215 var appTimeSplit = appTime[i].getAttribute(
"value").split(
' ');
216 if(appTime[i].getAttribute(
"value") !=
"0" &&
217 (appTimeSplit.length > 2 &&
218 (appTimeSplit[appTimeSplit.length-2]|0) != 1970
220 (appTimeSplit[appTimeSplit.length-2]|0) < 4000
231 Debug.log(
"It appears that active application status monitoring is currently OFF! " +
232 "\n\n\n" + windowTooltip,
233 Debug.HIGH_PRIORITY);
237 _allAppsArray =
new Array();
241 for(var i=0;i<appNames.length;i++)
244 "name" : appNames[i].getAttribute(
"value"),
245 "id" : appIds[i].getAttribute(
"value"),
246 "status" : appStatus[i].getAttribute(
"value"),
247 "time" : appTime[i].getAttribute(
"value"),
248 "stale" : appStale[i].getAttribute(
"value"),
249 "progress" : appProgress[i].getAttribute(
"value"),
250 "detail" : appDetail[i].getAttribute(
"value"),
251 "class" : appClasses[i].getAttribute(
"value"),
252 "url" : appUrls[i].getAttribute(
"value"),
253 "context" : appContexts[i].getAttribute(
"value")
256 var appTimeSplit = _allAppsArray[_allAppsArray.length-1].time.split(
' ');
257 if(!(appTimeSplit.length > 2 &&
258 (appTimeSplit[appTimeSplit.length-2]|0) != 1970
260 (appTimeSplit[appTimeSplit.length-2]|0) < 4000
262 _allAppsArray[_allAppsArray.length-1].progress = 0;
266 if(_allClassNames[appClasses[i].getAttribute(
"value")])
267 ++_allClassNames[appClasses[i].getAttribute(
"value")];
269 _allClassNames[appClasses[i].getAttribute(
"value")] = 1;
272 var hostname = appUrls[i].getAttribute(
"value");
273 if(hostname && hostname.length)
275 if(hostname.lastIndexOf(
':') >= 0)
276 hostname = hostname.substr(0,hostname.lastIndexOf(
':'));
277 if(hostname.lastIndexOf(
'/') >= 0)
278 hostname = hostname.substr(hostname.lastIndexOf(
'/')+1);
280 if(_allHostNames[hostname])
281 ++_allHostNames[hostname];
283 _allHostNames[hostname] = 1;
289 if(_allAppsArray.length == 0)
291 Debug.log(
"Empty apps array!",Debug.HIGH_PRIORITY);
292 reject(
"Empty Empty apps array!");
296 resolve(_allAppsArray);
299 if(_updateAppsTimeout) window.clearTimeout(_updateAppsTimeout);
300 _updateAppsTimeout = window.setTimeout(updateAppsArray, 1000 );
314 function updateAppsArray()
317 _arrayOnDisplayTable = setIntersection(_allAppsArray, _arrayOnDisplayTable);
318 displayTable(_arrayOnDisplayTable);
323 function displayTable(appsArray)
326 var statusDivElement = document.getElementById(
"appStatusDiv");
327 statusDivElement.innerHTML =
"";
330 if(appsArray && appsArray.length)
331 document.getElementById(
332 "lastUpdateTimeDiv").innerHTML =
333 "Showing " + appsArray.length +
334 "/" + _allAppsArray.length +
" Apps " +
335 "(Last update: " + appsArray[0].time +
")";
338 var table = document.createElement(
"TABLE");
342 var columnNames = [
"App Name",
"Status",
"Progress",
"Detail",
"Last Update",
"App Type",
"App URL",
"App ID",
"Parent Context Name"];
343 var columnKeys = [
"name",
"status",
"progress",
"detail",
"stale",
"class",
"url",
"id",
"context" ];
344 var columnCount = columnNames.length;
347 var row = table.insertRow(-1);
348 for (var i = 0; i < columnCount; i++)
350 var headerCell = document.createElement(
"TH");
351 headerCell.innerHTML = columnNames[i];
352 row.appendChild(headerCell);
356 for (var i = 0; i < appsArray.length; i++)
358 row = table.insertRow(-1);
359 for (var j = 0; j < columnKeys.length; ++j)
361 var cell = row.insertCell(-1);
364 cell.title = appsArray[i].name +
"'s " +
367 if(columnKeys[j] ==
"stale")
369 var staleString =
"";
370 var staleSeconds = appsArray[i][columnKeys[j]] | 0;
371 if(appsArray[i].time ==
"0")
372 staleString =
"No status";
373 else if(staleSeconds < 10)
374 staleString =
"Seconds ago";
375 else if(staleSeconds < 60)
376 staleString =
"One minute ago";
377 else if(staleSeconds < 40*60)
378 staleString = (((staleSeconds/60)|0)+1) +
" minutes ago";
379 else if(staleSeconds < 75*60)
380 staleString =
"One hour ago";
381 else if (staleSeconds < 60*60*2)
382 staleString = (((staleSeconds/60/60)|0)+1) +
" hours ago";
383 else if (staleSeconds < 60*60*48)
384 staleString = (((staleSeconds/60/60)|0)+1) +
" days ago";
386 cell.innerHTML = staleString;
388 else if(columnKeys[j] ==
"progress")
390 var progressNum = appsArray[i][columnKeys[j]] | 0;
391 if(progressNum > 100)
394 if(progressNum == 100)
395 cell.innerHTML =
"Done";
400 var progressPX = ((66*progressNum/100)|0);
401 if(progressPX > 0 && progressPX < 3) progressPX = 3;
403 cell.innerHTML =
" " + progressNum +
" %<div class='progressBar' style='width:" +
404 progressPX +
"px;'></div>";
408 else if (columnKeys[j] ==
"status")
410 var statusString = appsArray[i][columnKeys[j]];
414 statusString = statusString.split(
":::")[0];
419 Debug.log(
"What happened? " + e);
426 cell.style.background =
"radial-gradient(circle at 50% 120%, rgb(119, 208, 255), rgb(119, 208, 255) 10%, rgb(7, 105, 191) 80%, rgb(6, 39, 69) 100%)";
429 cell.style.background =
"radial-gradient(circle at 50% 120%, rgb(255, 207, 105), rgb(245, 218, 179) 10%, rgb(234, 131, 3) 80%, rgb(121, 68, 0) 100%)";
433 cell.style.background =
"radial-gradient(circle at 50% 120%, rgb(80, 236, 199), rgb(179, 204, 197) 10%, rgb(5, 148, 122) 80%, rgb(6, 39, 69) 100%)";
436 cell.style.background =
"radial-gradient(circle at 50% 120%, rgb(0, 255, 67), rgb(142, 255, 172) 10%, rgb(5, 148, 42) 80%, rgb(6, 39, 69) 100%)";
441 cell.style.background =
"radial-gradient(circle at 50% 120%, rgb(255, 124, 124), rgb(255, 159, 159) 10%, rgb(218, 0, 0) 80%, rgb(144, 1, 1) 100%)";
443 cell.style.cursor =
"pointer";
444 cell.id =
"cell-" + i +
"-" + j;
448 Debug.log(
"Cell " + this.
id);
450 var i = this.
id.split(
'-');
454 appsArray[i][columnKeys[j]],
455 Debug.HIGH_PRIORITY);
461 cell.innerHTML = statusString;
463 else if (columnKeys[j] ==
"detail")
465 cell.innerHTML = decodeURIComponent(appsArray[i][columnKeys[j]]);
468 cell.innerHTML = appsArray[i][columnKeys[j]];
470 if (columnKeys[j] ==
"status")
472 cell.style.textAlign =
"center";
473 cell.className =
"statusCell";
476 else if(columnKeys[j] ==
"progress" || columnKeys[j] ==
"id")
477 cell.style.textAlign =
"center";
483 statusDivElement.appendChild(table);
486 _arrayOnDisplayTable = appsArray;
495 function createFilterList()
497 Debug.log(
"createFilterList()");
499 localRenderFilterList(
501 document.getElementById(
'contextUl'),
503 localRenderFilterList(
505 document.getElementById(
'classUl'),
507 localRenderFilterList(
509 document.getElementById(
'hostUl'),
513 applyFilterItemListeners();
518 function localRenderFilterList(elemObject, ulelem, cbName)
522 var li = document.createElement(
'li');
523 var cb_input = document.createElement(
'input');
524 cb_input.setAttribute(
"type",
"checkbox");
525 cb_input.setAttribute(
"class", cbName);
526 cb_input.checked =
true;
527 cb_input.setAttribute(
"value",
"selectAll");
530 cb_input.onclick =
function(e) {console.log(
"cb"); this.checked = !this.checked;}
532 li.setAttribute(
'class',
'item');
533 li.appendChild(cb_input);
535 textnode = document.createTextNode(
" " +
"Select All" +
" ");
537 li.appendChild(textnode);
538 ulelem.appendChild(li);
542 for (var key in elemObject)
544 var li = document.createElement(
'li');
545 var cb_input = document.createElement(
'input');
546 cb_input.setAttribute(
"type",
"checkbox");
547 cb_input.setAttribute(
"class", cbName);
548 cb_input.checked =
true;
549 cb_input.setAttribute(
"value", key);
552 cb_input.onclick =
function(e) {console.log(
"cb"); this.checked = !this.checked;}
555 li.setAttribute(
'class',
'item');
556 li.appendChild(cb_input);
560 if (cbName ==
"className")
561 textnode = document.createTextNode(
" " + key.slice(5) +
" ");
563 textnode = document.createTextNode(
" " + key +
" ");
565 li.appendChild(textnode);
566 ulelem.appendChild(li);
576 function collapsibleList()
579 var collapsible = document.getElementsByClassName(
"collapsible");
581 Debug.log(collapsible.length +
" collapsible lists found.");
583 for (var i = 0; i < collapsible.length; i++)
585 collapsible[i].addEventListener(
"click",
588 Debug.log(
"click handler " + this.nextElementSibling.id);
590 this.firstElementChild.style.visibility =
"hidden";
592 this.classList.toggle(
"active");
593 var content = this.nextElementSibling;
594 if (content.style.display ===
"block")
595 content.style.display =
"none";
597 content.style.display =
"block";
606 function applyFilterItemListeners()
608 Debug.log(
"applyFilterItemListeners()");
610 var listElements = document.getElementsByTagName(
"li");
612 for (let i = 0; i < listElements.length; i++)
616 listElements[i].onmouseup =
function(e) { e.stopPropagation(); }
617 listElements[i].onmousedown =
function(e) { e.stopPropagation(); }
618 listElements[i].onclick =
621 var val = this.firstElementChild.value;
622 var type = this.firstElementChild.className;
625 Debug.log(
"Clicked list item " + val +
" type" + type);
628 this.firstElementChild.checked = !this.firstElementChild.checked;
631 var listChildren = document.getElementsByClassName(type);
632 console.log(
"listChildren",listChildren);
634 if(val ==
"selectAll")
636 for(var j = 0; j < listChildren.length; j++)
637 listChildren[j].checked = this.firstElementChild.checked;
651 var filteredClass = getFilteredArray(
"ClassName",
"class");
652 var filteredContext = getFilteredArray(
"ContextName",
"context");
653 var filteredHost = getFilteredArray(
"HostName",
"host");
656 if (filteredClass.length == 0 && filteredContext.length == 0 &&
657 filteredHost.length == 0)
659 displayTable(_allAppsArray);
668 for (var i = 0; i < _allAppsArray.length; i++)
672 for (var j = 0; j < filteredClass.length; j++)
673 if(_allAppsArray[i].name == filteredClass[j].name)
683 for (var j = 0; j < filteredContext.length; j++)
684 if(_allAppsArray[i].name == filteredContext[j].name)
694 for (var j = 0; j < filteredHost.length; j++)
695 if(_allAppsArray[i].name == filteredHost[j].name)
703 result.push(_allAppsArray[i]);
707 displayTable(result);
712 function getFilteredArray(filterName, type)
714 var filterObjects = document.getElementsByClassName(filterName);
715 var checkedItems =
new Array();
718 for(var i = 0; i < filterObjects.length; i++)
720 if (filterObjects[i].checked)
722 var val = filterObjects[i].getAttribute(
"value");
723 checkedItems.push(val);
728 var filtered = _allAppsArray.filter(
736 var hostname = app.url;
737 if(hostname.lastIndexOf(
':') >= 0)
738 hostname = hostname.substr(0,hostname.lastIndexOf(
':'));
739 if(hostname.lastIndexOf(
'/') >= 0)
740 hostname = hostname.substr(hostname.lastIndexOf(
'/')+1);
742 return checkedItems.includes(hostname);
746 return checkedItems.includes(app[type]);
754 function setIntersection(list1, list2)
758 for (let i = 0; i < list1.length; i++)
761 for(let j = 0; j < list2.length; j++)
763 if (list1[i].
id == list2[j].
id)
765 result.push(list1[i]);