code cleanup

This commit is contained in:
Matt Walsh 2022-12-14 13:08:49 -06:00
parent 49296e53f0
commit 2a577aaea7
4 changed files with 18 additions and 18 deletions

View file

@ -64,7 +64,7 @@ class CurrentWeather extends WeatherDisplay {
// test for data received // test for data received
if (!observations) { if (!observations) {
console.error('All current weather stations exhausted'); console.error('All current weather stations exhausted');
if (this.enabled) this.setStatus(STATUS.failed); if (this.isEnabled) this.setStatus(STATUS.failed);
// send failed to subscribers // send failed to subscribers
this.getDataCallback(undefined); this.getDataCallback(undefined);
return; return;

View file

@ -37,7 +37,7 @@ class Hourly extends WeatherDisplay {
} catch (e) { } catch (e) {
console.error('Get hourly forecast failed'); console.error('Get hourly forecast failed');
console.error(e.status, e.responseJSON); console.error(e.status, e.responseJSON);
if (this.enabled) this.setStatus(STATUS.failed); if (this.isEnabled) this.setStatus(STATUS.failed);
// return undefined to other subscribers // return undefined to other subscribers
this.getDataCallback(undefined); this.getDataCallback(undefined);
return; return;

View file

@ -65,6 +65,7 @@ const getWeather = async (latLon, haveDataCallback) => {
if (StationId in StationInfo) { if (StationId in StationInfo) {
city = StationInfo[StationId].city; city = StationInfo[StationId].city;
[city] = city.split('/'); [city] = city.split('/');
city = city.replace(/\s+$/, '');
} }
// populate the weather parameters // populate the weather parameters
@ -201,7 +202,7 @@ const loadDisplay = (direction) => {
// get the current display index or value // get the current display index or value
const currentDisplayIndex = () => { const currentDisplayIndex = () => {
const index = displays.findIndex((display) => display.isActive()); const index = displays.findIndex((display) => display.active);
return index; return index;
}; };
const currentDisplay = () => displays[currentDisplayIndex()]; const currentDisplay = () => displays[currentDisplayIndex()];

View file

@ -12,7 +12,6 @@ class WeatherDisplay {
// navId is used in messaging and sort order // navId is used in messaging and sort order
this.navId = navId; this.navId = navId;
this.elemId = undefined; this.elemId = undefined;
this.gifs = [];
this.data = undefined; this.data = undefined;
this.loadingStatus = STATUS.loading; this.loadingStatus = STATUS.loading;
this.name = name ?? elemId; this.name = name ?? elemId;
@ -34,7 +33,7 @@ class WeatherDisplay {
// store elemId once // store elemId once
this.storeElemId(elemId); this.storeElemId(elemId);
if (this.enabled) { if (this.isEnabled) {
this.setStatus(STATUS.loading); this.setStatus(STATUS.loading);
} else { } else {
this.setStatus(STATUS.disabled); this.setStatus(STATUS.disabled);
@ -55,13 +54,13 @@ class WeatherDisplay {
let savedStatus = window.localStorage.getItem(`display-enabled: ${this.elemId}`); let savedStatus = window.localStorage.getItem(`display-enabled: ${this.elemId}`);
if (savedStatus === null) savedStatus = defaultEnabled; if (savedStatus === null) savedStatus = defaultEnabled;
if (savedStatus === 'true' || savedStatus === true) { if (savedStatus === 'true' || savedStatus === true) {
this.enabled = true; this.isEnabled = true;
} else { } else {
this.enabled = false; this.isEnabled = false;
} }
// refresh (or initially store the state of the checkbox) // refresh (or initially store the state of the checkbox)
window.localStorage.setItem(`display-enabled: ${this.elemId}`, this.enabled); window.localStorage.setItem(`display-enabled: ${this.elemId}`, this.isEnabled);
// create a checkbox in the selected displays area // create a checkbox in the selected displays area
const label = document.createElement('label'); const label = document.createElement('label');
@ -72,7 +71,7 @@ class WeatherDisplay {
checkbox.value = true; checkbox.value = true;
checkbox.id = `${this.elemId}-checkbox`; checkbox.id = `${this.elemId}-checkbox`;
checkbox.name = `${this.elemId}-checkbox`; checkbox.name = `${this.elemId}-checkbox`;
checkbox.checked = this.enabled; checkbox.checked = this.isEnabled;
checkbox.addEventListener('change', (e) => this.checkboxChange(e)); checkbox.addEventListener('change', (e) => this.checkboxChange(e));
const span = document.createElement('span'); const span = document.createElement('span');
span.innerHTML = this.name; span.innerHTML = this.name;
@ -86,9 +85,9 @@ class WeatherDisplay {
checkboxChange(e) { checkboxChange(e) {
// update the state // update the state
this.enabled = e.target.checked; this.isEnabled = e.target.checked;
// store the value for the next load // store the value for the next load
window.localStorage.setItem(`display-enabled: ${this.elemId}`, this.enabled); window.localStorage.setItem(`display-enabled: ${this.elemId}`, this.isEnabled);
// calling get data will update the status and actually get the data if we're set to enabled // calling get data will update the status and actually get the data if we're set to enabled
this.getData(); this.getData();
} }
@ -130,7 +129,7 @@ class WeatherDisplay {
if (weatherParameters) this.weatherParameters = weatherParameters; if (weatherParameters) this.weatherParameters = weatherParameters;
// set status // set status
if (this.enabled) { if (this.isEnabled) {
this.setStatus(STATUS.loading); this.setStatus(STATUS.loading);
} else { } else {
this.setStatus(STATUS.disabled); this.setStatus(STATUS.disabled);
@ -168,7 +167,7 @@ class WeatherDisplay {
drawCurrentDateTime() { drawCurrentDateTime() {
// only draw if canvas is active to conserve battery // only draw if canvas is active to conserve battery
if (!this.isActive()) return; if (!this.active) return;
// Get the current date and time. // Get the current date and time.
const now = DateTime.local(); const now = DateTime.local();
@ -205,12 +204,12 @@ class WeatherDisplay {
this.elem.classList.remove('show'); this.elem.classList.remove('show');
} }
isActive() { get active() {
return this.elem.offsetHeight !== 0; return this.elem.offsetHeight !== 0;
} }
isEnabled() { get enabled() {
return this.enabled; return this.isEnabled;
} }
// navigation timings // navigation timings
@ -223,7 +222,7 @@ class WeatherDisplay {
// if the array forms are used totalScreens is overwritten by the size of the array // if the array forms are used totalScreens is overwritten by the size of the array
navBaseTime() { navBaseTime() {
// see if play is active and screen is active // see if play is active and screen is active
if (!isPlaying() || !this.isActive()) return; if (!isPlaying() || !this.active) return;
// increment the base count // increment the base count
this.navBaseCount += 1; this.navBaseCount += 1;
@ -412,7 +411,7 @@ class WeatherDisplay {
// still waiting for data (retries triggered) // still waiting for data (retries triggered)
stillWaiting() { stillWaiting() {
if (this.enabled) this.setStatus(STATUS.retrying); if (this.isEnabled) this.setStatus(STATUS.retrying);
// handle still waiting callbacks // handle still waiting callbacks
this.stillWaitingCallbacks.forEach((callback) => callback()); this.stillWaitingCallbacks.forEach((callback) => callback());
this.stillWaitingCallbacks = []; this.stillWaitingCallbacks = [];