Initial commit
This commit is contained in:
109
app/controllers/broadcasts_controller.rb
Normal file
109
app/controllers/broadcasts_controller.rb
Normal file
@@ -0,0 +1,109 @@
|
||||
class BroadcastsController < ApplicationController
|
||||
layout "project"
|
||||
|
||||
before_action :set_project
|
||||
before_action :build_broadcast, only: [:new, :create]
|
||||
before_action :set_broadcast, only: [:show, :destroy, :update]
|
||||
before_action :set_multi_view_broadcasts, only: [:show]
|
||||
|
||||
def index
|
||||
@broadcasts = filtered_broadcasts.order_by_recent.paginate(page: params[:page])
|
||||
end
|
||||
|
||||
def new
|
||||
end
|
||||
|
||||
def create
|
||||
@broadcast.attributes = broadcast_params
|
||||
|
||||
if @broadcast.save
|
||||
log_create_analytics
|
||||
redirect_to [@project, :broadcasts], notice: t(".notice")
|
||||
else
|
||||
render :new
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
@broadcast.update(broadcast_params)
|
||||
@files = @broadcast.files.order("created_at DESC").paginate(page: 1)
|
||||
|
||||
pagination_content = ApplicationController.render html: helpers.will_paginate(@files, params: { active_tab: params[:active_tab] })
|
||||
BroadcastsChannel.file_upload_updates(@broadcast, @files, pagination_content)
|
||||
end
|
||||
|
||||
def show
|
||||
@conference_url = url_for [@broadcast.project, @broadcast, :zoom_meeting]
|
||||
@recordings = @broadcast.broadcast_recordings.order_by_recent.paginate(page: params[:page])
|
||||
@files = @broadcast.files.order("created_at DESC").paginate(page: params[:page])
|
||||
render layout: 'application'
|
||||
end
|
||||
|
||||
def destroy
|
||||
if @broadcast.destroy
|
||||
redirect_to [@project, :broadcasts], alert: t(".alert")
|
||||
else
|
||||
redirect_to [@project, :broadcasts], alert: t(".api_error")
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def broadcast_params
|
||||
params.require(:broadcast).permit(:name, files: [])
|
||||
end
|
||||
|
||||
def set_project
|
||||
@project = policy_scope(Project).find(params[:project_id])
|
||||
end
|
||||
|
||||
def set_broadcast
|
||||
@broadcast = authorize policy_scope(Broadcast).find(params[:id])
|
||||
end
|
||||
|
||||
def build_broadcast
|
||||
@broadcast = authorize @project.broadcasts.build
|
||||
end
|
||||
|
||||
def broadcasts
|
||||
authorize policy_scope(@project.broadcasts)
|
||||
end
|
||||
|
||||
def set_multi_view_broadcasts
|
||||
authorized_broadcasts = authorize policy_scope(Broadcast).where(id: params[:multi_view_ids]).order_by_recent
|
||||
@multi_view_broadcasts = authorized_broadcasts.map { |b| MultiViewBroadcast.new(b, params[:multi_view_ids]) }
|
||||
end
|
||||
|
||||
def filtered_broadcasts
|
||||
results = broadcasts
|
||||
|
||||
if params[:query].present?
|
||||
results = results.search(params[:query])
|
||||
end
|
||||
|
||||
results
|
||||
end
|
||||
|
||||
def log_create_analytics
|
||||
TrackAnalyticsJob.perform_later(Current.user, Current.account, :track_create_live_stream, user_agent: request.user_agent, user_ip: request.remote_ip)
|
||||
end
|
||||
|
||||
class MultiViewBroadcast
|
||||
include Rails.application.routes.url_helpers
|
||||
|
||||
delegate_missing_to :@broadcast
|
||||
|
||||
def initialize(broadcast, multi_view_ids)
|
||||
@broadcast = broadcast
|
||||
@multi_view_ids = multi_view_ids
|
||||
end
|
||||
|
||||
def url
|
||||
project_broadcast_path(@broadcast.project, @broadcast, multi_view_ids: @multi_view_ids, locale: I18n.locale)
|
||||
end
|
||||
|
||||
def uid
|
||||
id
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user