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';
|
|
|
|
import STATUS 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;
|
|
|
|
|
|
|
|
this.version = document.getElementById('version').innerHTML;
|
2022-08-05 19:03:14 +00:00
|
|
|
|
|
|
|
// setup event listener
|
|
|
|
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-08-05 19:03:14 +00:00
|
|
|
let statusClass;
|
2020-09-08 19:39:17 +00:00
|
|
|
switch (display.status) {
|
|
|
|
case STATUS.loading:
|
2022-08-05 19:03:14 +00:00
|
|
|
statusClass = 'loading';
|
2020-09-08 19:39:17 +00:00
|
|
|
break;
|
|
|
|
case STATUS.loaded:
|
2022-08-05 19:03:14 +00:00
|
|
|
statusClass = 'press-here';
|
2020-09-08 19:39:17 +00:00
|
|
|
break;
|
|
|
|
case STATUS.failed:
|
2022-08-05 19:03:14 +00:00
|
|
|
statusClass = 'failed';
|
2020-09-08 19:39:17 +00:00
|
|
|
break;
|
|
|
|
case STATUS.noData:
|
2022-08-05 19:03:14 +00:00
|
|
|
statusClass = 'no-data';
|
2020-09-08 19:39:17 +00:00
|
|
|
break;
|
2020-09-18 16:24:45 +00:00
|
|
|
case STATUS.disabled:
|
2022-08-05 19:03:14 +00:00
|
|
|
statusClass = 'disabled';
|
2020-09-18 16:24:45 +00:00
|
|
|
break;
|
2020-09-08 19:39:17 +00:00
|
|
|
default:
|
|
|
|
}
|
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');
|
|
|
|
links.classList.remove('loading');
|
|
|
|
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);
|