Merge branch 'dev_aliyun' of https://bdgit.educoder.net/Hjqreturn/educoder into dev_aliyun

Adjustreact
daiao 5 years ago
commit 53a4e7d319

@ -7,17 +7,17 @@ class LiveLinksController < ApplicationController
def index
lives = @course.live_links
order_str = "on_status desc,id desc"
order_str = "on_status desc, live_time desc"
@total_count = lives.size
@my_live_id = @course.live_links.find_by(user_id: current_user.id)&.id
order_str = "live_links.id = #{@my_live_id} desc, #{order_str}" if @my_live_id.present?
# order_str = "live_links.id = #{@my_live_id} desc, #{order_str}" if @my_live_id.present?
lives = lives.order("#{order_str}")
@lives = paginate lives.includes(user: :user_extension)
end
def create
tip_exception("一个老师只能设置一个直播间") if @course.live_links.where(user_id: current_user.id).exists?
@course.live_links.create!(create_params.merge(user_id: current_user.id))
on_status = params[:live_time].present? && params[:live_time].to_time <= Time.now ? 1 : 0
@course.live_links.create!(create_params.merge(user_id: current_user.id, on_status: on_status))
render_ok
end
@ -38,7 +38,8 @@ class LiveLinksController < ApplicationController
end
end
else
current_live.update!(create_params)
on_status = params[:live_time].present? && params[:live_time].to_time <= Time.now ? 1 : 0
current_live.update!(create_params.merge(on_status: on_status))
end
render_ok
end
@ -51,7 +52,7 @@ class LiveLinksController < ApplicationController
private
def create_params
params.permit(:url, :description)
params.permit(:url, :description, :course_name, :platform, :live_time, :duration)
end
def current_live

@ -322,7 +322,7 @@ module TidingDecorator
end
def live_link_content
I18n.t(locale_format) % container&.user.try(:show_real_name)
I18n.t(locale_format) % container&.course_name
end
def student_graduation_topic_content

@ -4,8 +4,25 @@ class LiveLink < ApplicationRecord
has_many :tidings, as: :container, dependent: :destroy
validates :url, presence: true, format: { with: CustomRegexp::URL, message: "必须为网址超链接" }
validates :url, format: { with: CustomRegexp::URL, message: "必须为网址超链接" }
validates :description, length: { maximum: 100, too_long: "不能超过100个字符" }
validates :course_name, presence: true
validates :platform, presence: true, inclusion: {in: %W(tencent douyu bilibili vbt)}
# validates :live_time, presence: true
validates :duration, numericality: { only_integer: true, greater_than: 0}, allow_blank: true
def platform_name
case platform
when "tencent"
"腾讯课堂"
when "douyu"
"斗鱼直播"
when "vbt"
"威佰通"
else
platform
end
end
def op_auth?
user == User.current || User.current.admin_or_business?

@ -17,7 +17,10 @@ json.homeworks @homework_commons.each do |homework|
json.status_time curr_status[:time]
json.time_status curr_status[:time_status]
json.allow_late homework.allow_late
json.author homework.user.real_name
json.author homework.user&.real_name
json.author_img url_to_avatar(homework.user)
json.author_login homework.user&.login
json.created_at homework.created_at.strftime("%Y-%m-%d")
# 只有在主目录才显示
json.upper_category_name homework.course_second_category&.name unless params[:category]

@ -84,6 +84,7 @@ elsif @user_course_identity == Course::STUDENT
json.user_login @work.user.login
json.student_id @work.user.student_id
json.user_name @work.user.real_name
json.user_img url_to_avatar(@work.user)
json.group_name @member.course_group_name
end
@ -108,6 +109,7 @@ if @homework.homework_type == "practice"
json.view_answer_count work.myshixun.try(:view_answer_count).to_i
json.user_login work.user.try(:login)
json.user_name work.user.try(:real_name)
json.user_img url_to_avatar(work.user)
json.student_id work.user.try(:student_id)
json.group_name @students.select{|student| student.user_id == work.user_id}.first.try(:course_group_name)
json.work_status work.compelete_status
@ -169,6 +171,7 @@ elsif @homework.homework_type == "group" || @homework.homework_type == "normal"
json.user_login @is_evaluation ? "--" : work.user.try(:login)
json.user_name @is_evaluation ? "匿名" : work.user.try(:real_name)
json.user_img url_to_avatar(@is_evaluation ? "0" : work.user)
end
end

@ -1 +1 @@
json.(@live, :id, :description, :url)
json.(@live, :id, :description, :url, :platform, :live_time, :duration, :course_name)

@ -1,12 +1,13 @@
json.lives @lives do |live|
json.(live, :id, :description, :on_status)
json.(live, :id, :description, :on_status, :duration, :course_name)
json.url live.on_status ? live.url : ""
json.author_name live.user.show_real_name
json.author_login live.user.login
json.author_img url_to_avatar(live.user)
json.op_auth live.op_auth?
json.delete_auth live.delete_auth?
json.created_at live.created_at.strftime('%Y-%m-%d')
json.live_time live.live_time&.strftime('%Y-%m-%d %H:%M:%S')
json.platform live.platform_name
end
json.my_live_id @my_live_id
json.total_count @total_count

@ -238,4 +238,4 @@
2_end: "你提交的发布视频申请:%s审核未通过<br/><span>原因:%{reason}</span>"
PublicCourseStart_end: "你报名参与的开放课程:%s将于%s正式开课"
SubjectStartCourse_end: "您创建的开放课程:%s 已达到开课人数要求。您可以在24小时内自主开设新一期课程。如果超过24小时未开课平台将自动开课并复制您上一期的课程内容。"
LiveLink_end: "%s老师正在直播中"
LiveLink_end: "%s 直播将于30分钟后开始"

@ -173,7 +173,10 @@ zh-CN:
live_link:
description: '说明'
url: '链接'
course_name: '课程名称'
platform: '直播平台'
live_time: '开播时间'
duration: '直播时长'

@ -0,0 +1,8 @@
class AddColumnsToLiveLinks < ActiveRecord::Migration[5.2]
def change
add_column :live_links, :course_name, :string
add_column :live_links, :platform, :string
add_column :live_links, :live_time, :datetime
add_column :live_links, :duration, :integer
end
end

@ -0,0 +1,13 @@
namespace :live_notice do
desc "send a live message to students before 30 minutes"
task message: :environment do
lives = LiveLink.where(on_status: 0).where("live_time <= '#{Time.now + 30*60}' and live_time > '#{Time.now}'")
lives.each do |live|
LivePublishJob.perform_later(live.id)
end
end
task on_status: :environment do
LiveLink.where(on_status: 0).where("live_time <= '#{Time.now}'").update_all(on_status: 1)
end
end
Loading…
Cancel
Save