mirror of
https://github.com/netbymatt/ws4kp.git
synced 2026-04-17 17:19:30 -07:00
Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
703d64f6b2 | ||
|
|
e5a18ea073 | ||
|
|
e326c3464b | ||
|
|
c3e38b4077 | ||
|
|
eb11feb964 | ||
|
|
b2aca1ee8d | ||
|
|
5b257ace55 | ||
|
|
5dd8f4bd62 | ||
|
|
76fd93e6e1 |
2
dist/index.html
vendored
2
dist/index.html
vendored
File diff suppressed because one or more lines are too long
2
dist/resources/ws.min.js
vendored
2
dist/resources/ws.min.js
vendored
File diff suppressed because one or more lines are too long
4
package-lock.json
generated
4
package-lock.json
generated
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "ws4kp",
|
"name": "ws4kp",
|
||||||
"version": "5.4.3",
|
"version": "5.5.3",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "ws4kp",
|
"name": "ws4kp",
|
||||||
"version": "5.4.3",
|
"version": "5.5.3",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"eslint": "^8.21.0",
|
"eslint": "^8.21.0",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "ws4kp",
|
"name": "ws4kp",
|
||||||
"version": "5.4.3",
|
"version": "5.5.3",
|
||||||
"description": "Welcome to the WeatherStar 4000+ project page!",
|
"description": "Welcome to the WeatherStar 4000+ project page!",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@@ -3,15 +3,13 @@ import noSleep from './modules/utils/nosleep.mjs';
|
|||||||
import {
|
import {
|
||||||
message as navMessage, isPlaying, resize, resetStatuses, latLonReceived, stopAutoRefreshTimer, registerRefreshData,
|
message as navMessage, isPlaying, resize, resetStatuses, latLonReceived, stopAutoRefreshTimer, registerRefreshData,
|
||||||
} from './modules/navigation.mjs';
|
} from './modules/navigation.mjs';
|
||||||
|
import { round2 } from './modules/utils/units.mjs';
|
||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', () => {
|
document.addEventListener('DOMContentLoaded', () => {
|
||||||
init();
|
init();
|
||||||
});
|
});
|
||||||
|
|
||||||
const overrides = {};
|
let fullScreenOverride = false;
|
||||||
|
|
||||||
let AutoSelectQuery = false;
|
|
||||||
let FullScreenOverride = false;
|
|
||||||
|
|
||||||
const categories = [
|
const categories = [
|
||||||
'Land Features',
|
'Land Features',
|
||||||
@@ -30,7 +28,7 @@ const init = () => {
|
|||||||
e.target.select();
|
e.target.select();
|
||||||
});
|
});
|
||||||
|
|
||||||
registerRefreshData(LoadTwcData);
|
registerRefreshData(loadData);
|
||||||
|
|
||||||
document.getElementById('NavigateMenu').addEventListener('click', btnNavigateMenuClick);
|
document.getElementById('NavigateMenu').addEventListener('click', btnNavigateMenuClick);
|
||||||
document.getElementById('NavigateRefresh').addEventListener('click', btnNavigateRefreshClick);
|
document.getElementById('NavigateRefresh').addEventListener('click', btnNavigateRefreshClick);
|
||||||
@@ -41,11 +39,11 @@ const init = () => {
|
|||||||
document.getElementById('btnGetGps').addEventListener('click', btnGetGpsClick);
|
document.getElementById('btnGetGps').addEventListener('click', btnGetGpsClick);
|
||||||
|
|
||||||
document.getElementById('divTwc').addEventListener('click', () => {
|
document.getElementById('divTwc').addEventListener('click', () => {
|
||||||
if (document.fullscreenElement) UpdateFullScreenNavigate();
|
if (document.fullscreenElement) updateFullScreenNavigate();
|
||||||
});
|
});
|
||||||
|
|
||||||
document.addEventListener('keydown', documentKeydown);
|
document.addEventListener('keydown', documentKeydown);
|
||||||
document.addEventListener('touchmove', (e) => { if (FullScreenOverride) e.preventDefault(); });
|
document.addEventListener('touchmove', (e) => { if (fullScreenOverride) e.preventDefault(); });
|
||||||
|
|
||||||
$('#frmGetLatLng #txtAddress').devbridgeAutocomplete({
|
$('#frmGetLatLng #txtAddress').devbridgeAutocomplete({
|
||||||
serviceUrl: 'https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/suggest',
|
serviceUrl: 'https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/suggest',
|
||||||
@@ -58,21 +56,12 @@ const init = () => {
|
|||||||
maxSuggestions: 10,
|
maxSuggestions: 10,
|
||||||
},
|
},
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
transformResult: (response) => {
|
transformResult: (response) => ({
|
||||||
if (AutoSelectQuery) {
|
suggestions: response.suggestions.map((i) => ({
|
||||||
AutoSelectQuery = false;
|
value: i.text,
|
||||||
window.setTimeout(() => {
|
data: i.magicKey,
|
||||||
$(ac.suggestionsContainer.children[0]).click();
|
})),
|
||||||
}, 1);
|
}),
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
suggestions: $.map(response.suggestions, (i) => ({
|
|
||||||
value: i.text,
|
|
||||||
data: i.magicKey,
|
|
||||||
})),
|
|
||||||
};
|
|
||||||
},
|
|
||||||
minChars: 3,
|
minChars: 3,
|
||||||
showNoSuggestionNotice: true,
|
showNoSuggestionNotice: true,
|
||||||
noSuggestionNotice: 'No results found. Please try a different search string.',
|
noSuggestionNotice: 'No results found. Please try a different search string.',
|
||||||
@@ -80,24 +69,23 @@ const init = () => {
|
|||||||
width: 490,
|
width: 490,
|
||||||
});
|
});
|
||||||
|
|
||||||
const ac = $('#frmGetLatLng #txtAddress').devbridgeAutocomplete();
|
|
||||||
$('#frmGetLatLng').on('submit', () => {
|
$('#frmGetLatLng').on('submit', () => {
|
||||||
if (ac.suggestions[0]) $(ac.suggestionsContainer.children[0]).click();
|
const ac = $('#frmGetLatLng #txtAddress').devbridgeAutocomplete();
|
||||||
|
if (ac.suggestions[0]) $(ac.suggestionsContainer.children[0]).trigger('click');
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Auto load the previous query
|
// Auto load the previous query
|
||||||
const TwcQuery = localStorage.getItem('TwcQuery');
|
const query = localStorage.getItem('latLonQuery');
|
||||||
if (TwcQuery) {
|
const latLon = localStorage.getItem('latLonLon');
|
||||||
AutoSelectQuery = true;
|
if (query && latLon) {
|
||||||
const txtAddress = document.getElementById('txtAddress');
|
const txtAddress = document.getElementById('txtAddress');
|
||||||
txtAddress.value = TwcQuery;
|
txtAddress.value = query;
|
||||||
txtAddress.blur();
|
loadData(JSON.parse(latLon));
|
||||||
txtAddress.focus();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const TwcPlay = localStorage.getItem('TwcPlay');
|
const twcPlay = localStorage.getItem('play');
|
||||||
if (TwcPlay === null || TwcPlay === 'true') postMessage('navButton', 'play');
|
if (twcPlay === null || twcPlay === 'true') postMessage('navButton', 'play');
|
||||||
|
|
||||||
document.getElementById('btnClearQuery').addEventListener('click', () => {
|
document.getElementById('btnClearQuery').addEventListener('click', () => {
|
||||||
document.getElementById('spanCity').innerHTML = '';
|
document.getElementById('spanCity').innerHTML = '';
|
||||||
@@ -106,18 +94,14 @@ const init = () => {
|
|||||||
document.getElementById('spanRadarId').innerHTML = '';
|
document.getElementById('spanRadarId').innerHTML = '';
|
||||||
document.getElementById('spanZoneId').innerHTML = '';
|
document.getElementById('spanZoneId').innerHTML = '';
|
||||||
|
|
||||||
localStorage.removeItem('TwcScrollText');
|
|
||||||
localStorage.removeItem('TwcScrollTextChecked');
|
|
||||||
|
|
||||||
document.getElementById('chkAutoRefresh').checked = true;
|
document.getElementById('chkAutoRefresh').checked = true;
|
||||||
localStorage.removeItem('TwcAutoRefresh');
|
localStorage.removeItem('autoRefresh');
|
||||||
|
|
||||||
document.getElementById('radEnglish').checked = true;
|
localStorage.removeItem('play');
|
||||||
|
|
||||||
localStorage.removeItem('TwcPlay');
|
|
||||||
postMessage('navButton', 'play');
|
postMessage('navButton', 'play');
|
||||||
|
|
||||||
localStorage.removeItem('TwcQuery');
|
localStorage.removeItem('latLonQuery');
|
||||||
|
localStorage.removeItem('latLonLon');
|
||||||
});
|
});
|
||||||
|
|
||||||
// swipe functionality
|
// swipe functionality
|
||||||
@@ -129,38 +113,37 @@ const autocompleteOnSelect = async (suggestion, elem) => {
|
|||||||
// Do not auto get the same city twice.
|
// Do not auto get the same city twice.
|
||||||
if (elem.previousSuggestionValue === suggestion.value) return;
|
if (elem.previousSuggestionValue === suggestion.value) return;
|
||||||
|
|
||||||
if (overrides[suggestion.value]) {
|
const data = await json('https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/find', {
|
||||||
doRedirectToGeometry(overrides[suggestion.value]);
|
data: {
|
||||||
} else {
|
text: suggestion.value,
|
||||||
const data = await json('https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/find', {
|
magicKey: suggestion.data,
|
||||||
data: {
|
f: 'json',
|
||||||
text: suggestion.value,
|
},
|
||||||
magicKey: suggestion.data,
|
});
|
||||||
f: 'json',
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const loc = data.locations[0];
|
const loc = data.locations[0];
|
||||||
if (loc) {
|
if (loc) {
|
||||||
doRedirectToGeometry(loc.feature.geometry);
|
doRedirectToGeometry(loc.feature.geometry);
|
||||||
} else {
|
} else {
|
||||||
console.error('An unexpected error occurred. Please try a different search string.');
|
console.error('An unexpected error occurred. Please try a different search string.');
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const doRedirectToGeometry = (geom) => {
|
const doRedirectToGeometry = (geom) => {
|
||||||
const latLon = { lat: Math.round2(geom.y, 4), lon: Math.round2(geom.x, 4) };
|
const latLon = { lat: round2(geom.y, 4), lon: round2(geom.x, 4) };
|
||||||
LoadTwcData(latLon);
|
|
||||||
// Save the query
|
// Save the query
|
||||||
localStorage.setItem('TwcQuery', document.getElementById('txtAddress').value);
|
localStorage.setItem('latLonQuery', document.getElementById('txtAddress').value);
|
||||||
|
localStorage.setItem('latLonLon', JSON.stringify(latLon));
|
||||||
|
|
||||||
|
// get the data
|
||||||
|
loadData(latLon);
|
||||||
};
|
};
|
||||||
|
|
||||||
const btnFullScreenClick = () => {
|
const btnFullScreenClick = () => {
|
||||||
if (!document.fullscreenElement) {
|
if (!document.fullscreenElement) {
|
||||||
EnterFullScreen();
|
enterFullScreen();
|
||||||
} else {
|
} else {
|
||||||
ExitFullscreen();
|
exitFullscreen();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isPlaying()) {
|
if (isPlaying()) {
|
||||||
@@ -169,12 +152,12 @@ const btnFullScreenClick = () => {
|
|||||||
noSleep(false);
|
noSleep(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
UpdateFullScreenNavigate();
|
updateFullScreenNavigate();
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
const EnterFullScreen = () => {
|
const enterFullScreen = () => {
|
||||||
const element = document.getElementById('divTwc');
|
const element = document.getElementById('divTwc');
|
||||||
|
|
||||||
// Supports most browsers and their versions.
|
// Supports most browsers and their versions.
|
||||||
@@ -187,10 +170,10 @@ const EnterFullScreen = () => {
|
|||||||
} else {
|
} else {
|
||||||
// iOS doesn't support FullScreen API.
|
// iOS doesn't support FullScreen API.
|
||||||
window.scrollTo(0, 0);
|
window.scrollTo(0, 0);
|
||||||
FullScreenOverride = true;
|
fullScreenOverride = true;
|
||||||
}
|
}
|
||||||
resize();
|
resize();
|
||||||
UpdateFullScreenNavigate();
|
updateFullScreenNavigate();
|
||||||
|
|
||||||
// change hover text and image
|
// change hover text and image
|
||||||
const img = document.getElementById('ToggleFullScreen');
|
const img = document.getElementById('ToggleFullScreen');
|
||||||
@@ -198,11 +181,11 @@ const EnterFullScreen = () => {
|
|||||||
img.title = 'Exit fullscreen';
|
img.title = 'Exit fullscreen';
|
||||||
};
|
};
|
||||||
|
|
||||||
const ExitFullscreen = () => {
|
const exitFullscreen = () => {
|
||||||
// exit full-screen
|
// exit full-screen
|
||||||
|
|
||||||
if (FullScreenOverride) {
|
if (fullScreenOverride) {
|
||||||
FullScreenOverride = false;
|
fullScreenOverride = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (document.exitFullscreen) {
|
if (document.exitFullscreen) {
|
||||||
@@ -224,15 +207,15 @@ const ExitFullscreen = () => {
|
|||||||
|
|
||||||
const btnNavigateMenuClick = () => {
|
const btnNavigateMenuClick = () => {
|
||||||
postMessage('navButton', 'menu');
|
postMessage('navButton', 'menu');
|
||||||
UpdateFullScreenNavigate();
|
updateFullScreenNavigate();
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
const LoadTwcData = (_latLon) => {
|
const loadData = (_latLon) => {
|
||||||
// if latlon is provided store it locally
|
// if latlon is provided store it locally
|
||||||
if (_latLon) LoadTwcData.latLon = _latLon;
|
if (_latLon) loadData.latLon = _latLon;
|
||||||
// get the data
|
// get the data
|
||||||
const { latLon } = LoadTwcData;
|
const { latLon } = loadData;
|
||||||
// if there's no data stop
|
// if there's no data stop
|
||||||
if (!latLon) return;
|
if (!latLon) return;
|
||||||
|
|
||||||
@@ -256,39 +239,39 @@ const swipeCallBack = (direction) => {
|
|||||||
|
|
||||||
const btnNavigateRefreshClick = () => {
|
const btnNavigateRefreshClick = () => {
|
||||||
resetStatuses();
|
resetStatuses();
|
||||||
LoadTwcData();
|
loadData();
|
||||||
UpdateFullScreenNavigate();
|
updateFullScreenNavigate();
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
const btnNavigateNextClick = () => {
|
const btnNavigateNextClick = () => {
|
||||||
postMessage('navButton', 'next');
|
postMessage('navButton', 'next');
|
||||||
UpdateFullScreenNavigate();
|
updateFullScreenNavigate();
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
const btnNavigatePreviousClick = () => {
|
const btnNavigatePreviousClick = () => {
|
||||||
postMessage('navButton', 'previous');
|
postMessage('navButton', 'previous');
|
||||||
UpdateFullScreenNavigate();
|
updateFullScreenNavigate();
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
let NavigateFadeIntervalId = null;
|
let navigateFadeIntervalId = null;
|
||||||
|
|
||||||
const UpdateFullScreenNavigate = () => {
|
const updateFullScreenNavigate = () => {
|
||||||
document.activeElement.blur();
|
document.activeElement.blur();
|
||||||
document.getElementById('divTwcBottom').classList.remove('hidden');
|
document.getElementById('divTwcBottom').classList.remove('hidden');
|
||||||
document.getElementById('divTwcBottom').classList.add('visible');
|
document.getElementById('divTwcBottom').classList.add('visible');
|
||||||
|
|
||||||
if (NavigateFadeIntervalId) {
|
if (navigateFadeIntervalId) {
|
||||||
clearTimeout(NavigateFadeIntervalId);
|
clearTimeout(navigateFadeIntervalId);
|
||||||
NavigateFadeIntervalId = null;
|
navigateFadeIntervalId = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
NavigateFadeIntervalId = setTimeout(() => {
|
navigateFadeIntervalId = setTimeout(() => {
|
||||||
if (document.fullscreenElement) {
|
if (document.fullscreenElement) {
|
||||||
document.getElementById('divTwcBottom').classList.remove('visible');
|
document.getElementById('divTwcBottom').classList.remove('visible');
|
||||||
document.getElementById('divTwcBottom').classList.add('hidden');
|
document.getElementById('divTwcBottom').classList.add('hidden');
|
||||||
@@ -337,11 +320,9 @@ const documentKeydown = (e) => {
|
|||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
Math.round2 = (value, decimals) => Number(`${Math.round(`${value}e${decimals}`)}e-${decimals}`);
|
|
||||||
|
|
||||||
const btnNavigatePlayClick = () => {
|
const btnNavigatePlayClick = () => {
|
||||||
postMessage('navButton', 'playToggle');
|
postMessage('navButton', 'playToggle');
|
||||||
UpdateFullScreenNavigate();
|
updateFullScreenNavigate();
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
@@ -376,13 +357,13 @@ const btnGetGpsClick = async () => {
|
|||||||
const { City } = data.address;
|
const { City } = data.address;
|
||||||
const State = states.getTwoDigitCode(data.address.Region);
|
const State = states.getTwoDigitCode(data.address.Region);
|
||||||
const Country = data.address.CountryCode;
|
const Country = data.address.CountryCode;
|
||||||
const TwcQuery = `${ZipCode}, ${City}, ${State}, ${Country}`;
|
const query = `${ZipCode}, ${City}, ${State}, ${Country}`;
|
||||||
|
|
||||||
const txtAddress = document.getElementById('txtAddress');
|
const txtAddress = document.getElementById('txtAddress');
|
||||||
txtAddress.value = TwcQuery;
|
txtAddress.value = query;
|
||||||
txtAddress.blur();
|
txtAddress.blur();
|
||||||
txtAddress.focus();
|
txtAddress.focus();
|
||||||
|
|
||||||
// Save the query
|
// Save the query
|
||||||
localStorage.setItem('TwcQuery', TwcQuery);
|
localStorage.setItem('latLonQuery', query);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -19,7 +19,8 @@ class CurrentWeather extends WeatherDisplay {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async getData(_weatherParameters) {
|
async getData(_weatherParameters) {
|
||||||
if (!super.getData(_weatherParameters)) return;
|
// always load the data for use in the lower scroll
|
||||||
|
const superResult = super.getData(_weatherParameters);
|
||||||
const weatherParameters = _weatherParameters ?? this.weatherParameters;
|
const weatherParameters = _weatherParameters ?? this.weatherParameters;
|
||||||
|
|
||||||
// Load the observations
|
// Load the observations
|
||||||
@@ -39,6 +40,8 @@ class CurrentWeather extends WeatherDisplay {
|
|||||||
data: {
|
data: {
|
||||||
limit: 2,
|
limit: 2,
|
||||||
},
|
},
|
||||||
|
retryCount: 3,
|
||||||
|
stillWaiting: () => this.stillWaiting(),
|
||||||
});
|
});
|
||||||
|
|
||||||
// test data quality
|
// test data quality
|
||||||
@@ -60,14 +63,17 @@ class CurrentWeather extends WeatherDisplay {
|
|||||||
this.getDataCallback(undefined);
|
this.getDataCallback(undefined);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// preload the icon
|
|
||||||
preloadImg(getWeatherIconFromIconLink(observations.features[0].properties.icon));
|
|
||||||
|
|
||||||
// we only get here if there was no error above
|
// we only get here if there was no error above
|
||||||
this.data = { ...observations, station };
|
this.data = { ...observations, station };
|
||||||
this.setStatus(STATUS.loaded);
|
|
||||||
|
|
||||||
this.getDataCallback();
|
this.getDataCallback();
|
||||||
|
|
||||||
|
// stop here if we're disabled
|
||||||
|
if (!superResult) return;
|
||||||
|
|
||||||
|
// preload the icon
|
||||||
|
preloadImg(getWeatherIconFromIconLink(observations.features[0].properties.icon));
|
||||||
|
this.setStatus(STATUS.loaded);
|
||||||
}
|
}
|
||||||
|
|
||||||
// format the data for use outside this function
|
// format the data for use outside this function
|
||||||
@@ -163,7 +169,8 @@ class CurrentWeather extends WeatherDisplay {
|
|||||||
|
|
||||||
// make data available outside this class
|
// make data available outside this class
|
||||||
// promise allows for data to be requested before it is available
|
// promise allows for data to be requested before it is available
|
||||||
async getCurrentWeather() {
|
async getCurrentWeather(stillWaiting) {
|
||||||
|
if (stillWaiting) this.stillWaitingCallbacks.push(stillWaiting);
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
if (this.data) resolve(this.parseData());
|
if (this.data) resolve(this.parseData());
|
||||||
// data not available, put it into the data callback queue
|
// data not available, put it into the data callback queue
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ const incrementInterval = () => {
|
|||||||
|
|
||||||
const drawScreen = async () => {
|
const drawScreen = async () => {
|
||||||
// get the conditions
|
// get the conditions
|
||||||
const data = await getCurrentWeather();
|
const data = await getCurrentWeather(() => this.stillWaiting());
|
||||||
|
|
||||||
// nothing to do if there's no data yet
|
// nothing to do if there's no data yet
|
||||||
if (!data) return;
|
if (!data) return;
|
||||||
|
|||||||
@@ -28,6 +28,8 @@ class ExtendedForecast extends WeatherDisplay {
|
|||||||
data: {
|
data: {
|
||||||
units: 'us',
|
units: 'us',
|
||||||
},
|
},
|
||||||
|
retryCount: 3,
|
||||||
|
stillWaiting: () => this.stillWaiting(),
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('Unable to get extended forecast');
|
console.error('Unable to get extended forecast');
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ class HourlyGraph extends WeatherDisplay {
|
|||||||
async getData() {
|
async getData() {
|
||||||
if (!super.getData()) return;
|
if (!super.getData()) return;
|
||||||
|
|
||||||
const data = await getHourlyData();
|
const data = await getHourlyData(() => this.stillWaiting());
|
||||||
if (data === undefined) {
|
if (data === undefined) {
|
||||||
this.setStatus(STATUS.failed);
|
this.setStatus(STATUS.failed);
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ class Hourly extends WeatherDisplay {
|
|||||||
let forecast;
|
let forecast;
|
||||||
try {
|
try {
|
||||||
// get the forecast
|
// get the forecast
|
||||||
forecast = await json(weatherParameters.forecastGridData);
|
forecast = await json(weatherParameters.forecastGridData, { retryCount: 3, stillWaiting: () => this.stillWaiting() });
|
||||||
} 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);
|
||||||
@@ -120,7 +120,8 @@ class Hourly extends WeatherDisplay {
|
|||||||
|
|
||||||
// make data available outside this class
|
// make data available outside this class
|
||||||
// promise allows for data to be requested before it is available
|
// promise allows for data to be requested before it is available
|
||||||
async getCurrentData() {
|
async getCurrentData(stillWaiting) {
|
||||||
|
if (stillWaiting) this.stillWaitingCallbacks.push(stillWaiting);
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
if (this.data) resolve(this.data);
|
if (this.data) resolve(this.data);
|
||||||
// data not available, put it into the data callback queue
|
// data not available, put it into the data callback queue
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ class LatestObservations extends WeatherDisplay {
|
|||||||
// get data for regional stations
|
// get data for regional stations
|
||||||
const allConditions = await Promise.all(regionalStations.map(async (station) => {
|
const allConditions = await Promise.all(regionalStations.map(async (station) => {
|
||||||
try {
|
try {
|
||||||
const data = await json(`https://api.weather.gov/stations/${station.id}/observations/latest`);
|
const data = await json(`https://api.weather.gov/stations/${station.id}/observations/latest`, { retryCount: 3, stillWaiting: () => this.stillWaiting() });
|
||||||
// test for temperature, weather and wind values present
|
// test for temperature, weather and wind values present
|
||||||
if (data.properties.temperature.value === null
|
if (data.properties.temperature.value === null
|
||||||
|| data.properties.textDescription === ''
|
|| data.properties.textDescription === ''
|
||||||
|
|||||||
@@ -63,6 +63,8 @@ class LocalForecast extends WeatherDisplay {
|
|||||||
data: {
|
data: {
|
||||||
units: 'us',
|
units: 'us',
|
||||||
},
|
},
|
||||||
|
retryCount: 3,
|
||||||
|
stillWaiting: () => this.stillWaiting(),
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(`GetWeatherForecast failed: ${weatherParameters.forecast}`);
|
console.error(`GetWeatherForecast failed: ${weatherParameters.forecast}`);
|
||||||
|
|||||||
@@ -98,21 +98,27 @@ const getWeather = async (latLon) => {
|
|||||||
const updateStatus = (value) => {
|
const updateStatus = (value) => {
|
||||||
if (value.id < 0) return;
|
if (value.id < 0) return;
|
||||||
if (!progress) return;
|
if (!progress) return;
|
||||||
progress.drawCanvas(displays, countLoadedCanvases());
|
progress.drawCanvas(displays, countLoadedDisplays());
|
||||||
|
|
||||||
|
// calculate first enabled display
|
||||||
|
const firstDisplayIndex = displays.findIndex((display) => display.enabled);
|
||||||
|
|
||||||
// if this is the first display and we're playing, load it up so it starts playing
|
// if this is the first display and we're playing, load it up so it starts playing
|
||||||
if (isPlaying() && value.id === 0 && value.status === STATUS.loaded) {
|
if (isPlaying() && value.id === firstDisplayIndex && value.status === STATUS.loaded) {
|
||||||
navTo(msg.command.firstFrame);
|
navTo(msg.command.firstFrame);
|
||||||
}
|
}
|
||||||
|
|
||||||
// send loaded messaged to parent
|
// send loaded messaged to parent
|
||||||
if (countLoadedCanvases() < displays.length) return;
|
if (countLoadedDisplays() < displays.length) return;
|
||||||
|
|
||||||
// everything loaded, set timestamps
|
// everything loaded, set timestamps
|
||||||
AssignLastUpdate(new Date());
|
AssignLastUpdate(new Date());
|
||||||
};
|
};
|
||||||
|
|
||||||
const countLoadedCanvases = () => displays.reduce((acc, display) => {
|
// note: a display that is "still waiting"/"retrying" is considered loaded intentionally
|
||||||
|
// the weather.gov api has long load times for some products when you are the first
|
||||||
|
// requester for the product after the cache expires
|
||||||
|
const countLoadedDisplays = () => displays.reduce((acc, display) => {
|
||||||
if (display.status !== STATUS.loading) return acc + 1;
|
if (display.status !== STATUS.loading) return acc + 1;
|
||||||
return acc;
|
return acc;
|
||||||
}, 0);
|
}, 0);
|
||||||
|
|||||||
@@ -55,6 +55,9 @@ class Progress extends WeatherDisplay {
|
|||||||
case STATUS.disabled:
|
case STATUS.disabled:
|
||||||
statusClass = 'disabled';
|
statusClass = 'disabled';
|
||||||
break;
|
break;
|
||||||
|
case STATUS.retrying:
|
||||||
|
statusClass = 'retrying';
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ const STATUS = {
|
|||||||
failed: Symbol('failed'),
|
failed: Symbol('failed'),
|
||||||
noData: Symbol('noData'),
|
noData: Symbol('noData'),
|
||||||
disabled: Symbol('disabled'),
|
disabled: Symbol('disabled'),
|
||||||
|
retrying: Symbol('retyring'),
|
||||||
};
|
};
|
||||||
|
|
||||||
export default STATUS;
|
export default STATUS;
|
||||||
|
|||||||
@@ -11,9 +11,13 @@ const fetchAsync = async (_url, responseType, _params = {}) => {
|
|||||||
method: 'GET',
|
method: 'GET',
|
||||||
mode: 'cors',
|
mode: 'cors',
|
||||||
type: 'GET',
|
type: 'GET',
|
||||||
|
retryCount: 0,
|
||||||
..._params,
|
..._params,
|
||||||
};
|
};
|
||||||
// build a url, including the rewrite for cors if necessary
|
// store original number of retries
|
||||||
|
params.originalRetries = params.retryCount;
|
||||||
|
|
||||||
|
// build a url, including the rewrite for cors if necessary
|
||||||
let corsUrl = _url;
|
let corsUrl = _url;
|
||||||
if (params.cors === true) corsUrl = rewriteUrl(_url);
|
if (params.cors === true) corsUrl = rewriteUrl(_url);
|
||||||
const url = new URL(corsUrl, `${window.location.origin}/`);
|
const url = new URL(corsUrl, `${window.location.origin}/`);
|
||||||
@@ -30,7 +34,7 @@ const fetchAsync = async (_url, responseType, _params = {}) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// make the request
|
// make the request
|
||||||
const response = await fetch(url, params);
|
const response = await doFetch(url, params);
|
||||||
|
|
||||||
// check for ok response
|
// check for ok response
|
||||||
if (!response.ok) throw new Error(`Fetch error ${response.status} ${response.statusText} while fetching ${response.url}`);
|
if (!response.ok) throw new Error(`Fetch error ${response.status} ${response.statusText} while fetching ${response.url}`);
|
||||||
@@ -47,6 +51,48 @@ const fetchAsync = async (_url, responseType, _params = {}) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// fetch with retry and back-off
|
||||||
|
const doFetch = (url, params) => new Promise((resolve, reject) => {
|
||||||
|
fetch(url, params).then((response) => {
|
||||||
|
if (params.retryCount > 0) {
|
||||||
|
// 500 status codes should be retried after a short backoff
|
||||||
|
if (response.status >= 500 && response.status <= 599 && params.retryCount > 0) {
|
||||||
|
// call the "still waiting" function
|
||||||
|
if (typeof params.stillWaiting === 'function' && params.retryCount === params.originalRetries) {
|
||||||
|
params.stillWaiting();
|
||||||
|
}
|
||||||
|
// decrement and retry
|
||||||
|
const newParams = {
|
||||||
|
...params,
|
||||||
|
retryCount: params.retryCount - 1,
|
||||||
|
};
|
||||||
|
return resolve(delay(retryDelay(params.originalRetries - newParams.retryCount), doFetch, url, newParams));
|
||||||
|
}
|
||||||
|
// not 500 status
|
||||||
|
return resolve(response);
|
||||||
|
}
|
||||||
|
// out of retries
|
||||||
|
return resolve(response);
|
||||||
|
})
|
||||||
|
.catch((e) => reject(e));
|
||||||
|
});
|
||||||
|
|
||||||
|
const delay = (time, func, ...args) => new Promise((resolve) => {
|
||||||
|
setTimeout(() => {
|
||||||
|
resolve(func(...args));
|
||||||
|
}, time);
|
||||||
|
});
|
||||||
|
|
||||||
|
const retryDelay = (retryNumber) => {
|
||||||
|
switch (retryNumber) {
|
||||||
|
case 1: return 1000;
|
||||||
|
case 2: return 2000;
|
||||||
|
case 3: return 5000;
|
||||||
|
case 4: return 10000;
|
||||||
|
default: return 30000;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
export {
|
export {
|
||||||
json,
|
json,
|
||||||
text,
|
text,
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
// *********************************** unit conversions ***********************
|
// *********************************** unit conversions ***********************
|
||||||
|
|
||||||
const round2 = (value, decimals) => Number(`${Math.round(`${value}e${decimals}`)}e-${decimals}`);
|
const round2 = (value, decimals) => Math.trunc(value * 10 ** decimals) / 10 ** decimals;
|
||||||
|
|
||||||
const kphToMph = (Kph) => Math.round(Kph / 1.60934);
|
const kphToMph = (Kph) => Math.round(Kph / 1.60934);
|
||||||
const celsiusToFahrenheit = (Celsius) => Math.round((Celsius * 9) / 5 + 32);
|
const celsiusToFahrenheit = (Celsius) => Math.round((Celsius * 9) / 5 + 32);
|
||||||
@@ -14,4 +14,5 @@ export {
|
|||||||
kilometersToMiles,
|
kilometersToMiles,
|
||||||
metersToFeet,
|
metersToFeet,
|
||||||
pascalToInHg,
|
pascalToInHg,
|
||||||
|
round2,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ class WeatherDisplay {
|
|||||||
this.loadingStatus = STATUS.loading;
|
this.loadingStatus = STATUS.loading;
|
||||||
this.name = name ?? elemId;
|
this.name = name ?? elemId;
|
||||||
this.getDataCallbacks = [];
|
this.getDataCallbacks = [];
|
||||||
|
this.stillWaitingCallbacks = [];
|
||||||
this.defaultEnabled = defaultEnabled;
|
this.defaultEnabled = defaultEnabled;
|
||||||
this.okToDrawCurrentConditions = true;
|
this.okToDrawCurrentConditions = true;
|
||||||
this.okToDrawCurrentDateTime = true;
|
this.okToDrawCurrentDateTime = true;
|
||||||
@@ -51,7 +52,7 @@ class WeatherDisplay {
|
|||||||
if (this.elemId === 'progress') return false;
|
if (this.elemId === 'progress') return false;
|
||||||
|
|
||||||
// get the saved status of the checkbox
|
// get the saved status of the checkbox
|
||||||
let savedStatus = window.localStorage.getItem(`${this.elemId}Enabled`);
|
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.enabled = true;
|
||||||
@@ -60,7 +61,7 @@ class WeatherDisplay {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// refresh (or initially store the state of the checkbox)
|
// refresh (or initially store the state of the checkbox)
|
||||||
window.localStorage.setItem(`${this.elemId}Enabled`, this.enabled);
|
window.localStorage.setItem(`display-enabled: ${this.elemId}`, this.enabled);
|
||||||
|
|
||||||
// create a checkbox in the selected displays area
|
// create a checkbox in the selected displays area
|
||||||
const checkbox = document.createElement('template');
|
const checkbox = document.createElement('template');
|
||||||
@@ -76,7 +77,7 @@ class WeatherDisplay {
|
|||||||
// update the state
|
// update the state
|
||||||
this.enabled = e.target.checked;
|
this.enabled = e.target.checked;
|
||||||
// store the value for the next load
|
// store the value for the next load
|
||||||
window.localStorage.setItem(`${this.elemId}Enabled`, this.enabled);
|
window.localStorage.setItem(`display-enabled: ${this.elemId}`, this.enabled);
|
||||||
// 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();
|
||||||
}
|
}
|
||||||
@@ -392,6 +393,14 @@ class WeatherDisplay {
|
|||||||
|
|
||||||
return template;
|
return template;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// still waiting for data (retries triggered)
|
||||||
|
stillWaiting() {
|
||||||
|
if (this.enabled) this.setStatus(STATUS.retrying);
|
||||||
|
// handle still waiting callbacks
|
||||||
|
this.stillWaitingCallbacks.forEach((callback) => callback());
|
||||||
|
this.stillWaitingCallbacks = [];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default WeatherDisplay;
|
export default WeatherDisplay;
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -37,7 +37,8 @@
|
|||||||
padding-left: 4px;
|
padding-left: 4px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.loading {
|
.loading,
|
||||||
|
.retrying {
|
||||||
color: #ffff00;
|
color: #ffff00;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,23 +59,12 @@
|
|||||||
color: #C0C0C0;
|
color: #C0C0C0;
|
||||||
}
|
}
|
||||||
|
|
||||||
&.loading .loading {
|
&.loading .loading,
|
||||||
display: block;
|
&.press-here .press-here,
|
||||||
}
|
&.failed .failed,
|
||||||
|
&.no-data .no-data,
|
||||||
&.press-here .press-here {
|
&.disabled .disabled,
|
||||||
display: block;
|
&.retrying .retrying {
|
||||||
}
|
|
||||||
|
|
||||||
&.failed .failed {
|
|
||||||
display: block;
|
|
||||||
}
|
|
||||||
|
|
||||||
&.no-data .no-data {
|
|
||||||
display: block;
|
|
||||||
}
|
|
||||||
|
|
||||||
&.disabled .disabled {
|
|
||||||
display: block;
|
display: block;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
<div class="failed">Failed</div>
|
<div class="failed">Failed</div>
|
||||||
<div class="no-data">No Data</div>
|
<div class="no-data">No Data</div>
|
||||||
<div class="disabled">Disabled</div>
|
<div class="disabled">Disabled</div>
|
||||||
|
<div class="retrying">Retrying</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -50,5 +50,10 @@
|
|||||||
"[html]": {
|
"[html]": {
|
||||||
"editor.defaultFormatter": "j69.ejs-beautify"
|
"editor.defaultFormatter": "j69.ejs-beautify"
|
||||||
},
|
},
|
||||||
|
"files.exclude": {
|
||||||
|
"**/node_modules": true,
|
||||||
|
"**/debug.log": true,
|
||||||
|
"server/scripts/custom.js": true
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user