Skip to content

Commit ed0368b

Browse files
Merge pull request #4 from Jonathanlau92/add-user-sign-in-and-admin-page
Add user sign in and admin page
2 parents 5caf25a + 84df9e2 commit ed0368b

36 files changed

+1213
-2
lines changed

Gemfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ gem 'jbuilder', '~> 2.7'
2525
# Use Active Storage variant
2626
# gem 'image_processing', '~> 1.2'
2727

28+
# User registration, login,logout etc
29+
gem 'devise'
30+
# Admin page
31+
gem "administrate"
32+
2833
# Multi Pages form
2934
gem 'wicked'
3035

Gemfile.lock

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,20 @@ GEM
5858
zeitwerk (~> 2.2)
5959
addressable (2.7.0)
6060
public_suffix (>= 2.0.2, < 5.0)
61+
administrate (0.13.0)
62+
actionpack (>= 4.2)
63+
actionview (>= 4.2)
64+
activerecord (>= 4.2)
65+
autoprefixer-rails (>= 6.0)
66+
datetime_picker_rails (~> 0.0.7)
67+
jquery-rails (>= 4.0)
68+
kaminari (>= 1.0)
69+
momentjs-rails (~> 2.8)
70+
sassc-rails (~> 2.1)
71+
selectize-rails (~> 0.6)
72+
autoprefixer-rails (9.7.6)
73+
execjs
74+
bcrypt (3.1.13)
6175
bindex (0.8.1)
6276
bootsnap (1.4.6)
6377
msgpack (~> 1.0)
@@ -74,18 +88,43 @@ GEM
7488
childprocess (3.0.0)
7589
concurrent-ruby (1.1.6)
7690
crass (1.0.6)
91+
datetime_picker_rails (0.0.7)
92+
momentjs-rails (>= 2.8.1)
93+
devise (4.7.1)
94+
bcrypt (~> 3.0)
95+
orm_adapter (~> 0.1)
96+
railties (>= 4.1.0)
97+
responders
98+
warden (~> 1.2.3)
7799
dotenv (2.7.5)
78100
dotenv-rails (2.7.5)
79101
dotenv (= 2.7.5)
80102
railties (>= 3.2, < 6.1)
81103
erubi (1.9.0)
104+
execjs (2.7.0)
82105
ffi (1.12.2)
83106
globalid (0.4.2)
84107
activesupport (>= 4.2.0)
85108
i18n (1.8.2)
86109
concurrent-ruby (~> 1.0)
87110
jbuilder (2.10.0)
88111
activesupport (>= 5.0.0)
112+
jquery-rails (4.3.5)
113+
rails-dom-testing (>= 1, < 3)
114+
railties (>= 4.2.0)
115+
thor (>= 0.14, < 2.0)
116+
kaminari (1.2.0)
117+
activesupport (>= 4.1.0)
118+
kaminari-actionview (= 1.2.0)
119+
kaminari-activerecord (= 1.2.0)
120+
kaminari-core (= 1.2.0)
121+
kaminari-actionview (1.2.0)
122+
actionview
123+
kaminari-core (= 1.2.0)
124+
kaminari-activerecord (1.2.0)
125+
activerecord
126+
kaminari-core (= 1.2.0)
127+
kaminari-core (1.2.0)
89128
listen (3.1.5)
90129
rb-fsevent (~> 0.9, >= 0.9.4)
91130
rb-inotify (~> 0.9, >= 0.9.7)
@@ -102,10 +141,13 @@ GEM
102141
mini_mime (1.0.2)
103142
mini_portile2 (2.4.0)
104143
minitest (5.14.0)
144+
momentjs-rails (2.20.1)
145+
railties (>= 3.1)
105146
msgpack (1.3.3)
106147
nio4r (2.5.2)
107148
nokogiri (1.10.9)
108149
mini_portile2 (~> 2.4.0)
150+
orm_adapter (0.5.0)
109151
pg (1.2.3)
110152
public_suffix (4.0.4)
111153
puma (4.3.3)
@@ -146,6 +188,9 @@ GEM
146188
rb-inotify (0.10.1)
147189
ffi (~> 1.0)
148190
regexp_parser (1.7.0)
191+
responders (3.0.0)
192+
actionpack (>= 5.0)
193+
railties (>= 5.0)
149194
rollbar (2.25.0)
150195
ruby_dep (1.5.0)
151196
rubyzip (2.3.0)
@@ -159,6 +204,7 @@ GEM
159204
sprockets (> 3.0)
160205
sprockets-rails
161206
tilt
207+
selectize-rails (0.12.6)
162208
selenium-webdriver (3.142.7)
163209
childprocess (>= 0.5, < 4.0)
164210
rubyzip (>= 1.2.2)
@@ -181,6 +227,8 @@ GEM
181227
turbolinks-source (5.2.0)
182228
tzinfo (1.2.7)
183229
thread_safe (~> 0.1)
230+
warden (1.2.8)
231+
rack (>= 2.0.6)
184232
web-console (4.0.1)
185233
actionview (>= 6.0.0)
186234
activemodel (>= 6.0.0)
@@ -207,9 +255,11 @@ PLATFORMS
207255
ruby
208256

209257
DEPENDENCIES
258+
administrate
210259
bootsnap (>= 1.4.2)
211260
byebug
212261
capybara (>= 2.15)
262+
devise
213263
dotenv-rails
214264
jbuilder (~> 2.7)
215265
listen (>= 3.0.5, < 3.2)

app/assets/config/manifest.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
//= link_tree ../images
2+
//= link administrate/application.css
3+
//= link administrate/application.js
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# All Administrate controllers inherit from this
2+
# `Administrate::ApplicationController`, making it the ideal place to put
3+
# authentication logic or other before_actions.
4+
#
5+
# If you want to add pagination or other controller-level concerns,
6+
# you're free to overwrite the RESTful controller actions.
7+
module Admin
8+
class ApplicationController < Administrate::ApplicationController
9+
before_action :authenticate_user!
10+
11+
# def authenticate_admin
12+
# TODO Add authentication logic here.
13+
# end
14+
15+
# Override this value to specify the number of elements to display at a time
16+
# on index pages. Defaults to 20.
17+
# def records_per_page
18+
# params[:per_page] || 20
19+
# end
20+
end
21+
end
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
module Admin
2+
class StudentsController < Admin::ApplicationController
3+
# Overwrite any of the RESTful controller actions to implement custom behavior
4+
# For example, you may want to send an email after a foo is updated.
5+
#
6+
# def update
7+
# super
8+
# send_foo_updated_email(requested_resource)
9+
# end
10+
11+
# Override this method to specify custom lookup behavior.
12+
# This will be used to set the resource for the `show`, `edit`, and `update`
13+
# actions.
14+
#
15+
# def find_resource(param)
16+
# Foo.find_by!(slug: param)
17+
# end
18+
19+
# The result of this lookup will be available as `requested_resource`
20+
21+
# Override this if you have certain roles that require a subset
22+
# this will be used to set the records shown on the `index` action.
23+
#
24+
# def scoped_resource
25+
# if current_user.super_admin?
26+
# resource_class
27+
# else
28+
# resource_class.with_less_stuff
29+
# end
30+
# end
31+
32+
# Override `resource_params` if you want to transform the submitted
33+
# data before it's persisted. For example, the following would turn all
34+
# empty values into nil values. It uses other APIs such as `resource_class`
35+
# and `dashboard`:
36+
#
37+
# def resource_params
38+
# params.require(resource_class.model_name.param_key).
39+
# permit(dashboard.permitted_attributes).
40+
# transform_values { |value| value == "" ? nil : value }
41+
# end
42+
43+
# See https://administrate-prototype.herokuapp.com/customizing_controller_actions
44+
# for more information
45+
end
46+
end
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
module Admin
2+
class TutorsController < Admin::ApplicationController
3+
# Overwrite any of the RESTful controller actions to implement custom behavior
4+
# For example, you may want to send an email after a foo is updated.
5+
#
6+
# def update
7+
# super
8+
# send_foo_updated_email(requested_resource)
9+
# end
10+
11+
# Override this method to specify custom lookup behavior.
12+
# This will be used to set the resource for the `show`, `edit`, and `update`
13+
# actions.
14+
#
15+
# def find_resource(param)
16+
# Foo.find_by!(slug: param)
17+
# end
18+
19+
# The result of this lookup will be available as `requested_resource`
20+
21+
# Override this if you have certain roles that require a subset
22+
# this will be used to set the records shown on the `index` action.
23+
#
24+
# def scoped_resource
25+
# if current_user.super_admin?
26+
# resource_class
27+
# else
28+
# resource_class.with_less_stuff
29+
# end
30+
# end
31+
32+
# Override `resource_params` if you want to transform the submitted
33+
# data before it's persisted. For example, the following would turn all
34+
# empty values into nil values. It uses other APIs such as `resource_class`
35+
# and `dashboard`:
36+
#
37+
# def resource_params
38+
# params.require(resource_class.model_name.param_key).
39+
# permit(dashboard.permitted_attributes).
40+
# transform_values { |value| value == "" ? nil : value }
41+
# end
42+
43+
# See https://administrate-prototype.herokuapp.com/customizing_controller_actions
44+
# for more information
45+
end
46+
end
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
module Admin
2+
class UsersController < Admin::ApplicationController
3+
# Overwrite any of the RESTful controller actions to implement custom behavior
4+
# For example, you may want to send an email after a foo is updated.
5+
#
6+
# def update
7+
# super
8+
# send_foo_updated_email(requested_resource)
9+
# end
10+
11+
# Override this method to specify custom lookup behavior.
12+
# This will be used to set the resource for the `show`, `edit`, and `update`
13+
# actions.
14+
#
15+
# def find_resource(param)
16+
# Foo.find_by!(slug: param)
17+
# end
18+
19+
# The result of this lookup will be available as `requested_resource`
20+
21+
# Override this if you have certain roles that require a subset
22+
# this will be used to set the records shown on the `index` action.
23+
#
24+
# def scoped_resource
25+
# if current_user.super_admin?
26+
# resource_class
27+
# else
28+
# resource_class.with_less_stuff
29+
# end
30+
# end
31+
32+
# Override `resource_params` if you want to transform the submitted
33+
# data before it's persisted. For example, the following would turn all
34+
# empty values into nil values. It uses other APIs such as `resource_class`
35+
# and `dashboard`:
36+
#
37+
# def resource_params
38+
# params.require(resource_class.model_name.param_key).
39+
# permit(dashboard.permitted_attributes).
40+
# transform_values { |value| value == "" ? nil : value }
41+
# end
42+
43+
# See https://administrate-prototype.herokuapp.com/customizing_controller_actions
44+
# for more information
45+
end
46+
end
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
require "administrate/base_dashboard"
2+
3+
class StudentDashboard < Administrate::BaseDashboard
4+
# ATTRIBUTE_TYPES
5+
# a hash that describes the type of each of the model's fields.
6+
#
7+
# Each different type represents an Administrate::Field object,
8+
# which determines how the attribute is displayed
9+
# on pages throughout the dashboard.
10+
ATTRIBUTE_TYPES = {
11+
id: Field::Number,
12+
personal_consent: Field::Boolean,
13+
full_name: Field::String,
14+
school_email: Field::String,
15+
alternate_email: Field::String,
16+
sex: Field::String.with_options(searchable: false),
17+
subject_preferences: Field::String.with_options(searchable: false),
18+
education_level: Field::String.with_options(searchable: false),
19+
parental_consent: Field::Boolean,
20+
match_count: Field::Number,
21+
created_at: Field::DateTime,
22+
updated_at: Field::DateTime,
23+
subject_1: Field::String,
24+
subject_2: Field::String,
25+
subject_3: Field::String,
26+
others_subject: Field::String,
27+
contact_number: Field::String,
28+
}.freeze
29+
30+
# COLLECTION_ATTRIBUTES
31+
# an array of attributes that will be displayed on the model's index page.
32+
#
33+
# By default, it's limited to four items to reduce clutter on index pages.
34+
# Feel free to add, remove, or rearrange items.
35+
COLLECTION_ATTRIBUTES = %i[
36+
id
37+
personal_consent
38+
full_name
39+
school_email
40+
].freeze
41+
42+
# SHOW_PAGE_ATTRIBUTES
43+
# an array of attributes that will be displayed on the model's show page.
44+
SHOW_PAGE_ATTRIBUTES = %i[
45+
id
46+
personal_consent
47+
full_name
48+
school_email
49+
alternate_email
50+
sex
51+
subject_preferences
52+
education_level
53+
parental_consent
54+
match_count
55+
created_at
56+
updated_at
57+
subject_1
58+
subject_2
59+
subject_3
60+
others_subject
61+
contact_number
62+
].freeze
63+
64+
# FORM_ATTRIBUTES
65+
# an array of attributes that will be displayed
66+
# on the model's form (`new` and `edit`) pages.
67+
FORM_ATTRIBUTES = %i[
68+
personal_consent
69+
full_name
70+
school_email
71+
alternate_email
72+
sex
73+
subject_preferences
74+
education_level
75+
parental_consent
76+
match_count
77+
subject_1
78+
subject_2
79+
subject_3
80+
others_subject
81+
contact_number
82+
].freeze
83+
84+
# COLLECTION_FILTERS
85+
# a hash that defines filters that can be used while searching via the search
86+
# field of the dashboard.
87+
#
88+
# For example to add an option to search for open resources by typing "open:"
89+
# in the search field:
90+
#
91+
# COLLECTION_FILTERS = {
92+
# open: ->(resources) { resources.where(open: true) }
93+
# }.freeze
94+
COLLECTION_FILTERS = {}.freeze
95+
96+
# Overwrite this method to customize how students are displayed
97+
# across all pages of the admin dashboard.
98+
#
99+
# def display_resource(student)
100+
# "Student ##{student.id}"
101+
# end
102+
end

0 commit comments

Comments
 (0)