Automatic refresh after change of settings

routes/api.js
   - check error on return from server

public/javascripts/global.js
   -  reload pages with new values after save at settings

public/javascripts/map.js
   - removed status.loaded=true after call to laodAll

public/javascripts/showcharts.js
   - also load live at loadAll
This commit is contained in:
rxf
2023-04-07 18:09:24 +02:00
parent 22a6b9ab2c
commit abc05f177b
4 changed files with 11 additions and 21 deletions
+4 -17
View File
@@ -27,13 +27,10 @@ import { DateTime } from './luxon.min.js'
refresh: 0,
}
let status = {
loaded: false
}
// END global variables
// Register events
document.querySelector('#btnSave').addEventListener('click', () => {
document.querySelector('#btnSave').addEventListener('click', async () => {
const selDate = document.getElementById('startday').value
let starttime
if (selDate === 'today') {
@@ -52,8 +49,7 @@ import { DateTime } from './luxon.min.js'
if(peak < 130 ) {
params.peak = peak
}
status.loaded = false
await loadAll(params)
})
@@ -82,14 +78,6 @@ import { DateTime } from './luxon.min.js'
triggerEl.addEventListener('click', function (event) {
event.preventDefault()
tabTrigger.show()
if((!status.loaded) || (this.id === 'kartentab')) {
for (let x of tabtable) {
if (x.id === event.currentTarget.id) {
x.func(params, x.type, x.container)
}
}
logit(`tab changed to ${event.currentTarget.id}`)
}
})
})
@@ -108,12 +96,11 @@ import { DateTime } from './luxon.min.js'
params.sid = csid
let ok = await showChart(params, 'live', 'dlive')
if (ok) {
loadAll(params)
status.loaded = true
await loadAll(params)
}
} else {
// show the map
map.showMap(params, status)
map.showMap(params)
}
}
+2 -3
View File
@@ -13,7 +13,7 @@ let clickedcoords = {}
const colorscale = ['#d53e4f', '#fc8d59', '#fee08b', '#e6f598', '#99d594', '#3288bd', '#808080'];
const dba = [100, 80, 60, 40, 20, 0, -999];
export async function showMap(params, status) {
export async function showMap(params) {
utils.removeTabs()
if(map && map.remove) {
@@ -60,8 +60,7 @@ export async function showMap(params, status) {
bootstrap.Tab.getInstance(triggerEl).show() // Select tab by name
let ok = await showChart(params, 'live', 'dlive')
if (ok) {
loadAll(params)
status.loaded = true
await loadAll(params)
}
map.setView([clickedcoords.lat, clickedcoords.lng]);
})
+1 -1
View File
@@ -98,7 +98,7 @@ export async function showChart(params, typ, container) {
export const loadAll = async (params) => {
console.log('now load all in Background')
for (let i = 2; i < tabtable.length; i++) {
for (let i = 1; i < tabtable.length; i++) {
let ok = await showChart(params, tabtable[i].type, tabtable[i].container)
if (!ok) {
break;
+4
View File
@@ -32,6 +32,10 @@ router.get('/:cmd', async function(req, res, next) {
if (response.status !== 200) {
res.json({err: `Error from servercall: status = ${response.status}`})
}
if(response.data.err) {
res.json(response.data)
return
}
const options = response.data.options
for(let x of disttable) {
if (x.type === options.data) {