Compare commits

..

9 Commits

Author SHA1 Message Date
Matt Walsh
f82980ed09 5.9.1 2022-12-14 21:47:35 -06:00
Matt Walsh
af17b3c690 progress light mode colors 2022-12-14 21:47:27 -06:00
Matt Walsh
2c394c2e4a correct gulp build 2022-12-14 16:31:11 -06:00
Matt Walsh
97f8eda236 capture dist 2022-12-14 16:29:09 -06:00
Matt Walsh
deb107e4ec 5.9.0 2022-12-14 16:28:47 -06:00
Matt Walsh
111f077e20 add hazards 2022-12-14 16:28:33 -06:00
Matt Walsh
806ef91000 fullscreen element fix 2022-12-14 13:32:55 -06:00
Matt Walsh
2a577aaea7 code cleanup 2022-12-14 13:08:49 -06:00
Matt Walsh
49296e53f0 make gulp output easier to read 2022-12-14 11:22:55 -06:00
30 changed files with 284 additions and 56 deletions

2
dist/index.html vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -71,6 +71,7 @@ gulp.task('compress_js_vendor', () => gulp.src(jsVendorSources)
const mjsSources = [
'server/scripts/modules/currentweatherscroll.mjs',
'server/scripts/modules/hazards.mjs',
'server/scripts/modules/currentweather.mjs',
'server/scripts/modules/almanac.mjs',
'server/scripts/modules/icons.mjs',
@@ -164,4 +165,6 @@ gulp.task('invalidate', async () => cloudfront.createInvalidation({
},
}).promise());
module.exports = gulp.series(clean, gulp.parallel('build_js', 'compress_js_data', 'compress_js_vendor', 'copy_css', 'compress_html', 'copy_other_files'), gulp.parallel('upload', 'upload_images'), 'invalidate');
// upload_images could be in parallel with upload, but _images logs a lot and has little changes
// by running upload last the majority of the changes will be at the bottom of the log for easy viewing
module.exports = gulp.series(clean, gulp.parallel('build_js', 'compress_js_data', 'compress_js_vendor', 'copy_css', 'compress_html', 'copy_other_files'), 'upload_images', 'upload', 'invalidate');

4
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{
"name": "ws4kp",
"version": "5.8.0",
"version": "5.9.1",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "ws4kp",
"version": "5.8.0",
"version": "5.9.1",
"license": "MIT",
"dependencies": {
"eslint": "^8.21.0",

View File

@@ -1,6 +1,6 @@
{
"name": "ws4kp",
"version": "5.8.0",
"version": "5.9.1",
"description": "Welcome to the WeatherStar 4000+ project page!",
"main": "index.js",
"scripts": {

View File

@@ -90,8 +90,8 @@ const init = () => {
btnGetGpsClick();
}
const twcPlay = localStorage.getItem('play');
if (twcPlay === null || twcPlay === 'true') postMessage('navButton', 'play');
const play = localStorage.getItem('play');
if (play === null || play === 'true') postMessage('navButton', 'play');
document.getElementById('btnClearQuery').addEventListener('click', () => {
document.getElementById('spanCity').innerHTML = '';

View File

@@ -171,7 +171,7 @@ const imageName = (type) => {
};
// register display
const display = new Almanac(8, 'almanac');
const display = new Almanac(9, 'almanac');
registerDisplay(display);
export default display.getSun.bind(display);

View File

@@ -64,7 +64,7 @@ class CurrentWeather extends WeatherDisplay {
// test for data received
if (!observations) {
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
this.getDataCallback(undefined);
return;
@@ -204,7 +204,7 @@ const shortConditions = (_condition) => {
return condition;
};
const display = new CurrentWeather(0, 'current-weather');
const display = new CurrentWeather(1, 'current-weather');
registerDisplay(display);
export default display.getCurrentWeather.bind(display);

View File

@@ -163,4 +163,4 @@ const shortenExtendedForecastText = (long) => {
};
// register display
registerDisplay(new ExtendedForecast(7, 'extended-forecast'));
registerDisplay(new ExtendedForecast(8, 'extended-forecast'));

View File

@@ -0,0 +1,136 @@
// hourly forecast list
import STATUS from './status.mjs';
import { json } from './utils/fetch.mjs';
import WeatherDisplay from './weatherdisplay.mjs';
import { registerDisplay } from './navigation.mjs';
const hazardLevels = {
Extreme: 10,
Severe: 5,
};
class Hazards extends WeatherDisplay {
constructor(navId, elemId, defaultActive) {
// special height and width for scrolling
super(navId, elemId, 'Hazards', defaultActive);
this.showOnProgress = false;
// 0 screens skips this during "play"
this.timing.totalScreens = 0;
}
async getData(weatherParameters) {
// super checks for enabled
const superResult = super.getData(weatherParameters);
const alert = this.checkbox.querySelector('.alert');
alert.classList.remove('show');
try {
// get the forecast
const url = new URL('https://api.weather.gov/alerts/active');
url.searchParams.append('point', `${this.weatherParameters.latitude},${this.weatherParameters.longitude}`);
url.searchParams.append('limit', 5);
const alerts = await json(url, { retryCount: 3, stillWaiting: () => this.stillWaiting() });
const unsortedAlerts = alerts.features ?? [];
const sortedAlerts = unsortedAlerts.sort((a, b) => (hazardLevels[b.properties.severity] ?? 0) - (hazardLevels[a.properties.severity] ?? 0));
const filteredAlerts = sortedAlerts.filter((hazard) => hazard.properties.severity !== 'Unknown');
this.data = filteredAlerts;
// show alert indicator
if (this.data.length > 0) alert.classList.add('show');
} catch (e) {
console.error('Get hourly forecast failed');
console.error(e.status, e.responseJSON);
if (this.isEnabled) this.setStatus(STATUS.failed);
// return undefined to other subscribers
this.getDataCallback(undefined);
return;
}
this.getDataCallback();
if (!superResult) return;
this.drawLongCanvas();
}
async drawLongCanvas() {
// get the list element and populate
const list = this.elem.querySelector('.hazard-lines');
list.innerHTML = '';
const lines = this.data.map((data) => {
const fillValues = {};
// text
fillValues['hazard-text'] = `${data.properties.event}<br/><br/>${data.properties.description.replace('\n', '<br/><br/>')}`;
return this.fillTemplate('hazard', fillValues);
});
list.append(...lines);
// no alerts, skip this display by setting timing to zero
if (lines.length === 0) {
this.timing.totalScreens = 0;
this.setStatus(STATUS.loaded);
return;
}
// update timing
// set up the timing
this.timing.baseDelay = 20;
// 24 hours = 6 pages
const pages = Math.ceil(list.scrollHeight / 390); // first page is already displayed, last page doesn't happen
const timingStep = 75 * 4;
this.timing.delay = [150 + timingStep];
// add additional pages
for (let i = 0; i < pages; i += 1) this.timing.delay.push(timingStep);
// add the final 3 second delay
this.timing.delay.push(150);
this.calcNavTiming();
this.setStatus(STATUS.loaded);
}
drawCanvas() {
super.drawCanvas();
this.finishDraw();
}
showCanvas() {
// special to hourly to draw the remainder of the canvas
this.drawCanvas();
super.showCanvas();
}
// screen index change callback just runs the base count callback
screenIndexChange() {
this.baseCountChange(this.navBaseCount);
}
// base count change callback
baseCountChange(count) {
// calculate scroll offset and don't go past end
let offsetY = Math.min(this.elem.querySelector('.hazard-lines').getBoundingClientRect().height - 390, (count - 150));
// don't let offset go negative
if (offsetY < 0) offsetY = 0;
// copy the scrolled portion of the canvas
this.elem.querySelector('.main').scrollTo(0, offsetY);
}
// make data available outside this class
// promise allows for data to be requested before it is available
async getCurrentData(stillWaiting) {
if (stillWaiting) this.stillWaitingCallbacks.push(stillWaiting);
return new Promise((resolve) => {
if (this.data) resolve(this.data);
// data not available, put it into the data callback queue
this.getDataCallbacks.push(() => resolve(this.data));
});
}
}
// register display
registerDisplay(new Hazards(0, 'hazards', true));

View File

@@ -146,4 +146,4 @@ const drawPath = (path, ctx, options) => {
const formatTime = (time) => time.toFormat('ha').slice(0, -1);
// register display
registerDisplay(new HourlyGraph(3, 'hourly-graph'));
registerDisplay(new HourlyGraph(4, 'hourly-graph'));

View File

@@ -37,7 +37,7 @@ class Hourly extends WeatherDisplay {
} catch (e) {
console.error('Get hourly forecast failed');
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
this.getDataCallback(undefined);
return;
@@ -191,7 +191,7 @@ const expand = (data) => {
};
// register display
const display = new Hourly(2, 'hourly', false);
const display = new Hourly(3, 'hourly', false);
registerDisplay(display);
export default display.getCurrentData.bind(display);

View File

@@ -120,4 +120,4 @@ const shortenCurrentConditions = (_condition) => {
return condition;
};
// register display
registerDisplay(new LatestObservations(1, 'latest-observations'));
registerDisplay(new LatestObservations(2, 'latest-observations'));

View File

@@ -92,4 +92,4 @@ const parse = (forecast) => forecast.properties.periods.slice(0, 6).map((text) =
Text: text.detailedForecast,
}));
// register display
registerDisplay(new LocalForecast(6, 'local-forecast'));
registerDisplay(new LocalForecast(7, 'local-forecast'));

View File

@@ -26,8 +26,8 @@ const init = async () => {
resize();
// auto refresh
const TwcAutoRefresh = localStorage.getItem('TwcAutoRefresh');
if (!TwcAutoRefresh || TwcAutoRefresh === 'true') {
const autoRefresh = localStorage.getItem('autoRefresh');
if (!autoRefresh || autoRefresh === 'true') {
document.getElementById('chkAutoRefresh').checked = true;
} else {
document.getElementById('chkAutoRefresh').checked = false;
@@ -65,6 +65,7 @@ const getWeather = async (latLon, haveDataCallback) => {
if (StationId in StationInfo) {
city = StationInfo[StationId].city;
[city] = city.split('/');
city = city.replace(/\s+$/, '');
}
// populate the weather parameters
@@ -102,8 +103,11 @@ const updateStatus = (value) => {
if (!progress) return;
progress.drawCanvas(displays, countLoadedDisplays());
// first display is hazards and it must load before evaluating the first display
if (displays[0].status === STATUS.loading) return;
// calculate first enabled display
const firstDisplayIndex = displays.findIndex((display) => display.enabled);
const firstDisplayIndex = displays.findIndex((display) => display.enabled && display.timing.totalScreens > 0);
// if this is the first display and we're playing, load it up so it starts playing
if (isPlaying() && value.id === firstDisplayIndex && value.status === STATUS.loaded) {
@@ -164,7 +168,7 @@ const navTo = (direction) => {
let firstDisplay;
let displayCount = 0;
do {
if (displays[displayCount].status === STATUS.loaded) firstDisplay = displays[displayCount];
if (displays[displayCount].status === STATUS.loaded && displays[displayCount].timing.totalScreens > 0) firstDisplay = displays[displayCount];
displayCount += 1;
} while (!firstDisplay && displayCount < displays.length);
@@ -185,7 +189,7 @@ const loadDisplay = (direction) => {
for (let i = 0; i < totalDisplays; i += 1) {
// convert form simple 0-10 to start at current display index +/-1 and wrap
idx = wrap(curIdx + (i + 1) * direction, totalDisplays);
if (displays[idx].status === STATUS.loaded) break;
if (displays[idx].status === STATUS.loaded && displays[idx].timing.totalScreens > 0) break;
}
// if new display index is less than current display a wrap occurred, test for reload timeout
if (idx <= curIdx) {
@@ -201,7 +205,7 @@ const loadDisplay = (direction) => {
// get the current display index or value
const currentDisplayIndex = () => {
const index = displays.findIndex((display) => display.isActive());
const index = displays.findIndex((display) => display.active);
return index;
};
const currentDisplay = () => displays[currentDisplayIndex()];
@@ -209,7 +213,7 @@ const currentDisplay = () => displays[currentDisplayIndex()];
const setPlaying = (newValue) => {
playing = newValue;
const playButton = document.getElementById('NavigatePlay');
localStorage.setItem('TwcPlay', playing);
localStorage.setItem('play', playing);
if (playing) {
noSleep(true);
@@ -260,9 +264,8 @@ const getDisplay = (index) => displays[index];
// resize the container on a page resize
const resize = () => {
const marginOffset = (document.fullscreenElement) ? 0 : 16;
const widthZoomPercent = (window.innerWidth - marginOffset) / 640;
const heightZoomPercent = (window.innerHeight - marginOffset) / 480;
const widthZoomPercent = (document.getElementById('divTwcBottom').getBoundingClientRect().width) / 640;
const heightZoomPercent = (window.innerHeight) / 480;
const scale = Math.min(widthZoomPercent, heightZoomPercent);
if (scale < 1.0 || document.fullscreenElement) {
@@ -319,7 +322,7 @@ const autoRefreshChange = (e) => {
stopAutoRefreshTimer();
}
localStorage.setItem('TwcAutoRefresh', checked);
localStorage.setItem('autoRefresh', checked);
};
const AssignLastUpdate = (date) => {

View File

@@ -26,6 +26,7 @@ class Progress extends WeatherDisplay {
}
async drawCanvas(displays, loadedCount) {
if (!this.elem) return;
super.drawCanvas();
// get the progress bar cover (makes percentage)
@@ -34,6 +35,7 @@ class Progress extends WeatherDisplay {
// if no displays provided just draw the backgrounds (above)
if (!displays) return;
const lines = displays.map((display, index) => {
if (display.showOnProgress === false) return false;
const fill = {};
fill.name = display.name;

View File

@@ -222,4 +222,4 @@ class Radar extends WeatherDisplay {
}
// register display
registerDisplay(new Radar(9, 'radar'));
registerDisplay(new Radar(10, 'radar'));

View File

@@ -204,4 +204,4 @@ const getAndFormatPoint = async (lat, lon) => {
};
// register display
registerDisplay(new RegionalForecast(5, 'regional-forecast'));
registerDisplay(new RegionalForecast(6, 'regional-forecast'));

View File

@@ -158,4 +158,4 @@ const getTravelCitiesDayName = (cities) => cities.reduce((dayName, city) => {
}, '');
// register display, not active by default
registerDisplay(new TravelForecast(4, 'travel', false));
registerDisplay(new TravelForecast(5, 'travel', false));

View File

@@ -12,7 +12,6 @@ class WeatherDisplay {
// navId is used in messaging and sort order
this.navId = navId;
this.elemId = undefined;
this.gifs = [];
this.data = undefined;
this.loadingStatus = STATUS.loading;
this.name = name ?? elemId;
@@ -21,6 +20,7 @@ class WeatherDisplay {
this.defaultEnabled = defaultEnabled;
this.okToDrawCurrentConditions = true;
this.okToDrawCurrentDateTime = true;
this.showOnProgress = true;
// default navigation timing
this.timing = {
@@ -34,7 +34,7 @@ class WeatherDisplay {
// store elemId once
this.storeElemId(elemId);
if (this.enabled) {
if (this.isEnabled) {
this.setStatus(STATUS.loading);
} else {
this.setStatus(STATUS.disabled);
@@ -55,13 +55,13 @@ class WeatherDisplay {
let savedStatus = window.localStorage.getItem(`display-enabled: ${this.elemId}`);
if (savedStatus === null) savedStatus = defaultEnabled;
if (savedStatus === 'true' || savedStatus === true) {
this.enabled = true;
this.isEnabled = true;
} else {
this.enabled = false;
this.isEnabled = false;
}
// 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
const label = document.createElement('label');
@@ -72,12 +72,15 @@ class WeatherDisplay {
checkbox.value = true;
checkbox.id = `${this.elemId}-checkbox`;
checkbox.name = `${this.elemId}-checkbox`;
checkbox.checked = this.enabled;
checkbox.checked = this.isEnabled;
checkbox.addEventListener('change', (e) => this.checkboxChange(e));
const span = document.createElement('span');
span.innerHTML = this.name;
const alert = document.createElement('span');
alert.innerHTML = '!!!';
alert.classList.add('alert');
label.append(checkbox, span);
label.append(checkbox, span, alert);
this.checkbox = label;
@@ -86,9 +89,9 @@ class WeatherDisplay {
checkboxChange(e) {
// update the state
this.enabled = e.target.checked;
this.isEnabled = e.target.checked;
// 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
this.getData();
}
@@ -130,7 +133,7 @@ class WeatherDisplay {
if (weatherParameters) this.weatherParameters = weatherParameters;
// set status
if (this.enabled) {
if (this.isEnabled) {
this.setStatus(STATUS.loading);
} else {
this.setStatus(STATUS.disabled);
@@ -168,7 +171,7 @@ class WeatherDisplay {
drawCurrentDateTime() {
// only draw if canvas is active to conserve battery
if (!this.isActive()) return;
if (!this.active) return;
// Get the current date and time.
const now = DateTime.local();
@@ -205,12 +208,12 @@ class WeatherDisplay {
this.elem.classList.remove('show');
}
isActive() {
get active() {
return this.elem.offsetHeight !== 0;
}
isEnabled() {
return this.enabled;
get enabled() {
return this.isEnabled;
}
// navigation timings
@@ -223,7 +226,7 @@ class WeatherDisplay {
// if the array forms are used totalScreens is overwritten by the size of the array
navBaseTime() {
// see if play is active and screen is active
if (!isPlaying() || !this.isActive()) return;
if (!isPlaying() || !this.active) return;
// increment the base count
this.navBaseCount += 1;
@@ -258,10 +261,10 @@ class WeatherDisplay {
// call the appropriate screen index change method
if (!this.screenIndexChange) {
await this.drawCanvas();
this.showCanvas();
} else {
this.screenIndexChange(this.screenIndex);
}
this.showCanvas();
}
// take the three timing formats shown above and break them into arrays for consistent usage in navigation functions
@@ -341,6 +344,7 @@ class WeatherDisplay {
screenIndexFromBaseCount() {
// test for timing enabled
if (!this.timing) return 0;
if (this.timing.totalScreens === 0) return false;
// find the first timing in the timing array that is greater than the base count
if (this.timing && !this.timing.fullDelay) this.calcNavTiming();
const timingIndex = this.timing.fullDelay.findIndex((delay) => delay > this.navBaseCount);
@@ -412,7 +416,7 @@ class WeatherDisplay {
// still waiting for data (retries triggered)
stillWaiting() {
if (this.enabled) this.setStatus(STATUS.retrying);
if (this.isEnabled) this.setStatus(STATUS.retrying);
// handle still waiting callbacks
this.stillWaitingCallbacks.forEach((callback) => callback());
this.stillWaitingCallbacks = [];

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,27 @@
@use 'shared/_colors'as c;
@use 'shared/_utils'as u;
.weather-display .main.hazards {
&.main {
overflow-y: hidden;
.hazard-lines {
min-height: 400px;
padding-top: 10px;
background-color: rgb(112, 35, 35);
.hazard {
font-family: 'Star4000';
font-size: 24pt;
color: white;
@include u.text-shadow(0px);
position: relative;
text-transform: uppercase;
margin-top: 110px;
margin-left: 80px;
margin-right: 80px;
}
}
}
}

View File

@@ -270,9 +270,11 @@ button {
#container {
position: relative;
width: 100%;
height: 100%;
width: 640px;
height: 480px;
overflow: hidden;
background-image: url(../images/BackGround1_1.png);
}
#divTwc:fullscreen #container {
@@ -316,14 +318,47 @@ button {
margin-bottom: 15px;
@include u.status-colors();
@media (prefers-color-scheme: light) {
.loading,
.retrying {
color: hsl(60, 100%, 30%);
}
.press-here {
color: hsl(120, 100%, 30%);
cursor: pointer;
}
.failed {
color: hsl(0, 100%, 30%);
}
.no-data {
color: hsl(0, 0%, 30%);
}
.disabled {
color: hsl(0, 0%, 30%);
}
}
.press-here {
color: white;
color: black;
}
label {
display: block;
max-width: 300px;
.alert {
display: none;
&.show {
display: inline;
color: red;
}
}
}
}

View File

@@ -96,6 +96,10 @@
width: 640px;
height: 310px;
overflow: hidden;
&.no-header {
height: 400px;
}
}
&.has-box {

View File

@@ -10,4 +10,5 @@
@import 'progress';
@import 'radar';
@import 'regional-forecast';
@import 'almanac';
@import 'almanac';
@import 'hazards';

View File

@@ -28,6 +28,7 @@
<script type="text/javascript" src="scripts/vendor/auto/nosleep.js"></script>
<script type="text/javascript" src="scripts/vendor/auto/swiped-events.js"></script>
<script type="text/javascript" src="scripts/vendor/auto/suncalc.js"></script>
<script type="module" src="scripts/modules/hazards.mjs"></script>
<script type="module" src="scripts/modules/currentweatherscroll.mjs"></script>
<script type="module" src="scripts/modules/currentweather.mjs"></script>
<script type="module" src="scripts/modules/almanac.mjs"></script>
@@ -41,6 +42,7 @@
<script type="module" src="scripts/modules/regionalforecast.mjs"></script>
<script type="module" src="scripts/modules/travelforecast.mjs"></script>
<script type="module" src="scripts/modules/progress.mjs"></script>
<script type="module" src="scripts/modules/radar.mjs"></script>
<script type="module" src="scripts/index.mjs"></script>
<!-- data -->
@@ -117,6 +119,9 @@
<div id="radar-html" class="weather-display">
<%- include('partials/radar.ejs') %>
</div>
<div id="hazards-html" class="weather-display show">
<%- include('partials/hazards.ejs') %>
</div>
</div>
<div id="divTwcBottom">
<div id="divTwcBottomLeft">

View File

@@ -0,0 +1,8 @@
<div class="main has-scroll hazards no-header">
<div class="hazard-lines">
<div class="hazard template">
<div class="hazard-text"></div>
</div>
</div>
</div>
<%- include('scroll.ejs') %>