Plugin download page WIP

This commit is contained in:
Alex Ling 2020-07-22 13:52:28 +00:00
parent dcfd1c8765
commit 2773c1e67f
4 changed files with 103 additions and 0 deletions

View File

@ -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(() => {});
};

View File

@ -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

View File

@ -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

View File

@ -0,0 +1,42 @@
<% if plugins.empty? %>
<div class="uk-container uk-text-center">
<h2>No Plugins found</h2>
<p>We could't find any plugins in the directory <code><%= Config.current.plugin_path %></code>.</p>
<p>You can download official plugins from the <a href="https://github.com/hkalexling/mango-plugins">Mango plugins repository</a>.</p>
</div>
<% else %>
<h2 class=uk-title>Download with Plugins</h2>
<div class="uk-grid-small" uk-grid>
<div class="uk-width-3-4">
<div class="uk-margin">
<label class="uk-form-label" for="search-input">&nbsp;</label>
<div class="uk-form-controls">
<input id="search-input" class="uk-input" type="text" placeholder="<%= plugin.placeholder %>">
</div>
</div>
</div>
<div class="uk-width-1-4">
<div class="uk-margin">
<label class="uk-form-label" for="plugin-select">Choose a plugin</label>
<div class="uk-form-controls">
<select id="plugin-select" class="uk-select">
<% plugins.each do |s| %>
<option><%= s %></option>
<% end %>
</select>
</div>
</div>
</div>
</div>
<% end %>
<% content_for "script" do %>
<script>
var plugin = "<%= plugin.filename %>";
</script>
<script src="<%= base_url %>js/alert.js"></script>
<script src="<%= base_url %>js/plugin-download.js"></script>
<% end %>