Files
noise/public/javascripts/global.js
T

89 lines
2.8 KiB
JavaScript

// Client side javascript
"use strict"
import * as map from './map.js'
import * as dt from './datetime.js'
import {logerror, logit} from './logit.js'
import * as chart_live from './chart_live.js'
import * as chart_houravg from './chart_houravg.js'
import * as chart_dayavg from './chart_dayavg.js'
import * as chart_daynight from './chart_daynight.js'
import * as chart_lden from './chart_lden.js'
import * as utils from "./chart_utilities.js";
import {tabtable} from './showcharts.js'
(async () => {
// global constants
const Stuttgart = [48.779, 9.16]
const MAXROWS_IN_TABLE = 1000
const defaultStartime = '2023-01-01 00:00'
// END global constants
// global variables
let params = { // set defaults
drawlines: false,
nbrentries: 0,
device: '',
coordinates: false,
center: Stuttgart,
zoom: 10,
refresh: 0,
starttime: '2023-01-01T00:00:00Z', //date2ISO(defaultStartime),
endtime: '2023-03-01T00:00:00Z' //date2ISO(emptyTimes.emptyHMtime)
}
// END global variables
// remove the taps (if shownig the map)
const removeTabs = () => {
document.querySelector('#navi').style.display = 'none'
}
// show thw tabs again
const showTabs = () => {
document.querySelector('#navi').style.display = 'block'
}
// main function:
// show the map if calle w/o any parameter
// if called with a sensor-ID, show the live chart for this sensor
async function main() {
// initialise tabs
let triggerTabList = [].slice.call(document.querySelectorAll('.nav-link'))
triggerTabList.forEach(function (triggerEl) {
let tabTrigger = new bootstrap.Tab(triggerEl)
triggerEl.addEventListener('click', function (event) {
event.preventDefault()
tabTrigger.show()
for(let x of tabtable) {
if (x.id === event.currentTarget.id) {
x.func(params, x.type, x.container)
}
}
logit(`tab chaned to ${event.currentTarget.id}`)
})
})
dt.showDate(true)
// and show date/time every minute
setInterval(() => dt.showDate(false), 1000)
// show version and version-date
document.querySelector('#versn').setHTML(`Version: ${sysparams.version} vom ${sysparams.date.slice(0,10)}`)
const csid = parseInt(sysparams.csid)
if(csid !== -1) {
let triggerEl = document.querySelector('#livetab')
bootstrap.Tab.getInstance(triggerEl).show() // Select tab by name
params.sid = csid
await chart_live.showLive(params)
}
// show the map
removeTabs()
map.showMap(params)
}
main().catch(console.error)
})()