JavaScript side of multi-session support in Arbiter UI

Signed-off-by: Tamás Fenyvesi <tamas.fenyvesi@doknet.hu>
master
Tamás Fenyvesi 2020-05-05 18:54:42 +02:00
parent 64c9008ea7
commit 8f55214d1b
1 changed files with 143 additions and 86 deletions

View File

@ -198,27 +198,38 @@
var selectedCandidateIdx = null;
//Set basic interval function to do updates
setInterval(doUpdate,5000); //Loop every 5 seconds
//Multi-session mode
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(){
//Get the update status, and do something with it:
$.get("/arbiter/lastUpdate",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);
//Update available sessions:
var currSession;
$.get("/arbiter/sessions/current", function(data){
currSession = data; //JSON.stringify(data);
console.log("Current: " + currSession);
});
function getCurrSession(callback) {
if (multiSession) {
if (currSession == "") {
// get only once
currSession = getSessionIdFromUrl();
}
//we don't show session selector in multi-session mode (one can list sessions at /arbiter)
callback();
} else {
$.ajax({
url: "/arbiter/sessions/current",
async: true,
error: function (query, status, error) {
console.log("Error getting data: " + error);
},
success: function (data) {
currSession = data;
console.log("Current session: " + currSession);
//Update available sessions in session selector
$.get("/arbiter/sessions/all", function(data){
var keys = data; // JSON.stringify(data);
@ -239,15 +250,56 @@
$("#sessionSelect option[value='" + keys[currSelectedIdx] +"']").attr("selected", "selected");
$("#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
//First section: summary status
if(lastStatusUpdateTime != statusTime){
//Get JSON: address set by SummaryStatusResource
$.get("/arbiter/summary",function(data){
var summaryStatusUrl = multiSession ? "/arbiter/" + currSession + "/summary" : "/arbiter/summary";
$.get(summaryStatusUrl,function(data){
var summaryStatusDiv = $('#statusdiv');
summaryStatusDiv.html('');
@ -262,7 +314,8 @@
//Second section: Optimization settings
if(lastSettingsUpdateTime != settingsTime){
//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 configDiv = $('#settingsdiv');
@ -277,9 +330,9 @@
//Third section: Summary results table (summary info for each candidate)
if(lastResultsUpdateTime != resultsTime){
//Get JSON; address set by SummaryResultsResource
$.get("/arbiter/results",function(data){
//Get JSON for results table
var resultsUrl = multiSession ? "/arbiter/" + currSession + "/results" : "/arbiter/results";
$.get(resultsUrl,function(data){
//Expect an array of CandidateInfo type objects here
resultsTableContent = data;
drawResultTable();
@ -291,7 +344,10 @@
//Finally: Currently selected result
if(selectedCandidateIdx != null){
//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 resultsViewDiv = $('#resultsviewdiv');
@ -302,6 +358,7 @@
});
}
})
})
}
function createTable(tableObj,tableId,appendTo){