Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 32 additions & 17 deletions app/controllers/admin/talks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,31 +23,38 @@ def update_talks

def start_on_air
@talk = Talk.find(params[:talk][:id])
on_air_talks_of_other_days = @talk.track.talks.includes([:conference_day, :video]).accepted_and_intermission.reject { |t| t.conference_day.id == @talk.conference_day.id }.select { |t| t.video.on_air? }
if on_air_talks_of_other_days.size.positive?
@talks = @conference.talks.accepted_and_intermission.order('conference_day_id ASC, start_time ASC, track_id ASC')
flash.now.alert = "Talk id=#{on_air_talks_of_other_days.map(&:id).join(',')} are already on_air."
render(:index, status: :unprocessable_entity)
else
@current_on_air_videos = Video.includes(talk: :conference).where(talks: { conference_id: conference.id }, on_air: true)
ActiveRecord::Base.transaction do
# Disable onair of all talks that are onair
@current_on_air_videos.each do |video|
video.update!(on_air: false)
end

respond_to do |format|
on_air_talks_of_other_days = @talk.track.talks.includes([:conference_day, :video]).accepted_and_intermission.reject { |t| t.conference_day.id == @talk.conference_day.id }.select { |t| t.video.on_air? }
if on_air_talks_of_other_days.size.positive?
format.turbo_stream {
flash[:alert] = "Talk id=#{on_air_talks_of_other_days.map(&:id).join(',')} are already on_air."
}
else
@talk.start_streaming
format.turbo_stream {
flash[:notice] = "OnAirに切り替えました: #{@talk.start_to_end} #{@talk.speaker_names.join(',')} #{@talk.title}"
}
# Update the current talk to onair
@talk.video.update!(on_air: true)
end

ActionCable.server.broadcast(
"on_air_#{conference.abbr}", Video.on_air_v2(conference.id)
)
flash.now.notice = "OnAirに切り替えました: #{@talk.start_to_end} #{@talk.speaker_names.join(',')} #{@talk.title}"
end
end

def stop_on_air
@talk = Talk.find(params[:talk][:id])
@talk.stop_streaming
@talk.video.update!(on_air: false)
ActionCable.server.broadcast(
"on_air_#{conference.abbr}", Video.on_air_v2(conference.id)
)

respond_to do |format|
format.turbo_stream {
flash.now[:notice] = "Waitingに切り替えました: #{@talk.start_to_end} #{@talk.speaker_names.join(',')} #{@talk.title}"
}
end
flash.now.notice = "Waitingに切り替えました: #{@talk.start_to_end} #{@talk.speaker_names.join(',')} #{@talk.title}"
end

def export_talks_for_website
Expand Down Expand Up @@ -88,4 +95,12 @@ def export_talks_for_website
end
end
end

helper_method :turbo_stream_flash

private

def turbo_stream_flash
turbo_stream.append('flashes', partial: 'flash')
end
end
4 changes: 3 additions & 1 deletion app/controllers/admin/tracks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ class Admin::TracksController < ApplicationController
include SecuredAdmin

def index
@conference = Conference.includes(:conference_days, :tracks).find_by(abbr: event_name)
@date = params[:date] || @conference.conference_days.first.date.strftime('%Y-%m-%d')
@conference_day = @conference.conference_days.select { |day| day.date.strftime('%Y-%m-%d') == @date }.first
@track_name = params[:track_name] || @conference.tracks.first.name
@track = @conference.tracks.find_by(name: @track_name)
@talks = @conference
.talks
.includes(:speakers, :media_package_harvest_jobs)
.where(conference_day_id: @conference.conference_days.find_by(date: @date).id, track_id: @track.id)
.order('conference_day_id ASC, start_time ASC, track_id ASC').includes(:video, :speakers, :conference_day, :track)

Expand Down Expand Up @@ -38,7 +40,7 @@ def update_offset
)
end
ActionCable.server.broadcast(
"on_air_#{conference.abbr}", Video.on_air_v2(conference.id)
"on_air_#{@conference.abbr}", Video.on_air_v2(@conference.id)
)
redirect_to(admin_tracks_path, flash: { success: 'Offset updated' })
end
Expand Down
20 changes: 17 additions & 3 deletions app/controllers/api/v1/talks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,30 @@ def show
end

def update
talk = Talk.find(params[:id])
@talk = Talk.find(params[:id])
conference = @talk.conference
body = JSON.parse(request.body.read, { symbolize_names: true })
if body[:on_air].nil?
render_400
else
if body[:on_air]
talk.start_streaming
@current_on_air_videos = Video.includes(talk: :conference).where(talks: { conference_id: conference.id }, on_air: true)
ActiveRecord::Base.transaction do
# Disable onair of all talks that are onair
@current_on_air_videos.each do |video|
video.update!(on_air: false)
end

# Update the current talk to onair
@talk.video.update!(on_air: true)
end

else
talk.stop_streaming
@talk.video.update!(on_air: false)
end
ActionCable.server.broadcast(
"on_air_#{conference.abbr}", Video.on_air_v2(conference.id)
)
render(json: { message: 'OK' }, status: 200)
end
end
Expand Down
1 change: 0 additions & 1 deletion app/controllers/talks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ def index
@talks.where(show_on_timetable: true)
elsif @conference.cfp_result_visible
@talks.where(show_on_timetable: true,
conference_day_id: @conference.conference_days.externals.map(&:id),
proposals: { status: :accepted })
else
# NOTE: Proposal 採択前は conference_days が nil
Expand Down
1 change: 1 addition & 0 deletions app/models/conference.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class Conference < ApplicationRecord
has_many :stamp_rally_check_points
has_many :stamp_rally_check_ins
has_one :stamp_rally_configure
has_many :videos, through: :talks

scope :upcoming, -> {
merge(where(conference_status: Conference::STATUS_REGISTERED).or(where(conference_status: Conference::STATUS_OPENED)))
Expand Down
25 changes: 1 addition & 24 deletions app/models/talk.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class Talk < ApplicationRecord
has_many :media_package_harvest_jobs
has_many :check_in_talks
has_many :speaker_invitations, dependent: :destroy
has_many :media_package_harvest_jobs, dependent: :destroy

has_many :proposal_items, autosave: true, dependent: :destroy
has_many :profiles, through: :registered_talks
Expand Down Expand Up @@ -357,30 +358,6 @@ def selected_proposal_items
r
end

def start_streaming
ActiveRecord::Base.transaction do
other_talks_in_track = conference.tracks.find_by(name: track.name).talks
.accepted_and_intermission
.reject { |t| t.id == id }
other_talks_in_track.each do |other_talk|
other_talk.video.update!(on_air: false)
end

video.update!(on_air: true)
end

ActionCable.server.broadcast(
"on_air_#{conference.abbr}", Video.on_air_v2(conference.id)
)
end

def stop_streaming
video.update!(on_air: false)
ActionCable.server.broadcast(
"on_air_#{conference.abbr}", Video.on_air_v2(conference.id)
)
end

def live?
method = proposal_items.find_by(label: 'presentation_method')
return false unless method
Expand Down
11 changes: 11 additions & 0 deletions app/views/admin/talks/start_on_air.turbo_stream.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,14 @@
<%= turbo_stream.replace "talk_#{@talk.id}" do %>
<%= render partial: 'admin/tracks/partial/on_air_button', locals: { talk: @talk } %>
<% end %>

<% @current_on_air_videos&.each do |video| %>
<% if video.talk.present? && video.talk.id != @talk.id %>
<%= turbo_stream.replace "talk_#{video.talk.id}" do %>
<%= render partial: 'admin/tracks/partial/on_air_button', locals: { talk: video.talk } %>
<% end %>
<% end %>
<% end %>

<%= turbo_stream_flash %>
<%= yield %>
3 changes: 3 additions & 0 deletions app/views/admin/talks/stop_on_air.turbo_stream.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@
<%= turbo_stream.replace "talk_#{@talk.id}" do %>
<%= render partial: 'admin/tracks/partial/on_air_button', locals: { talk: @talk } %>
<% end %>

<%= turbo_stream_flash %>
<%= yield %>
2 changes: 1 addition & 1 deletion app/views/admin/tracks/_tracks_nav.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
<% if talk.video && talk.abstract != 'intermission' %>
<% if already_recorded?(talk) %>
録画済み
<% else if MediaPackageHarvestJob.where(talk_id: talk.id).present? %>
<% else if talk.media_package_harvest_jobs.present? %>
録画中
<% else %>
未録画
Expand Down
2 changes: 1 addition & 1 deletion app/views/admin/tracks/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
</div>

<%= turbo_frame_tag "modal" %>
<div id="flashes" class="position-fixed bottom-0 end-0" style="margin: 0.75rem; z-index: 101"></div>
<div id="flashes" class="position-fixed bottom-0 end-0" style="margin: 0.75rem"></div>

<%= javascript_include_tag 'admin/tracks/media_live.js' %>
<%= javascript_include_tag 'admin/tracks/tracks_control.js' %>
36 changes: 0 additions & 36 deletions spec/models/talk_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,42 +44,6 @@
require 'rails_helper'

describe Talk, type: :model do
context 'update on_air status' do
before do
create(:cndt2020)
end
let!(:talk1) { create(:talk1, :accepted, track_id: 1) }
let!(:talk2) { create(:talk2, :accepted, :conference_day_id_1) }
let!(:talk3) { create(:talk3, :accepted, track_id: 1) }
let!(:video1) { create(:video, :off_air) }
let!(:video2) { create(:video, :on_air, :talk2) }
let!(:video3) { create(:video, :on_air, :talk3) }
context 'start streaming talk1' do
before do
talk1.start_streaming
end

it 'should be on_air' do
expect(talk1.video.on_air).to(eq(true))
end

it "shouldn't be on_air whatever talks has different conference_day_id" do
expect(talk3.video.on_air).to(eq(false))
end

example 'talk in the same track and same conference_day should be off_air' do
expect(talk2.video.on_air).to(eq(false))
end
end

context 'stop streaming' do
it 'should be off_air' do
talk1.stop_streaming
expect(talk1.video.on_air).to(eq(false))
end
end
end

context 'live?' do
let!(:cndt2020) { create(:cndt2020) }
let!(:talk) { create(:talk1) }
Expand Down
10 changes: 5 additions & 5 deletions spec/requests/admin/talks_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@

it 'can not to change to start on air' do
post admin_start_on_air_path(event: 'cndt2020'), params: { talk: { id: talk2.id } }.to_json, headers: { "Content-Type": 'application/json' }, as: :turbo_stream
expect(response).to(be_successful)
expect(response).to(have_http_status('200'))
expect(response).to_not(be_successful)
expect(response).to(have_http_status('422'))
expect(Video.find(talk2.video.id).on_air).to(be_falsey)
expect(flash[:alert]).to(include("Talk id=#{talk1.id} are already on_air."))
expect(flash.now[:alert]).to(include("Talk id=#{talk1.id} are already on_air."))
end
end
end
Expand All @@ -130,8 +130,8 @@

it 'can not to change to start on air' do
post admin_start_on_air_path(event: 'cndt2020'), params: { talk: { id: intermission2.id } }.to_json, headers: { "Content-Type": 'application/json' }, as: :turbo_stream
expect(response).to(be_successful)
expect(response).to(have_http_status('200'))
expect(response).to_not(be_successful)
expect(response).to(have_http_status('422'))
expect(Video.find(intermission2.video.id).on_air).to(be_falsey)
expect(flash[:alert]).to(include("Talk id=#{intermission1.id} are already on_air."))
end
Expand Down
Loading