diff --git a/app/controllers/attendance_tracker_controller.rb b/app/controllers/attendance_tracker_controller.rb index 5b18c45..dec9d71 100644 --- a/app/controllers/attendance_tracker_controller.rb +++ b/app/controllers/attendance_tracker_controller.rb @@ -24,9 +24,12 @@ class AttendanceTrackerController < ApplicationController current_time_entry = Toggl.current_time_entry return nil if current_time_entry.nil? + # Match both 'Lecture 1' and 'Lecture 1: Prep', etc + lecture_title = current_time_entry['description'].split(':')[0] + lecture = Lecture .joins(:course) - .find_by(title: current_time_entry['description'], course: { toggl_project: current_time_entry['project_id'] }) + .find_by(title: lecture_title, course: { toggl_project: current_time_entry['project_id'] }) return lecture if lecture.present? diff --git a/app/controllers/lecture_controller.rb b/app/controllers/lecture_controller.rb index 5cd3f2a..d87aa17 100644 --- a/app/controllers/lecture_controller.rb +++ b/app/controllers/lecture_controller.rb @@ -13,9 +13,16 @@ class LectureController < ApplicationController def start lecture = Lecture.find(params[:id]) + catch_up = params[:catch_up].present? + + description = if catch_up + "#{lecture.title}: Catch-up" + else + lecture.title + end Toggl::start_time_entry( - description: lecture.title, + description:, project_id: lecture.course.toggl_project, ) diff --git a/app/jobs/scrape_toggl_job.rb b/app/jobs/scrape_toggl_job.rb index a9da21d..c369c8f 100644 --- a/app/jobs/scrape_toggl_job.rb +++ b/app/jobs/scrape_toggl_job.rb @@ -80,6 +80,7 @@ class ScrapeTogglJob < ApplicationJob preparation_regex = /^(.+): ?(?:Prep|Preparation)?$/ review_regex = /^(.+): ?(?:Review|Recap)/ + catchup_regex = /^(.+): ?(?:Catch-up|Catch up|Catch Up)/ if (lecture_title_match = entry_title.match(preparation_regex)) and (lecture = lectures.find_by(title: lecture_title_match[1])) lecture.tracked_time_entries.create!( @@ -96,6 +97,14 @@ class ScrapeTogglJob < ApplicationJob associated_toggl_entry_id: entry['time_entries'][0]['id'], ) + # broadcast_update_to lecture, :lectures + elsif (lecture_title_match = entry_title.match(catchup_regex)) and (lecture = lectures.find_by(title: lecture_title_match[1])) + lecture.tracked_time_entries.create!( + kind: :catchup, + toggl_data: entry, + associated_toggl_entry_id: entry['time_entries'][0]['id'], + ) + # broadcast_update_to lecture, :lectures end end diff --git a/app/views/lectures/_lecture_action.html.erb b/app/views/lectures/_lecture_action.html.erb index 0d3d8d9..03efae6 100644 --- a/app/views/lectures/_lecture_action.html.erb +++ b/app/views/lectures/_lecture_action.html.erb @@ -7,21 +7,25 @@ <% elsif joinable_time.future? %> <%= button_to "Prepare", lecture_start_preparation_path(id: lecture.id), - class: 'action-button' - %> + class: 'action-button' %> <% elsif joinable_time.past? && !lecture.attended? %> - <% start_label = if lecture.is_live? then - "Join" - else - "Start" - end %> - <%= button_to start_label, - lectures_start_path(id: lecture.id), - class: 'action-button' - %> + <% if lecture.end_time.future? %> + <% start_label = if lecture.is_live? + "Join" + else + "Start" + end %> + + <%= button_to start_label, + lectures_start_path(id: lecture.id), + class: 'action-button' %> + <% else %> + <%= button_to 'Catch Up', + lectures_start_path(id: lecture.id, catch_up: true), + class: 'action-button' %> + <% end %> <% else %> <%= button_to "Review", lecture_start_review_path(id: lecture.id), - class: 'action-button' - %> + class: 'action-button' %> <% end %>