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

dev_video
caicai8 5 years ago
commit a4b26ed8a3

@ -227,7 +227,8 @@ class ChallengesController < ApplicationController
@challenge.update_attributes(picture_path: nil, web_route: nil, expect_picture_path: nil, original_picture_path: nil)
end
# 关卡评测执行文件如果被修改,需要修改脚本内容
unless @shixun.published
logger.info("############shixun_publiced:#{@shixun.public == 0}")
if @shixun.public == 0
script = modify_shixun_script @shixun, @shixun.evaluate_script
@shixun.shixun_info.update_column(:evaluate_script, script)
end

@ -0,0 +1,44 @@
class LiveLinksController < ApplicationController
before_action :require_login
before_action :find_course, only: [:index, :create]
before_action :user_course_identity
before_action :teacher_allowed, only: [:create]
def index
lives = @course.live_links.order("id desc")
@total_count = lives.size
@lives = paginate lives.includes(user: :user_extension)
end
def create
@course.live_links.create!( create_params.merge(user_id: current_user.id))
render_ok
end
def update
tip_exception(403, "无权限操作") unless current_user.id == current_live.user_id || current_user.admin?
tip_exception("请勿重复开启") if current_live.on_status && params[:on_status].to_i == 1
ActiveRecord::Base.transaction do
current_live.update!(on_status: params[:on_status])
# 开启时发送消息,关闭直播时删除对应的消息
if params[:on_status].to_i == 1
LivePublishJob.perform_later(current_live.id)
else
current_live.tidings.destroy_all
end
end
render_ok
end
private
def create_params
params.permit(:url, :description)
end
def current_live
@_current_live = LiveLink.find params[:id]
end
end

@ -321,6 +321,10 @@ module TidingDecorator
I18n.t(locale_format(parent_container_type)) % container&.exercise_name
end
def live_link_content
I18n.t(locale_format) % container&.user.try(:show_real_name)
end
def student_graduation_topic_content
I18n.t(locale_format) % container&.graduation_topic.try(:name)
end

@ -128,6 +128,8 @@ module CoursesHelper
course.informs.count
when "online_learning"
course.shixuns.count
when "video"
course.course_videos.count + course.live_links.count
end
end

@ -0,0 +1,27 @@
# 直播开启的消息通知
class LivePublishJob < ApplicationJob
queue_as :notify
def perform(live_id)
live = LiveLink.find_by(id: live_id)
return if live.blank? || live.course.blank?
course = live.course
attrs = %i[
user_id trigger_user_id container_id container_type parent_container_id parent_container_type
belong_container_id belong_container_type viewed tiding_type created_at updated_at
]
same_attrs = {
trigger_user_id: live.user_id, container_id: live.id, container_type: 'LiveLink',
parent_container_id: live.id, parent_container_type: 'LiveLink',
belong_container_id: live.course_id, belong_container_type: 'Course',
viewed: 0, tiding_type: 'LiveLink'
}
Tiding.bulk_insert(*attrs) do |worker|
course.students.pluck(:user_id).each do |user_id|
worker.add same_attrs.merge(user_id: user_id)
end
end
end
end

@ -4,4 +4,5 @@ module CustomRegexp
LASTNAME = /\A[a-zA-Z0-9\u4e00-\u9fa5]+\z/
NICKNAME = /\A[\u4e00-\u9fa5_a-zA-Z0-9]+\z/
PASSWORD = /\A[a-z_A-Z0-9\-\.!@#\$%\\\^&\*\)\(\+=\{\}\[\]\/",'_<>~\·`\?:;|]{8,16}\z/
URL = /\Ahttps?:\/\/[-A-Za-z0-9+&@#\/%?=~_|!:,.;]+[-A-Za-z0-9+&@#\/%=~_|]\z/
end

@ -85,6 +85,9 @@ class Course < ApplicationRecord
has_many :course_videos, dependent: :destroy
has_many :videos, through: :course_videos
# 直播
has_many :live_links, dependent: :destroy
validate :validate_sensitive_string
scope :hidden, ->(is_hidden = true) { where(is_hidden: is_hidden) }

@ -0,0 +1,13 @@
class LiveLink < ApplicationRecord
belongs_to :course
belongs_to :user
has_many :tidings, as: :container, dependent: :destroy
validates :url, presence: true, format: { with: CustomRegexp::URL, message: "必须为网址超链接" }
validates :description, length: { maximum: 100, too_long: "不能超过100个字符" }
def op_auth?
user == User.current || User.current.admin?
end
end

@ -0,0 +1,8 @@
json.lives @lives do |live|
json.(live, :id, :url, :description, :on_status)
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?
end
json.total_count @total_count

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

@ -170,6 +170,10 @@ zh-CN:
name: '名称'
tag_discipline:
name: '名称'
live:
description: '说明'
url: '链接'

@ -550,6 +550,8 @@ Rails.application.routes.draw do
end
end
resources :live_links, only: [:index, :update, :create], shallow: true
resources :homework_commons, shallow: true do
member do

@ -0,0 +1,13 @@
class CreateLiveLinks < ActiveRecord::Migration[5.2]
def change
create_table :live_links do |t|
t.references :course, index: true
t.references :user, index: true
t.string :url
t.text :description
t.boolean :on_status, default: 0
t.timestamps
end
end
end

Binary file not shown.

Before

Width:  |  Height:  |  Size: 128 KiB

After

Width:  |  Height:  |  Size: 207 KiB

@ -0,0 +1,5 @@
require 'rails_helper'
RSpec.describe LivePublishJob, type: :job do
pending "add some examples to (or delete) #{__FILE__}"
end

@ -0,0 +1,5 @@
require 'rails_helper'
RSpec.describe LiveLink, type: :model do
pending "add some examples to (or delete) #{__FILE__}"
end

@ -4349,7 +4349,7 @@
// Actual scrollable element.
d.scroller = elt("div", [d.sizer, d.heightForcer, d.gutters], "CodeMirror-scroll");
d.scroller.setAttribute("tabIndex", "-1");
// The element in which the editor lives.
// The element in which the editor live_links.
d.wrapper = elt("div", [d.scrollbarFiller, d.gutterFiller, d.scroller], "CodeMirror");
// Work around IE7 z-index bug (not perfect, hence IE7 not really being supported)

Loading…
Cancel
Save