/* HeuristicLab
* Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
*
* This file is part of HeuristicLab.
*
* HeuristicLab is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* HeuristicLab is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with HeuristicLab. If not, see .
*/
var hubber = $.connection.jobUpdaterHub;
$(function () {
// $.connection.hub.logging = true;
var v = document.getElementById("userId").innerHTML;
$.connection.hub.qs = { 'userid': v };
$.connection.hub.start().done(function () {
hubber.server.initConnection();
redrawMain();
});
//processes updates task info for each individual task
hubber.client.processData = function (id, data, name) {
var obj = JSON.parse(data);
editTaskData(id, obj);
saveData(id, obj.StateLog, name);
console.log("#UPDATED " + id);
}
//processes updated job info
hubber.client.processJobData = function (calc, fin) {
editJobData(calc, fin);
}
//Called when server is done with request
hubber.client.requestDone = function () {
if (document.getElementById("refreshtogg").checked) {
setTimeout(function () {
hubber.server.updateAll();
console.log("#REFRESH ALL");
}, 5000 + (dataCollection.length * 500));
}
}
})
//Toggles the refresh button. ON is refresh every 5 sec, OFF is no refresh
function autoRefresh() {
if (document.getElementById("refreshtogg").checked)
hubber.server.updateAll();
}
//Restarts an aborted, paused or failed task
function restart(id) {
document.getElementById("restarterbtn" + id).disabled = true;
document.getElementById("restarterbtn" + id).value = "Sending restart request...";
hubber.server.restartTask(id);
}
//Writes the new job info to the page
function editJobData(c, f) {
$("#jobcalculating").html("Calculating: " + c);
$("#jobfinished").html("Finished: " + f);
}
//Writes updated task info to the page
function editTaskData(id, task) {
//lastupdate
if (task.LastHeartbeat != null) {
var dat = new Date(task.LastHeartbeat);
$("#lastupdpar" + id).html("Last update: " + dat.toUTCString());
}
else
$("#lastupdpar" + id).html("No updates yet");
//task restarter
document.getElementById("restarter" + id).style.display = "none";
//state
if (task.State == "0") {//OFFLINE
$("#statepar" + id).css({
'color': 'gray',
'font-weight': 'normal'
});
$("#statepar" + id).html("State: Offline");
}
else if (task.State == "1") {//WAITING
$("#statepar" + id).css({
'color': 'white',
'font-weight': 'normal'
});
$("#statepar" + id).html("State: Waiting");
}
else if (task.State == "2") {//TRANSFERRING
$("#statepar" + id).css({
'color': 'white',
'font-weight': 'normal',
'text-shadow': '2px 2px black'
});
$("#statepar" + id).html("State: Transferring");
}
else if (task.State == "3") {//CALCULATING
$("#statepar" + id).css({
'color': 'white',
'font-weight': 'normal'
});
$("#statepar" + id).html("State: Calculating");
}
else if (task.State == "4") {//PAUSED
$("#statepar" + id).css({
'color': 'white',
'font-weight': 'normal'
});
$("#statepar" + id).html("State: Paused");
//Able to restart
document.getElementById("restarter" + id).style.display = "";
document.getElementById("restarterbtn" + id).disabled = false;
document.getElementById("restarterbtn" + id).value = "Restart task";
}
else if (task.State == "5") {//FINISHED
$("#statepar" + id).css({
'color': '#009900',
'font-weight': '900',
'text-shadow': '1px 1px black'
});
$("#statepar" + id).html("State: Finished");
var datf = new Date(task.StateLog[task.StateLog.length - 1].DateTime);
$("#lastupdpar" + id).html("Finished: " + datf.toUTCString());
}
else if (task.State == "6") {//ABORTED
$("#statepar" + id).css({
'color': '#e60000',
'font-weight': '900',
'text-shadow': '1px 1px black'
});
$("#statepar" + id).html("State: Aborted");
//Able to restart
document.getElementById("restarter" + id).style.display = "";
document.getElementById("restarterbtn" + id).disabled = false;
document.getElementById("restarterbtn" + id).value = "Restart task";
}
else if (task.State == "7") {//FAILED
$("#statepar" + id).css({
'color': '#e60000',
'font-weight': '900',
'text-shadow': '1px 1px black'
});
$("#statepar" + id).html("State: Failed");
//Able to restart
document.getElementById("restarter" + id).style.display = "";
document.getElementById("restarterbtn" + id).disabled = false;
document.getElementById("restarterbtn" + id).value = "Restart task";
}
//execution time
$("#executionpar" + id).html(task.ExecutionTime + " executed");
//exception
if (task.StateLog[task.StateLog.length - 1].Exception != null)
if (task.StateLog[task.StateLog.length - 1].Exception != "") {
$("#exceptionpar" + id).html("Exception: " + task.StateLog[task.StateLog.length - 1].Exception)
$("#exceptionpar" + id).css({
'color': '#e60000',
'font-weight': '700',
'text-shadow': '1px 1px black'
});
}
else if (task.State == "6") {
$("#exceptionpar" + id).html("Task is aborted.")
$("#exceptionpar" + id).css({
'color': '#e65c00',
'font-weight': '700',
'text-shadow': '1px 1px black'
});
}
else {
$("#exceptionpar" + id).html("No exceptions");
$("#exceptionpar" + id).css({
'color': 'white',
'text-shadow': '2px 2px black'
});
}
else {
$("#exceptionpar" + id).html("No exceptions");
$("#exceptionpar" + id).css({
'color': 'white',
'text-shadow': '2px 2px black'
});
}
//state changes
$("#statechangespar" + id).html("Statelogs: " + task.StateLog.length);
//graph title
var dat1 = new Date(task.StateLog[0].DateTime);
var dat2 = new Date(task.StateLog[task.StateLog.length - 1].DateTime);
$("#graphtitle" + id).html(
"From " + dat1.toUTCString() +
"
to " + dat2.toUTCString()
);
}