2019-01-18 21:25:30 +00:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
import SmartSettings from 'smartsettings';
|
2019-01-26 22:14:18 +00:00
|
|
|
import NanoModal from 'nanomodal';
|
2019-01-18 21:25:30 +00:00
|
|
|
|
|
|
|
import Config from './Config.mjs';
|
2019-01-19 13:14:00 +00:00
|
|
|
import GetFromUrl from './Helpers/GetFromUrl.mjs';
|
2021-01-30 21:27:39 +00:00
|
|
|
import Gauge from './Gauge.mjs';
|
2019-01-18 21:25:30 +00:00
|
|
|
|
2020-04-02 19:26:48 +00:00
|
|
|
// import Tour from './Tour.mjs';
|
2019-06-11 14:35:31 +00:00
|
|
|
|
2019-07-20 10:49:53 +00:00
|
|
|
function show_nanomodal(html, options = {}) {
|
2019-06-11 14:35:31 +00:00
|
|
|
return new Promise((resolve, _reject) => {
|
2019-07-20 10:49:53 +00:00
|
|
|
let modal = NanoModal(html, options);
|
2019-06-11 14:35:31 +00:00
|
|
|
modal.onHide(resolve);
|
|
|
|
modal.show();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-05-09 12:38:51 +00:00
|
|
|
async function show_changelog(only_if_changed) {
|
|
|
|
let current_version = `${Config.version}, built ${Config.build_date.toDateString()}`;
|
|
|
|
console.log(`[UI] Comparing current '${current_version}' to '${localStorage.getItem("last_seen_version")}'`);
|
|
|
|
if(only_if_changed && localStorage.getItem("last_seen_version") == current_version) {
|
|
|
|
console.log("[UI] Not showing changelog.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log("[UI] Showing changelog");
|
2019-07-20 10:49:53 +00:00
|
|
|
await show_nanomodal(await GetFromUrl(`${Config.api_root}?action=changelog`), {
|
|
|
|
classes: "reverse",
|
|
|
|
autoRemove: true
|
|
|
|
});
|
2019-06-11 14:35:31 +00:00
|
|
|
|
2019-05-09 12:38:51 +00:00
|
|
|
localStorage.setItem("last_seen_version", current_version);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-01-18 21:25:30 +00:00
|
|
|
class UI {
|
2019-01-19 13:14:00 +00:00
|
|
|
constructor(in_config, in_map_manager) {
|
|
|
|
this.config = in_config;
|
2019-01-18 21:25:30 +00:00
|
|
|
this.map_manager = in_map_manager;
|
|
|
|
|
2020-04-27 22:56:34 +00:00
|
|
|
this.ui_panel = new SmartSettings("Settings");
|
2021-01-30 21:27:39 +00:00
|
|
|
this.gauge = new Gauge(document.getElementById("canvas-guage"));
|
|
|
|
this.gauge.set_reading_type(Config.default_reading_type);
|
|
|
|
|
2019-01-19 13:14:00 +00:00
|
|
|
// this.ui_panel.watch((event) => console.log(event));
|
2019-06-11 14:35:31 +00:00
|
|
|
|
2020-04-02 19:26:48 +00:00
|
|
|
this.tour_enabled = false;
|
|
|
|
if(this.tour_enabled) this.tour = new Tour(this.map_manager);
|
2019-01-19 13:14:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async setup() {
|
2019-06-30 17:40:26 +00:00
|
|
|
await show_changelog(true);
|
|
|
|
|
2019-01-19 13:14:00 +00:00
|
|
|
this.reading_types = JSON.parse(
|
|
|
|
await GetFromUrl(`${this.config.api_root}?action=list-reading-types`)
|
|
|
|
);
|
|
|
|
|
2020-04-27 22:56:36 +00:00
|
|
|
this.ui_panel.loadConfig([
|
2019-01-19 13:14:00 +00:00
|
|
|
{
|
|
|
|
type: "select",
|
2019-01-19 13:35:25 +00:00
|
|
|
name: "Reading Type",
|
|
|
|
items: this.reading_types.map((type) => type.friendly_text),
|
2019-06-30 17:48:31 +00:00
|
|
|
callback: (async (event) => {
|
2019-04-23 14:49:15 +00:00
|
|
|
let new_type = this.reading_types.find((type) => type.friendly_text == event.target.value).short_descr;
|
2019-01-19 13:35:25 +00:00
|
|
|
|
2019-06-30 17:48:31 +00:00
|
|
|
|
|
|
|
document.querySelector("main").classList.add("working-visual");
|
2021-01-30 21:16:02 +00:00
|
|
|
await this.map_manager.device_markers.update_markers(new_type);
|
2021-01-30 21:27:39 +00:00
|
|
|
this.gauge.set_reading_type(new_type);
|
2019-06-30 17:48:31 +00:00
|
|
|
document.querySelector("main").classList.remove("working-visual");
|
2019-01-19 13:35:25 +00:00
|
|
|
}).bind(this)
|
2019-01-26 22:14:18 +00:00
|
|
|
},
|
2020-04-27 22:57:37 +00:00
|
|
|
{
|
|
|
|
type: "button",
|
|
|
|
name: "View disclaimer",
|
|
|
|
callback: ((_event) => {
|
|
|
|
window.open("https://github.com/ConnectedHumber/Air-Quality-Web/tree/dev#disclaimer", "_blank")
|
|
|
|
})
|
|
|
|
},
|
2019-02-01 18:57:06 +00:00
|
|
|
{
|
|
|
|
type: "button",
|
|
|
|
name: "Report bug",
|
|
|
|
callback: ((_event) => {
|
|
|
|
window.open("https://github.com/ConnectedHumber/Air-Quality-Web/issues/new", "_blank");
|
|
|
|
})
|
|
|
|
},
|
2019-01-26 22:14:18 +00:00
|
|
|
{
|
|
|
|
type: "button",
|
|
|
|
name: `${Config.version}, built ${Config.build_date.toDateString()}`,
|
|
|
|
callback: (async (_event) => {
|
2019-05-09 12:38:51 +00:00
|
|
|
show_changelog(false);
|
2019-01-26 22:14:18 +00:00
|
|
|
})
|
2019-01-18 21:25:30 +00:00
|
|
|
}
|
2020-04-27 22:56:36 +00:00
|
|
|
]);
|
2021-01-30 21:27:39 +00:00
|
|
|
this.ui_panel.setIndex("Reading Type", this.reading_types.findIndex((type) => type.short_descr == Config.default_reading_type));
|
2019-05-09 12:38:51 +00:00
|
|
|
|
2020-04-02 19:26:48 +00:00
|
|
|
if(this.tour_enabled) await this.tour.run_once();
|
2019-01-18 21:25:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default UI;
|