Add started text to table
This commit is contained in:
parent
9c6dea41f1
commit
b0d134fabd
@ -1,16 +1,39 @@
|
|||||||
class AttendanceTrackerController < ApplicationController
|
class AttendanceTrackerController < ApplicationController
|
||||||
def index
|
def index
|
||||||
@courses = Course.all.sort_by(&:title)
|
@courses = Course.all.sort_by(&:title)
|
||||||
|
@current_lecture = get_current_lecture
|
||||||
end
|
end
|
||||||
|
|
||||||
def today
|
def today
|
||||||
@courses = Course.all.sort_by(&:title)
|
@courses = Course.all.sort_by(&:title)
|
||||||
@date = Date.today
|
@date = Date.today
|
||||||
|
@current_lecture = get_current_lecture
|
||||||
@lectures = @courses.flat_map { |course| course.lectures.filter { |a| a.start_time.today? } }.sort_by { |l| l.start_time }
|
@lectures = @courses.flat_map { |course| course.lectures.filter { |a| a.start_time.today? } }.sort_by { |l| l.start_time }
|
||||||
end
|
end
|
||||||
|
|
||||||
def course_focus
|
def course_focus
|
||||||
@course = Course.find(params[:id])
|
@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?
|
||||||
|
|
||||||
|
lecture = Lecture
|
||||||
|
.joins(:course)
|
||||||
|
.find_by(title: current_time_entry['description'], 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
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,4 +1,11 @@
|
|||||||
module Toggl
|
module Toggl
|
||||||
|
def self.current_time_entry
|
||||||
|
JSON.parse(HTTParty.get(
|
||||||
|
"#{TOGGL_PORTAL_URL}/current",
|
||||||
|
headers: { 'Accept' => 'application/json' }
|
||||||
|
).body)
|
||||||
|
end
|
||||||
|
|
||||||
def self.entries_for_project(toggl_project_id, start_time:, end_time:)
|
def self.entries_for_project(toggl_project_id, start_time:, end_time:)
|
||||||
JSON.parse(HTTParty.post(
|
JSON.parse(HTTParty.post(
|
||||||
"#{TOGGL_PORTAL_URL}/report",
|
"#{TOGGL_PORTAL_URL}/report",
|
||||||
|
|||||||
@ -14,10 +14,11 @@
|
|||||||
<% lectures.each do |lecture| %>
|
<% lectures.each do |lecture| %>
|
||||||
<% status_classes = class_names({
|
<% status_classes = class_names({
|
||||||
'lecture-future': lecture.start_time.future?,
|
'lecture-future': lecture.start_time.future?,
|
||||||
|
'bg-purple-100': lecture == @current_lecture,
|
||||||
'bg-green-100': lecture.attended?,
|
'bg-green-100': lecture.attended?,
|
||||||
}) %>
|
}) %>
|
||||||
|
|
||||||
<div class="<%= status_classes %> px-6 py-4 flex justify-between bg-white items-center grid grid-cols-4">
|
<div class="<%= status_classes %> px-6 py-4 flex justify-between items-center grid grid-cols-4">
|
||||||
<div class="whitespace-nowrap text-sm font-medium text-gray-900">
|
<div class="whitespace-nowrap text-sm font-medium text-gray-900">
|
||||||
<%= lecture.title %>
|
<%= lecture.title %>
|
||||||
</div>
|
</div>
|
||||||
@ -29,7 +30,9 @@
|
|||||||
<div class="whitespace-nowrap text-sm font-medium text-gray-900">
|
<div class="whitespace-nowrap text-sm font-medium text-gray-900">
|
||||||
<% joinable_time = lecture.start_time - 5.minutes %>
|
<% joinable_time = lecture.start_time - 5.minutes %>
|
||||||
|
|
||||||
<% if joinable_time.future? %>
|
<% if lecture == @current_lecture %>
|
||||||
|
Started
|
||||||
|
<% elsif joinable_time.future? %>
|
||||||
<%= button_to "Prepare",
|
<%= button_to "Prepare",
|
||||||
lecture_start_preparation_path(id: lecture.id),
|
lecture_start_preparation_path(id: lecture.id),
|
||||||
class: 'action-button'
|
class: 'action-button'
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
<div class="-mx-4 -my-2 overflow-x-auto sm:-mx-6 lg:-mx-8">
|
<div class="-mx-4 -my-2 overflow-x-auto sm:-mx-6 lg:-mx-8">
|
||||||
<div class="inline-block py-2 align-middle px-6 lg:px-8 w-full">
|
<div class="inline-block py-2 align-middle px-6 lg:px-8 w-full">
|
||||||
<div class="overflow-hidden shadow ring-1 ring-black ring-opacity-5 rounded-lg">
|
<div class="overflow-hidden shadow ring-1 ring-black ring-opacity-5 rounded-lg">
|
||||||
<%= render partial: 'course_table', locals: { course: @course } %>
|
<%= render partial: 'course_table', locals: { course: @course, current_lecture: @current_lecture } %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -16,10 +16,11 @@
|
|||||||
<% @lectures.each do |lecture| %>
|
<% @lectures.each do |lecture| %>
|
||||||
<% status_classes = class_names({
|
<% status_classes = class_names({
|
||||||
'lecture-future': lecture.start_time.future?,
|
'lecture-future': lecture.start_time.future?,
|
||||||
|
'bg-purple-100': lecture == @current_lecture,
|
||||||
'bg-green-100': lecture.attended?,
|
'bg-green-100': lecture.attended?,
|
||||||
}) %>
|
}) %>
|
||||||
|
|
||||||
<div class="<%= status_classes %> px-6 py-4 flex justify-between bg-white items-center grid grid-cols-4">
|
<div class="px-6 py-4 flex justify-between items-center grid grid-cols-4 <%= status_classes %>">
|
||||||
<div class="whitespace-nowrap text-sm font-medium text-gray-900">
|
<div class="whitespace-nowrap text-sm font-medium text-gray-900">
|
||||||
<%= lecture.course.title %>
|
<%= lecture.course.title %>
|
||||||
</div>
|
</div>
|
||||||
@ -34,7 +35,9 @@
|
|||||||
|
|
||||||
<div class="whitespace-nowrap text-sm font-medium text-gray-900">
|
<div class="whitespace-nowrap text-sm font-medium text-gray-900">
|
||||||
<% joinable_time = lecture.start_time - 5.minutes %>
|
<% joinable_time = lecture.start_time - 5.minutes %>
|
||||||
<% if joinable_time.future? %>
|
<% if lecture == @current_lecture %>
|
||||||
|
Started
|
||||||
|
<% elsif joinable_time.future? %>
|
||||||
<%= button_to "Prepare",
|
<%= button_to "Prepare",
|
||||||
lecture_start_preparation_path(id: lecture.id),
|
lecture_start_preparation_path(id: lecture.id),
|
||||||
class: 'action-button'
|
class: 'action-button'
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user