Add administrate
This commit is contained in:
parent
285cf78d63
commit
3300017d98
1
Gemfile
1
Gemfile
@ -76,3 +76,4 @@ gem "font-awesome-sass"
|
|||||||
gem "httparty"
|
gem "httparty"
|
||||||
|
|
||||||
gem "sidekiq"
|
gem "sidekiq"
|
||||||
|
gem "administrate"
|
||||||
|
|||||||
33
Gemfile.lock
33
Gemfile.lock
@ -68,6 +68,14 @@ GEM
|
|||||||
tzinfo (~> 2.0)
|
tzinfo (~> 2.0)
|
||||||
addressable (2.8.5)
|
addressable (2.8.5)
|
||||||
public_suffix (>= 2.0.2, < 6.0)
|
public_suffix (>= 2.0.2, < 6.0)
|
||||||
|
administrate (0.19.0)
|
||||||
|
actionpack (>= 5.0)
|
||||||
|
actionview (>= 5.0)
|
||||||
|
activerecord (>= 5.0)
|
||||||
|
jquery-rails (>= 4.0)
|
||||||
|
kaminari (>= 1.0)
|
||||||
|
sassc-rails (~> 2.1)
|
||||||
|
selectize-rails (~> 0.6)
|
||||||
bindex (0.8.1)
|
bindex (0.8.1)
|
||||||
bootsnap (1.16.0)
|
bootsnap (1.16.0)
|
||||||
msgpack (~> 1.2)
|
msgpack (~> 1.2)
|
||||||
@ -109,6 +117,22 @@ GEM
|
|||||||
jbuilder (2.11.5)
|
jbuilder (2.11.5)
|
||||||
actionview (>= 5.0.0)
|
actionview (>= 5.0.0)
|
||||||
activesupport (>= 5.0.0)
|
activesupport (>= 5.0.0)
|
||||||
|
jquery-rails (4.6.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)
|
||||||
loofah (2.21.3)
|
loofah (2.21.3)
|
||||||
crass (~> 1.0.2)
|
crass (~> 1.0.2)
|
||||||
nokogiri (>= 1.12.0)
|
nokogiri (>= 1.12.0)
|
||||||
@ -187,6 +211,13 @@ GEM
|
|||||||
rubyzip (2.3.2)
|
rubyzip (2.3.2)
|
||||||
sassc (2.4.0)
|
sassc (2.4.0)
|
||||||
ffi (~> 1.9)
|
ffi (~> 1.9)
|
||||||
|
sassc-rails (2.1.2)
|
||||||
|
railties (>= 4.0.0)
|
||||||
|
sassc (>= 2.0)
|
||||||
|
sprockets (> 3.0)
|
||||||
|
sprockets-rails
|
||||||
|
tilt
|
||||||
|
selectize-rails (0.12.6)
|
||||||
selenium-webdriver (4.10.0)
|
selenium-webdriver (4.10.0)
|
||||||
rexml (~> 3.2, >= 3.2.5)
|
rexml (~> 3.2, >= 3.2.5)
|
||||||
rubyzip (>= 1.2.2, < 3.0)
|
rubyzip (>= 1.2.2, < 3.0)
|
||||||
@ -209,6 +240,7 @@ GEM
|
|||||||
tailwindcss-rails (2.0.30-arm64-darwin)
|
tailwindcss-rails (2.0.30-arm64-darwin)
|
||||||
railties (>= 6.0.0)
|
railties (>= 6.0.0)
|
||||||
thor (1.2.2)
|
thor (1.2.2)
|
||||||
|
tilt (2.2.0)
|
||||||
timeout (0.4.0)
|
timeout (0.4.0)
|
||||||
turbo-rails (1.4.0)
|
turbo-rails (1.4.0)
|
||||||
actionpack (>= 6.0.0)
|
actionpack (>= 6.0.0)
|
||||||
@ -237,6 +269,7 @@ PLATFORMS
|
|||||||
arm64-darwin-22
|
arm64-darwin-22
|
||||||
|
|
||||||
DEPENDENCIES
|
DEPENDENCIES
|
||||||
|
administrate
|
||||||
bootsnap
|
bootsnap
|
||||||
capybara
|
capybara
|
||||||
debug
|
debug
|
||||||
|
|||||||
21
app/controllers/admin/application_controller.rb
Normal file
21
app/controllers/admin/application_controller.rb
Normal file
@ -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_admin
|
||||||
|
|
||||||
|
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
app/controllers/admin/attendances_controller.rb
Normal file
46
app/controllers/admin/attendances_controller.rb
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
module Admin
|
||||||
|
class AttendancesController < 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(action_name)).
|
||||||
|
# transform_values { |value| value == "" ? nil : value }
|
||||||
|
# end
|
||||||
|
|
||||||
|
# See https://administrate-demo.herokuapp.com/customizing_controller_actions
|
||||||
|
# for more information
|
||||||
|
end
|
||||||
|
end
|
||||||
46
app/controllers/admin/courses_controller.rb
Normal file
46
app/controllers/admin/courses_controller.rb
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
module Admin
|
||||||
|
class CoursesController < 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(action_name)).
|
||||||
|
# transform_values { |value| value == "" ? nil : value }
|
||||||
|
# end
|
||||||
|
|
||||||
|
# See https://administrate-demo.herokuapp.com/customizing_controller_actions
|
||||||
|
# for more information
|
||||||
|
end
|
||||||
|
end
|
||||||
46
app/controllers/admin/lectures_controller.rb
Normal file
46
app/controllers/admin/lectures_controller.rb
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
module Admin
|
||||||
|
class LecturesController < 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(action_name)).
|
||||||
|
# transform_values { |value| value == "" ? nil : value }
|
||||||
|
# end
|
||||||
|
|
||||||
|
# See https://administrate-demo.herokuapp.com/customizing_controller_actions
|
||||||
|
# for more information
|
||||||
|
end
|
||||||
|
end
|
||||||
69
app/dashboards/attendance_dashboard.rb
Normal file
69
app/dashboards/attendance_dashboard.rb
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
require "administrate/base_dashboard"
|
||||||
|
|
||||||
|
class AttendanceDashboard < 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,
|
||||||
|
associated_toggl_entry: Field::String,
|
||||||
|
kind: Field::Select.with_options(searchable: false, collection: ->(field) { field.resource.class.send(field.attribute.to_s.pluralize).keys }),
|
||||||
|
lecture: Field::BelongsTo,
|
||||||
|
created_at: Field::DateTime,
|
||||||
|
updated_at: Field::DateTime,
|
||||||
|
}.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
|
||||||
|
associated_toggl_entry
|
||||||
|
kind
|
||||||
|
lecture
|
||||||
|
].freeze
|
||||||
|
|
||||||
|
# SHOW_PAGE_ATTRIBUTES
|
||||||
|
# an array of attributes that will be displayed on the model's show page.
|
||||||
|
SHOW_PAGE_ATTRIBUTES = %i[
|
||||||
|
id
|
||||||
|
associated_toggl_entry
|
||||||
|
kind
|
||||||
|
lecture
|
||||||
|
created_at
|
||||||
|
updated_at
|
||||||
|
].freeze
|
||||||
|
|
||||||
|
# FORM_ATTRIBUTES
|
||||||
|
# an array of attributes that will be displayed
|
||||||
|
# on the model's form (`new` and `edit`) pages.
|
||||||
|
FORM_ATTRIBUTES = %i[
|
||||||
|
associated_toggl_entry
|
||||||
|
kind
|
||||||
|
lecture
|
||||||
|
].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 attendances are displayed
|
||||||
|
# across all pages of the admin dashboard.
|
||||||
|
#
|
||||||
|
# def display_resource(attendance)
|
||||||
|
# "Attendance ##{attendance.id}"
|
||||||
|
# end
|
||||||
|
end
|
||||||
75
app/dashboards/course_dashboard.rb
Normal file
75
app/dashboards/course_dashboard.rb
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
require "administrate/base_dashboard"
|
||||||
|
|
||||||
|
class CourseDashboard < 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,
|
||||||
|
lectures: Field::HasMany,
|
||||||
|
panopto_folders: Field::String.with_options(searchable: false),
|
||||||
|
title: Field::String,
|
||||||
|
toggl_project: Field::Number,
|
||||||
|
unit_code: Field::String,
|
||||||
|
created_at: Field::DateTime,
|
||||||
|
updated_at: Field::DateTime,
|
||||||
|
}.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
|
||||||
|
lectures
|
||||||
|
panopto_folders
|
||||||
|
title
|
||||||
|
].freeze
|
||||||
|
|
||||||
|
# SHOW_PAGE_ATTRIBUTES
|
||||||
|
# an array of attributes that will be displayed on the model's show page.
|
||||||
|
SHOW_PAGE_ATTRIBUTES = %i[
|
||||||
|
id
|
||||||
|
lectures
|
||||||
|
panopto_folders
|
||||||
|
title
|
||||||
|
toggl_project
|
||||||
|
unit_code
|
||||||
|
created_at
|
||||||
|
updated_at
|
||||||
|
].freeze
|
||||||
|
|
||||||
|
# FORM_ATTRIBUTES
|
||||||
|
# an array of attributes that will be displayed
|
||||||
|
# on the model's form (`new` and `edit`) pages.
|
||||||
|
FORM_ATTRIBUTES = %i[
|
||||||
|
lectures
|
||||||
|
panopto_folders
|
||||||
|
title
|
||||||
|
toggl_project
|
||||||
|
unit_code
|
||||||
|
].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 courses are displayed
|
||||||
|
# across all pages of the admin dashboard.
|
||||||
|
#
|
||||||
|
# def display_resource(course)
|
||||||
|
# "Course ##{course.id}"
|
||||||
|
# end
|
||||||
|
end
|
||||||
78
app/dashboards/lecture_dashboard.rb
Normal file
78
app/dashboards/lecture_dashboard.rb
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
require "administrate/base_dashboard"
|
||||||
|
|
||||||
|
class LectureDashboard < 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,
|
||||||
|
attendance: Field::HasOne,
|
||||||
|
course: Field::BelongsTo,
|
||||||
|
recording_id: Field::String,
|
||||||
|
start_time: Field::DateTime,
|
||||||
|
status: Field::Select.with_options(searchable: false, collection: ->(field) { field.resource.class.send(field.attribute.to_s.pluralize).keys }),
|
||||||
|
title: Field::String,
|
||||||
|
created_at: Field::DateTime,
|
||||||
|
updated_at: Field::DateTime,
|
||||||
|
}.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
|
||||||
|
attendance
|
||||||
|
course
|
||||||
|
recording_id
|
||||||
|
].freeze
|
||||||
|
|
||||||
|
# SHOW_PAGE_ATTRIBUTES
|
||||||
|
# an array of attributes that will be displayed on the model's show page.
|
||||||
|
SHOW_PAGE_ATTRIBUTES = %i[
|
||||||
|
id
|
||||||
|
attendance
|
||||||
|
course
|
||||||
|
recording_id
|
||||||
|
start_time
|
||||||
|
status
|
||||||
|
title
|
||||||
|
created_at
|
||||||
|
updated_at
|
||||||
|
].freeze
|
||||||
|
|
||||||
|
# FORM_ATTRIBUTES
|
||||||
|
# an array of attributes that will be displayed
|
||||||
|
# on the model's form (`new` and `edit`) pages.
|
||||||
|
FORM_ATTRIBUTES = %i[
|
||||||
|
attendance
|
||||||
|
course
|
||||||
|
recording_id
|
||||||
|
start_time
|
||||||
|
status
|
||||||
|
title
|
||||||
|
].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 lectures are displayed
|
||||||
|
# across all pages of the admin dashboard.
|
||||||
|
#
|
||||||
|
# def display_resource(lecture)
|
||||||
|
# "Lecture ##{lecture.id}"
|
||||||
|
# end
|
||||||
|
end
|
||||||
@ -1,3 +1,10 @@
|
|||||||
Rails.application.routes.draw do
|
Rails.application.routes.draw do
|
||||||
|
namespace :admin do
|
||||||
|
resources :attendances
|
||||||
|
resources :courses
|
||||||
|
resources :lectures
|
||||||
|
|
||||||
|
root to: "attendances#index"
|
||||||
|
end
|
||||||
root controller: :attendance_tracker, action: :index
|
root controller: :attendance_tracker, action: :index
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user