Extract course table to partial

This commit is contained in:
Joshua Coles 2023-10-26 12:06:06 +01:00
parent 9b57b7a646
commit 9c6dea41f1
2 changed files with 64 additions and 63 deletions

View File

@ -0,0 +1,63 @@
<div class="divide-y divide-gray-300 w-full">
<div class="py-3.5 justify-between bg-gray-50 text-left text-sm font-semibold text-gray-900 px-6 grid grid-cols-4">
<div>Lecture</div>
<div>Status</div>
<div>Action</div>
<div>Recording</div>
</div>
<% course.lectures.sort_by(&:start_time).group_by(&:week_number).each do |(week_number, lectures)| %>
<div class="py-3.5 bg-gray-50 text-left text-sm font-semibold text-gray-900 px-6 grid grid-cols-4">
Week <%= week_number %>
</div>
<% lectures.each do |lecture| %>
<% status_classes = class_names({
'lecture-future': lecture.start_time.future?,
'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="whitespace-nowrap text-sm font-medium text-gray-900">
<%= lecture.title %>
</div>
<div class="whitespace-nowrap text-sm font-medium text-gray-900" data-controller="popover" data-action="mouseenter->popover#show mouseleave->popover#hide">
<%= render partial: 'lecture_status_icons', locals: { lecture: } %>
</div>
<div class="whitespace-nowrap text-sm font-medium text-gray-900">
<% joinable_time = lecture.start_time - 5.minutes %>
<% if joinable_time.future? %>
<%= button_to "Prepare",
lecture_start_preparation_path(id: lecture.id),
class: 'action-button'
%>
<% elsif joinable_time.past? && !lecture.attended? %>
<% start_label = if lecture.is_live? then
"Join"
else
"Start"
end %>
<%= button_to start_label,
lectures_start_path(id: lecture.id),
class: 'action-button'
%>
<% else %>
<%= button_to "Review",
lecture_start_review_path(id: lecture.id),
class: 'action-button'
%>
<% end %>
</div>
<div class="whitespace-nowrap text-sm font-medium text-gray-900">
<% if lecture.recording %>
<%= link_to "Open recording", lecture.recording&.recording_url %>
<% end %>
</div>
</div>
<% end %>
<% end %>
</div>

View File

@ -5,69 +5,7 @@
<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="overflow-hidden shadow ring-1 ring-black ring-opacity-5 rounded-lg">
<div class="divide-y divide-gray-300 w-full">
<div class="py-3.5 justify-between bg-gray-50 text-left text-sm font-semibold text-gray-900 px-6 grid grid-cols-4">
<div>Lecture</div>
<div>Status</div>
<div>Action</div>
<div>Recording</div>
</div>
<% @course.lectures.sort_by(&:start_time).group_by(&:week_number).each do |(week_number, lectures)| %>
<div class="py-3.5 bg-gray-50 text-left text-sm font-semibold text-gray-900 px-6 grid grid-cols-4">
Week <%= week_number %>
</div>
<% lectures.each do |lecture| %>
<% status_classes = class_names({
'lecture-future': lecture.start_time.future?,
'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="whitespace-nowrap text-sm font-medium text-gray-900">
<%= lecture.title %>
</div>
<div class="whitespace-nowrap text-sm font-medium text-gray-900" data-controller="popover" data-action="mouseenter->popover#show mouseleave->popover#hide">
<%= render partial: 'lecture_status_icons', locals: { lecture: } %>
</div>
<div class="whitespace-nowrap text-sm font-medium text-gray-900">
<% joinable_time = lecture.start_time - 5.minutes %>
<% if joinable_time.future? %>
<%= button_to "Prepare",
lecture_start_preparation_path(id: lecture.id),
class: 'action-button'
%>
<% elsif joinable_time.past? && !lecture.attended? %>
<% start_label = if lecture.is_live? then
"Join"
else
"Start"
end %>
<%= button_to start_label,
lectures_start_path(id: lecture.id),
class: 'action-button'
%>
<% else %>
<%= button_to "Review",
lecture_start_review_path(id: lecture.id),
class: 'action-button'
%>
<% end %>
</div>
<div class="whitespace-nowrap text-sm font-medium text-gray-900">
<% if lecture.recording %>
<%= link_to "Open recording", lecture.recording&.recording_url %>
<% end %>
</div>
</div>
<% end %>
<% end %>
</div>
<%= render partial: 'course_table', locals: { course: @course } %>
</div>
</div>
</div>