color selected displays checkboxes to show loading status
This commit is contained in:
parent
b336b01059
commit
8df8fc25dc
|
@ -1,6 +1,6 @@
|
|||
// regional forecast and observations
|
||||
import { loadImg } from './utils/image.mjs';
|
||||
import STATUS from './status.mjs';
|
||||
import STATUS, { calcStatusClass, statusClasses } from './status.mjs';
|
||||
import WeatherDisplay from './weatherdisplay.mjs';
|
||||
import {
|
||||
registerProgress, message, getDisplay, msg,
|
||||
|
@ -38,28 +38,7 @@ class Progress extends WeatherDisplay {
|
|||
|
||||
fill.name = display.name;
|
||||
|
||||
let statusClass;
|
||||
switch (display.status) {
|
||||
case STATUS.loading:
|
||||
statusClass = 'loading';
|
||||
break;
|
||||
case STATUS.loaded:
|
||||
statusClass = 'press-here';
|
||||
break;
|
||||
case STATUS.failed:
|
||||
statusClass = 'failed';
|
||||
break;
|
||||
case STATUS.noData:
|
||||
statusClass = 'no-data';
|
||||
break;
|
||||
case STATUS.disabled:
|
||||
statusClass = 'disabled';
|
||||
break;
|
||||
case STATUS.retrying:
|
||||
statusClass = 'retrying';
|
||||
break;
|
||||
default:
|
||||
}
|
||||
const statusClass = calcStatusClass(display.status);
|
||||
|
||||
// make the line
|
||||
const line = this.fillTemplate('item', fill);
|
||||
|
@ -68,7 +47,7 @@ class Progress extends WeatherDisplay {
|
|||
|
||||
// update the status
|
||||
const links = line.querySelector('.links');
|
||||
links.classList.remove('loading');
|
||||
links.classList.remove(...statusClasses);
|
||||
links.classList.add(statusClass);
|
||||
links.dataset.index = index;
|
||||
return line;
|
||||
|
|
|
@ -7,4 +7,29 @@ const STATUS = {
|
|||
retrying: Symbol('retyring'),
|
||||
};
|
||||
|
||||
const calcStatusClass = (statusCode) => {
|
||||
switch (statusCode) {
|
||||
case STATUS.loading:
|
||||
return 'loading';
|
||||
case STATUS.loaded:
|
||||
return 'press-here';
|
||||
case STATUS.failed:
|
||||
return 'failed';
|
||||
case STATUS.noData:
|
||||
return 'no-data';
|
||||
case STATUS.disabled:
|
||||
return 'disabled';
|
||||
case STATUS.retrying:
|
||||
return 'retrying';
|
||||
default:
|
||||
return '';
|
||||
}
|
||||
};
|
||||
|
||||
const statusClasses = ['loading', 'press-here', 'failed', 'no-data', 'disabled', 'retrying'];
|
||||
|
||||
export default STATUS;
|
||||
export {
|
||||
calcStatusClass,
|
||||
statusClasses,
|
||||
};
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
// base weather display class
|
||||
|
||||
import STATUS from './status.mjs';
|
||||
import STATUS, { calcStatusClass, statusClasses } from './status.mjs';
|
||||
import { DateTime } from '../vendor/auto/luxon.mjs';
|
||||
import { elemForEach } from './utils/elem.mjs';
|
||||
import {
|
||||
|
@ -64,13 +64,24 @@ class WeatherDisplay {
|
|||
window.localStorage.setItem(`display-enabled: ${this.elemId}`, this.enabled);
|
||||
|
||||
// create a checkbox in the selected displays area
|
||||
const checkbox = document.createElement('template');
|
||||
checkbox.innerHTML = `<label for="${this.elemId}Enabled">
|
||||
<input type="checkbox" value="true" id="${this.elemId}Enabled" name="${this.elemId}Enabled"${this.enabled ? ' checked' : ''}/>
|
||||
${this.name}</label>`;
|
||||
checkbox.content.firstChild.addEventListener('change', (e) => this.checkboxChange(e));
|
||||
const label = document.createElement('label');
|
||||
label.for = `${this.elemId}-checkbox`;
|
||||
label.id = `${this.elemId}-label`;
|
||||
const checkbox = document.createElement('input');
|
||||
checkbox.type = 'checkbox';
|
||||
checkbox.value = true;
|
||||
checkbox.id = `${this.elemId}-checkbox`;
|
||||
checkbox.name = `${this.elemId}-checkbox`;
|
||||
checkbox.checked = this.enabled;
|
||||
checkbox.addEventListener('change', (e) => this.checkboxChange(e));
|
||||
const span = document.createElement('span');
|
||||
span.innerHTML = this.name;
|
||||
|
||||
return checkbox.content.firstChild;
|
||||
label.append(checkbox, span);
|
||||
|
||||
this.checkbox = label;
|
||||
|
||||
return label;
|
||||
}
|
||||
|
||||
checkboxChange(e) {
|
||||
|
@ -89,6 +100,11 @@ class WeatherDisplay {
|
|||
id: this.navId,
|
||||
status: this.status,
|
||||
});
|
||||
|
||||
// update coloring of checkbox at bottom of page
|
||||
if (!this.checkbox) return;
|
||||
this.checkbox.classList.remove(...statusClasses);
|
||||
this.checkbox.classList.add(calcStatusClass(value));
|
||||
}
|
||||
|
||||
get status() {
|
||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -1,3 +1,5 @@
|
|||
@use 'shared/_utils'as u;
|
||||
|
||||
@font-face {
|
||||
font-family: "Star4000";
|
||||
src: url('../fonts/Star4000.woff') format('woff');
|
||||
|
@ -312,11 +314,17 @@ button {
|
|||
|
||||
#enabledDisplays {
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
@include u.status-colors();
|
||||
|
||||
#enabledDisplays label {
|
||||
display: block;
|
||||
max-width: 300px;
|
||||
.press-here {
|
||||
color: white;
|
||||
}
|
||||
|
||||
label {
|
||||
display: block;
|
||||
max-width: 300px;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#divTwcBottom img {
|
||||
|
|
|
@ -37,27 +37,7 @@
|
|||
padding-left: 4px;
|
||||
}
|
||||
|
||||
.loading,
|
||||
.retrying {
|
||||
color: #ffff00;
|
||||
}
|
||||
|
||||
.press-here {
|
||||
color: #00ff00;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.failed {
|
||||
color: #ff0000;
|
||||
}
|
||||
|
||||
.no-data {
|
||||
color: #C0C0C0;
|
||||
}
|
||||
|
||||
.disabled {
|
||||
color: #C0C0C0;
|
||||
}
|
||||
@include u.status-colors();
|
||||
|
||||
&.loading .loading,
|
||||
&.press-here .press-here,
|
||||
|
|
|
@ -14,4 +14,29 @@
|
|||
0 $outline 0 c.$text-shadow,
|
||||
(-$outline) $outline 0 c.$text-shadow,
|
||||
(-$outline) 0 0 c.$text-shadow;
|
||||
}
|
||||
|
||||
@mixin status-colors() {
|
||||
|
||||
.loading,
|
||||
.retrying {
|
||||
color: #ffff00;
|
||||
}
|
||||
|
||||
.press-here {
|
||||
color: #00ff00;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.failed {
|
||||
color: #ff0000;
|
||||
}
|
||||
|
||||
.no-data {
|
||||
color: #C0C0C0;
|
||||
}
|
||||
|
||||
.disabled {
|
||||
color: #C0C0C0;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue