-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #554 from Floppy/activeadmin
Add comprehensive admin interface to manage data behind the scenes
- Loading branch information
Showing
21 changed files
with
677 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
ActiveAdmin.register Creator do | ||
# See permitted parameters documentation: | ||
# https://github.com/activeadmin/activeadmin/blob/master/docs/2-resource-customization.md#setting-up-strong-parameters | ||
# | ||
# Uncomment all parameters which should be permitted for assignment | ||
# | ||
# permit_params :name | ||
# | ||
# or | ||
# | ||
# permit_params do | ||
# permitted = [:name] | ||
# permitted << :other if params[:action] == 'create' && current_user.admin? | ||
# permitted | ||
# end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# frozen_string_literal: true | ||
|
||
ActiveAdmin.register_page "Dashboard" do | ||
menu priority: 1, label: proc { I18n.t("active_admin.dashboard") } | ||
|
||
content title: proc { I18n.t("active_admin.dashboard") } do | ||
columns do | ||
column do | ||
panel "Recent Models" do | ||
table do | ||
tbody do | ||
Model.all.order(:created_at).limit(20).map do |model| | ||
tr do | ||
td { link_to(model.name, admin_model_path(model)) } | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
column do | ||
panel "Task Queue" do | ||
table do | ||
tbody do | ||
Delayed::Job.all.order(:created_at).limit(20).map do |job| | ||
tr do | ||
td { link_to(job.id, admin_task_path(job)) } | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
ActiveAdmin.register Delayed::Job, as: "Task" do | ||
actions :all, except: [:new] | ||
|
||
collection_action :run_all, method: :post do | ||
successes, failures = Delayed::Worker.new.work_off | ||
if failures > 0 | ||
flash[:alert] = "#{failures} failed Tasks when running them." | ||
end | ||
if successes > 0 | ||
flash[:notice] = "#{successes} Tasks run successfully" | ||
end | ||
if failures == 0 && successes == 0 | ||
flash[:notice] = "Yawn... no Tasks run" | ||
end | ||
redirect_to admin_tasks_url | ||
I18n.locale = :en # Running tasks can mess up the locale. | ||
end | ||
|
||
if Rails.env.development? | ||
collection_action :delete_all, method: :post do | ||
n = Delayed::Job.delete_all | ||
redirect_to admin_tasks_url, notice: "#{n} tasks deleted." | ||
end | ||
end | ||
|
||
collection_action :mark_all_for_re_run, method: :post do | ||
n = Delayed::Job.update_all("run_at = created_at") | ||
redirect_to admin_tasks_url, notice: "Marked all tasks (#{n}) for re-running." | ||
end | ||
|
||
member_action :run, method: :post do | ||
task = Delayed::Job.find(params[:id]) | ||
begin | ||
task.invoke_job | ||
task.destroy | ||
redirect_to admin_tasks_url, notice: "1 Task run, apparently successfully, but who knows!" | ||
rescue => e | ||
redirect_to admin_tasks_url, alert: "Failed to run a Task: #{e}" | ||
end | ||
I18n.locale = :en # Running Tasks can mess up the locale. | ||
end | ||
|
||
action_item :run do | ||
links = link_to("Run All Tasks", run_all_admin_tasks_url, method: :post) | ||
links += (" " + link_to("Mark all for re-run", mark_all_for_re_run_admin_tasks_url, method: :post)).html_safe | ||
links += (" " + link_to("Delete All Tasks", delete_all_admin_tasks_url, method: :post)).html_safe if Rails.env.development? | ||
links | ||
end | ||
|
||
index do | ||
selectable_column | ||
id_column | ||
column "P", :priority | ||
column "A", :attempts | ||
column("Error", :last_error, sortable: :last_error) { |post| post.last_error.present? ? post.last_error.split('\n').first : "" } | ||
column(:created_at, sortable: :created_at) { |job| job.created_at.iso8601.tr("T", " ") } | ||
column(:run_at, sortable: :run_at) { |post| post.run_at.present? ? post.run_at.iso8601.tr("T", " ") : nil } | ||
column :queue | ||
column("Running", sortable: :locked_at) { |dj| dj.locked_at.present? ? "#{(Time.now - dj.locked_at).round(1)}s by #{dj.locked_by}" : "" } | ||
actions | ||
end | ||
|
||
show title: ->(dj) { "Task #{dj.id}" } do |task| | ||
panel "Task" do | ||
attributes_table_for task do | ||
row :id | ||
row :priority | ||
row :attempts | ||
row :queue | ||
row :run_at | ||
row :locked_at | ||
row :failed_at | ||
row :locked_by | ||
row :created_at | ||
row :updated_at | ||
end | ||
end | ||
|
||
panel "Handler" do | ||
pre task.handler | ||
rescue => e | ||
div "Couldn't render handler: #{e.message}" | ||
end | ||
|
||
panel "Last error" do | ||
pre task.last_error | ||
rescue => e | ||
div "Couldn't render last error: #{e.message}" | ||
end | ||
end | ||
|
||
form do |f| | ||
f.inputs("Task") do | ||
f.input :id, input_html: {readonly: true} | ||
f.input :priority | ||
f.input :attempts | ||
f.input :queue | ||
f.input :created_at, input_html: {readonly: true}, as: :string | ||
f.input :updated_at, input_html: {readonly: true}, as: :string | ||
f.input :run_at, input_html: {readonly: true}, as: :string | ||
f.input :locked_at, input_html: {readonly: true}, as: :string | ||
f.input :failed_at, input_html: {readonly: true}, as: :string | ||
f.input :locked_by, input_html: {readonly: true} | ||
end | ||
|
||
f.buttons | ||
end | ||
|
||
controller do | ||
def update | ||
@task = Delayed::Job.find(params[:id]) | ||
@task.assign_attributes(params[:task], without_protection: true) | ||
if @task.save | ||
redirect_to admin_tasks_url, notice: "Task #{@task} saved successfully" | ||
else | ||
render :edit | ||
end | ||
I18n.locale = :en # Running Tasks can mess up the locale. | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
ActiveAdmin.register Library do | ||
# See permitted parameters documentation: | ||
# https://github.com/activeadmin/activeadmin/blob/master/docs/2-resource-customization.md#setting-up-strong-parameters | ||
# | ||
# Uncomment all parameters which should be permitted for assignment | ||
# | ||
# permit_params :path | ||
# | ||
# or | ||
# | ||
# permit_params do | ||
# permitted = [:path] | ||
# permitted << :other if params[:action] == 'create' && current_user.admin? | ||
# permitted | ||
# end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
ActiveAdmin.register ModelFile do | ||
# See permitted parameters documentation: | ||
# https://github.com/activeadmin/activeadmin/blob/master/docs/2-resource-customization.md#setting-up-strong-parameters | ||
# | ||
# Uncomment all parameters which should be permitted for assignment | ||
# | ||
# permit_params :filename, :model_id, :presupported, :printed, :y_up | ||
# | ||
# or | ||
# | ||
# permit_params do | ||
# permitted = [:filename, :model_id, :presupported, :printed, :y_up] | ||
# permitted << :other if params[:action] == 'create' && current_user.admin? | ||
# permitted | ||
# end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
ActiveAdmin.register Model do | ||
# See permitted parameters documentation: | ||
# https://github.com/activeadmin/activeadmin/blob/master/docs/2-resource-customization.md#setting-up-strong-parameters | ||
# | ||
# Uncomment all parameters which should be permitted for assignment | ||
# | ||
# permit_params :name, :path, :library_id, :preview_file_id, :creator_id, :thingiverse_id, :cgtrader_path, :cults3d_path, :mmf_slug, :tag_list | ||
# | ||
# or | ||
# | ||
# permit_params do | ||
# permitted = [:name, :path, :library_id, :preview_file_id, :creator_id, :thingiverse_id, :cgtrader_path, :cults3d_path, :mmf_slug, :tag_list] | ||
# permitted << :other if params[:action] == 'create' && current_user.admin? | ||
# permitted | ||
# end | ||
end |
Empty file.
Oops, something went wrong.