From 0dca69ae3fca4b7c72dbee012c3ccd6a945522ec Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 23 Aug 2019 17:10:52 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E7=AB=8B=E5=8D=B3=E5=8F=91=E5=B8=83?= =?UTF-8?q?=E7=9A=84=E8=AF=BE=E5=A0=82=E7=BB=93=E6=9D=9F=E6=97=B6=E9=97=B4?= =?UTF-8?q?=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/exercises_controller.rb | 3 ++- .../graduation_tasks_controller.rb | 4 ++-- .../homework_commons_controller.rb | 23 +++++++++++-------- app/controllers/polls_controller.rb | 3 ++- 4 files changed, 20 insertions(+), 13 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index c9162448b..5db704fce 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -688,7 +688,8 @@ class ExercisesController < ApplicationController def publish tip_exception("缺少截止时间参数") if params[:end_time].blank? tip_exception("截止时间不能早于当前时间") if params[:end_time] <= strf_time(Time.now) - tip_exception("截止时间不能晚于课堂结束时间") if @course.end_date.present? && params[:end_time] > strf_time(@course.end_date.end_of_day) + tip_exception("截止时间不能晚于课堂结束时间(#{@course.end_date.end_of_day.strftime("%Y-%m-%d %H:%M")})") if + @course.end_date.present? && params[:end_time] > strf_time(@course.end_date.end_of_day) ActiveRecord::Base.transaction do begin check_ids = Exercise.where(id: params[:check_ids]) diff --git a/app/controllers/graduation_tasks_controller.rb b/app/controllers/graduation_tasks_controller.rb index 0885eeae2..4cae4e08b 100644 --- a/app/controllers/graduation_tasks_controller.rb +++ b/app/controllers/graduation_tasks_controller.rb @@ -410,7 +410,7 @@ class GraduationTasksController < ApplicationController elsif @task.status < 2 tip_exception("截止时间不能为空") if params[:end_time].blank? tip_exception("截止时间不能早于当前时间") if params[:end_time] <= Time.now.strftime("%Y-%m-%d %H:%M:%S") - tip_exception("截止时间不能早于课堂结束时间") if @course.end_date.present? && params[:end_time] > @course.end_date.end_of_day + tip_exception("截止时间不能晚于课堂结束时间(#{@course.end_date.end_of_day.strftime("%Y-%m-%d %H:%M")})") if @course.end_date.present? && params[:end_time] > @course.end_date.end_of_day @task.end_time = params[:end_time] end @@ -421,7 +421,7 @@ class GraduationTasksController < ApplicationController if params[:allow_late].to_i == 1 tip_exception("补交结束时间不能为空") if params[:late_time].blank? tip_exception("补交结束时间不能早于截止时间") if params[:late_time] <= @task.end_time - tip_exception("补交结束时间不能晚于课堂结束时间") if @course.end_date.present? && params[:late_time] > + tip_exception("补交结束时间不能晚于课堂结束时间(#{@course.end_date.end_of_day.strftime("%Y-%m-%d %H:%M")})") if @course.end_date.present? && params[:late_time] > @course.end_date.end_of_day tip_exception("迟交扣分应为正整数") if params[:late_penalty] && params[:late_penalty].to_i < 0 diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index b95d0d2b4..081e2fdf1 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -447,7 +447,8 @@ class HomeworkCommonsController < ApplicationController tip_exception("发布时间不能早于当前时间") if params[:publish_time] <= Time.now.strftime("%Y-%m-%d %H:%M:%S") tip_exception("截止时间不能早于当前时间") if params[:end_time] <= Time.now.strftime("%Y-%m-%d %H:%M:%S") tip_exception("截止时间不能早于发布时间") if params[:publish_time] > params[:end_time] - tip_exception("截止时间不能晚于课堂结束时间") if @course.end_date.present? && params[:end_time] > @course.end_date.end_of_day + tip_exception("截止时间不能晚于课堂结束时间(#{@course.end_date.end_of_day.strftime("%Y-%m-%d %H:%M")})") if + @course.end_date.present? && params[:end_time] > @course.end_date.end_of_day @homework.unified_setting = 1 @homework.homework_group_settings.destroy_all @@ -469,7 +470,8 @@ class HomeworkCommonsController < ApplicationController tip_exception("发布时间不能早于当前时间") if setting[:publish_time] <= strf_time(Time.now) tip_exception("截止时间不能早于当前时间") if setting[:end_time] <= strf_time(Time.now) tip_exception("截止时间不能早于发布时间") if setting[:publish_time] > setting[:end_time] - tip_exception("截止时间不能晚于课堂结束时间") if @course.end_date.present? && setting[:end_time] > @course.end_date.end_of_day + tip_exception("截止时间不能晚于课堂结束时间(#{@course.end_date.end_of_day.strftime("%Y-%m-%d %H:%M")})") if + @course.end_date.present? && setting[:end_time] > @course.end_date.end_of_day publish_time = setting[:publish_time] == "" ? Time.now : setting[:publish_time] @@ -503,7 +505,8 @@ class HomeworkCommonsController < ApplicationController if @homework.end_time > Time.now && @homework.unified_setting tip_exception("截止时间不能为空") if params[:end_time].blank? tip_exception("截止时间不能早于当前时间") if params[:end_time] <= strf_time(Time.now) - tip_exception("截止时间不能晚于课堂结束时间") if @course.end_date.present? && params[:end_time] > strf_time(@course.end_date.end_of_day) + tip_exception("截止时间不能晚于课堂结束时间(#{@course.end_date.end_of_day.strftime("%Y-%m-%d %H:%M")})") if + @course.end_date.present? && params[:end_time] > strf_time(@course.end_date.end_of_day) @homework.end_time = params[:end_time] @@ -521,7 +524,8 @@ class HomeworkCommonsController < ApplicationController tip_exception("截止时间不能早于等于当前时间") if setting[:end_time] <= strf_time(Time.now) tip_exception("截止时间不能早于发布时间") if setting[:publish_time] > setting[:end_time] - tip_exception("截止时间不能晚于课堂结束时间") if @course.end_date.present? && setting[:end_time] > strf_time(@course.end_date.end_of_day) + tip_exception("截止时间不能晚于课堂结束时间(#{@course.end_date.end_of_day.strftime("%Y-%m-%d %H:%M")})") if + @course.end_date.present? && setting[:end_time] > strf_time(@course.end_date.end_of_day) group_settings.none_published.update_all(publish_time: setting[:publish_time]) group_settings.none_end.update_all(end_time: setting[:end_time]) @@ -539,7 +543,7 @@ class HomeworkCommonsController < ApplicationController current_late_penalty = @homework.late_penalty if params[:allow_late] tip_exception("补交结束时间必须晚于截止时间") if params[:late_time] <= strf_time(@homework.end_time) - tip_exception("补交结束时间不能晚于课堂结束时间") if @course.end_date.present? && params[:late_time] > + tip_exception("补交结束时间不能晚于课堂结束时间(#{@course.end_date.end_of_day.strftime("%Y-%m-%d %H:%M")})") if @course.end_date.present? && params[:late_time] > strf_time(@course.end_date.end_of_day) tip_exception("迟交扣分不能小于0") if params[:late_penalty] && params[:late_penalty].to_i < 0 @@ -647,7 +651,7 @@ class HomeworkCommonsController < ApplicationController tip_exception("匿评开启时间不能早于截止时间") if params[:evaluation_start] < strf_time(@homework.end_time) tip_exception("匿评结束时间不能为空") if params[:evaluation_end].blank? tip_exception("匿评截止时间必须晚于匿评开启时间") if params[:evaluation_end] <= params[:evaluation_start] - tip_exception("匿评截止时间不能晚于课堂结束时间") if @course.end_date.present? && params[:evaluation_end] > + tip_exception("匿评截止时间不能晚于课堂结束时间(#{@course.end_date.end_of_day.strftime("%Y-%m-%d %H:%M")})") if @course.end_date.present? && params[:evaluation_end] > strf_time(@course.end_date.end_of_day) tip_exception("匿评数必须为正整数") if params[:evaluation_num].blank? || params[:evaluation_num].to_i < 1 tip_exception("缺评扣分不能为空") if params[:absence_penalty].blank? @@ -675,7 +679,7 @@ class HomeworkCommonsController < ApplicationController tip_exception("匿评结束时间不能为空") if @homework.anonymous_comment && params[:evaluation_end].blank? tip_exception("匿评截止时间必须晚于匿评开启时间") if @homework.anonymous_comment && params[:evaluation_end] <= strf_time(@homework_detail_manual.evaluation_start) - tip_exception("匿评截止时间不能晚于课堂结束时间") if @homework.anonymous_comment && + tip_exception("匿评截止时间不能晚于课堂结束时间(#{@course.end_date.end_of_day.strftime("%Y-%m-%d %H:%M")})") if @homework.anonymous_comment && @course.end_date.present? && params[:evaluation_end] > strf_time(@course.end_date.end_of_day) @homework_detail_manual.evaluation_end = !@homework.anonymous_comment ? nil : params[:evaluation_end] @@ -701,7 +705,7 @@ class HomeworkCommonsController < ApplicationController tip_exception("匿评申诉结束时间不能为空") if @homework.anonymous_appeal && params[:appeal_time].blank? tip_exception("匿评开启时间不能早于匿评截止时间") if @homework.anonymous_appeal && params[:appeal_time] <= strf_time(@homework_detail_manual.evaluation_end) - tip_exception("匿评申诉结束不能晚于课堂结束时间") if @homework.anonymous_appeal && + tip_exception("匿评申诉结束不能晚于课堂结束时间(#{@course.end_date.end_of_day.strftime("%Y-%m-%d %H:%M")})") if @homework.anonymous_appeal && @course.end_date.present? && params[:appeal_time] > strf_time(@course.end_date.end_of_day) @homework_detail_manual.appeal_time = @homework.anonymous_appeal ? params[:appeal_time] : nil @@ -1054,7 +1058,8 @@ class HomeworkCommonsController < ApplicationController tip_exception("请至少选择一个分班") if params[:group_ids].blank? && @course.course_groups.size != 0 tip_exception("缺少截止时间参数") if params[:end_time].blank? tip_exception("截止时间不能早于当前时间") if params[:end_time] <= strf_time(Time.now) - tip_exception("截止时间不能晚于课堂结束时间") if @course.end_date.present? && params[:end_time] > strf_time(@course.end_date.end_of_day) + tip_exception("截止时间不能晚于课堂结束时间(#{@course.end_date.end_of_day.strftime("%Y-%m-%d %H:%M")})") if + @course.end_date.present? && params[:end_time] > strf_time(@course.end_date.end_of_day) homeworks = @course.homework_commons.where(id: params[:homework_ids]) homeworks = homeworks.includes(:homework_group_settings, :homework_detail_manual) diff --git a/app/controllers/polls_controller.rb b/app/controllers/polls_controller.rb index ba3030424..0f301dd4f 100644 --- a/app/controllers/polls_controller.rb +++ b/app/controllers/polls_controller.rb @@ -246,7 +246,8 @@ class PollsController < ApplicationController def publish tip_exception("缺少截止时间参数") if params[:end_time].blank? tip_exception("截止时间不能早于当前时间") if params[:end_time] <= strf_time(Time.now) - tip_exception("截止时间不能晚于课堂结束时间") if @course.end_date.present? && params[:end_time] > strf_time(@course.end_date.end_of_day) + tip_exception("截止时间不能晚于课堂结束时间(#{@course.end_date.end_of_day.strftime("%Y-%m-%d %H:%M")})") if + @course.end_date.present? && params[:end_time] > strf_time(@course.end_date.end_of_day) ActiveRecord::Base.transaction do begin check_ids = Poll.where(id: params[:check_ids]) From 61d288cd5ad3f69a8f6521c9fb2763d29a94a3f0 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 23 Aug 2019 17:24:28 +0800 Subject: [PATCH 2/6] =?UTF-8?q?=E5=AE=9E=E8=B7=B5=E8=AF=BE=E7=A8=8B?= =?UTF-8?q?=EF=BC=9A=E6=96=B0=E5=BB=BA=E5=92=8C=E7=BC=96=E8=BE=91=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=EF=BC=8C=E7=AE=80=E4=BB=8B=E7=9A=84=E5=AD=97=E7=AC=A6?= =?UTF-8?q?=E6=95=B0=E6=89=A9=E5=BC=A0=E5=88=B08000=EF=BC=8C=E9=A1=BB?= =?UTF-8?q?=E7=9F=A5=E7=9A=84=E5=AD=97=E7=AC=A6=E6=95=B0=E6=89=A9=E5=BC=A0?= =?UTF-8?q?=E5=88=B02000?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/subject.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/subject.rb b/app/models/subject.rb index 3c94ad870..96d060353 100644 --- a/app/models/subject.rb +++ b/app/models/subject.rb @@ -22,8 +22,8 @@ class Subject < ApplicationRecord has_many :courses, -> { where("is_delete = 0").order("courses.created_at ASC") } validates :name, length: { maximum: 60 } - validates :description, length: { maximum: 5000 } - validates :learning_notes, length: { maximum: 500 } + validates :description, length: { maximum: 8000 } + validates :learning_notes, length: { maximum: 2000 } scope :visible, lambda{where(status: 2)} scope :published, lambda{where(status: 1)} From 9e93f9c59e87b6cea973f123c0eec71459afdbca Mon Sep 17 00:00:00 2001 From: caicai8 <1149225589@qq.com> Date: Sat, 24 Aug 2019 10:34:55 +0800 Subject: [PATCH 3/6] =?UTF-8?q?=E5=B7=B2=E5=8F=91=E5=B8=83=E8=AF=95?= =?UTF-8?q?=E5=8D=B7=E7=BC=96=E8=BE=91=E4=BF=9D=E5=AD=98=E9=9C=80=E8=A6=81?= =?UTF-8?q?=E5=BC=B9=E6=A1=86=E8=AF=A2=E9=97=AE=E6=98=AF=E5=90=A6=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E5=88=86=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../courses/common/CNotificationHOC.js | 10 +++--- .../modules/courses/exercise/ExerciseNew.js | 22 +++++++++++-- .../courses/exercise/new/JudgeEditor.js | 14 ++++++-- .../courses/exercise/new/NullEditor.js | 14 ++++++-- .../courses/exercise/new/SingleEditor.js | 32 ++++++++++++------- 5 files changed, 69 insertions(+), 23 deletions(-) diff --git a/public/react/src/modules/courses/common/CNotificationHOC.js b/public/react/src/modules/courses/common/CNotificationHOC.js index 95e36957f..9a08268b1 100644 --- a/public/react/src/modules/courses/common/CNotificationHOC.js +++ b/public/react/src/modules/courses/common/CNotificationHOC.js @@ -106,11 +106,11 @@ export function CNotificationHOC(options = {}) { confirm = (object) => { - const { title, content, onOk, onCancel, okText } = object; + const { title, content,subContent, onOk, onCancel, okText } = object; this.onCancel = onCancel this.onOk = onOk this.okText = okText || '' - this.setState({ title, content, dialogOpen: true }) + this.setState({ title, content , subContent , dialogOpen: true }) } onDialogOkBtnClick = () => { this.onOk && this.onOk(); @@ -141,17 +141,17 @@ export function CNotificationHOC(options = {}) { this.onOk = null } render() { - const { snackbarOpen, snackbarText, snackbarHorizontal, snackbarVertical, dialogOpen, content ,defineOpen } = this.state; + const { snackbarOpen, snackbarText, snackbarHorizontal, snackbarVertical, dialogOpen, content ,subContent ,defineOpen } = this.state; return ( - { + let url=`/exercise_questions/${question_id}/update_scores.json` + axios.post((url),{ + standard_answers:answerArray + }).then((result)=>{ + if(result){ + this.props.showNotification(`${result.data.message}`); + this.addSuccess(); + } + }).catch((error)=>{ + console.log(error); + }) + } + fetchExercise = () => { const Id = this.props.match.params.Id this.isEdit = !!Id @@ -507,7 +523,7 @@ class ExerciceNew extends Component{ { exercise_questions.map((item, index) => { if (item.question_type == 0 || item.question_type == 1) { if (item.isNew) { - return + return } else { return + return } else { return } } else if (item.question_type == 3) { if (item.isNew) { - return + return } else { return } diff --git a/public/react/src/modules/courses/exercise/new/JudgeEditor.js b/public/react/src/modules/courses/exercise/new/JudgeEditor.js index ab93b5bc5..16ccad54a 100644 --- a/public/react/src/modules/courses/exercise/new/JudgeEditor.js +++ b/public/react/src/modules/courses/exercise/new/JudgeEditor.js @@ -93,10 +93,20 @@ class SingleEditor extends Component{ question_choices, standard_answers: answerArray, insert_id: question_id_to_insert_after || undefined - }) - .then((response) => { + }).then((response) => { if (response.data.status == 0) { this.props.addSuccess() + }else if(response.data.status == 3){ + this.props.confirm({ + content:'修改了标准答案', + subContent:"是否重新计算学生答题的成绩?", + onOk:()=>{ + this.props.sureChangeScore(question_id,answerArray) + }, + onCancel:()=>{ + this.props.addSuccess(); + } + }) } }) .catch(function (error) { diff --git a/public/react/src/modules/courses/exercise/new/NullEditor.js b/public/react/src/modules/courses/exercise/new/NullEditor.js index dca67032f..f3c736196 100644 --- a/public/react/src/modules/courses/exercise/new/NullEditor.js +++ b/public/react/src/modules/courses/exercise/new/NullEditor.js @@ -133,10 +133,20 @@ class NullEditor extends Component{ standard_answers: answerArray, insert_id: question_id_to_insert_after || undefined, is_ordered:newis_ordered, - }) - .then((response) => { + }).then((response) => { if (response.data.status == 0) { this.props.addSuccess() + }else if(response.data.status == 3){ + this.props.confirm({ + content:'修改了标准答案', + subContent:"是否重新计算学生答题的成绩?", + onOk:()=>{ + this.props.sureChangeScore(question_id,answerArray) + }, + onCancel:()=>{ + this.props.addSuccess(); + } + }) } }) .catch(function (error) { diff --git a/public/react/src/modules/courses/exercise/new/SingleEditor.js b/public/react/src/modules/courses/exercise/new/SingleEditor.js index b979b62c1..8053f4f21 100644 --- a/public/react/src/modules/courses/exercise/new/SingleEditor.js +++ b/public/react/src/modules/courses/exercise/new/SingleEditor.js @@ -105,8 +105,6 @@ class SingleEditor extends Component{ if(!question_title) { this.refs['titleEditor'].showError() this.props.showNotification('题目:不能为空'); return; - - } for(let i = 0; i < question_choices.length; i++) { @@ -115,7 +113,6 @@ class SingleEditor extends Component{ this.props.showNotification(`请先输入 ${tagArray[i]} 选项的内容`); return; } } - /** { "question_title":"同学朋友间常用的沟通工具是什么?", @@ -134,15 +131,25 @@ class SingleEditor extends Component{ question_choices, standard_answers: answerArray, insert_id: question_id_to_insert_after || undefined + }).then((response) => { + if (response.data.status == 0) { + this.props.addSuccess() + }else if(response.data.status == 3){ + this.props.confirm({ + content:'修改了标准答案', + subContent:"是否重新计算学生答题的成绩?", + onOk:()=>{ + this.props.sureChangeScore(question_id,answerArray) + }, + onCancel:()=>{ + this.props.addSuccess(); + } + }) + } }) - .then((response) => { - if (response.data.status == 0) { - this.props.addSuccess() - } - }) - .catch(function (error) { - console.log(error); - }); + .catch(function (error) { + console.log(error); + }); } else { const url = `/exercises/${Id}/exercise_questions.json` @@ -167,6 +174,9 @@ class SingleEditor extends Component{ onCancel = () => { this.props.onEditorCancel() } + + + componentDidMount = () => { } From de0aef568f4e703e5c7dcb579ea17f882e7ed716 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Sat, 24 Aug 2019 11:00:43 +0800 Subject: [PATCH 4/6] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E6=A0=87=E5=87=86=E7=AD=94=E6=A1=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/exercises_helper.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index f59bee5ac..e65bd2f01 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -44,6 +44,8 @@ module ExercisesHelper stand_answer = 0 end + Rails.logger.info("#######_____________ques_score_________________#{ques_score}") + ques_option = { "q_id":q.id, #该问题的id "q_type":q.question_type, From f4f2dcc114dab53aa3c8b739f6fe8710801bc88e Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Sat, 24 Aug 2019 11:07:44 +0800 Subject: [PATCH 5/6] =?UTF-8?q?=E8=AF=95=E5=8D=B7=E7=9A=84=E7=AD=94?= =?UTF-8?q?=E9=A2=98=E7=8A=B6=E6=80=81=E6=98=BE=E7=A4=BA=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/exercises_helper.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index e65bd2f01..0cc6a9ec5 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -32,7 +32,7 @@ module ExercisesHelper ques_score = 0.0 end else - ques_score = answers_content.select(:score).pluck(:score).sum + ques_score = answers_content.score_reviewed.select(:score).pluck(:score).sum end if ques_score >= q.question_score #满分作答为正确 @@ -44,8 +44,6 @@ module ExercisesHelper stand_answer = 0 end - Rails.logger.info("#######_____________ques_score_________________#{ques_score}") - ques_option = { "q_id":q.id, #该问题的id "q_type":q.question_type, From f4d19f9ec687df659edddd95134cfb4fb95ae58e Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Sat, 24 Aug 2019 11:09:15 +0800 Subject: [PATCH 6/6] =?UTF-8?q?=E9=87=91=E8=AF=BE=E5=85=AC=E5=91=8A?= =?UTF-8?q?=E6=A0=8F=E7=9A=84=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/courses_controller.rb | 26 ++++++++++++++++++------- app/models/course.rb | 2 +- app/models/inform.rb | 3 +++ app/views/courses/informs.json.jbuilder | 6 +++++- config/routes.rb | 1 + 5 files changed, 29 insertions(+), 9 deletions(-) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 470315bdc..c8707d72e 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -26,14 +26,14 @@ class CoursesController < ApplicationController :base_info, :get_historical_courses, :create_group_by_importing_file, :attahcment_category_list,:export_member_scores_excel, :duplicate_course, :switch_to_teacher, :switch_to_assistant, :switch_to_student, :exit_course, - :informs, :update_informs, :online_learning, :update_task_position, :tasks_list, :join_excellent_course] + :informs, :update_informs, :new_informs, :online_learning, :update_task_position, :tasks_list, :join_excellent_course] before_action :user_course_identity, except: [:join_excellent_course, :index, :create, :new, :apply_to_join_course, :search_course_list, :get_historical_course_students, :mine, :search_slim, :board_list] before_action :teacher_allowed, only: [:update, :destroy, :settings, :search_teacher_candidate, :transfer_to_course_group, :delete_from_course, :search_users, :add_students_by_search, :get_historical_courses, :add_teacher_popup, :add_teacher] before_action :admin_allowed, only: [:set_invite_code_halt, :set_public_or_private, :change_course_admin, - :set_course_group, :create_group_by_importing_file, :update_informs, + :set_course_group, :create_group_by_importing_file, :update_informs, :new_informs, :update_task_position, :tasks_list] before_action :teacher_or_admin_allowed, only: [:graduation_group_list, :create_graduation_group, :join_graduation_group, :change_course_teacher, :export_member_scores_excel, :course_group_list, @@ -42,6 +42,7 @@ class CoursesController < ApplicationController before_action :find_board, only: :board_list before_action :validate_page_size, only: :mine before_action :course_tasks, only: [:tasks_list, :update_task_position] + before_action :validate_inform_params, only: [:update_informs, :new_informs] if RUBY_PLATFORM =~ /linux/ require 'simple_xlsx_reader' @@ -159,7 +160,7 @@ class CoursesController < ApplicationController CourseMember.create!(course_id: @course.id, user_id: s_member.user_id, role: 2) end - Inform.create(container: @course, description: @subject.learning_notes) + Inform.create(container: @course, description: @subject.learning_notes, name: "学习须知") end course_module_types = params[:course_module_types] @@ -234,14 +235,20 @@ class CoursesController < ApplicationController end def informs - + @informs = @course.informs end - def update_informs - tip_exception("公告内容不能为空") if params[:description].blank? - inform = @course.inform || Inform.new(container: @course) + def new_informs + inform = Inform.new(container: @course) + inform.name = params[:name] inform.description = params[:description] inform.save! + normal_status("创建成功") + end + + def update_informs + inform = @course.informs.find_by(id: params[:inform_id]) + inform.update_attributes!(name: params[:name], description: params[:description]) normal_status("更新成功") end @@ -1259,6 +1266,11 @@ class CoursesController < ApplicationController end end + def validate_inform_params + tip_exception("公告标题不能为空") if params[:name].blank? + tip_exception("公告内容不能为空") if params[:description].blank? + end + # def find_container # case params[:container_type] # when 'shixun_homework', 'common_homework', 'group_homework' diff --git a/app/models/course.rb b/app/models/course.rb index e2fc5140b..5a2a065ba 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -9,7 +9,7 @@ class Course < ApplicationRecord # 所属实践课程 belongs_to :subject, optional: true - has_one :inform, as: :container, dependent: :destroy + has_many :informs, as: :container, dependent: :destroy has_many :course_infos, dependent: :destroy # 课堂左侧导航栏的模块 diff --git a/app/models/inform.rb b/app/models/inform.rb index faf1d48e6..5caf80c5f 100644 --- a/app/models/inform.rb +++ b/app/models/inform.rb @@ -1,3 +1,6 @@ class Inform < ApplicationRecord belongs_to :container, polymorphic: true, optional: true + + validates :name, length: { maximum: 60 } + validates :description, length: { maximum: 5000 } end diff --git a/app/views/courses/informs.json.jbuilder b/app/views/courses/informs.json.jbuilder index d584be917..7fc396184 100644 --- a/app/views/courses/informs.json.jbuilder +++ b/app/views/courses/informs.json.jbuilder @@ -1 +1,5 @@ -json.description @course.inform&.description \ No newline at end of file +json.informs @informs do |inform| + json.id inform.id + json.name inform.name + json.description inform.description +end \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index de4f46a40..5ed8ecd69 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -349,6 +349,7 @@ Rails.application.routes.draw do post 'exit_course' get 'informs' post 'update_informs' + post 'new_informs' get 'online_learning' post 'join_excellent_course' get 'tasks_list'