2019-03-13 14:18:05 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function API(baseurl){
|
|
|
|
|
|
2019-03-14 08:36:02 +01:00
|
|
|
|
this.baseurl = baseurl;
|
|
|
|
|
|
|
|
|
|
this.get = function(page, handler = null){
|
|
|
|
|
var x = new XMLHttpRequest();
|
|
|
|
|
var async = (handler != null);
|
|
|
|
|
|
|
|
|
|
if (async)
|
|
|
|
|
{
|
|
|
|
|
x.onload = function(){
|
|
|
|
|
var responseText = x.responseText;
|
|
|
|
|
handler( responseText );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
x.open("GET", this.baseurl + page, async);
|
|
|
|
|
x.send();
|
|
|
|
|
|
|
|
|
|
if (!async)
|
|
|
|
|
return x.responseText
|
|
|
|
|
}
|
|
|
|
|
this.post = function(page, handler = null){
|
|
|
|
|
var x = new XMLHttpRequest();
|
|
|
|
|
if (handler != null)
|
|
|
|
|
{
|
|
|
|
|
x.onload = function(){
|
|
|
|
|
var responseText = x.responseText;
|
|
|
|
|
handler( responseText );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
x.open("POST", this.baseurl + page);
|
|
|
|
|
x.send();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.getJson = function(page, handler){
|
|
|
|
|
var j = function(t){
|
|
|
|
|
handler(JSON.parse(t));
|
|
|
|
|
};
|
|
|
|
|
return this.get( page, j );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.call = function(endpoint,method,parameters = []){
|
|
|
|
|
var x = new XMLHttpRequest();
|
|
|
|
|
x.open("POST", this.baseurl + endpoint, false);
|
|
|
|
|
x.setRequestHeader("content-type","application/json");
|
|
|
|
|
|
|
|
|
|
var methodCall = {
|
|
|
|
|
"MethodName": method,
|
|
|
|
|
"Parameters": parameters
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
x.send(JSON.stringify(methodCall));
|
|
|
|
|
|
|
|
|
|
var result = JSON.parse(x.responseText);
|
|
|
|
|
if (result.Exception != null)
|
|
|
|
|
throw result.Exception;
|
2019-03-13 14:18:05 +01:00
|
|
|
|
|
2019-03-14 08:36:02 +01:00
|
|
|
|
return result.Result;
|
|
|
|
|
}
|
2019-03-14 13:31:15 +01:00
|
|
|
|
|
|
|
|
|
this.loadPage = function (page) {
|
|
|
|
|
|
|
|
|
|
var hContent = $("content");
|
|
|
|
|
var x = new XMLHttpRequest();
|
|
|
|
|
|
|
|
|
|
x.open("GET", this.baseurl + page, false);
|
|
|
|
|
x.setRequestHeader("x-template-unframed","unframed");
|
|
|
|
|
x.send();
|
|
|
|
|
|
|
|
|
|
hContent.innerHTML = x.responseText;
|
|
|
|
|
|
|
|
|
|
history.pushState(null, page, this.baseurl + page);
|
|
|
|
|
|
|
|
|
|
this.fireOnLoad( hContent );
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.fireOnLoad = function(element){
|
|
|
|
|
if (element.onload != null)
|
|
|
|
|
{
|
|
|
|
|
element.onload();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (var n=0;n<element.children.length;n++)
|
|
|
|
|
this.fireOnLoad(element.children[n]);
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-14 08:36:02 +01:00
|
|
|
|
}
|
2019-03-13 14:18:05 +01:00
|
|
|
|
|
2019-03-14 08:36:02 +01:00
|
|
|
|
function $(id)
|
|
|
|
|
{
|
|
|
|
|
return document.getElementById(id);
|
|
|
|
|
}
|
|
|
|
|
function CE(eName)
|
|
|
|
|
{
|
|
|
|
|
return document.createElement(eName);
|
|
|
|
|
}
|
2019-03-13 14:18:05 +01:00
|
|
|
|
|
|
|
|
|
|
2019-03-14 08:36:02 +01:00
|
|
|
|
var api = null;
|
2019-03-13 14:18:05 +01:00
|
|
|
|
|
|
|
|
|
function loadStatistics()
|
2019-03-14 08:36:02 +01:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var stats = api.call("api/management","GetStatistics");
|
|
|
|
|
|
2019-03-14 13:31:15 +01:00
|
|
|
|
$("ServerTime").innerText = "ServerTime: " + stats.ServerTime;
|
|
|
|
|
|
2019-03-14 08:36:02 +01:00
|
|
|
|
$("indHttpServer").attributes["state"].value = stats.States.HttpServer;
|
|
|
|
|
$("indManager").attributes["state"].value = stats.States.Manager;
|
|
|
|
|
$("indCrawler").attributes["state"].value = stats.States.Crawler;
|
|
|
|
|
$("indChecks").attributes["state"].value = stats.States.Checks;
|
|
|
|
|
$("indDispatcher").attributes["state"].value = stats.States.Dispatcher;
|
|
|
|
|
|
|
|
|
|
} catch (e)
|
|
|
|
|
{
|
2019-03-14 13:31:15 +01:00
|
|
|
|
$("ServerTime").innerText = "Server unreachable";
|
|
|
|
|
|
2019-03-14 08:36:02 +01:00
|
|
|
|
$("indHttpServer").attributes["state"].value = 3;
|
|
|
|
|
$("indManager").attributes["state"].value = 0;
|
|
|
|
|
$("indCrawler").attributes["state"].value = 0;
|
|
|
|
|
$("indChecks").attributes["state"].value = 0;
|
|
|
|
|
$("indDispatcher").attributes["state"].value = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function initApi(baseurl)
|
2019-03-13 14:18:05 +01:00
|
|
|
|
{
|
2019-03-14 08:36:02 +01:00
|
|
|
|
api = new API(baseurl);
|
|
|
|
|
setInterval( loadStatistics, 1000 );
|
2019-03-13 14:18:05 +01:00
|
|
|
|
|
2019-03-14 13:31:15 +01:00
|
|
|
|
for (var n=0;n<document.body.children.length;n++)
|
|
|
|
|
api.fireOnLoad(document.body.children[n]);
|
2019-03-13 14:18:05 +01:00
|
|
|
|
|
2019-03-14 13:31:15 +01:00
|
|
|
|
}
|
2019-03-13 14:18:05 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|