mirror of
https://github.com/hkalexling/Mango.git
synced 2026-04-25 00:00:52 -04:00
Instantiate Plugin objects with IDs
This commit is contained in:
@@ -35,7 +35,7 @@ class Plugin
|
||||
raise "Job does not have a plugin ID specificed"
|
||||
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!
|
||||
|
||||
pages = info["pages"].as_i
|
||||
|
||||
+6
-13
@@ -106,28 +106,21 @@ class Plugin
|
||||
|
||||
def self.list
|
||||
self.build_info_ary
|
||||
|
||||
@@info_ary.map &.title
|
||||
@@info_ary.map do |m|
|
||||
{id: m.id, title: m.title}
|
||||
end
|
||||
end
|
||||
|
||||
def info
|
||||
@info.not_nil!
|
||||
end
|
||||
|
||||
def self.new_from_id(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)
|
||||
def initialize(id : String)
|
||||
Plugin.build_info_ary
|
||||
|
||||
@info = @@info_ary.find { |i| i.title == title }
|
||||
@info = @@info_ary.find { |i| i.id == id }
|
||||
if @info.nil?
|
||||
raise Error.new "Plugin with title #{title} not found"
|
||||
raise Error.new "Plugin with ID #{id} not found"
|
||||
end
|
||||
|
||||
@js_path = File.join info.dir, "index.js"
|
||||
|
||||
+4
-4
@@ -80,13 +80,13 @@ class MainRouter < Router
|
||||
|
||||
get "/download/plugins" do |env|
|
||||
begin
|
||||
title = env.params.query["plugin"]?
|
||||
id = env.params.query["plugin"]?
|
||||
plugins = Plugin.list
|
||||
|
||||
if title
|
||||
plugin = Plugin.new URI.decode title
|
||||
if id
|
||||
plugin = Plugin.new id
|
||||
else
|
||||
plugin = Plugin.new plugins[0]
|
||||
plugin = Plugin.new plugins[0][:id]
|
||||
end
|
||||
|
||||
layout "plugin-download"
|
||||
|
||||
@@ -22,8 +22,8 @@
|
||||
<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>
|
||||
<% plugins.each do |p| %>
|
||||
<option value="<%= p[:id] %>"><%= p[:title] %></option>
|
||||
<% end %>
|
||||
</select>
|
||||
</div>
|
||||
@@ -64,7 +64,7 @@
|
||||
|
||||
<% content_for "script" do %>
|
||||
<script>
|
||||
var plugin = "<%= plugin.info.title %>";
|
||||
var pid = "<%= plugin.info.id %>";
|
||||
</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>
|
||||
|
||||
Reference in New Issue
Block a user