Skip to content
Snippets Groups Projects

added support of multiple instances

Merged Hahn Axel (hahn) requested to merge abstract_ubd_class into master
5 files
+ 197
139
Compare changes
  • Side-by-side
  • Inline
Files
5
@@ -24,7 +24,7 @@ const OUT_ID_MAIN='header-section';
const OUT_ID_APPS='app-section';
const OUT_ID_TAGS='tag-section';
const ID_TAGINPUT='E_TAGS';
const ID_DELTAGS='button-disable-all-tags';
// callback object after changing a tag filter
const FILTER_CALLBACK="oUbdApps.update()";
@@ -48,8 +48,8 @@ var AM_TAGLIST={};
*/
function _getAMApiUrl(sPath){
return AM_PRETTYURL
? AM_SERVER_URL+sPath
: AM_SERVER_URL+'/index.php?request='+sPath
? AM_SERVER_URL+'/api'+sPath
: AM_SERVER_URL+'/api/index.php?request='+sPath
;
}
@@ -119,6 +119,7 @@ function _2digits(i){
}
if(sLast!==sReturn){
document.getElementById(ID_TAGINPUT).value=sReturn;
document.getElementById(ID_DELTAGS).style.display=sReturn ? 'inline' : 'none';
eval(FILTER_CALLBACK);
}
}
@@ -156,7 +157,7 @@ function _renderTaglist(aData){
: ''
);
}
sReturn+='<button onclick="cbTagToggle(true);return false;"> </button>'
sReturn+='<button id="'+ID_DELTAGS+'" onclick="cbTagToggle(true);return false;"> '+AM_ICONS['delete']+' </button>'
// sReturn+='<input id="'+ID_TAGINPUT+'" type="text" size="20" value="'+AM_TAGS+'"'+'>'
sReturn+='<input id="'+ID_TAGINPUT+'" type="hidden" size="20" value="'+AM_TAGS+'">'
AM_TAGLIST=_TAGLIST;
@@ -187,9 +188,11 @@ function _getAllAppsStatus(aAllData){
+' (update every '+REFRESHTIME+' sec)'
// +'</p>';
// let aAllData=JSON.parse(sData);
var appOut='';
for (var key in aAllData){
sReturn+=_getSingleAppStatus(aAllData[key]);
appOut+=_getSingleAppStatus(aAllData[key]);
}
sReturn+=appOut ? appOut : '<div class="app result2">NO DATA.<br>No application matches this combination of tags.</div>';
return sReturn;
}
@@ -262,44 +265,76 @@ function _getSingleAppStatus(aData){
}
// ----------------------------------------------------------------------
// MAIN
// init instance
// ----------------------------------------------------------------------
// for auth header with basic auth
let oHeaders=(AM_USER)
? { "Authorization": "Basic " + btoa(AM_USER + ":" + AM_PASSWORD) }
: {}
;
document.getElementById(OUT_ID_MAIN).innerHTML=''+AM_ICONS['connect']+' Connected instance <a href="'+AM_SERVER_URL+'">'+AM_SERVER_URL+'</a>';
// initialize tags
var oUbdTag=new ubd(
{
'domid': OUT_ID_TAGS,
'url': _getUrlForTags(),
'header': { "headers": oHeaders },
'renderer': _renderTaglist,
'ttl': 0,
}
);
// initialize visible apps
var oUbdApps=new ubd(
{
'domid': OUT_ID_APPS,
'url': _getUrlWithTags, // remark: this is a function
'header': { "headers": oHeaders },
'renderer': _getAllAppsStatus,
'ttl': REFRESHTIME,
}
);
/**
* set a appmonitor instance that are defined in AM_INSTANCES
* see inc_config.js
*
* @param {integer} i number of instance to activate
*/
function initInstance(i){
AM_SERVER_URL=AM_INSTANCES[i]['url'];
AM_TAGS=AM_INSTANCES[i]['tags'];
AM_USER=AM_INSTANCES[i]['user'];
AM_PASSWORD=AM_INSTANCES[i]['password'];
// for auth header with basic auth
let oHeaders=(AM_USER)
? { "Authorization": "Basic " + btoa(AM_USER + ":" + AM_PASSWORD) }
: {}
;
// fill in initial values ... and update based on given ttl
oUbdTag.update();
oUbdApps.update();
// initialize tags
oUbdTag=new ubd(
{
'domid': OUT_ID_TAGS,
'url': _getUrlForTags(),
'header': { "headers": oHeaders },
'renderer': _renderTaglist,
'ttl': 0,
}
);
// initialize visible apps
oUbdApps=new ubd(
{
'domid': OUT_ID_APPS,
'url': _getUrlWithTags, // remark: this is a function
'header': { "headers": oHeaders },
'renderer': _getAllAppsStatus,
'ttl': REFRESHTIME,
}
);
let sInstances='';
for (var j=0; j<AM_INSTANCES.length; j++){
sInstances+='<option value="'+j+'" '
+(i==j ? 'selected ' : '')
+ '>'+AM_INSTANCES[j]['label']+'</option>';
}
sInstances=sInstances
? AM_ICONS['connect']+' Connected instance '
+ '<select onchange="initInstance(this.value); return false;">'+sInstances+'</select> '
+ ' <a href="'+AM_SERVER_URL+'">'+AM_SERVER_URL+'</a>'
: '';
document.getElementById(OUT_ID_MAIN).innerHTML= sInstances;
// fill in initial values ... and update based on given ttl
window.setTimeout("oUbdTag.update();", 50);
window.setTimeout("oUbdApps.update();", 400);
}
// ----------------------------------------------------------------------
// MAIN
// ----------------------------------------------------------------------
initInstance(0);
// ----------------------------------------------------------------------
\ No newline at end of file
Loading