From 58c12803092a6c77525261a36dfc9715d79e1706 Mon Sep 17 00:00:00 2001 From: Joshua Coles Date: Mon, 2 Oct 2023 09:47:46 +0100 Subject: [PATCH] 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). --- app/assets/stylesheets/application.css | 8 ++++++++ app/dashboards/lecture_dashboard.rb | 6 +++++- app/dashboards/recording_dashboard.rb | 1 + app/jobs/scrape_panopto_job.rb | 3 +-- app/models/lecture.rb | 2 +- app/models/recording.rb | 9 +++++++++ app/views/attendance_tracker/index.html.erb | 8 +++++--- ...191113_change_lecture_recording_ownership_relation.rb | 6 ++++++ .../20231002083755_add_cancelled_status_to_lecture.rb | 5 +++++ db/schema.rb | 7 ++++--- 10 files changed, 45 insertions(+), 10 deletions(-) create mode 100644 db/migrate/20231001191113_change_lecture_recording_ownership_relation.rb create mode 100644 db/migrate/20231002083755_add_cancelled_status_to_lecture.rb diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index ed8c1b0..10eb75a 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -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); +} \ No newline at end of file diff --git a/app/dashboards/lecture_dashboard.rb b/app/dashboards/lecture_dashboard.rb index 6e438a3..536f502 100644 --- a/app/dashboards/lecture_dashboard.rb +++ b/app/dashboards/lecture_dashboard.rb @@ -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 diff --git a/app/dashboards/recording_dashboard.rb b/app/dashboards/recording_dashboard.rb index 22dd54e..9d998d9 100644 --- a/app/dashboards/recording_dashboard.rb +++ b/app/dashboards/recording_dashboard.rb @@ -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, diff --git a/app/jobs/scrape_panopto_job.rb b/app/jobs/scrape_panopto_job.rb index 62d911e..c5909ad 100644 --- a/app/jobs/scrape_panopto_job.rb +++ b/app/jobs/scrape_panopto_job.rb @@ -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 diff --git a/app/models/lecture.rb b/app/models/lecture.rb index f5fa816..80a489f 100644 --- a/app/models/lecture.rb +++ b/app/models/lecture.rb @@ -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 diff --git a/app/models/recording.rb b/app/models/recording.rb index dac26ae..a20d9a8 100644 --- a/app/models/recording.rb +++ b/app/models/recording.rb @@ -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 diff --git a/app/views/attendance_tracker/index.html.erb b/app/views/attendance_tracker/index.html.erb index 497e672..cb296c3 100644 --- a/app/views/attendance_tracker/index.html.erb +++ b/app/views/attendance_tracker/index.html.erb @@ -25,8 +25,10 @@ <% 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 %> - + <%= lecture.title %> @@ -34,7 +36,7 @@ <%= lecture.start_time.to_fs(:dmy) %> - <% if lecture.start_time.future? %> + <% if lecture.start_time.future? || lecture.cancelled %> diff --git a/db/migrate/20231001191113_change_lecture_recording_ownership_relation.rb b/db/migrate/20231001191113_change_lecture_recording_ownership_relation.rb new file mode 100644 index 0000000..a60445d --- /dev/null +++ b/db/migrate/20231001191113_change_lecture_recording_ownership_relation.rb @@ -0,0 +1,6 @@ +class ChangeLectureRecordingOwnershipRelation < ActiveRecord::Migration[7.0] + def change + remove_column :lectures, :recording_id + add_belongs_to :recordings, :lecture + end +end diff --git a/db/migrate/20231002083755_add_cancelled_status_to_lecture.rb b/db/migrate/20231002083755_add_cancelled_status_to_lecture.rb new file mode 100644 index 0000000..ae0dfd8 --- /dev/null +++ b/db/migrate/20231002083755_add_cancelled_status_to_lecture.rb @@ -0,0 +1,5 @@ +class AddCancelledStatusToLecture < ActiveRecord::Migration[7.0] + def change + add_column :lectures, :cancelled, :boolean, default: false + end +end diff --git a/db/schema.rb b/db/schema.rb index 5dfc295..77cc6de 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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