diff --git a/app/controllers/concerns/Trackable.rb b/app/controllers/concerns/Trackable.rb new file mode 100644 index 0000000..946df78 --- /dev/null +++ b/app/controllers/concerns/Trackable.rb @@ -0,0 +1,5 @@ +module Trackable + def total_overall_time + tracked_time_entries.sum(&:duration) + end +end diff --git a/app/jobs/scrape_toggl_job.rb b/app/jobs/scrape_toggl_job.rb index 86e7b68..b74736c 100644 --- a/app/jobs/scrape_toggl_job.rb +++ b/app/jobs/scrape_toggl_job.rb @@ -12,7 +12,7 @@ class ScrapeTogglJob < ApplicationJob # @param [Course] course def scrape_course(course) toggl_project_id = course.toggl_project - lectures = course.lectures.order(:start_time).includes(:attendance) + lectures = course.lectures.order(:start_time).includes(:tracked_time_entries) return if lectures.empty? @@ -52,6 +52,12 @@ class ScrapeTogglJob < ApplicationJob # TODO: What should happen if the time entry is materially before the lecture? kind: ) and next + elsif (work_item = course.work_items.find_by(title: entry_title)) + work_item.tracked_time_entries.create!( + toggl_data: entry, + associated_toggl_entry_id: entry['time_entries'][0]['id'], + kind: :generic + ) and next end concurrent_unlabeled = entry['time_entries'].any? do |inner_entry| diff --git a/app/models/lecture.rb b/app/models/lecture.rb index b025126..e25b895 100644 --- a/app/models/lecture.rb +++ b/app/models/lecture.rb @@ -9,6 +9,8 @@ class Lecture < ApplicationRecord :problems_class, ], default: :lecture + include Trackable + def prepared? tracked_time_entries.where(kind: [:preparation]).any? end @@ -25,10 +27,6 @@ class Lecture < ApplicationRecord tracked_time_entries.preparation.sum(&:duration).seconds end - def total_overall_time - tracked_time_entries.sum(&:duration).seconds - end - def total_attendance_time tracked_time_entries.where(kind: [:concurrent, :catchup]).sum(&:duration).seconds end diff --git a/app/models/tracked_time_entry.rb b/app/models/tracked_time_entry.rb index da53706..908e4cf 100644 --- a/app/models/tracked_time_entry.rb +++ b/app/models/tracked_time_entry.rb @@ -6,7 +6,9 @@ class TrackedTimeEntry < ApplicationRecord :catchup, :preparation, - :review + :review, + + :generic ] def duration diff --git a/app/models/work_item.rb b/app/models/work_item.rb index ded75ae..f63a20d 100644 --- a/app/models/work_item.rb +++ b/app/models/work_item.rb @@ -2,6 +2,16 @@ class WorkItem < ApplicationRecord belongs_to :course has_many :tracked_time_entries, dependent: :destroy, as: :subject + validate :due_date_after_start_date + + include Trackable + + def due_date_after_start_date + if due_date.present? && start_time.present? && due_date < start_time + errors.add(:due_date, "can't be before start date") + end + end + def week_number ((start_time.beginning_of_week - course.semester_start_date.to_time) / 1.week).floor + 1 end diff --git a/app/views/work_items/_work_item.html.erb b/app/views/work_items/_work_item.html.erb new file mode 100644 index 0000000..7f3f98f --- /dev/null +++ b/app/views/work_items/_work_item.html.erb @@ -0,0 +1,48 @@ +