课堂直播模块

dev_video
cxt 5 years ago
parent 107359163a
commit 10693c4bae

@ -0,0 +1,33 @@
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
render_forbidden("无权限操作") unless current_user.id == current_live.user_id || current_user.admin?
current_live.update!(on_status: params[:on_status])
render_ok
end
private
def create_params
params.permit(:url, :description)
end
def current_live
@_current_live = LiveLink.find params[:id]
end
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

@ -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,11 @@
class LiveLink < ApplicationRecord
belongs_to :course
belongs_to :user
validates :url, presence: true
validates :description, length: { maximum: 100, too_long: "不能超过100个字符" }
def op_auth?
user == User.current || User.current.admin?
end
end

@ -0,0 +1,7 @@
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

@ -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

@ -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