From 4485624f79d6855de6611d3fd74f3bef31f34abc Mon Sep 17 00:00:00 2001 From: Joshua Coles Date: Sun, 4 Feb 2024 13:35:28 +0000 Subject: [PATCH] Add archived to dashboard and change homepage to only show active (ie not archived) courses --- app/controllers/attendance_tracker_controller.rb | 6 +++--- app/dashboards/course_dashboard.rb | 9 ++++++++- app/models/course.rb | 2 ++ 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/app/controllers/attendance_tracker_controller.rb b/app/controllers/attendance_tracker_controller.rb index e7a4c20..187f604 100644 --- a/app/controllers/attendance_tracker_controller.rb +++ b/app/controllers/attendance_tracker_controller.rb @@ -1,16 +1,16 @@ class AttendanceTrackerController < ApplicationController def index - @courses = Course.all.sort_by(&:title) + @courses = Course.active.sort_by(&:title) @current_lecture = get_current_lecture end def overview - @courses = Course.all.sort_by(&:title) + @courses = Course.active.sort_by(&:title) @current_lecture = get_current_lecture end def today - @courses = Course.all.sort_by(&:title) + @courses = Course.active.sort_by(&:title) @date = Date.today @current_lecture = get_current_lecture @lectures = @courses.flat_map { |course| course.lectures.filter { |a| a.start_time.today? } }.sort_by { |l| l.start_time } diff --git a/app/dashboards/course_dashboard.rb b/app/dashboards/course_dashboard.rb index b7e8f01..42c3572 100644 --- a/app/dashboards/course_dashboard.rb +++ b/app/dashboards/course_dashboard.rb @@ -15,6 +15,7 @@ class CourseDashboard < Administrate::BaseDashboard panopto_folders: Field::String.with_options(searchable: false), semester_start_date: Field::Date, title: Field::String, + archived: Field::Boolean, homepage: Field::String, toggl_project: Field::Number, unit_code: Field::String, @@ -30,6 +31,7 @@ class CourseDashboard < Administrate::BaseDashboard COLLECTION_ATTRIBUTES = %i[ title unit_code + archived homepage lectures work_items @@ -42,6 +44,7 @@ class CourseDashboard < Administrate::BaseDashboard id title unit_code + archived homepage panopto_folders semester_start_date @@ -59,6 +62,7 @@ class CourseDashboard < Administrate::BaseDashboard FORM_ATTRIBUTES = %i[ title unit_code + archived homepage panopto_folders semester_start_date @@ -75,7 +79,10 @@ class CourseDashboard < Administrate::BaseDashboard # COLLECTION_FILTERS = { # open: ->(resources) { resources.where(open: true) } # }.freeze - COLLECTION_FILTERS = {}.freeze + COLLECTION_FILTERS = { + archived: ->(resources) { resources.where(archived: true) }, + active: ->(resources) { resources.where(archived: false) } + }.freeze # Overwrite this method to customize how courses are displayed # across all pages of the admin dashboard. diff --git a/app/models/course.rb b/app/models/course.rb index c3c34cc..1272ef5 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -6,6 +6,8 @@ class Course < ApplicationRecord # we them independently to avoid re-importing lectures. has_many :recordings, dependent: :destroy + scope :active, -> { where(archived: false) } + def lectures_and_work_items (lectures + work_items).sort_by(&:start_time) end