Flesh out work items in the UI
All checks were successful
Build and Publish Docker Container / build (push) Successful in 5m43s
All checks were successful
Build and Publish Docker Container / build (push) Successful in 5m43s
This commit is contained in:
parent
f9f4762450
commit
c8b688ce57
15
app/controllers/work_item_controller.rb
Normal file
15
app/controllers/work_item_controller.rb
Normal file
@ -0,0 +1,15 @@
|
||||
class WorkItemController < ApplicationController
|
||||
def start_time_entry
|
||||
work_item = WorkItem.find(params[:id])
|
||||
|
||||
Toggl::start_time_entry(
|
||||
description: work_item.title,
|
||||
project_id: work_item.course.toggl_project,
|
||||
)
|
||||
end
|
||||
|
||||
def complete
|
||||
work_item = WorkItem.find(params[:id])
|
||||
work_item.complete!
|
||||
end
|
||||
end
|
||||
2
app/helpers/work_item_helper.rb
Normal file
2
app/helpers/work_item_helper.rb
Normal file
@ -0,0 +1,2 @@
|
||||
module WorkItemHelper
|
||||
end
|
||||
7
app/models/concerns/course_item.rb
Normal file
7
app/models/concerns/course_item.rb
Normal file
@ -0,0 +1,7 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module CourseItem
|
||||
def week_number
|
||||
((start_time.beginning_of_week - course.semester_start_date.to_time) / 1.week).floor + 1
|
||||
end
|
||||
end
|
||||
@ -9,7 +9,7 @@ class Lecture < ApplicationRecord
|
||||
:problems_class,
|
||||
], default: :lecture
|
||||
|
||||
include Trackable
|
||||
include Trackable, CourseItem
|
||||
|
||||
def prepared?
|
||||
tracked_time_entries.where(kind: [:preparation]).any?
|
||||
@ -35,10 +35,6 @@ class Lecture < ApplicationRecord
|
||||
tracked_time_entries.review.sum(&:duration).seconds
|
||||
end
|
||||
|
||||
def week_number
|
||||
((start_time.beginning_of_week - course.semester_start_date.to_time) / 1.week).floor + 1
|
||||
end
|
||||
|
||||
def live_video_url
|
||||
nil
|
||||
end
|
||||
|
||||
@ -2,17 +2,38 @@ class WorkItem < ApplicationRecord
|
||||
belongs_to :course
|
||||
has_many :tracked_time_entries, dependent: :destroy, as: :subject
|
||||
|
||||
validate :due_date_after_start_date
|
||||
validate :date_orderings
|
||||
include Trackable, CourseItem
|
||||
|
||||
include Trackable
|
||||
def start_time
|
||||
available_from
|
||||
end
|
||||
|
||||
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")
|
||||
def completed?
|
||||
completed_at.present?
|
||||
end
|
||||
|
||||
def complete!
|
||||
update(completed_at: Time.now)
|
||||
end
|
||||
|
||||
def workable?
|
||||
available_from.past? && !completed?
|
||||
end
|
||||
|
||||
def started?
|
||||
!tracked_time_entries.empty?
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def date_orderings
|
||||
if due_at.present? && available_from.present? && due_at < available_from
|
||||
errors.add(:due_at, "can't be before date work item is available")
|
||||
end
|
||||
|
||||
if completed_at.present? && available_from.present? && completed_at < available_from
|
||||
errors.add(:completed_at, "can't be before date work item is available")
|
||||
end
|
||||
end
|
||||
|
||||
def week_number
|
||||
((start_time.beginning_of_week - course.semester_start_date.to_time) / 1.week).floor + 1
|
||||
end
|
||||
end
|
||||
|
||||
4
app/views/work_item/complete.html.erb
Normal file
4
app/views/work_item/complete.html.erb
Normal file
@ -0,0 +1,4 @@
|
||||
<div>
|
||||
<h1 class="font-bold text-4xl">WorkItem#complete</h1>
|
||||
<p>Find me in app/views/work_item/complete.html.erb</p>
|
||||
</div>
|
||||
4
app/views/work_item/start_time_entry.html.erb
Normal file
4
app/views/work_item/start_time_entry.html.erb
Normal file
@ -0,0 +1,4 @@
|
||||
<div>
|
||||
<h1 class="font-bold text-4xl">WorkItem#start_time_entry</h1>
|
||||
<p>Find me in app/views/work_item/start_time_entry.html.erb</p>
|
||||
</div>
|
||||
@ -1,4 +1,8 @@
|
||||
<tr class="bg-purple-200">
|
||||
<tr class="<%= class_names({
|
||||
'lecture-future': work_item.available_from.future?,
|
||||
'bg-purple-200': work_item.workable?,
|
||||
'bg-green-100': work_item.completed?,
|
||||
}) %>">
|
||||
<td class="whitespace-nowrap py-4 pl-4 pr-3 text-sm font-medium text-gray-900 sm:pl-6">
|
||||
<%= work_item.title %>
|
||||
</td>
|
||||
@ -7,12 +11,19 @@
|
||||
</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 class="flex flex-row gap-2 justify-center">
|
||||
<% if work_item.completed? %>
|
||||
<i class="fa fa-check text-green-700"></i>
|
||||
<% elsif work_item.started? %>
|
||||
<i class="fa fa-play text-blue-700"></i>
|
||||
<% else %>
|
||||
<%# Symbol to show work has not started yet %>
|
||||
<i class="fa fa-clock text-blue-gray-700"></i>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<template data-popover-target="content">
|
||||
<% unless work_item.tracked_time_entries.empty? %>
|
||||
<% if work_item.started? %>
|
||||
<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) %>
|
||||
@ -23,26 +34,25 @@
|
||||
</td>
|
||||
|
||||
<td class="whitespace-nowrap px-3 py-4 text-sm text-gray-500">
|
||||
<% if work_item.start_time.future? %>
|
||||
<%= button_to "Prepare",
|
||||
"X",
|
||||
<% if work_item.workable? %>
|
||||
<% start_label = if work_item.started? then
|
||||
"Continue"
|
||||
else
|
||||
"Start"
|
||||
end %>
|
||||
<%= button_to start_label,
|
||||
work_item_start_time_entry_path(work_item),
|
||||
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">
|
||||
<% if work_item.started? && !work_item.completed? %>
|
||||
<%= button_to "Complete",
|
||||
work_item_complete_path(work_item),
|
||||
class: 'action-button'
|
||||
%>
|
||||
<% end %>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
@ -15,5 +15,8 @@ Rails.application.routes.draw do
|
||||
post '/lectures/:id/start_preparation', to: 'lecture#start_preparation', as: :lecture_start_preparation
|
||||
post '/lectures/:id/start_review', to: 'lecture#start_review', as: :lecture_start_review
|
||||
|
||||
get '/work_items/:id/start_time_entry', to: 'work_item#start_time_entry', as: :work_item_start_time_entry
|
||||
get '/work_items/:id/complete', to: 'work_item#complete', as: :work_item_complete
|
||||
|
||||
post '/lectures/:id/checkin', to: 'lecture#checkin', as: :lecture_checkin
|
||||
end
|
||||
|
||||
6
db/migrate/20231008144635_rename_work_item_columns.rb
Normal file
6
db/migrate/20231008144635_rename_work_item_columns.rb
Normal file
@ -0,0 +1,6 @@
|
||||
class RenameWorkItemColumns < ActiveRecord::Migration[7.1]
|
||||
def change
|
||||
rename_column :work_items, :start_time, :available_from
|
||||
rename_column :work_items, :due_date, :due_at
|
||||
end
|
||||
end
|
||||
@ -0,0 +1,5 @@
|
||||
class AddCompletionTimeToWorkItem < ActiveRecord::Migration[7.1]
|
||||
def change
|
||||
add_column :work_items, :completed_at, :datetime
|
||||
end
|
||||
end
|
||||
7
db/schema.rb
generated
7
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_08_143146) do
|
||||
ActiveRecord::Schema[7.1].define(version: 2023_10_08_145328) do
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
|
||||
@ -64,10 +64,11 @@ ActiveRecord::Schema[7.1].define(version: 2023_10_08_143146) do
|
||||
create_table "work_items", force: :cascade do |t|
|
||||
t.string "title", null: false
|
||||
t.bigint "course_id", null: false
|
||||
t.datetime "due_date", null: false
|
||||
t.datetime "due_at", null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.datetime "start_time"
|
||||
t.datetime "available_from"
|
||||
t.datetime "completed_at"
|
||||
t.index ["course_id"], name: "index_work_items_on_course_id"
|
||||
end
|
||||
|
||||
|
||||
13
test/controllers/work_item_controller_test.rb
Normal file
13
test/controllers/work_item_controller_test.rb
Normal file
@ -0,0 +1,13 @@
|
||||
require "test_helper"
|
||||
|
||||
class WorkItemControllerTest < ActionDispatch::IntegrationTest
|
||||
test "should get start_time_entry" do
|
||||
get work_item_start_time_entry_url
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should get complete" do
|
||||
get work_item_complete_url
|
||||
assert_response :success
|
||||
end
|
||||
end
|
||||
Loading…
Reference in New Issue
Block a user