diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index c9b56bb98..b9c2086d8 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -562,16 +562,16 @@ class ShixunsController < ApplicationController commit_id = commit["id"] end - # 如果该实训是金课中的实训,则将当前用户加入到当期开课的课堂 - # if StageShixun.exists?(shixun_id: @shixun.id, subject_id: Subject.where(excellent: 1)) - # subject = Subject.where(excellent: 1, id: StageShixun.where(shixun_id: @shixun.id).pluck(:subject_id)).take - # course = subject.courses.where("start_date is not null and start_date <= '#{Date.today}' and end_date is not null and end_date >= '#{Date.today}'").take - # if course.present? && !CourseMember.exists?(course_id: course.id, user_id: current_user.id) - # # 为了不影响后续操作,用create而不是create! - # CourseMember.create(course_id: course.id, user_id: current_user.id, role: 4) - # CourseAddStudentCreateWorksJob.perform_later(course.id, [current_user.id]) - # end - # end + 如果该实训是金课中的实训,则将当前用户加入到当期开课的课堂 + if StageShixun.exists?(shixun_id: @shixun.id, subject_id: Subject.where(excellent: 1)) + subject = Subject.where(id: StageShixun.where(shixun_id: @shixun.id).pluck(:subject_id), excellent: 1).take(1) + course = subject.courses.where("start_date is not null and start_date <= '#{Date.today}' and end_date is not null and end_date >= '#{Date.today}'").take + if course.present? && !CourseMember.exists?(course_id: course.id, user_id: current_user.id) + # 为了不影响后续操作,用create而不是create! + CourseMember.create(course_id: course.id, user_id: current_user.id, role: 4) + CourseAddStudentCreateWorksJob.perform_later(course.id, [current_user.id]) + end + end ActiveRecord::Base.transaction do begin diff --git a/app/controllers/subjects_controller.rb b/app/controllers/subjects_controller.rb index 5389ff961..431423d87 100644 --- a/app/controllers/subjects_controller.rb +++ b/app/controllers/subjects_controller.rb @@ -149,7 +149,7 @@ class SubjectsController < ApplicationController end def choose_subject_shixun - @search = params[:search] + @search = params[:search].strip @type = params[:type] # 超级管理员用户显示所有未隐藏的实训、非管理员显示合作团队用户的实训(对本单位公开且未隐藏) if current_user.admin? @@ -163,7 +163,7 @@ class SubjectsController < ApplicationController tag_ids = @shixuns.joins(:shixun_tag_repertoires).pluck(:tag_repertoire_id).uniq @tags = TagRepertoire.select([:id, :name]).where(id: tag_ids) - if params[:search] + unless @search.blank? @shixuns = @shixuns.where("name like ?", "%#{@search}%") end diff --git a/app/models/subject.rb b/app/models/subject.rb index 113460375..5116cce75 100644 --- a/app/models/subject.rb +++ b/app/models/subject.rb @@ -21,7 +21,7 @@ class Subject < ApplicationRecord # 开放课堂 has_many :courses, -> { order("courses.id ASC") } - validates :name, length: { maximum: 40 } + validates :name, length: { maximum: 60 } validates :description, length: { maximum: 5000 } validates :learning_notes, length: { maximum: 500 } diff --git a/public/react/src/modules/courses/elearning/Elearning.js b/public/react/src/modules/courses/elearning/Elearning.js index d587d88c8..81f300538 100644 --- a/public/react/src/modules/courses/elearning/Elearning.js +++ b/public/react/src/modules/courses/elearning/Elearning.js @@ -75,7 +75,19 @@ class Elearning extends Component{ }; //开始学习 Startlearning=()=>{ - this.Tojoinclass(); + let {userlogin} = this.state; + if (userlogin === undefined) { + this.setState({ + isRender: true + }) + return + } + if (userlogin === "") { + this.setState({ + isRender: true + }) + return; + } if(this.props.isNotMember()===true){ this.setState({ yslJointhe:true @@ -221,20 +233,10 @@ class Elearning extends Component{ }) }; Tojoinclass=()=> { - let {userlogin} = this.state; - if (userlogin === undefined) { - this.setState({ - isRender: true - }) - return - } - if (userlogin === "") { this.setState({ isRender: true }) - return; - } - } + }; render(){ let{description,whethertoedit,isSpin,start_learning,hidestartshixunsreplacevalues,learned,last_shixun,stages,isRender} =this.state; diff --git a/public/react/src/modules/courses/elearning/YslDetailCards.js b/public/react/src/modules/courses/elearning/YslDetailCards.js index 38cc32d18..a1ad44e67 100644 --- a/public/react/src/modules/courses/elearning/YslDetailCards.js +++ b/public/react/src/modules/courses/elearning/YslDetailCards.js @@ -34,13 +34,30 @@ class YslDetailCards extends Component{ }; startgameid=(id)=>{ // 上面传过来的方法是用来没登入弹出弹框的 - this.props.Tojoinclass(); + try { + let {userlogin} = this.props; + if (userlogin === undefined) { + this.props.Tojoinclass(); + return + } + if (userlogin === "") { + this.props.Tojoinclass(); + return; + } + }catch (e) { - if(this.props.isNotMember()===true){ - //这个是外部传过来的 - this.props.Startlearningtwo(); - return } + + try { + if(this.props.isNotMember()===true){ + //这个是外部传过来的 + this.props.Startlearningtwo(); + return + } + }catch (e) { + + } + let url = "/shixuns/" + id + "/shixun_exec.json"; axios.get(url).then((response) => {