Compare commits
3 Commits
9529d2cdc8
...
28cffcfb42
Author | SHA1 | Date | |
---|---|---|---|
28cffcfb42 | |||
96fe8a4cdf | |||
0c532fb979 |
@ -15,7 +15,7 @@
|
||||
|
||||
<body>
|
||||
<div class="topnav">
|
||||
<a class="active" href="/home/index.html">Home</a>
|
||||
<a class="active" href="/home">Home</a>
|
||||
<div style="display: flex; justify-content: flex-end;">
|
||||
<a href="/devices">Devices</a>
|
||||
<a href="/profile">Profile</a>
|
||||
|
@ -4,6 +4,13 @@
|
||||
<meta charset="UTF-8" />
|
||||
<title>Temperature Alarm</title>
|
||||
<link rel="stylesheet" href="/styles/frontpage.css">
|
||||
<script type="module">
|
||||
import { isLoggedIn } from "./shared/utils.js";
|
||||
|
||||
if (isLoggedIn()) {
|
||||
location.href = "/home";
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<main>
|
||||
|
@ -42,8 +42,8 @@ function buildTable(data) {
|
||||
|
||||
data.sort((a, b) => new Date(b.date).getTime() - new Date(a.date).getTime());
|
||||
|
||||
// TODO allow showing more than 50 by e.g. clicking
|
||||
data = data.slice(0, 50);
|
||||
// TODO allow showing more than 50 by e.g. clicking
|
||||
data = data.slice(0, 50);
|
||||
|
||||
data.forEach((log) => {
|
||||
var averageTemp = (log.tempHigh + log.tempLow) / 2.0;
|
||||
@ -115,10 +115,10 @@ async function init() {
|
||||
x: new Date(log.date).getTime(),
|
||||
y: log.temperature,
|
||||
})),
|
||||
parsing: false,
|
||||
})),
|
||||
},
|
||||
options: {
|
||||
parsing: false,
|
||||
plugins: {
|
||||
tooltip: {
|
||||
callbacks: {
|
||||
@ -127,6 +127,8 @@ async function init() {
|
||||
},
|
||||
decimation: {
|
||||
enabled: true,
|
||||
algorithm: "lttb",
|
||||
samples: window.innerWidth / 2,
|
||||
},
|
||||
},
|
||||
scales: {
|
||||
|
@ -15,34 +15,42 @@ export async function request(method, path, body = null) {
|
||||
headers,
|
||||
body: body ? JSON.stringify(body) : undefined,
|
||||
})
|
||||
.then(async response => {
|
||||
try {
|
||||
const json = await response.json();
|
||||
.then(async response => {
|
||||
if (response.status === 401) {
|
||||
location.href = "/login";
|
||||
}
|
||||
|
||||
if (response.ok) return resolve(json);
|
||||
try {
|
||||
const json = await response.json();
|
||||
|
||||
if (json.error) return reject(json.error);
|
||||
if (response.ok) return resolve(json);
|
||||
|
||||
if (json.message) return reject(json.message);
|
||||
if (json.error) return reject(json.error);
|
||||
|
||||
if (json.title) return reject(json.title);
|
||||
if (json.message) return reject(json.message);
|
||||
|
||||
if (json.errors) return reject(Object.values(json.errors)[0][0]);
|
||||
} finally {
|
||||
reject("Request failed with HTTP code " + response.status);
|
||||
}
|
||||
})
|
||||
.catch(err => reject(err.message));
|
||||
if (json.title) return reject(json.title);
|
||||
|
||||
if (json.errors) return reject(Object.values(json.errors)[0][0]);
|
||||
} finally {
|
||||
reject("Request failed with HTTP code " + response.status);
|
||||
}
|
||||
})
|
||||
.catch(err => reject(err.message));
|
||||
});
|
||||
}
|
||||
|
||||
export function logout() {
|
||||
localStorage.removeItem("user");
|
||||
document.cookie = "auth-token=";
|
||||
window.location.href = "/";
|
||||
localStorage.removeItem("user");
|
||||
document.cookie = "auth-token=";
|
||||
window.location.href = "/";
|
||||
}
|
||||
|
||||
export function getUser() {
|
||||
return JSON.parse(localStorage.getItem("user"));
|
||||
}
|
||||
|
||||
export function isLoggedIn() {
|
||||
return document.cookie.match(/\bauth-token=/) && localStorage.getItem("user");
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user