Initial commit
This commit is contained in:
80
www/res/access.js
Normal file
80
www/res/access.js
Normal file
@ -0,0 +1,80 @@
|
||||
"use strict";
|
||||
|
||||
const ERROR_MESSAGES = {
|
||||
401: 'Ungültige Anmeldedaten',
|
||||
'NetworkError when attempting to fetch resource.': 'Netzwerkfehler',
|
||||
};
|
||||
|
||||
class ApiError extends Error {
|
||||
constructor(statusCode, message) {
|
||||
super(statusCode + ' - ' + message);
|
||||
this.statusCode = statusCode;
|
||||
this.name = 'ApiError';
|
||||
this.localizedMessage = ERROR_MESSAGES[statusCode];
|
||||
}
|
||||
}
|
||||
|
||||
function escapeHTML(str) {
|
||||
const p = document.createElement("p");
|
||||
p.appendChild(document.createTextNode(str));
|
||||
return p.innerHTML;
|
||||
}
|
||||
|
||||
function fmtDate(date) {
|
||||
return date.toLocaleDateString('de-AT', {
|
||||
day: '2-digit',
|
||||
month: '2-digit',
|
||||
year: 'numeric',
|
||||
});
|
||||
}
|
||||
|
||||
function fmtDateTime(date) {
|
||||
return date.toLocaleDateString('de-AT', {
|
||||
day: '2-digit',
|
||||
month: '2-digit',
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
});
|
||||
}
|
||||
|
||||
function fmtDateWeekday(date) {
|
||||
return date.toLocaleDateString('de-AT', {
|
||||
weekday: 'long',
|
||||
});
|
||||
}
|
||||
|
||||
function fmtOe(oe) {
|
||||
return oe.toLocaleString('de-AT', {minimumFractionDigits: 0, maximumFractionDigits: 0});
|
||||
}
|
||||
|
||||
function fmtKmw(kmw) {
|
||||
return kmw.toLocaleString('de-AT', {minimumFractionDigits: 1, maximumFractionDigits: 1});
|
||||
}
|
||||
|
||||
function fmtInt(num) {
|
||||
return num.toLocaleString('de-AT', {minimumFractionDigits: 0, maximumFractionDigits: 0});
|
||||
}
|
||||
|
||||
function groupBy(list, key) {
|
||||
return list.reduce((groups, value) => {
|
||||
(groups[value[key]] = groups[value[key]] ?? []).push(value);
|
||||
return groups;
|
||||
}, {});
|
||||
}
|
||||
|
||||
function getCurrentLastSeason() {
|
||||
const date = new Date();
|
||||
return date.getFullYear() - ((date.getMonth() + 1) <= 6 ? 1 : 0);
|
||||
}
|
||||
|
||||
function getDefaultQualityLevel(kmw) {
|
||||
const list = Object.values(WINE_QUALITY_LEVELS).filter(q => !q['is_predicate']).sort((a, b) => a['min_kmw'] - b['min_kmw']);
|
||||
let last = list[0];
|
||||
for (const q of list) {
|
||||
if (q['min_kmw'] > kmw) {
|
||||
return last;
|
||||
}
|
||||
last = q;
|
||||
}
|
||||
return last;
|
||||
}
|
Reference in New Issue
Block a user