JavaScript side of multi-session support in Arbiter UI
Signed-off-by: Tamás Fenyvesi <tamas.fenyvesi@doknet.hu>master
parent
64c9008ea7
commit
8f55214d1b
|
@ -198,27 +198,38 @@
|
||||||
|
|
||||||
var selectedCandidateIdx = null;
|
var selectedCandidateIdx = null;
|
||||||
|
|
||||||
//Set basic interval function to do updates
|
//Multi-session mode
|
||||||
setInterval(doUpdate,5000); //Loop every 5 seconds
|
var multiSession = null;
|
||||||
|
//Session selection
|
||||||
|
var currSession = "";
|
||||||
|
|
||||||
|
function getSessionIdFromUrl() {
|
||||||
|
// path is like /arbiter/:sessionId/overview
|
||||||
|
var sessionIdRegexp = /\/arbiter\/([^\/]+)/g;
|
||||||
|
var match = sessionIdRegexp.exec(window.location.pathname)
|
||||||
|
return match[1];
|
||||||
|
}
|
||||||
|
|
||||||
function doUpdate(){
|
function getCurrSession(callback) {
|
||||||
//Get the update status, and do something with it:
|
if (multiSession) {
|
||||||
$.get("/arbiter/lastUpdate",function(data){
|
if (currSession == "") {
|
||||||
//Encoding: matches names in UpdateStatus class
|
// get only once
|
||||||
var jsonObj = JSON.parse(JSON.stringify(data));
|
currSession = getSessionIdFromUrl();
|
||||||
var statusTime = jsonObj['statusUpdateTime'];
|
}
|
||||||
var settingsTime = jsonObj['settingsUpdateTime'];
|
//we don't show session selector in multi-session mode (one can list sessions at /arbiter)
|
||||||
var resultsTime = jsonObj['resultsUpdateTime'];
|
callback();
|
||||||
//console.log("Last update times: " + statusTime + ", " + settingsTime + ", " + resultsTime);
|
} else {
|
||||||
|
$.ajax({
|
||||||
//Update available sessions:
|
url: "/arbiter/sessions/current",
|
||||||
var currSession;
|
async: true,
|
||||||
$.get("/arbiter/sessions/current", function(data){
|
error: function (query, status, error) {
|
||||||
currSession = data; //JSON.stringify(data);
|
console.log("Error getting data: " + error);
|
||||||
console.log("Current: " + currSession);
|
},
|
||||||
});
|
success: function (data) {
|
||||||
|
currSession = data;
|
||||||
|
console.log("Current session: " + currSession);
|
||||||
|
|
||||||
|
//Update available sessions in session selector
|
||||||
$.get("/arbiter/sessions/all", function(data){
|
$.get("/arbiter/sessions/all", function(data){
|
||||||
var keys = data; // JSON.stringify(data);
|
var keys = data; // JSON.stringify(data);
|
||||||
|
|
||||||
|
@ -240,14 +251,55 @@
|
||||||
$("#sessionSelectDiv").show();
|
$("#sessionSelectDiv").show();
|
||||||
}
|
}
|
||||||
// console.log("Got sessions: " + keys + ", current: " + currSession);
|
// console.log("Got sessions: " + keys + ", current: " + currSession);
|
||||||
|
callback();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function getSessionSettings(callback) {
|
||||||
|
// load only once
|
||||||
|
if (multiSession != null) {
|
||||||
|
getCurrSession(callback);
|
||||||
|
} else {
|
||||||
|
$.ajax({
|
||||||
|
url: "/arbiter/multisession",
|
||||||
|
async: true,
|
||||||
|
error: function (query, status, error) {
|
||||||
|
console.log("Error getting data: " + error);
|
||||||
|
},
|
||||||
|
success: function (data) {
|
||||||
|
multiSession = data == "true";
|
||||||
|
getCurrSession(callback);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Initial update
|
||||||
|
doUpdate();
|
||||||
|
//Set basic interval function to do updates
|
||||||
|
setInterval(doUpdate,5000); //Loop every 5 seconds
|
||||||
|
|
||||||
|
function doUpdate(){
|
||||||
|
//Get the update status, and do something with it:
|
||||||
|
getSessionSettings(function(){
|
||||||
|
var sessionUpdateUrl = multiSession ? "/arbiter/" + currSession + "/lastUpdate" : "/arbiter/lastUpdate";
|
||||||
|
$.get(sessionUpdateUrl,function(data){
|
||||||
|
//Encoding: matches names in UpdateStatus class
|
||||||
|
var jsonObj = JSON.parse(JSON.stringify(data));
|
||||||
|
var statusTime = jsonObj['statusUpdateTime'];
|
||||||
|
var settingsTime = jsonObj['settingsUpdateTime'];
|
||||||
|
var resultsTime = jsonObj['resultsUpdateTime'];
|
||||||
|
//console.log("Last update times: " + statusTime + ", " + settingsTime + ", " + resultsTime);
|
||||||
|
|
||||||
//Check last update times for each part of document, and update as necessary
|
//Check last update times for each part of document, and update as necessary
|
||||||
//First section: summary status
|
//First section: summary status
|
||||||
if(lastStatusUpdateTime != statusTime){
|
if(lastStatusUpdateTime != statusTime){
|
||||||
//Get JSON: address set by SummaryStatusResource
|
var summaryStatusUrl = multiSession ? "/arbiter/" + currSession + "/summary" : "/arbiter/summary";
|
||||||
$.get("/arbiter/summary",function(data){
|
$.get(summaryStatusUrl,function(data){
|
||||||
var summaryStatusDiv = $('#statusdiv');
|
var summaryStatusDiv = $('#statusdiv');
|
||||||
summaryStatusDiv.html('');
|
summaryStatusDiv.html('');
|
||||||
|
|
||||||
|
@ -262,7 +314,8 @@
|
||||||
//Second section: Optimization settings
|
//Second section: Optimization settings
|
||||||
if(lastSettingsUpdateTime != settingsTime){
|
if(lastSettingsUpdateTime != settingsTime){
|
||||||
//Get JSON for components
|
//Get JSON for components
|
||||||
$.get("/arbiter/config",function(data){
|
var settingsUrl = multiSession ? "/arbiter/" + currSession + "/config" : "/arbiter/config";
|
||||||
|
$.get(settingsUrl,function(data){
|
||||||
var str = JSON.stringify(data);
|
var str = JSON.stringify(data);
|
||||||
|
|
||||||
var configDiv = $('#settingsdiv');
|
var configDiv = $('#settingsdiv');
|
||||||
|
@ -277,9 +330,9 @@
|
||||||
|
|
||||||
//Third section: Summary results table (summary info for each candidate)
|
//Third section: Summary results table (summary info for each candidate)
|
||||||
if(lastResultsUpdateTime != resultsTime){
|
if(lastResultsUpdateTime != resultsTime){
|
||||||
|
//Get JSON for results table
|
||||||
//Get JSON; address set by SummaryResultsResource
|
var resultsUrl = multiSession ? "/arbiter/" + currSession + "/results" : "/arbiter/results";
|
||||||
$.get("/arbiter/results",function(data){
|
$.get(resultsUrl,function(data){
|
||||||
//Expect an array of CandidateInfo type objects here
|
//Expect an array of CandidateInfo type objects here
|
||||||
resultsTableContent = data;
|
resultsTableContent = data;
|
||||||
drawResultTable();
|
drawResultTable();
|
||||||
|
@ -291,7 +344,10 @@
|
||||||
//Finally: Currently selected result
|
//Finally: Currently selected result
|
||||||
if(selectedCandidateIdx != null){
|
if(selectedCandidateIdx != null){
|
||||||
//Get JSON for components
|
//Get JSON for components
|
||||||
$.get("/arbiter/candidateInfo/"+selectedCandidateIdx,function(data){
|
var candidateInfoUrl = multiSession
|
||||||
|
? "/arbiter/" + currSession + "/candidateInfo/" + selectedCandidateIdx
|
||||||
|
: "/arbiter/candidateInfo/" + selectedCandidateIdx;
|
||||||
|
$.get(candidateInfoUrl,function(data){
|
||||||
var str = JSON.stringify(data);
|
var str = JSON.stringify(data);
|
||||||
|
|
||||||
var resultsViewDiv = $('#resultsviewdiv');
|
var resultsViewDiv = $('#resultsviewdiv');
|
||||||
|
@ -302,6 +358,7 @@
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function createTable(tableObj,tableId,appendTo){
|
function createTable(tableObj,tableId,appendTo){
|
||||||
|
|
Loading…
Reference in New Issue