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'.
49 lines
1.4 KiB
Ruby
49 lines
1.4 KiB
Ruby
class AttendanceTrackerController < ApplicationController
|
|
before_action :refresh_toggl
|
|
|
|
def overview
|
|
@courses = Course.active.sort_by(&:title)
|
|
@current_lecture = get_current_lecture
|
|
end
|
|
|
|
def today
|
|
@courses = Course.active.sort_by(&:title)
|
|
@date = Date.today
|
|
@current_lecture = get_current_lecture
|
|
@lectures = @courses.flat_map { |course| course.lectures.filter { |a| a.start_time.to_date == @date } }.sort_by { |l| l.start_time }
|
|
end
|
|
|
|
def course_focus
|
|
@course = Course.find(params[:id])
|
|
@current_lecture = get_current_lecture
|
|
end
|
|
|
|
private
|
|
|
|
def get_current_lecture
|
|
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: lecture_title, course: { toggl_project: current_time_entry['project_id'] })
|
|
|
|
return lecture if lecture.present?
|
|
|
|
start_time = Time.new(current_time_entry['start'])
|
|
lecture = Lecture.joins(:course)
|
|
.find_by(start_time: (start_time - 10.minutes)..(start_time + 10.minutes), course: { toggl_project: current_time_entry['project_id'] })
|
|
|
|
return lecture if lecture.present?
|
|
|
|
nil
|
|
end
|
|
|
|
def refresh_toggl
|
|
ScrapeTogglJob.perform_later(Course.active.ids)
|
|
end
|
|
end
|