Improve info when config is reloaded. (#16)
- 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:
parent
0e2288565d
commit
ab7d379408
6 changed files with 83 additions and 59 deletions
|
@ -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() {
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue