Update Lecture-Recording relationship and add Lecture cancellation status

The commit introduces notable changes to the Lecture-Recording model relationship in our application and adds a new cancellation status to Lecture model.

Models Lecture and Recording previously had a belongs_to :recording and belongs_to :lecture relationship respectively. However, this setup was not reflecting the correct relationship between these two entities in the actual educational setup where a lecture can have a recording but a recording is always of a lecture. Thus, the relationship has been revised to has_one :recording in Lecture and belongs_to :lecture in Recording models.

Also, added the ability to mark a lecture as "cancelled". This addresses the requirement of representing real-world scenarios where lectures are sometimes cancelled. This cancellation status is then reflected in the Attendance Tracker view and is also handled in the ScrapePanoptoJob.

Additionally, new changes are reflected in the application's schema, migration files, admin dashboard, and stylesheets (for displaying cancelled lectures).
This commit is contained in:
Joshua Coles 2023-10-02 09:47:46 +01:00
parent d8a6f27734
commit 58c1280309
10 changed files with 45 additions and 10 deletions

View File

@ -14,3 +14,11 @@
*= require _font-awesome *= require _font-awesome
*= require_self *= require_self
*/ */
.lecture-future {
background: repeating-linear-gradient(45deg, #f3f4f6, #f3f4f6 10px, white 10px, white 20px);
}
.lecture-cancelled {
background: repeating-linear-gradient(45deg, rgb(254 226 226/var(--tw-bg-opacity)), rgb(254 226 226/var(--tw-bg-opacity)) 10px, white 10px, white 20px);
}

View File

@ -12,9 +12,10 @@ class LectureDashboard < Administrate::BaseDashboard
attendance: Field::HasOne, attendance: Field::HasOne,
course: Field::BelongsTo, course: Field::BelongsTo,
event_uuid: Field::String, event_uuid: Field::String,
recording: Field::BelongsTo, recording: Field::HasOne,
start_time: Field::DateTime, start_time: Field::DateTime,
title: Field::String, title: Field::String,
cancelled: Field::Boolean,
created_at: Field::DateTime, created_at: Field::DateTime,
updated_at: Field::DateTime, updated_at: Field::DateTime,
}.freeze }.freeze
@ -27,6 +28,7 @@ class LectureDashboard < Administrate::BaseDashboard
COLLECTION_ATTRIBUTES = %i[ COLLECTION_ATTRIBUTES = %i[
title title
course course
cancelled
start_time start_time
recording recording
].freeze ].freeze
@ -37,6 +39,7 @@ class LectureDashboard < Administrate::BaseDashboard
id id
attendance attendance
course course
cancelled
event_uuid event_uuid
recording recording
start_time start_time
@ -51,6 +54,7 @@ class LectureDashboard < Administrate::BaseDashboard
FORM_ATTRIBUTES = %i[ FORM_ATTRIBUTES = %i[
attendance attendance
course course
cancelled
event_uuid event_uuid
recording recording
start_time start_time

View File

@ -10,6 +10,7 @@ class RecordingDashboard < Administrate::BaseDashboard
ATTRIBUTE_TYPES = { ATTRIBUTE_TYPES = {
id: Field::Number, id: Field::Number,
course: Field::BelongsTo, course: Field::BelongsTo,
lecture: Field::BelongsTo,
recording_uuid: Field::String, recording_uuid: Field::String,
start_time: Field::DateTime, start_time: Field::DateTime,
title: Field::String, title: Field::String,

View File

@ -36,11 +36,10 @@ class ScrapePanoptoJob < ApplicationJob
lecture.update!(recording_id: new_recording.id) lecture.update!(recording_id: new_recording.id)
else else
# Else create a new lecture # Else create a new lecture
Lecture.create!( lecture = Lecture.create!(
title: new_recording.nice_title, title: new_recording.nice_title,
start_time: new_recording.start_time, start_time: new_recording.start_time,
course_id: new_recording.course_id, course_id: new_recording.course_id,
recording_id: new_recording.id
) )
end end
end end

View File

@ -1,7 +1,7 @@
class Lecture < ApplicationRecord class Lecture < ApplicationRecord
belongs_to :course belongs_to :course
has_one :attendance has_one :attendance
belongs_to :recording, optional: true has_one :recording
def week_number def week_number
((start_time.beginning_of_week - course.semester_start_date.to_time) / 1.week).floor + 1 ((start_time.beginning_of_week - course.semester_start_date.to_time) / 1.week).floor + 1

View File

@ -1,6 +1,7 @@
# This is a Foreign Object Reference Table, keyed to the external data source by #recording_uuid # This is a Foreign Object Reference Table, keyed to the external data source by #recording_uuid
class Recording < ApplicationRecord class Recording < ApplicationRecord
belongs_to :course belongs_to :course
belongs_to :lecture, optional: true
def recording_url def recording_url
return nil if recording_uuid.nil? return nil if recording_uuid.nil?
@ -17,4 +18,12 @@ class Recording < ApplicationRecord
title title
end end
def create_lecture!(fixup_time: false)
Lecture.create!(
title: nice_title,
course: course,
recording: self
)
end
end end

View File

@ -25,8 +25,10 @@
</tr> </tr>
<% lectures.each do |lecture| %> <% lectures.each do |lecture| %>
<% style = if lecture.start_time.future? then 'background: repeating-linear-gradient(45deg, #f3f4f6, #f3f4f6 10px, white 10px, white 20px);' else '' end %> <tr class="<%= class_names({
<tr style="<%= style %>"> 'lecture-future': lecture.start_time.future?,
'lecture-cancelled': lecture.cancelled,
}) %>">
<td class="whitespace-nowrap py-4 pl-4 pr-3 text-sm font-medium text-gray-900 sm:pl-6"> <td class="whitespace-nowrap py-4 pl-4 pr-3 text-sm font-medium text-gray-900 sm:pl-6">
<%= lecture.title %> <%= lecture.title %>
</td> </td>
@ -34,7 +36,7 @@
<%= lecture.start_time.to_fs(:dmy) %> <%= lecture.start_time.to_fs(:dmy) %>
</td> </td>
<% if lecture.start_time.future? %> <% if lecture.start_time.future? || lecture.cancelled %>
<td class="whitespace-nowrap px-3 py-4 text-sm text-gray-500"> <td class="whitespace-nowrap px-3 py-4 text-sm text-gray-500">
</td> </td>

View File

@ -0,0 +1,6 @@
class ChangeLectureRecordingOwnershipRelation < ActiveRecord::Migration[7.0]
def change
remove_column :lectures, :recording_id
add_belongs_to :recordings, :lecture
end
end

View File

@ -0,0 +1,5 @@
class AddCancelledStatusToLecture < ActiveRecord::Migration[7.0]
def change
add_column :lectures, :cancelled, :boolean, default: false
end
end

7
db/schema.rb generated
View File

@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.0].define(version: 2023_10_01_183712) do ActiveRecord::Schema[7.0].define(version: 2023_10_02_083755) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@ -39,10 +39,9 @@ ActiveRecord::Schema[7.0].define(version: 2023_10_01_183712) do
t.datetime "created_at", null: false t.datetime "created_at", null: false
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
t.bigint "course_id" t.bigint "course_id"
t.bigint "recording_id"
t.string "event_uuid" t.string "event_uuid"
t.boolean "cancelled", default: false
t.index ["course_id"], name: "index_lectures_on_course_id" t.index ["course_id"], name: "index_lectures_on_course_id"
t.index ["recording_id"], name: "index_lectures_on_recording_id"
end end
create_table "recordings", force: :cascade do |t| create_table "recordings", force: :cascade do |t|
@ -52,7 +51,9 @@ ActiveRecord::Schema[7.0].define(version: 2023_10_01_183712) do
t.bigint "course_id", null: false t.bigint "course_id", null: false
t.datetime "created_at", null: false t.datetime "created_at", null: false
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
t.bigint "lecture_id"
t.index ["course_id"], name: "index_recordings_on_course_id" t.index ["course_id"], name: "index_recordings_on_course_id"
t.index ["lecture_id"], name: "index_recordings_on_lecture_id"
t.index ["recording_uuid"], name: "index_recordings_on_recording_uuid", unique: true t.index ["recording_uuid"], name: "index_recordings_on_recording_uuid", unique: true
end end