2021-11-21 13:03:18 +00:00
|
|
|
Handlebars.registerHelper("to_date", function (timestamp) {
|
2023-10-08 16:46:03 +00:00
|
|
|
return new Date(timestamp * 1000).toLocaleString();
|
2021-11-21 13:03:18 +00:00
|
|
|
});
|
|
|
|
|
2023-10-08 16:46:03 +00:00
|
|
|
tstor.servers = {
|
|
|
|
_template: null,
|
2021-11-21 13:03:18 +00:00
|
|
|
|
2023-10-08 16:46:03 +00:00
|
|
|
_getTemplate: function () {
|
|
|
|
if (this._template != null) {
|
|
|
|
return this._template;
|
|
|
|
}
|
2021-11-21 13:03:18 +00:00
|
|
|
|
2023-10-08 16:46:03 +00:00
|
|
|
const tTemplate = fetch("/assets/templates/servers.html")
|
|
|
|
.then((response) => {
|
|
|
|
if (response.ok) {
|
|
|
|
return response.text();
|
|
|
|
} else {
|
|
|
|
tstor.message.error(
|
|
|
|
"Error getting data from server. Response: " + response.status
|
|
|
|
);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.then((t) => {
|
|
|
|
return Handlebars.compile(t);
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
tstor.message.error("Error getting servers template: " + error.message);
|
|
|
|
});
|
2021-11-21 13:03:18 +00:00
|
|
|
|
2023-10-08 16:46:03 +00:00
|
|
|
this._template = tTemplate;
|
|
|
|
return tTemplate;
|
|
|
|
},
|
2021-11-21 13:03:18 +00:00
|
|
|
|
2023-10-08 16:46:03 +00:00
|
|
|
_getRoutesJson: function () {
|
|
|
|
return fetch("/api/servers")
|
|
|
|
.then(function (response) {
|
|
|
|
if (response.ok) {
|
|
|
|
return response.json();
|
|
|
|
} else {
|
|
|
|
tstor.message.error(
|
|
|
|
"Error getting data from server. Response: " + response.status
|
|
|
|
);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch(function (error) {
|
|
|
|
tstor.message.error("Error getting status info: " + error.message);
|
|
|
|
});
|
|
|
|
},
|
2021-11-21 13:03:18 +00:00
|
|
|
|
2023-10-08 16:46:03 +00:00
|
|
|
loadView: function () {
|
|
|
|
this._getTemplate().then((t) =>
|
|
|
|
this._getRoutesJson().then((routes) => {
|
|
|
|
document.getElementById("template_target").innerHTML = t(routes);
|
|
|
|
})
|
|
|
|
);
|
|
|
|
},
|
|
|
|
};
|