// base weather display class
/* globals navigation, utils, draw, UNITS, luxon */
const STATUS = {
loading: Symbol('loading'),
loaded: Symbol('loaded'),
failed: Symbol('failed'),
noData: Symbol('noData'),
disabled: Symbol('disabled'),
};
// eslint-disable-next-line no-unused-vars
class WeatherDisplay {
constructor(navId, elemId, name, defaultEnabled) {
// navId is used in messaging
this.navId = navId;
this.elemId = undefined;
this.gifs = [];
this.data = undefined;
this.loadingStatus = STATUS.loading;
this.name = name?name:elemId;
// default navigation timing
this.timing = {
totalScreens: 1,
baseDelay: 5000, // 5 seconds
delay: 1, // 1*1second = 1 second total display time
};
this.navBaseCount = 0;
this.screenIndex = -1; // special starting condition
if (elemId !== 'progress') this.addCheckbox(elemId, defaultEnabled);
if (this.enabled) {
this.setStatus(STATUS.loading);
} else {
this.setStatus(STATUS.disabled);
}
this.createCanvas(elemId);
}
addCheckbox(elemId, defaultEnabled = true) {
// get the saved status of the checkbox
let savedStatus = window.localStorage.getItem(`${elemId}Enabled`);
if (savedStatus === null) savedStatus = defaultEnabled;
if (savedStatus === 'true' || savedStatus === true) {
this.enabled = true;
} else {
this.enabled = false;
}
// create a checkbox in the selected displays area
const checkbox = ``;
const availableDisplays = document.getElementById('enabledDisplays');
availableDisplays.innerHTML += checkbox;
const checkboxElem = document.getElementById(`${elemId}Enabled`);
checkboxElem.addEventListener('click', this.checkboxChange);
}
checkboxChange(e) {
console.log(e);
}
// set data status and send update to navigation module
setStatus(value) {
this.status = value;
navigation.updateStatus({
id: this.navId,
status: this.status,
});
}
get status() {
return this.loadingStatus;
}
set status(state) {
this.loadingStatus = state;
}
createCanvas(elemId, width = 640, height = 480) {
// only create it once
if (this.elemId) return;
this.elemId = elemId;
const container = document.getElementById('container');
container.innerHTML += `