2020-09-08 19:39:17 +00:00
|
|
|
// regional forecast and observations
|
2022-11-22 22:19:10 +00:00
|
|
|
import { loadImg } from './utils/image.mjs';
|
2022-12-14 17:20:25 +00:00
|
|
|
import STATUS, { calcStatusClass, statusClasses } from './status.mjs';
|
2022-11-22 22:29:10 +00:00
|
|
|
import WeatherDisplay from './weatherdisplay.mjs';
|
2022-12-06 22:14:56 +00:00
|
|
|
import {
|
|
|
|
registerProgress, message, getDisplay, msg,
|
|
|
|
} from './navigation.mjs';
|
2020-09-08 19:39:17 +00:00
|
|
|
|
|
|
|
class Progress extends WeatherDisplay {
|
2020-10-29 21:44:28 +00:00
|
|
|
constructor(navId, elemId) {
|
2022-11-22 03:50:22 +00:00
|
|
|
super(navId, elemId, '', false);
|
2020-09-08 19:39:17 +00:00
|
|
|
|
|
|
|
// pre-load background image (returns promise)
|
2022-11-22 22:19:10 +00:00
|
|
|
this.backgroundImage = loadImg('images/BackGround1_1.png');
|
2020-09-08 19:39:17 +00:00
|
|
|
|
|
|
|
// disable any navigation timing
|
|
|
|
this.timing = false;
|
|
|
|
|
2022-12-07 16:53:18 +00:00
|
|
|
// setup event listener for dom-required initialization
|
|
|
|
document.addEventListener('DOMContentLoaded', () => {
|
|
|
|
this.version = document.getElementById('version').innerHTML;
|
|
|
|
this.elem.querySelector('.container').addEventListener('click', this.lineClick.bind(this));
|
|
|
|
});
|
2022-12-06 22:14:56 +00:00
|
|
|
|
|
|
|
this.okToDrawCurrentConditions = false;
|
2020-09-08 19:39:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async drawCanvas(displays, loadedCount) {
|
|
|
|
super.drawCanvas();
|
|
|
|
|
2022-08-05 20:40:53 +00:00
|
|
|
// get the progress bar cover (makes percentage)
|
|
|
|
if (!this.progressCover) this.progressCover = this.elem.querySelector('.scroll .cover');
|
|
|
|
|
2020-09-08 19:39:17 +00:00
|
|
|
// if no displays provided just draw the backgrounds (above)
|
|
|
|
if (!displays) return;
|
2022-08-05 19:03:14 +00:00
|
|
|
const lines = displays.map((display, index) => {
|
|
|
|
const fill = {};
|
|
|
|
|
|
|
|
fill.name = display.name;
|
2020-09-08 19:39:17 +00:00
|
|
|
|
2022-12-14 17:20:25 +00:00
|
|
|
const statusClass = calcStatusClass(display.status);
|
2022-08-05 19:03:14 +00:00
|
|
|
|
|
|
|
// make the line
|
|
|
|
const line = this.fillTemplate('item', fill);
|
|
|
|
// because of timing, this might get called before the template is loaded
|
|
|
|
if (!line) return false;
|
|
|
|
|
|
|
|
// update the status
|
|
|
|
const links = line.querySelector('.links');
|
2022-12-14 17:20:25 +00:00
|
|
|
links.classList.remove(...statusClasses);
|
2022-08-05 19:03:14 +00:00
|
|
|
links.classList.add(statusClass);
|
|
|
|
links.dataset.index = index;
|
|
|
|
return line;
|
|
|
|
}).filter((d) => d);
|
|
|
|
|
|
|
|
// get the container and update
|
|
|
|
const container = this.elem.querySelector('.container');
|
|
|
|
container.innerHTML = '';
|
|
|
|
container.append(...lines);
|
|
|
|
|
|
|
|
this.finishDraw();
|
2020-09-08 19:39:17 +00:00
|
|
|
|
|
|
|
// calculate loaded percent
|
2020-10-29 21:44:28 +00:00
|
|
|
const loadedPercent = (loadedCount / displays.length);
|
2020-09-08 19:39:17 +00:00
|
|
|
|
2022-08-05 20:53:16 +00:00
|
|
|
this.progressCover.style.width = `${(1.0 - loadedPercent) * 100}%`;
|
2020-09-08 19:39:17 +00:00
|
|
|
if (loadedPercent < 1.0) {
|
2022-08-05 20:40:53 +00:00
|
|
|
// show the progress bar and set width
|
|
|
|
this.progressCover.parentNode.classList.add('show');
|
2020-09-08 19:39:17 +00:00
|
|
|
} else {
|
2022-08-05 20:53:16 +00:00
|
|
|
// hide the progressbar after 1 second (lines up with with width transition animation)
|
|
|
|
setTimeout(() => this.progressCover.parentNode.classList.remove('show'), 1000);
|
2020-09-08 19:39:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-05 19:03:14 +00:00
|
|
|
lineClick(e) {
|
|
|
|
// get index
|
|
|
|
const indexRaw = e.target?.parentNode?.dataset?.index;
|
|
|
|
if (indexRaw === undefined) return;
|
|
|
|
const index = +indexRaw;
|
2020-09-08 21:27:03 +00:00
|
|
|
|
2020-09-17 21:34:38 +00:00
|
|
|
// stop playing
|
2022-12-06 22:14:56 +00:00
|
|
|
message('navButton');
|
2020-09-08 21:27:03 +00:00
|
|
|
// use the y value to determine an index
|
2022-12-06 22:14:56 +00:00
|
|
|
const display = getDisplay(index);
|
2020-09-08 21:27:03 +00:00
|
|
|
if (display && display.status === STATUS.loaded) {
|
2022-12-06 22:14:56 +00:00
|
|
|
display.showCanvas(msg.command.firstFrame);
|
2022-11-22 03:50:22 +00:00
|
|
|
this.elem.classList.remove('show');
|
2020-09-08 21:27:03 +00:00
|
|
|
}
|
2020-09-08 19:39:17 +00:00
|
|
|
}
|
2020-10-29 21:44:28 +00:00
|
|
|
}
|
2022-11-22 22:19:10 +00:00
|
|
|
|
2022-12-06 22:14:56 +00:00
|
|
|
// register our own display
|
|
|
|
const progress = new Progress(-1, 'progress');
|
|
|
|
registerProgress(progress);
|