From 1ce553f54130ac5d2844476fa95029768f737c70 Mon Sep 17 00:00:00 2001 From: Alex Ling Date: Sun, 1 Mar 2020 03:05:40 +0000 Subject: [PATCH] Add the /admin/downloads page for monitoring download queue --- public/js/download-manager.js | 42 ++++++++++++++++++++++++++++++++++ src/routes/admin.cr | 5 ++++ src/views/download-manager.ecr | 32 ++++++++++++++++++++++++++ 3 files changed, 79 insertions(+) create mode 100644 public/js/download-manager.js create mode 100644 src/views/download-manager.ecr diff --git a/public/js/download-manager.js b/public/js/download-manager.js new file mode 100644 index 0000000..be64934 --- /dev/null +++ b/public/js/download-manager.js @@ -0,0 +1,42 @@ +$(() => { + load(); +}); +const load = () => { + $.ajax({ + type: 'GET', + url: '/api/admin/mangadex/queue', + dataType: 'json' + }) + .done(data => { + console.log(data); + const rows = data.map(obj => { + var cls = 'uk-label '; + if (obj.status === 'Completed') + cls += 'uk-label-success'; + if (obj.status === 'Error') + cls += 'uk-label-danger'; + if (obj.status === 'MissingPages') + cls += 'uk-label-warning'; + + const statusSpan = `${obj.status}`; + return ` + ${obj.title} + ${obj.manga_title} + ${obj.success_count}/${obj.pages} + ${moment(obj.time).fromNow()} + ${statusSpan} + + + + + `; + }); + + const tbody = `${rows.join('')}`; + $('tbody').remove(); + $('table').append(tbody); + }) + .fail((jqXHR, status) => { + alert('danger', `Failed to fetch download queue. Error: [${jqXHR.status}] ${jqXHR.statusText}`); + }); +}; diff --git a/src/routes/admin.cr b/src/routes/admin.cr index 899ddb6..02ca4c1 100644 --- a/src/routes/admin.cr +++ b/src/routes/admin.cr @@ -99,5 +99,10 @@ class AdminRouter < Router env.redirect redirect_url.to_s end end + + get "/admin/downloads" do |env| + base_url = @context.config.mangadex["base_url"]; + layout "download-manager" + end end end diff --git a/src/views/download-manager.ecr b/src/views/download-manager.ecr new file mode 100644 index 0000000..3f2590d --- /dev/null +++ b/src/views/download-manager.ecr @@ -0,0 +1,32 @@ +
+
+ + + +
+
+ + +
+
+ + + + + + + + + + + +
ChapterMangaProgressTime SubmittedStatusActions
+ +<% content_for "script" do %> + + + + +<% end %>