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

View File

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

View File

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

View File

@ -1,7 +1,7 @@
class Lecture < ApplicationRecord
belongs_to :course
has_one :attendance
belongs_to :recording, optional: true
has_one :recording
def week_number
((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
class Recording < ApplicationRecord
belongs_to :course
belongs_to :lecture, optional: true
def recording_url
return nil if recording_uuid.nil?
@ -17,4 +18,12 @@ class Recording < ApplicationRecord
title
end
def create_lecture!(fixup_time: false)
Lecture.create!(
title: nice_title,
course: course,
recording: self
)
end
end

View File

@ -25,8 +25,10 @@
</tr>
<% 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 style="<%= style %>">
<tr class="<%= class_names({
'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">
<%= lecture.title %>
</td>
@ -34,7 +36,7 @@
<%= lecture.start_time.to_fs(:dmy) %>
</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>

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.
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
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 "updated_at", null: false
t.bigint "course_id"
t.bigint "recording_id"
t.string "event_uuid"
t.boolean "cancelled", default: false
t.index ["course_id"], name: "index_lectures_on_course_id"
t.index ["recording_id"], name: "index_lectures_on_recording_id"
end
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.datetime "created_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 ["lecture_id"], name: "index_recordings_on_lecture_id"
t.index ["recording_uuid"], name: "index_recordings_on_recording_uuid", unique: true
end