User configuration applies at start, jump and goToNow

This commit is contained in:
l_samenv
2024-09-04 08:54:28 +02:00
parent 2ea2219b67
commit 345a231bdd
5 changed files with 37 additions and 5 deletions

View File

@ -44,6 +44,7 @@
<script src="externalFiles/Chart.bundle.min.js"></script>
<script src="externalFiles/hammer.js"></script>
<script src="externalFiles/chartjs-zoom.js"></script>
<script src="jsFiles/SEAWebClientLocalStorage.js"></script>
<script src="jsFiles/SEAWebClientResponsivity.js"></script>
<script src="jsFiles/SEAWebClientSwiper.js"></script>
<script src="jsFiles/SEAWebClientGroup.js"></script>

View File

@ -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);

View File

@ -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.

View File

@ -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;

View File

@ -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;
}