Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/uwblueprint/sdc-api
Browse files Browse the repository at this point in the history
  • Loading branch information
faizaanmadhani committed Mar 31, 2020
2 parents c9413f0 + f4e8350 commit fe461a1
Show file tree
Hide file tree
Showing 27 changed files with 770 additions and 96 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby]

gem 'activeadmin'
gem 'devise'
gem 'devise-jwt', '~> 0.5.9'
gem 'pg', '~> 1.1'
57 changes: 57 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,17 @@ GEM
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.1, >= 1.2.0)
activeadmin (2.6.1)
arbre (~> 1.2, >= 1.2.1)
formtastic (~> 3.1)
formtastic_i18n (~> 0.4)
inherited_resources (~> 1.7)
jquery-rails (~> 4.2)
kaminari (~> 1.0, >= 1.0.1)
railties (>= 5.2, < 6.1)
ransack (~> 2.1, >= 2.1.1)
sassc-rails (~> 2.1)
sprockets (>= 3.0, < 4.1)
activejob (6.0.0)
activesupport (= 6.0.0)
globalid (>= 0.3.6)
Expand All @@ -59,6 +70,8 @@ GEM
annotate (3.0.3)
activerecord (>= 3.2, < 7.0)
rake (>= 10.4, < 14.0)
arbre (1.2.1)
activesupport (>= 3.0.0)
ast (2.4.0)
bcrypt (3.1.13)
bootsnap (1.4.5)
Expand Down Expand Up @@ -100,12 +113,39 @@ GEM
railties (>= 4.2.0)
ffi (1.11.1)
ffi (1.11.1-x64-mingw32)
formtastic (3.1.5)
actionpack (>= 3.2.13)
formtastic_i18n (0.6.0)
globalid (0.4.2)
activesupport (>= 4.2.0)
has_scope (0.7.2)
actionpack (>= 4.1)
activesupport (>= 4.1)
i18n (1.6.0)
concurrent-ruby (~> 1.0)
inherited_resources (1.11.0)
actionpack (>= 5.0, < 6.1)
has_scope (~> 0.6)
railties (>= 5.0, < 6.1)
responders (>= 2, < 4)
jaro_winkler (1.5.3)
jquery-rails (4.3.5)
rails-dom-testing (>= 1, < 3)
railties (>= 4.2.0)
thor (>= 0.14, < 2.0)
jwt (2.2.1)
kaminari (1.2.0)
activesupport (>= 4.1.0)
kaminari-actionview (= 1.2.0)
kaminari-activerecord (= 1.2.0)
kaminari-core (= 1.2.0)
kaminari-actionview (1.2.0)
actionview
kaminari-core (= 1.2.0)
kaminari-activerecord (1.2.0)
activerecord
kaminari-core (= 1.2.0)
kaminari-core (1.2.0)
listen (3.1.5)
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
Expand Down Expand Up @@ -135,6 +175,8 @@ GEM
ast (~> 2.4.0)
pg (1.1.4)
pg (1.1.4-x64-mingw32)
polyamorous (2.3.2)
activerecord (>= 5.2.1)
puma (3.12.1)
rack (2.0.7)
rack-cors (1.0.5)
Expand Down Expand Up @@ -169,6 +211,11 @@ GEM
thor (>= 0.20.3, < 2.0)
rainbow (3.0.0)
rake (13.0.0)
ransack (2.3.2)
activerecord (>= 5.2.1)
activesupport (>= 5.2.1)
i18n
polyamorous (= 2.3.2)
rb-fsevent (0.10.3)
rb-inotify (0.10.0)
ffi (~> 1.0)
Expand Down Expand Up @@ -201,6 +248,14 @@ GEM
unicode-display_width (>= 1.4.0, < 1.7)
ruby-progressbar (1.10.1)
ruby_dep (1.5.0)
sassc (2.2.1-x64-mingw32)
ffi (~> 1.9)
sassc-rails (2.1.2)
railties (>= 4.0.0)
sassc (>= 2.0)
sprockets (> 3.0)
sprockets-rails
tilt
spring (2.1.0)
spring-watcher-listen (2.0.1)
listen (>= 2.7, < 4.0)
Expand All @@ -214,6 +269,7 @@ GEM
sprockets (>= 3.0.0)
thor (0.20.3)
thread_safe (0.3.6)
tilt (2.0.10)
tzinfo (1.2.5)
thread_safe (~> 0.1)
tzinfo-data (1.2019.3)
Expand All @@ -236,6 +292,7 @@ PLATFORMS
x64-mingw32

DEPENDENCIES
activeadmin
annotate
bootsnap (>= 1.4.2)
byebug
Expand Down
29 changes: 29 additions & 0 deletions app/admin/admin_users.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# frozen_string_literal: true

ActiveAdmin.register AdminUser do
permit_params :email, :password, :password_confirmation

index do
selectable_column
id_column
column :email
column :current_sign_in_at
column :sign_in_count
column :created_at
actions
end

filter :email
filter :current_sign_in_at
filter :sign_in_count
filter :created_at

form do |f|
f.inputs do
f.input :email
f.input :password
f.input :password_confirmation
end
f.actions
end
end
33 changes: 33 additions & 0 deletions app/admin/dashboard.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# 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 Flowcharts' do
table_for Flowchart.order('id').limit(10) do
column('Title', &:title)
column('Description', &:description)
end
end
end
column do
panel 'Recent Icons' do
table_for FlowchartIcon.order('id').limit(10) do
column('ID', &:id)
column('URL', &:url)
end
end
end
end
columns do
column do
panel 'Info' do
para 'Welcome to the admin dashboard for SDC flowcharts!'
end
end
end
end
end
18 changes: 18 additions & 0 deletions app/admin/flowchart_icon_helpers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# frozen_string_literal: true

ActiveAdmin.register FlowchartIconHelper, as: 'Icon Connectors' 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 :flowchart_node_id, :flowchart_icon_id
#
# or
#
# permit_params do
# permitted = [:flowchart_node_id, :flowchart_icon_id]
# permitted << :other if params[:action] == 'create' && current_user.admin?
# permitted
# end
end
5 changes: 5 additions & 0 deletions app/admin/flowchart_icons.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true

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

ActiveAdmin.register FlowchartNode do
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,
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]]
end
end
end
50 changes: 50 additions & 0 deletions app/admin/flowcharts.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# frozen_string_literal: true

ActiveAdmin.register Flowchart do
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_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_icon_helpers_attributes: %i[id flowchart_icon_id flowchart_node_id _destroy]]]
end
end

form do |f|
f.inputs 'Details' do
f.input :title, label: 'Flowchart title'
f.input :description, label: 'Description'
f.hidden_field :height, value: 1
unless f.object.new_record?
f.input :root_id, label: 'Root Node ID'
end
end
unless f.object.new_record?
f.inputs 'Flowchart Nodes' do
f.has_many :flowchart_nodes, new_record: true, allow_destroy: true, heading: false do |n|
n.input :id, label: 'Node ID', input_html: { disabled: true }
n.input :header, label: 'Node Title'
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 :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|
i.input :flowchart_icon, label: 'Icon ID'
end
end
end
end
f.actions
end
end
1 change: 1 addition & 0 deletions app/assets/javascripts/active_admin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
//= require active_admin/base
17 changes: 17 additions & 0 deletions app/assets/stylesheets/active_admin.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// SASS variable overrides must be declared before loading up Active Admin's styles.
//
// To view the variables that Active Admin provides, take a look at
// `app/assets/stylesheets/active_admin/mixins/_variables.scss` in the
// Active Admin source.
//
// For example, to change the sidebar width:
// $sidebar-width: 242px;

// Active Admin's got SASS!
@import "active_admin/mixins";
@import "active_admin/base";

// Overriding any non-variable SASS must be done after the fact.
// For example, to change the default status-tag color:
//
// .status_tag { background: #6090DB; }
4 changes: 2 additions & 2 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

class ApplicationController < ActionController::API
respond_to :json
class ApplicationController < ActionController::Base
respond_to :json, :html
def render_resource(resource)
if resource.errors.empty?
render json: resource
Expand Down
27 changes: 27 additions & 0 deletions app/models/admin_user.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# frozen_string_literal: true

# == Schema Information
#
# Table name: admin_users
#
# id :bigint not null, primary key
# email :string default(""), not null
# encrypted_password :string default(""), not null
# remember_created_at :datetime
# reset_password_sent_at :datetime
# reset_password_token :string
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#
# index_admin_users_on_email (email) UNIQUE
# index_admin_users_on_reset_password_token (reset_password_token) UNIQUE
#

class AdminUser < ApplicationRecord
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
devise :database_authenticatable,
:recoverable, :rememberable, :validatable
end
5 changes: 4 additions & 1 deletion app/models/flowchart.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@
#

class Flowchart < ApplicationRecord
has_many :flowchart_nodes
# attr_accessible :flowchart_nodes_attributes
accepts_nested_attributes_for :flowchart_nodes, allow_destroy: true
validates :title, presence: true
validates :description, presence: true
validates :height, numericality: { only_integer: true, greater_than_or_equal_to: 0 }, presence: true
# validates :height, numericality: { only_integer: true, greater_than_or_equal_to: 0 }, presence: true
validates :root_id, numericality: { only_integer: true, greater_than_or_equal_to: 0 }, allow_nil: true
validates :deleted, inclusion: { in: [true, false] }, allow_nil: true # defaults to false

Expand Down
4 changes: 4 additions & 0 deletions app/models/flowchart_icon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,8 @@
class FlowchartIcon < ApplicationRecord
has_many :flowchart_icon_helpers
has_many :flowchart_node, through: :flowchart_icon_helpers

def display_name
url
end
end
7 changes: 6 additions & 1 deletion app/models/flowchart_node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@

class FlowchartNode < ApplicationRecord
belongs_to :flowchart
belongs_to :parent, class_name: 'FlowchartNode', optional: true
belongs_to :parent, class_name: 'FlowchartNode', optional: true, foreign_key: 'flowchart_node_id'
has_many :flowchart_icon_helpers
accepts_nested_attributes_for :flowchart_icon_helpers, allow_destroy: true
has_many :flowchart_icons, through: :flowchart_icon_helpers
validates :text, presence: true
validates :header, presence: true
Expand Down Expand Up @@ -106,6 +107,10 @@ def children
FlowchartNode.where(flowchart_node_id: id).find_each
end

def display_name
header
end

def as_json(_options = {})
super(include: :flowchart_icons)
end
Expand Down
Loading

0 comments on commit fe461a1

Please sign in to comment.