From 345a231bddd766f2c542c26f02d9a2170041e71c Mon Sep 17 00:00:00 2001 From: l_samenv Date: Wed, 4 Sep 2024 08:54:28 +0200 Subject: [PATCH] User configuration applies at start, jump and goToNow --- client/SEAWebClient.html | 1 + .../curves_settings_popup.js | 4 +-- client/jsFiles/SEAWebClientCommunication.js | 2 +- client/jsFiles/SEAWebClientGraphics.js | 4 +-- client/jsFiles/SEAWebClientLocalStorage.js | 31 +++++++++++++++++++ 5 files changed, 37 insertions(+), 5 deletions(-) create mode 100644 client/jsFiles/SEAWebClientLocalStorage.js diff --git a/client/SEAWebClient.html b/client/SEAWebClient.html index 06687bf..7757a5e 100644 --- a/client/SEAWebClient.html +++ b/client/SEAWebClient.html @@ -44,6 +44,7 @@ + diff --git a/client/components/curves_settings_popup/curves_settings_popup.js b/client/components/curves_settings_popup/curves_settings_popup.js index aca89e4..32f12f3 100644 --- a/client/components/curves_settings_popup/curves_settings_popup.js +++ b/client/components/curves_settings_popup/curves_settings_popup.js @@ -7,7 +7,7 @@ class CurvesSettingsPopup extends HTMLElement{ initTable(){ - let userConfiguration = this.getUserConfiguration(); + let userConfiguration = getUserConfiguration(); let tbody = this.querySelector("#curves-settings-popup-table tbody"); tbody.innerHTML = ""; @@ -25,7 +25,7 @@ class CurvesSettingsPopup extends HTMLElement{ let formattedUserConfiguration = this.getFormattedUserConfiguration(localStorageBuffer); localStorage.clear(); - this.saveUserConfiguration(localStorageBuffer); + saveUserConfiguration(localStorageBuffer); this.hide(); this.applySettingsCallback(formattedUserConfiguration); diff --git a/client/jsFiles/SEAWebClientCommunication.js b/client/jsFiles/SEAWebClientCommunication.js index 3f10541..69f5a5c 100644 --- a/client/jsFiles/SEAWebClientCommunication.js +++ b/client/jsFiles/SEAWebClientCommunication.js @@ -350,7 +350,7 @@ function successHandler(s, message) { begin = timeRange[0] - timeRange[1]; select.value = begin; // Server-request for variable-list.*/ - reqJSON(0, "http://" + hostPort + "/getvars?time=" + timeRange + "&id=" + reqJSON(0, "http://" + hostPort + "/getvars?time=" + timeRange + "&userconfiguration=" + JSON.stringify(getFormattedUserConfigurationFromLocalStorage()) + "&id=" + clientID, successHandler, errorHandler); break; // Response to a "getvars"-server-request. diff --git a/client/jsFiles/SEAWebClientGraphics.js b/client/jsFiles/SEAWebClientGraphics.js index 0e03473..c2eb376 100644 --- a/client/jsFiles/SEAWebClientGraphics.js +++ b/client/jsFiles/SEAWebClientGraphics.js @@ -831,7 +831,7 @@ let graphs = (function (){ msRightTimestampGetVars = dateTimestampMs + timeValueMs; msRightTimestampGetGraph = dateTimestampMs + 24*60*60*1000; - AJAX("http://" + hostPort + "/getvars?time=" + msLeftTimestampGetVars/1000 + "," + msRightTimestampGetVars/1000 + "&id="+ clientID).getJSON().then(function(data){ + AJAX("http://" + hostPort + "/getvars?time=" + msLeftTimestampGetVars/1000 + "," + msRightTimestampGetVars/1000 + "&userconfiguration=" + JSON.stringify(getFormattedUserConfigurationFromLocalStorage()) + "&id="+ clientID).getJSON().then(function(data){ blocks = data.blocks; document.getElementById("device").innerHTML = data.device maxTime = msRightTimestampGetGraph; @@ -901,7 +901,7 @@ let graphs = (function (){ let msLeftTimestamp = msRightTimestamp - 30*60*1000; cursorLine(null); - AJAX("http://" + hostPort + "/getvars?time=" + msLeftTimestamp/1000 + "," + msRightTimestamp/1000 + "&id="+ clientID).getJSON().then(function(data){ + AJAX("http://" + hostPort + "/getvars?time=" + msLeftTimestamp/1000 + "," + msRightTimestamp/1000 + "&userconfiguration=" + JSON.stringify(getFormattedUserConfigurationFromLocalStorage()) + "&id="+ clientID).getJSON().then(function(data){ currentMaxTime = msRightTimestamp + 60000; currentMinTime = msLeftTimestamp; diff --git a/client/jsFiles/SEAWebClientLocalStorage.js b/client/jsFiles/SEAWebClientLocalStorage.js new file mode 100644 index 0000000..8af8b26 --- /dev/null +++ b/client/jsFiles/SEAWebClientLocalStorage.js @@ -0,0 +1,31 @@ +function getUserConfiguration(){ + let userConfiguration = []; + for(let i = 0; i < localStorage.length; i++){ + userConfiguration.push(JSON.parse(localStorage.getItem(localStorage.key(i)))); + } + return userConfiguration; +} + +function saveUserConfiguration(userConfiguration){ + for(let i = 0; i < userConfiguration.length; i++){ + localStorage.setItem(i, JSON.stringify(userConfiguration[i])); + } +} + +function getFormattedUserConfigurationFromLocalStorage(){ + let formatedUserConfiguration = {}; + + for(let configurationLineObject of getUserConfiguration()){ + // Every entry in the localStorage has a variable field and at least one field cat, color or unit, + // so there is no need to check their presence + + let key = configurationLineObject["variable"]; + delete configurationLineObject["variable"]; + if(configurationLineObject.hasOwnProperty("parameter")){ + key += "." + configurationLineObject["parameter"]; + delete configurationLineObject["parameter"]; + } + formatedUserConfiguration[key] = configurationLineObject; + } + return formatedUserConfiguration; +} \ No newline at end of file