diff --git a/assets/js/servers.js b/assets/js/servers.js new file mode 100644 index 0000000..f966011 --- /dev/null +++ b/assets/js/servers.js @@ -0,0 +1,54 @@ +Handlebars.registerHelper("to_date", function (timestamp) { + return new Date(timestamp * 1000).toLocaleString() +}); + +Distribyted.servers = { + _template: null, + + _getTemplate: function () { + if (this._template != null) { + return this._template + } + + const tTemplate = fetch('/assets/templates/servers.html') + .then((response) => { + if (response.ok) { + return response.text(); + } else { + Distribyted.message.error('Error getting data from server. Response: ' + response.status); + } + }) + .then((t) => { + return Handlebars.compile(t); + }) + .catch(error => { + Distribyted.message.error('Error getting servers template: ' + error.message); + }); + + this._template = tTemplate; + return tTemplate; + }, + + _getRoutesJson: function () { + return fetch('/api/servers') + .then(function (response) { + if (response.ok) { + return response.json(); + } else { + Distribyted.message.error('Error getting data from server. Response: ' + response.status) + } + }) + .catch(function (error) { + Distribyted.message.error('Error getting status info: ' + error.message) + }); + }, + + loadView: function () { + this._getTemplate() + .then(t => + this._getRoutesJson().then(routes => { + document.getElementById('template_target').innerHTML = t(routes); + }) + ); + } +} \ No newline at end of file diff --git a/assets/templates/routes.html b/assets/templates/routes.html index 1960a93..1a7690e 100644 --- a/assets/templates/routes.html +++ b/assets/templates/routes.html @@ -1,10 +1,9 @@ {{#.}}
Name | / | -Peers/Seeders | +Peers/Seeders | Status | Actions | @@ -24,7 +23,7 @@{{name}} | {{ibytes downloadedBytes timePassed}} / {{ibytes uploadedBytes timePassed}} | -{{{torrent_info peers seeders pieceSize}}} | +{{{torrent_info peers seeders pieceSize}}} | {{{torrent_status pieceChunks totalPieces}}} | diff --git a/assets/templates/servers.html b/assets/templates/servers.html new file mode 100644 index 0000000..a23e4c7 --- /dev/null +++ b/assets/templates/servers.html @@ -0,0 +1,45 @@ +{{#.}} + +
---|