Improve info when config is reloaded. ()

- Using toasts as message outputs (still a lot of room for improvement)

Signed-off-by: Antonio Navarro Perez <antnavper@gmail.com>
This commit is contained in:
Antonio Navarro Perez 2020-11-09 11:33:19 +01:00 committed by GitHub
parent 0e2288565d
commit ab7d379408
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 83 additions and 59 deletions

View file

@ -57,21 +57,22 @@ function bin2string(array) {
function reload() {
fetch("/api/reload", {
method: "POST",
}).then(function (response) {
if (response.ok) {
return response.text();
} else {
toastError(
"Error saving configuration file. Response: " + response.status
);
}
})
.then(function (text) {
toastInfo(text);
})
.catch(function (error) {
toastError("Error reloading server: " + error.message);
});
.then(function (response) {
if (response.ok) {
return response.json();
} else {
toastError(
"Error saving configuration file. Response: " + response.status
);
}
})
.then(function (json) {
toastInfo(json.message);
})
.catch(function (error) {
toastError("Error reloading server: " + error.message);
});
}
function save() {

View file

@ -1,25 +1,29 @@
function toast(msg, color, time) {
Toastify({
text: msg,
duration: time,
newWindow: true,
close: true,
gravity: "top",
position: "right",
backgroundColor: color,
stopOnFocus: true,
}).showToast();
}
function toastError(msg) {
Toastify({
text: msg,
duration: 5000,
newWindow: true,
close: true,
gravity: "top", // `top` or `bottom`
position: 'right', // `left`, `center` or `right`
backgroundColor: "red",
stopOnFocus: true, // Prevents dismissing of toast on hover
}).showToast();
toast(msg, "red", 5000);
}
function toastInfo(msg) {
Toastify({
text: msg,
duration: 5000,
newWindow: true,
close: true,
gravity: "top", // `top` or `bottom`
position: 'right', // `left`, `center` or `right`
backgroundColor: "green",
stopOnFocus: true, // Prevents dismissing of toast on hover
}).showToast();
}
toast(msg, "green", 5000);
}
function toastMessage(msg) {
toast(msg, "grey", 10000);
}
var stream = new EventSource("/api/events");
stream.addEventListener("event", function (e) {
toastMessage(e.data);
});