Add ability to start lecture and redirect to recorded content.
This commit is contained in:
parent
0e0d26d06d
commit
7c96b2c2bc
13
README.md
13
README.md
@ -1 +1,14 @@
|
||||
# Lecture Attendance Management System
|
||||
|
||||
## Alterations
|
||||
|
||||
### Continuum Mechanics
|
||||
|
||||
```ruby
|
||||
continuum_mechanics = Course.find(nil)
|
||||
|
||||
continuum_mechanics.import_from_calendar!
|
||||
continuum_mechanics.lectures.filter { |lecture| lecture.start_time.monday? }.map {|lecture| lecture.update!(kind: Lecture.kinds[:problems_class]) }
|
||||
continuum_mechanics.lectures.find_by(start_time: '2023-10-02 08:15:00.000000').destroy!
|
||||
continuum_mechanics.renumber_lectures!
|
||||
```
|
||||
|
||||
@ -2,6 +2,10 @@
|
||||
@tailwind components;
|
||||
@tailwind utilities;
|
||||
|
||||
.action-button {
|
||||
@apply rounded bg-indigo-600 px-2 py-1 font-semibold text-white shadow-sm hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@layer components {
|
||||
|
||||
14
app/controllers/lecture_controller.rb
Normal file
14
app/controllers/lecture_controller.rb
Normal file
@ -0,0 +1,14 @@
|
||||
class LectureController < ApplicationController
|
||||
def start
|
||||
lecture = Lecture.find(params[:id])
|
||||
|
||||
Toggl::start_time_entry(
|
||||
description: lecture.title,
|
||||
project_id: lecture.course.toggl_project,
|
||||
)
|
||||
|
||||
if lecture.recording.present?
|
||||
redirect_to lecture.recording.recording_url, allow_other_host: true
|
||||
end
|
||||
end
|
||||
end
|
||||
2
app/helpers/lecture_helper.rb
Normal file
2
app/helpers/lecture_helper.rb
Normal file
@ -0,0 +1,2 @@
|
||||
module LectureHelper
|
||||
end
|
||||
@ -10,4 +10,17 @@ module Toggl
|
||||
headers: { 'Content-Type' => 'application/json', 'Accept' => 'application/json' }
|
||||
).body)
|
||||
end
|
||||
|
||||
def self.start_time_entry(description:, project_id:)
|
||||
HTTParty.post(
|
||||
"http://localhost:3005/start_time_entry",
|
||||
body: {
|
||||
"created_with": "Attendance Tracker",
|
||||
"description": description,
|
||||
"duration": -1,
|
||||
"project_id": project_id,
|
||||
}.to_json,
|
||||
headers: { 'Content-Type' => 'application/json', 'Accept' => 'application/json' }
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
@ -61,6 +61,7 @@ class Course < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
# What should this do for existing attendances?
|
||||
def renumber_lectures!
|
||||
lectures.group_by(&:kind).each do |kind, lectures|
|
||||
lectures.sort_by(&:start_time).each_with_index do |lecture, index|
|
||||
|
||||
@ -5,7 +5,7 @@ class Lecture < ApplicationRecord
|
||||
|
||||
enum :kind, [
|
||||
:lecture,
|
||||
:problem_class,
|
||||
:problems_class,
|
||||
], default: :lecture
|
||||
|
||||
def week_number
|
||||
|
||||
@ -66,12 +66,15 @@
|
||||
|
||||
<td class="whitespace-nowrap px-3 py-4 text-sm text-gray-500">
|
||||
<% if lecture.attendance.nil? %>
|
||||
<button type="button" class="rounded bg-indigo-600 px-2 py-1 font-semibold text-white shadow-sm hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600">
|
||||
Start
|
||||
</button>
|
||||
<%= button_to "Start",
|
||||
lectures_start_path(id: lecture.id),
|
||||
class: 'action-button'
|
||||
%>
|
||||
<% else %>
|
||||
<% if lecture.recording %>
|
||||
<%= link_to "Open recording", lecture.recording&.recording_url %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</td>
|
||||
<% end %>
|
||||
</tr>
|
||||
|
||||
4
app/views/lecture/start.html.erb
Normal file
4
app/views/lecture/start.html.erb
Normal file
@ -0,0 +1,4 @@
|
||||
<div>
|
||||
<h1 class="font-bold text-4xl">Lecture#start</h1>
|
||||
<p>Find me in app/views/lecture/start.html.erb</p>
|
||||
</div>
|
||||
@ -9,4 +9,6 @@ Rails.application.routes.draw do
|
||||
end
|
||||
|
||||
root controller: :attendance_tracker, action: :index
|
||||
|
||||
post '/lectures/:id/start', to: 'lecture#start', as: :lectures_start
|
||||
end
|
||||
|
||||
8
test/controllers/lecture_controller_test.rb
Normal file
8
test/controllers/lecture_controller_test.rb
Normal file
@ -0,0 +1,8 @@
|
||||
require "test_helper"
|
||||
|
||||
class LectureControllerTest < ActionDispatch::IntegrationTest
|
||||
test "should get start" do
|
||||
get lecture_start_url
|
||||
assert_response :success
|
||||
end
|
||||
end
|
||||
Loading…
Reference in New Issue
Block a user