Skip to content

Commit

Permalink
Add admin page to view all data upon login
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathanlau92 committed Apr 28, 2020
1 parent f688635 commit 84df9e2
Show file tree
Hide file tree
Showing 12 changed files with 505 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ gem 'jbuilder', '~> 2.7'

# User registration, login,logout etc
gem 'devise'
# Admin page
gem "administrate"

# Multi Pages form
gem 'wicked'
Expand Down
36 changes: 36 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,19 @@ GEM
zeitwerk (~> 2.2)
addressable (2.7.0)
public_suffix (>= 2.0.2, < 5.0)
administrate (0.13.0)
actionpack (>= 4.2)
actionview (>= 4.2)
activerecord (>= 4.2)
autoprefixer-rails (>= 6.0)
datetime_picker_rails (~> 0.0.7)
jquery-rails (>= 4.0)
kaminari (>= 1.0)
momentjs-rails (~> 2.8)
sassc-rails (~> 2.1)
selectize-rails (~> 0.6)
autoprefixer-rails (9.7.6)
execjs
bcrypt (3.1.13)
bindex (0.8.1)
bootsnap (1.4.6)
Expand All @@ -75,6 +88,8 @@ GEM
childprocess (3.0.0)
concurrent-ruby (1.1.6)
crass (1.0.6)
datetime_picker_rails (0.0.7)
momentjs-rails (>= 2.8.1)
devise (4.7.1)
bcrypt (~> 3.0)
orm_adapter (~> 0.1)
Expand All @@ -86,13 +101,30 @@ GEM
dotenv (= 2.7.5)
railties (>= 3.2, < 6.1)
erubi (1.9.0)
execjs (2.7.0)
ffi (1.12.2)
globalid (0.4.2)
activesupport (>= 4.2.0)
i18n (1.8.2)
concurrent-ruby (~> 1.0)
jbuilder (2.10.0)
activesupport (>= 5.0.0)
jquery-rails (4.3.5)
rails-dom-testing (>= 1, < 3)
railties (>= 4.2.0)
thor (>= 0.14, < 2.0)
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 All @@ -109,6 +141,8 @@ GEM
mini_mime (1.0.2)
mini_portile2 (2.4.0)
minitest (5.14.0)
momentjs-rails (2.20.1)
railties (>= 3.1)
msgpack (1.3.3)
nio4r (2.5.2)
nokogiri (1.10.9)
Expand Down Expand Up @@ -170,6 +204,7 @@ GEM
sprockets (> 3.0)
sprockets-rails
tilt
selectize-rails (0.12.6)
selenium-webdriver (3.142.7)
childprocess (>= 0.5, < 4.0)
rubyzip (>= 1.2.2)
Expand Down Expand Up @@ -220,6 +255,7 @@ PLATFORMS
ruby

DEPENDENCIES
administrate
bootsnap (>= 1.4.2)
byebug
capybara (>= 2.15)
Expand Down
2 changes: 2 additions & 0 deletions app/assets/config/manifest.js
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
//= link_tree ../images
//= link administrate/application.css
//= link administrate/application.js
21 changes: 21 additions & 0 deletions app/controllers/admin/application_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# All Administrate controllers inherit from this
# `Administrate::ApplicationController`, making it the ideal place to put
# authentication logic or other before_actions.
#
# If you want to add pagination or other controller-level concerns,
# you're free to overwrite the RESTful controller actions.
module Admin
class ApplicationController < Administrate::ApplicationController
before_action :authenticate_user!

# def authenticate_admin
# TODO Add authentication logic here.
# end

# Override this value to specify the number of elements to display at a time
# on index pages. Defaults to 20.
# def records_per_page
# params[:per_page] || 20
# end
end
end
46 changes: 46 additions & 0 deletions app/controllers/admin/students_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
module Admin
class StudentsController < Admin::ApplicationController
# Overwrite any of the RESTful controller actions to implement custom behavior
# For example, you may want to send an email after a foo is updated.
#
# def update
# super
# send_foo_updated_email(requested_resource)
# end

# Override this method to specify custom lookup behavior.
# This will be used to set the resource for the `show`, `edit`, and `update`
# actions.
#
# def find_resource(param)
# Foo.find_by!(slug: param)
# end

# The result of this lookup will be available as `requested_resource`

# Override this if you have certain roles that require a subset
# this will be used to set the records shown on the `index` action.
#
# def scoped_resource
# if current_user.super_admin?
# resource_class
# else
# resource_class.with_less_stuff
# end
# end

# Override `resource_params` if you want to transform the submitted
# data before it's persisted. For example, the following would turn all
# empty values into nil values. It uses other APIs such as `resource_class`
# and `dashboard`:
#
# def resource_params
# params.require(resource_class.model_name.param_key).
# permit(dashboard.permitted_attributes).
# transform_values { |value| value == "" ? nil : value }
# end

# See https://administrate-prototype.herokuapp.com/customizing_controller_actions
# for more information
end
end
46 changes: 46 additions & 0 deletions app/controllers/admin/tutors_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
module Admin
class TutorsController < Admin::ApplicationController
# Overwrite any of the RESTful controller actions to implement custom behavior
# For example, you may want to send an email after a foo is updated.
#
# def update
# super
# send_foo_updated_email(requested_resource)
# end

# Override this method to specify custom lookup behavior.
# This will be used to set the resource for the `show`, `edit`, and `update`
# actions.
#
# def find_resource(param)
# Foo.find_by!(slug: param)
# end

# The result of this lookup will be available as `requested_resource`

# Override this if you have certain roles that require a subset
# this will be used to set the records shown on the `index` action.
#
# def scoped_resource
# if current_user.super_admin?
# resource_class
# else
# resource_class.with_less_stuff
# end
# end

# Override `resource_params` if you want to transform the submitted
# data before it's persisted. For example, the following would turn all
# empty values into nil values. It uses other APIs such as `resource_class`
# and `dashboard`:
#
# def resource_params
# params.require(resource_class.model_name.param_key).
# permit(dashboard.permitted_attributes).
# transform_values { |value| value == "" ? nil : value }
# end

# See https://administrate-prototype.herokuapp.com/customizing_controller_actions
# for more information
end
end
46 changes: 46 additions & 0 deletions app/controllers/admin/users_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
module Admin
class UsersController < Admin::ApplicationController
# Overwrite any of the RESTful controller actions to implement custom behavior
# For example, you may want to send an email after a foo is updated.
#
# def update
# super
# send_foo_updated_email(requested_resource)
# end

# Override this method to specify custom lookup behavior.
# This will be used to set the resource for the `show`, `edit`, and `update`
# actions.
#
# def find_resource(param)
# Foo.find_by!(slug: param)
# end

# The result of this lookup will be available as `requested_resource`

# Override this if you have certain roles that require a subset
# this will be used to set the records shown on the `index` action.
#
# def scoped_resource
# if current_user.super_admin?
# resource_class
# else
# resource_class.with_less_stuff
# end
# end

# Override `resource_params` if you want to transform the submitted
# data before it's persisted. For example, the following would turn all
# empty values into nil values. It uses other APIs such as `resource_class`
# and `dashboard`:
#
# def resource_params
# params.require(resource_class.model_name.param_key).
# permit(dashboard.permitted_attributes).
# transform_values { |value| value == "" ? nil : value }
# end

# See https://administrate-prototype.herokuapp.com/customizing_controller_actions
# for more information
end
end
102 changes: 102 additions & 0 deletions app/dashboards/student_dashboard.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
require "administrate/base_dashboard"

class StudentDashboard < Administrate::BaseDashboard
# ATTRIBUTE_TYPES
# a hash that describes the type of each of the model's fields.
#
# Each different type represents an Administrate::Field object,
# which determines how the attribute is displayed
# on pages throughout the dashboard.
ATTRIBUTE_TYPES = {
id: Field::Number,
personal_consent: Field::Boolean,
full_name: Field::String,
school_email: Field::String,
alternate_email: Field::String,
sex: Field::String.with_options(searchable: false),
subject_preferences: Field::String.with_options(searchable: false),
education_level: Field::String.with_options(searchable: false),
parental_consent: Field::Boolean,
match_count: Field::Number,
created_at: Field::DateTime,
updated_at: Field::DateTime,
subject_1: Field::String,
subject_2: Field::String,
subject_3: Field::String,
others_subject: Field::String,
contact_number: Field::String,
}.freeze

# COLLECTION_ATTRIBUTES
# an array of attributes that will be displayed on the model's index page.
#
# By default, it's limited to four items to reduce clutter on index pages.
# Feel free to add, remove, or rearrange items.
COLLECTION_ATTRIBUTES = %i[
id
personal_consent
full_name
school_email
].freeze

# SHOW_PAGE_ATTRIBUTES
# an array of attributes that will be displayed on the model's show page.
SHOW_PAGE_ATTRIBUTES = %i[
id
personal_consent
full_name
school_email
alternate_email
sex
subject_preferences
education_level
parental_consent
match_count
created_at
updated_at
subject_1
subject_2
subject_3
others_subject
contact_number
].freeze

# FORM_ATTRIBUTES
# an array of attributes that will be displayed
# on the model's form (`new` and `edit`) pages.
FORM_ATTRIBUTES = %i[
personal_consent
full_name
school_email
alternate_email
sex
subject_preferences
education_level
parental_consent
match_count
subject_1
subject_2
subject_3
others_subject
contact_number
].freeze

# COLLECTION_FILTERS
# a hash that defines filters that can be used while searching via the search
# field of the dashboard.
#
# For example to add an option to search for open resources by typing "open:"
# in the search field:
#
# COLLECTION_FILTERS = {
# open: ->(resources) { resources.where(open: true) }
# }.freeze
COLLECTION_FILTERS = {}.freeze

# Overwrite this method to customize how students are displayed
# across all pages of the admin dashboard.
#
# def display_resource(student)
# "Student ##{student.id}"
# end
end
Loading

0 comments on commit 84df9e2

Please sign in to comment.