16 lines
781 B
JavaScript
16 lines
781 B
JavaScript
const { renderView } = require('#src/web/view');
|
|
|
|
function formatInterval(value, unit) {
|
|
const amount = Math.max(1, Number(value) || 0);
|
|
const normalized = String(unit || 'minutes');
|
|
return 'Every ' + amount + ' ' + normalized.replace(/s$/, '') + (amount === 1 ? '' : 's');
|
|
}
|
|
|
|
module.exports = function renderWeatherLocationsPage(data, message, currentUser) {
|
|
return renderView('data-sources/weather/list', {
|
|
title: 'Weather locations', active: 'weather', message, currentUser: currentUser || null,
|
|
weatherLocations: (data.weatherLocations || []).map(function (location) {
|
|
return Object.assign({}, location, { intervalLabel: formatInterval(location.update_interval_value, location.update_interval_unit) });
|
|
}), pagination: data.pagination || null
|
|
});
|
|
}; |