Add archived to dashboard and change homepage to only show active (ie not archived) courses

This commit is contained in:
Joshua Coles 2024-02-04 13:35:28 +00:00
parent 04566509dc
commit 4485624f79
3 changed files with 13 additions and 4 deletions

View File

@ -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 }

View File

@ -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.

View File

@ -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