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';
|
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;
|
|
|
|
|
|
|
|
this.ui_panel = new SmartSettings("Settings");
|
2019-01-19 13:14:00 +00:00
|
|
|
// this.ui_panel.watch((event) => console.log(event));
|
|
|
|
}
|
|
|
|
|
|
|
|
async setup() {
|
|
|
|
this.reading_types = JSON.parse(
|
|
|
|
await GetFromUrl(`${this.config.api_root}?action=list-reading-types`)
|
|
|
|
);
|
|
|
|
|
2019-01-18 21:25:30 +00:00
|
|
|
this.ui_panel.loadConfig([
|
|
|
|
{
|
|
|
|
type: "range",
|
|
|
|
name: "Heatmap Blob Radius",
|
|
|
|
items: [
|
|
|
|
0.001, // min
|
|
|
|
0.05, // max
|
|
|
|
Config.heatmap.blob_radius, // initial value
|
|
|
|
0.001 // step
|
|
|
|
],
|
|
|
|
callback: ((event) => {
|
|
|
|
this.map_manager.heatmap.overlay_config.radius = parseFloat(event.target.value);
|
|
|
|
}).bind(this)
|
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),
|
|
|
|
callback: ((event) => {
|
|
|
|
let new_type = this.reading_types.find((type) => type.friendly_text == event.target.value).id;
|
|
|
|
|
|
|
|
this.map_manager.heatmap.update_reading_type(new_type);
|
|
|
|
}).bind(this)
|
2019-01-26 22:14:18 +00:00
|
|
|
},
|
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) => {
|
|
|
|
NanoModal(
|
|
|
|
await GetFromUrl(`${Config.api_root}?action=changelog`)
|
|
|
|
).show();
|
|
|
|
})
|
2019-01-18 21:25:30 +00:00
|
|
|
}
|
|
|
|
]);
|
2019-02-20 17:44:02 +00:00
|
|
|
this.ui_panel.setIndex("Reading Type", this.reading_types.findIndex((type) => type.short_descr == "PM25"));
|
2019-01-18 21:25:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default UI;
|