mirror of
https://github.com/hkalexling/Mango.git
synced 2025-08-03 11:25:29 -04:00
Instantiate Plugin objects with IDs
This commit is contained in:
parent
361d37d742
commit
0e9a659828
@ -1,16 +1,16 @@
|
|||||||
const loadPlugin = title => {
|
const loadPlugin = id => {
|
||||||
localStorage.setItem('plugin', title);
|
localStorage.setItem('plugin', id);
|
||||||
const url = `${location.protocol}//${location.host}${location.pathname}`;
|
const url = `${location.protocol}//${location.host}${location.pathname}`;
|
||||||
const newURL = `${url}?${$.param({
|
const newURL = `${url}?${$.param({
|
||||||
plugin: encodeURIComponent(title)
|
plugin: id
|
||||||
})}`;
|
})}`;
|
||||||
window.location.href = newURL;
|
window.location.href = newURL;
|
||||||
};
|
};
|
||||||
|
|
||||||
$(() => {
|
$(() => {
|
||||||
var storedTitle = localStorage.getItem('plugin');
|
var storedID = localStorage.getItem('plugin');
|
||||||
if (storedTitle && storedTitle !== plugin) {
|
if (storedID && storedID !== pid) {
|
||||||
loadPlugin(storedTitle);
|
loadPlugin(storedID);
|
||||||
} else {
|
} else {
|
||||||
$('#controls').removeAttr('hidden');
|
$('#controls').removeAttr('hidden');
|
||||||
}
|
}
|
||||||
@ -20,10 +20,10 @@ $(() => {
|
|||||||
search();
|
search();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
$('#plugin-select').val(plugin);
|
$('#plugin-select').val(pid);
|
||||||
$('#plugin-select').change(() => {
|
$('#plugin-select').change(() => {
|
||||||
const title = $('#plugin-select').val();
|
const id = $('#plugin-select').val();
|
||||||
loadPlugin(title);
|
loadPlugin(id);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -39,7 +39,7 @@ const search = () => {
|
|||||||
url: base_url + 'api/admin/plugin/search',
|
url: base_url + 'api/admin/plugin/search',
|
||||||
data: JSON.stringify({
|
data: JSON.stringify({
|
||||||
query: query,
|
query: query,
|
||||||
plugin: plugin
|
plugin: pid
|
||||||
}),
|
}),
|
||||||
contentType: "application/json",
|
contentType: "application/json",
|
||||||
dataType: 'json'
|
dataType: 'json'
|
||||||
@ -112,7 +112,7 @@ const download = () => {
|
|||||||
type: 'POST',
|
type: 'POST',
|
||||||
url: base_url + 'api/admin/plugin/download',
|
url: base_url + 'api/admin/plugin/download',
|
||||||
data: JSON.stringify({
|
data: JSON.stringify({
|
||||||
plugin: plugin,
|
plugin: pid,
|
||||||
chapters: chapters,
|
chapters: chapters,
|
||||||
title: mangaTitle
|
title: mangaTitle
|
||||||
}),
|
}),
|
||||||
|
@ -35,7 +35,7 @@ class Plugin
|
|||||||
raise "Job does not have a plugin ID specificed"
|
raise "Job does not have a plugin ID specificed"
|
||||||
end
|
end
|
||||||
|
|
||||||
plugin = Plugin.new_from_id job.plugin_id.not_nil!
|
plugin = Plugin.new job.plugin_id.not_nil!
|
||||||
info = plugin.select_chapter job.plugin_chapter_id.not_nil!
|
info = plugin.select_chapter job.plugin_chapter_id.not_nil!
|
||||||
|
|
||||||
pages = info["pages"].as_i
|
pages = info["pages"].as_i
|
||||||
|
@ -106,28 +106,21 @@ class Plugin
|
|||||||
|
|
||||||
def self.list
|
def self.list
|
||||||
self.build_info_ary
|
self.build_info_ary
|
||||||
|
@@info_ary.map do |m|
|
||||||
@@info_ary.map &.title
|
{id: m.id, title: m.title}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def info
|
def info
|
||||||
@info.not_nil!
|
@info.not_nil!
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.new_from_id(id : String)
|
def initialize(id : String)
|
||||||
self.build_info_ary
|
|
||||||
|
|
||||||
info = @@info_ary.find { |i| i.id == id }
|
|
||||||
raise Error.new "Plugin with id #{id} not found" unless info
|
|
||||||
self.new info.title
|
|
||||||
end
|
|
||||||
|
|
||||||
def initialize(title : String)
|
|
||||||
Plugin.build_info_ary
|
Plugin.build_info_ary
|
||||||
|
|
||||||
@info = @@info_ary.find { |i| i.title == title }
|
@info = @@info_ary.find { |i| i.id == id }
|
||||||
if @info.nil?
|
if @info.nil?
|
||||||
raise Error.new "Plugin with title #{title} not found"
|
raise Error.new "Plugin with ID #{id} not found"
|
||||||
end
|
end
|
||||||
|
|
||||||
@js_path = File.join info.dir, "index.js"
|
@js_path = File.join info.dir, "index.js"
|
||||||
|
@ -80,13 +80,13 @@ class MainRouter < Router
|
|||||||
|
|
||||||
get "/download/plugins" do |env|
|
get "/download/plugins" do |env|
|
||||||
begin
|
begin
|
||||||
title = env.params.query["plugin"]?
|
id = env.params.query["plugin"]?
|
||||||
plugins = Plugin.list
|
plugins = Plugin.list
|
||||||
|
|
||||||
if title
|
if id
|
||||||
plugin = Plugin.new URI.decode title
|
plugin = Plugin.new id
|
||||||
else
|
else
|
||||||
plugin = Plugin.new plugins[0]
|
plugin = Plugin.new plugins[0][:id]
|
||||||
end
|
end
|
||||||
|
|
||||||
layout "plugin-download"
|
layout "plugin-download"
|
||||||
|
@ -22,8 +22,8 @@
|
|||||||
<label class="uk-form-label" for="plugin-select">Choose a plugin</label>
|
<label class="uk-form-label" for="plugin-select">Choose a plugin</label>
|
||||||
<div class="uk-form-controls">
|
<div class="uk-form-controls">
|
||||||
<select id="plugin-select" class="uk-select">
|
<select id="plugin-select" class="uk-select">
|
||||||
<% plugins.each do |s| %>
|
<% plugins.each do |p| %>
|
||||||
<option><%= s %></option>
|
<option value="<%= p[:id] %>"><%= p[:title] %></option>
|
||||||
<% end %>
|
<% end %>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
@ -64,7 +64,7 @@
|
|||||||
|
|
||||||
<% content_for "script" do %>
|
<% content_for "script" do %>
|
||||||
<script>
|
<script>
|
||||||
var plugin = "<%= plugin.info.title %>";
|
var pid = "<%= plugin.info.id %>";
|
||||||
</script>
|
</script>
|
||||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
|
||||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.tablesorter/2.31.3/js/jquery.tablesorter.combined.min.js"></script>
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.tablesorter/2.31.3/js/jquery.tablesorter.combined.min.js"></script>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user