Implement catch-up tracking feature
All checks were successful
Build and Publish Docker Container / build (push) Successful in 5m29s
All checks were successful
Build and Publish Docker Container / build (push) Successful in 5m29s
This update enhances tracking functionality. It adds the ability to track time spent 'catching up' on lectures, with distinctions made within the controllers and views to handle these new 'catch-up' entries. Also implemented a flexible match for lecture titles to include various forms such as 'Lecture 1', 'Lecture 1: Prep' and the 'Catch-up'.
This commit is contained in:
parent
f850526a59
commit
4b3204d2f4
@ -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?
|
||||
|
||||
|
||||
@ -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,
|
||||
)
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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 %>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user