Continue adding problem sheets
This commit is contained in:
parent
7344ac3d67
commit
f9f4762450
5
app/controllers/concerns/Trackable.rb
Normal file
5
app/controllers/concerns/Trackable.rb
Normal file
@ -0,0 +1,5 @@
|
||||
module Trackable
|
||||
def total_overall_time
|
||||
tracked_time_entries.sum(&:duration)
|
||||
end
|
||||
end
|
||||
@ -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|
|
||||
|
||||
@ -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
|
||||
|
||||
@ -6,7 +6,9 @@ class TrackedTimeEntry < ApplicationRecord
|
||||
:catchup,
|
||||
|
||||
:preparation,
|
||||
:review
|
||||
:review,
|
||||
|
||||
:generic
|
||||
]
|
||||
|
||||
def duration
|
||||
|
||||
@ -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
|
||||
|
||||
48
app/views/work_items/_work_item.html.erb
Normal file
48
app/views/work_items/_work_item.html.erb
Normal file
@ -0,0 +1,48 @@
|
||||
<tr class="bg-purple-200">
|
||||
<td class="whitespace-nowrap py-4 pl-4 pr-3 text-sm font-medium text-gray-900 sm:pl-6">
|
||||
<%= work_item.title %>
|
||||
</td>
|
||||
|
||||
<td class="whitespace-nowrap px-3 py-4 text-sm text-gray-500">
|
||||
</td>
|
||||
|
||||
<td class="whitespace-nowrap px-3 py-4 text-sm text-gray-500" data-controller="popover" data-action="mouseenter->popover#show mouseleave->popover#hide">
|
||||
<div class="flex flex-row gap-2">
|
||||
<i class="fa fa-times text-red-700"></i>
|
||||
</div>
|
||||
|
||||
<template data-popover-target="content">
|
||||
<% unless work_item.tracked_time_entries.empty? %>
|
||||
<div class="absolute p-1 w-max whitespace-normal break-words rounded-lg border border-blue-gray-50 bg-white text-blue-gray-500 shadow-lg shadow-blue-gray-500/10 focus:outline-none" data-popover-target="card">
|
||||
<div>
|
||||
Time spent: <%= humanise_duration(work_item.total_overall_time) %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
</template>
|
||||
</td>
|
||||
|
||||
<td class="whitespace-nowrap px-3 py-4 text-sm text-gray-500">
|
||||
<% if work_item.start_time.future? %>
|
||||
<%= button_to "Prepare",
|
||||
"X",
|
||||
class: 'action-button'
|
||||
%>
|
||||
<% elsif work_item.start_time.past? && work_item.due_date.future? %>
|
||||
<%= button_to "Start",
|
||||
"X",
|
||||
class: 'action-button'
|
||||
%>
|
||||
<% else %>
|
||||
<div class="flex justify-center">
|
||||
<%= button_to "Review",
|
||||
"X",
|
||||
class: 'action-button'
|
||||
%>
|
||||
</div>
|
||||
<% end %>
|
||||
</td>
|
||||
|
||||
<td class="whitespace-nowrap px-3 py-4 text-sm text-gray-500">
|
||||
</td>
|
||||
</tr>
|
||||
5
db/migrate/20231008143146_add_set_date_to_work_item.rb
Normal file
5
db/migrate/20231008143146_add_set_date_to_work_item.rb
Normal file
@ -0,0 +1,5 @@
|
||||
class AddSetDateToWorkItem < ActiveRecord::Migration[7.1]
|
||||
def change
|
||||
add_column :work_items, :start_time, :datetime
|
||||
end
|
||||
end
|
||||
3
db/schema.rb
generated
3
db/schema.rb
generated
@ -10,7 +10,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema[7.1].define(version: 2023_10_07_145018) do
|
||||
ActiveRecord::Schema[7.1].define(version: 2023_10_08_143146) do
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
|
||||
@ -67,6 +67,7 @@ ActiveRecord::Schema[7.1].define(version: 2023_10_07_145018) do
|
||||
t.datetime "due_date", null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.datetime "start_time"
|
||||
t.index ["course_id"], name: "index_work_items_on_course_id"
|
||||
end
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user