diff --git a/public/js/plugin-download.js b/public/js/plugin-download.js new file mode 100644 index 0000000..f785a13 --- /dev/null +++ b/public/js/plugin-download.js @@ -0,0 +1,36 @@ +$(() => { + $('#search-input').keypress(event => { + if (event.which === 13) { + search(); + } + }); +}); + +let searching = false; +const search = () => { + if (searching) + return; + + const query = $('#search-input').val(); + $.ajax({ + type: 'POST', + url: base_url + 'api/admin/plugin/search', + data: JSON.stringify({ + query: query, + plugin: plugin + }), + contentType: "application/json", + dataType: 'json' + }) + .done(data => { + console.log(data); + if (data.error) { + alert('danger', `Search failed. Error: ${data.error}`); + return; + } + }) + .fail((jqXHR, status) => { + alert('danger', `Search failed. Error: [${jqXHR.status}] ${jqXHR.statusText}`); + }) + .always(() => {}); +}; diff --git a/src/routes/api.cr b/src/routes/api.cr index 6ef86c8..1c39a41 100644 --- a/src/routes/api.cr +++ b/src/routes/api.cr @@ -259,5 +259,24 @@ class APIRouter < Router }.to_json end end + + post "/api/admin/plugin/search" do |env| + begin + query = env.params.json["query"].as String + plugin = Plugin.new env.params.json["plugin"].as String + + chapters = plugin.search query + + send_json env, { + "success" => true, + "chapters" => chapters, + }.to_json + rescue e + send_json env, { + "success" => false, + "error" => e.message, + }.to_json + end + end end end diff --git a/src/routes/main.cr b/src/routes/main.cr index 8699223..dfd452a 100644 --- a/src/routes/main.cr +++ b/src/routes/main.cr @@ -78,6 +78,12 @@ class MainRouter < Router layout "download" end + get "/download/plugins" do |env| + plugins = Plugin.list + plugin = Plugin.new plugins[0] + layout "plugin-download" + end + get "/" do |env| begin username = get_username env diff --git a/src/views/plugin-download.html.ecr b/src/views/plugin-download.html.ecr new file mode 100644 index 0000000..faf502a --- /dev/null +++ b/src/views/plugin-download.html.ecr @@ -0,0 +1,42 @@ +<% if plugins.empty? %> +
+

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.

+
+ +<% else %> +

Download with Plugins

+ +
+
+
+ +
+ +
+
+
+
+
+ +
+ +
+
+
+
+<% end %> + + +<% content_for "script" do %> + + + +<% end %>