Skip to content

Commit

Permalink
Admin dashboard fixes (#62)
Browse files Browse the repository at this point in the history
* add flowchart_node_id to seed data

* add active admin

* add icons to activeadmin

* add flowchart node form

* add icon_helper resource, dashboard

* modified flowchart create vs. edit form

* add link to icons in node view

* linting and test fixes

* linting fixes

* minor dashboard fixes

* linting

* linting fix
  • Loading branch information
Aphexis authored Apr 3, 2020
1 parent 038038d commit 8a739a9
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 12 deletions.
1 change: 1 addition & 0 deletions app/admin/admin_users.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

ActiveAdmin.register AdminUser do
menu priority: 2
permit_params :email, :password, :password_confirmation

index do
Expand Down
4 changes: 2 additions & 2 deletions app/admin/dashboard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
column do
panel 'Recent Flowcharts' do
table_for Flowchart.order('id').limit(10) do
column('Title', &:title)
column('Title') { |f| link_to(f.title, admin_flowchart_path(f.id)) }
column('Description', &:description)
end
end
end
column do
panel 'Recent Icons' do
table_for FlowchartIcon.order('id').limit(10) do
column('ID', &:id)
column('ID') { |i| link_to(i.id, admin_flowchart_path(i.id)) }
column('URL', &:url)
end
end
Expand Down
1 change: 1 addition & 0 deletions app/admin/flowchart_icon_helpers.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

ActiveAdmin.register FlowchartIconHelper, as: 'Icon Connectors' do
menu priority: 6
# See permitted parameters documentation:
# https://github.com/activeadmin/activeadmin/blob/master/docs/2-resource-customization.md#setting-up-strong-parameters
#
Expand Down
1 change: 1 addition & 0 deletions app/admin/flowchart_icons.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# frozen_string_literal: true

ActiveAdmin.register FlowchartIcon, as: 'Icon' do
menu priority: 5
permit_params :url
end
10 changes: 6 additions & 4 deletions app/admin/flowchart_nodes.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
# frozen_string_literal: true

ActiveAdmin.register FlowchartNode do
menu priority: 4
sidebar 'Flowchart Details', only: %i[show edit] do
ul do
li link_to 'Node Icons', admin_icon_connectors_path('q[flowchart_node_id_eq]' => flowchart_node.id)
end
end

belongs_to :flowchart
permit_params :id, :text, :header, :next_question, :is_root, :flowchart_id, :deleted, :flowchart_node_id, :flowchart_id, :is_leaf, :breadcrumb_title,
belongs_to :flowchart, optional: true
permit_params :id, :text, :header, :next_question, :is_root, :flowchart_id, :deleted, :flowchart_node_id, :flowchart_id, :is_leaf, :breadcrumb_title, :button_text,
flowchart_icon_helpers_attributes: %i[id flowchart_icon_id flowchart_node_id _destroy]

controller do
def permitted_params
params.permit :authenticity_token, :commit, :_method, :flowchart_id, :id, flowchart_node: [:id, :text, :header, :breadcrumb_title, :next_question, :is_root, :flowchart_id, :flowchart_node_id, :is_leaf, :deleted, :flowchart_id,
flowchart_icon_helpers_attributes: %i[id flowchart_icon_id flowchart_node_id _destroy]]
params.permit :authenticity_token, :commit, :_method, :flowchart_id, :id,
flowchart_node: [:id, :text, :header, :breadcrumb_title, :next_question, :is_root, :flowchart_id, :flowchart_node_id, :is_leaf, :deleted, :flowchart_id, :button_text,
flowchart_icon_helpers_attributes: %i[id flowchart_icon_id flowchart_node_id _destroy]]
end
end
end
7 changes: 4 additions & 3 deletions app/admin/flowcharts.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
# frozen_string_literal: true

ActiveAdmin.register Flowchart do
menu priority: 3
sidebar 'Flowchart Details', only: %i[show edit] do
ul do
li link_to 'Flowchart Nodes', admin_flowchart_flowchart_nodes_path(resource)
end
end

permit_params :id, :title, :description, :root_id, :created_at, :updated_at, :deleted, :height,
flowchart_node_attributes: [:id, :text, :header, :button_text, :next_question, :child_id, :sibling_id, :is_root, :flowchart_id, :flowchart_node_id, :deleted, :_destroy,
flowchart_node_attributes: [:id, :text, :header, :button_text, :next_question, :child_id, :sibling_id, :is_root, :flowchart_id, :flowchart_node_id, :is_leaf, :breadcrumb_title, :deleted, :_destroy,
flowchart_icon_helpers_attributes: %i[id flowchart_icon_id flowchart_node_id _destroy]]

controller do
def permitted_params
params.permit :authenticity_token, :commit, flowchart: [:id, :title, :description, :root_id, :created_at, :updated_at, :deleted, :height,
flowchart_nodes_attributes: [:id, :text, :header, :button_text, :next_question, :is_root, :flowchart_id, :flowchart_node_id, :deleted, :_destroy,
flowchart_nodes_attributes: [:id, :text, :header, :button_text, :next_question, :is_root, :flowchart_id, :flowchart_node_id, :is_leaf, :breadcrumb_title, :deleted, :_destroy,
flowchart_icon_helpers_attributes: %i[id flowchart_icon_id flowchart_node_id _destroy]]]
end
end
Expand All @@ -36,7 +37,7 @@ def permitted_params
n.input :text, label: 'Node Text'
n.input :next_question, label: 'Node Question'
n.input :breadcrumb_title, label: 'Breadcrumb Title'
n.input :parent, label: 'Parent Node', as: :select, collection: FlowchartNode.select(:header).where(flowchart_id: f.object.id)
n.input :flowchart_node_id, label: 'Parent Node', as: :select, collection: FlowchartNode.where(flowchart_id: f.object.id)
n.input :is_root, label: 'Root Node?'
n.input :is_leaf, label: 'Leaf Node?'
n.has_many :flowchart_icon_helpers, new_record: 'Add Icon', allow_destroy: true, heading: 'Node Icons' do |i|
Expand Down
4 changes: 4 additions & 0 deletions app/models/flowchart_icon_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,8 @@
class FlowchartIconHelper < ApplicationRecord
belongs_to :flowchart_node
belongs_to :flowchart_icon

def display_name
id
end
end
3 changes: 0 additions & 3 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,12 @@ class Application < Rails::Application
# Middleware like session, flash, cookies can be added back manually.
# Skip views, helpers and assets when generating a new resource.
config.api_only = true

puts Rails.env

# Middleware for ActiveAdmin
config.middleware.use Rack::MethodOverride
config.middleware.use ActionDispatch::Flash
config.middleware.use ActionDispatch::Cookies
config.middleware.use ActionDispatch::Session::CookieStore

config.middleware.insert_before 0, Rack::Cors do
allow do
origins '*'
Expand Down

0 comments on commit 8a739a9

Please sign in to comment.