// base weather display class /* globals navigation, utils, draw, UNITS, luxon, currentWeatherScroll */ 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 // create the canvas, also stores this.elemId this.createCanvas(elemId); if (elemId !== 'progress') this.addCheckbox(defaultEnabled); if (this.enabled) { this.setStatus(STATUS.loading); } else { this.setStatus(STATUS.disabled); } this.startNavCount(); } addCheckbox(defaultEnabled = true) { // get the saved status of the checkbox let savedStatus = window.localStorage.getItem(`${this.elemId}Enabled`); if (savedStatus === null) savedStatus = defaultEnabled; if (savedStatus === 'true' || savedStatus === true) { this.enabled = true; } else { this.enabled = false; } // refresh (or initially store the state of the checkbox) window.localStorage.setItem(`${this.elemId}Enabled`, this.enabled); // create a checkbox in the selected displays area const checkbox = document.createElement('template'); checkbox.innerHTML = ``; checkbox.content.firstChild.addEventListener('change', (e) => this.checkboxChange(e)); const availableDisplays = document.getElementById('enabledDisplays'); availableDisplays.appendChild(checkbox.content.firstChild); } checkboxChange(e) { // update the state this.enabled = e.target.checked; // store the value for the next load window.localStorage.setItem(`${this.elemId}Enabled`, this.enabled); // calling get data will update the status and actually get the data if we're set to enabled this.getData(); } // 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; // create a canvas const canvas = document.createElement('template'); canvas.innerHTML = `