diff --git a/public/js/subscription-manager.js b/public/js/subscription-manager.js new file mode 100644 index 0000000..f733cf4 --- /dev/null +++ b/public/js/subscription-manager.js @@ -0,0 +1,57 @@ +const component = () => { + return { + subscriptions: [], + plugins: [], + pid: undefined, + + init() { + fetch(`${base_url}api/admin/plugin`) + .then((res) => res.json()) + .then((data) => { + if (!data.success) throw new Error(data.error); + this.plugins = data.plugins; + + const pid = localStorage.getItem("plugin"); + if (pid && this.plugins.map((p) => p.id).includes(pid)) + this.pid = pid; + else if (this.plugins.length > 0) + this.pid = this.plugins[0].id; + + if (this.pid) this.list(pid); + }) + .catch((e) => { + alert( + "danger", + `Failed to list the available plugins. Error: ${e}` + ); + }); + }, + pluginChanged() { + localStorage.setItem("plugin", this.pid); + this.list(this.pid); + }, + list(pid) { + fetch( + `${base_url}api/admin/plugin/subscriptions?${new URLSearchParams( + { + plugin: pid, + } + )}`, + { + method: "GET", + } + ) + .then((response) => response.json()) + .then((data) => { + if (!data.success) throw new Error(data.error); + this.subscriptions = data.subscriptions; + }) + .catch((e) => { + alert( + "danger", + `Failed to list subscriptions. Error: ${e}` + ); + }); + }, + }; +}; diff --git a/src/routes/admin.cr b/src/routes/admin.cr index fd63ec8..c78df86 100644 --- a/src/routes/admin.cr +++ b/src/routes/admin.cr @@ -70,6 +70,10 @@ struct AdminRouter layout "download-manager" end + get "/admin/subscriptions" do |env| + layout "subscription-manager" + end + get "/admin/missing" do |env| layout "missing-items" end diff --git a/src/views/layout.html.ecr b/src/views/layout.html.ecr index c32bfb5..3bdeb33 100644 --- a/src/views/layout.html.ecr +++ b/src/views/layout.html.ecr @@ -19,6 +19,7 @@ <% end %> @@ -51,6 +52,7 @@
  • Plugins
  • Download Manager
  • +
  • Subscription Manager
  • diff --git a/src/views/subscription-manager.html.ecr b/src/views/subscription-manager.html.ecr new file mode 100644 index 0000000..8c0525b --- /dev/null +++ b/src/views/subscription-manager.html.ecr @@ -0,0 +1,29 @@ +

    Subscription Manager

    +
    +
    +
    +

    No Plugins Found

    +

    We could't find any plugins in the directory <%= Config.current.plugin_path %>.

    +

    You can download official plugins from the Mango plugins repository.

    +
    + +
    +
    + +
    + +
    +
    +
    +
    +
    + +<% content_for "script" do %> + <%= render_component "moment" %> + + +<% end %>