Skip to content

Commit

Permalink
Merge pull request #554 from Floppy/activeadmin
Browse files Browse the repository at this point in the history
Add comprehensive admin interface to manage data behind the scenes
  • Loading branch information
Floppy authored Jun 24, 2022
2 parents dcc88d1 + 3aee4a6 commit da114af
Show file tree
Hide file tree
Showing 21 changed files with 677 additions and 8 deletions.
4 changes: 3 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,13 @@ gem "delayed_job_active_record", "~> 4.1"
gem "activerecord-nulldb-adapter", "~> 0.8.0"

gem "memoist", "~> 0.16.2"
gem "will_paginate", "~> 3.3"
gem "stopwords-filter", require: "stopwords"

gem "devise", "~> 4.8"

gem "data_migrate", "~> 8.0"

gem "rails-settings-cached", "~> 2.8"
gem "activeadmin", "~> 2.13"

gem "kaminari", "~> 1.2"
48 changes: 46 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ GEM
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.1, >= 1.2.0)
activeadmin (2.13.1)
arbre (~> 1.2, >= 1.2.1)
formtastic (>= 3.1, < 5.0)
formtastic_i18n (~> 0.4)
inherited_resources (~> 1.7)
jquery-rails (~> 4.2)
kaminari (~> 1.0, >= 1.2.1)
railties (>= 6.1, < 7.1)
ransack (>= 2.1.1, < 4)
activejob (7.0.3)
activesupport (= 7.0.3)
globalid (>= 0.3.6)
Expand All @@ -70,6 +79,9 @@ GEM
tzinfo (~> 2.0)
acts-as-taggable-on (9.0.1)
activerecord (>= 6.0, < 7.1)
arbre (1.5.0)
activesupport (>= 3.0.0, < 7.1)
ruby2_keywords (>= 0.0.2, < 1.0)
ast (2.4.2)
bcrypt (3.1.18)
bindex (0.8.1)
Expand Down Expand Up @@ -116,6 +128,9 @@ GEM
i18n (>= 1.8.11, < 2)
ffi (1.15.5)
formatador (0.3.0)
formtastic (4.0.0)
actionpack (>= 5.2.0)
formtastic_i18n (0.7.0)
globalid (1.0.0)
activesupport (>= 5.0)
guard (2.18.0)
Expand All @@ -141,6 +156,9 @@ GEM
haml (>= 4.0.6, < 6.0)
html2haml (>= 1.0.1)
railties (>= 5.1)
has_scope (0.8.0)
actionpack (>= 5.2)
activesupport (>= 5.2)
hiredis (0.6.3)
html2haml (2.2.0)
erubis (~> 2.7.0)
Expand All @@ -149,9 +167,30 @@ GEM
ruby_parser (~> 3.5)
i18n (1.10.0)
concurrent-ruby (~> 1.0)
inherited_resources (1.13.1)
actionpack (>= 5.2, < 7.1)
has_scope (~> 0.6)
railties (>= 5.2, < 7.1)
responders (>= 2, < 4)
jbuilder (2.11.5)
actionview (>= 5.0.0)
activesupport (>= 5.0.0)
jquery-rails (4.5.0)
rails-dom-testing (>= 1, < 3)
railties (>= 4.2.0)
thor (>= 0.14, < 2.0)
kaminari (1.2.2)
activesupport (>= 4.1.0)
kaminari-actionview (= 1.2.2)
kaminari-activerecord (= 1.2.2)
kaminari-core (= 1.2.2)
kaminari-actionview (1.2.2)
actionview
kaminari-core (= 1.2.2)
kaminari-activerecord (1.2.2)
activerecord
kaminari-core (= 1.2.2)
kaminari-core (1.2.2)
listen (3.7.1)
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
Expand Down Expand Up @@ -246,6 +285,10 @@ GEM
zeitwerk (~> 2.5)
rainbow (3.1.1)
rake (13.0.6)
ransack (3.2.1)
activerecord (>= 6.1.5)
activesupport (>= 6.1.5)
i18n
rb-fsevent (0.11.0)
rb-inotify (0.10.1)
ffi (~> 1.0)
Expand Down Expand Up @@ -291,6 +334,7 @@ GEM
rubocop (>= 1.7.0, < 2.0)
rubocop-ast (>= 0.4.0)
ruby-progressbar (1.11.0)
ruby2_keywords (0.0.5)
ruby_parser (3.15.1)
sexp_processor (~> 4.9)
sass-rails (6.0.0)
Expand Down Expand Up @@ -352,7 +396,6 @@ GEM
websocket-driver (0.7.5)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
will_paginate (3.3.1)
zeitwerk (2.5.4)

PLATFORMS
Expand All @@ -361,6 +404,7 @@ PLATFORMS
x86_64-linux

DEPENDENCIES
activeadmin (~> 2.13)
activerecord-nulldb-adapter (~> 0.8.0)
acts-as-taggable-on (~> 9.0)
bootsnap (>= 1.4.4)
Expand All @@ -377,6 +421,7 @@ DEPENDENCIES
guard-rspec (~> 4.7)
hiredis
jbuilder (~> 2.11)
kaminari (~> 1.2)
listen (~> 3.7)
logs (~> 0.3.0)
memoist (~> 0.16.2)
Expand All @@ -398,7 +443,6 @@ DEPENDENCIES
tzinfo-data
web-console (>= 4.1.0)
webpacker (~> 5.4)
will_paginate (~> 3.3)

RUBY VERSION
ruby 3.0.0p0
Expand Down
16 changes: 16 additions & 0 deletions app/admin/creators.rb
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
36 changes: 36 additions & 0 deletions app/admin/dashboard.rb
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
121 changes: 121 additions & 0 deletions app/admin/delayed_job.rb
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
16 changes: 16 additions & 0 deletions app/admin/libraries.rb
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
16 changes: 16 additions & 0 deletions app/admin/model_files.rb
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
16 changes: 16 additions & 0 deletions app/admin/models.rb
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 added app/admin/parts.rb
Empty file.
Loading

0 comments on commit da114af

Please sign in to comment.