Merge branches 'dev_aliyun' and 'dev_cxt' of https://bdgit.educoder.net/Hjqreturn/educoder into dev_cxt

dev_forge
杨树明 5 years ago
commit d187685df9

@ -1627,8 +1627,9 @@ class ExercisesController < ApplicationController
ex_and_user = user_groups_id & ex_group_settings #用户已设置的分班 ex_and_user = user_groups_id & ex_group_settings #用户已设置的分班
unpublish_group = unpublish_group + ex_and_user - ex_ended_groups #已发布的全部班级减去截止的全部班级 unpublish_group = unpublish_group + ex_and_user - ex_ended_groups #已发布的全部班级减去截止的全部班级
else else
ex_ended_groups = ex_all_group_settings.exercise_group_ended.pluck(:course_group_id).uniq
ex_and_user = user_groups_id & ex_group_settings #用户已设置的分班 ex_and_user = user_groups_id & ex_group_settings #用户已设置的分班
unpublish_group = unpublish_group + ex_and_user unpublish_group = unpublish_group + ex_and_user - ex_ended_groups
end end
end end
end end

@ -1,5 +1,6 @@
class Weapps::CoursesController < Weapps::BaseController class Weapps::CoursesController < Weapps::BaseController
# before_action :require_wechat_login! # before_action :require_wechat_login!
before_action :teacher_allowed, except: [:create]
def create def create
return render_error("只有老师身份才能创建课堂") unless current_user.is_teacher? return render_error("只有老师身份才能创建课堂") unless current_user.is_teacher?
@ -12,11 +13,12 @@ class Weapps::CoursesController < Weapps::BaseController
end end
def edit def edit
@course = current_course
end end
def update def update
Weapps::UpdateCourseService.call(current_course, course_params)
render_ok
end end
private private
@ -24,4 +26,12 @@ class Weapps::CoursesController < Weapps::BaseController
def course_params def course_params
params.permit(:name, :course_list_name, :credit, course_module_types: []) params.permit(:name, :course_list_name, :credit, course_module_types: [])
end end
def current_course
@_current_course = Course.find params[:id]
end
def teacher_allowed
return render_forbidden unless current_user.course_identity(current_course) < Course::STUDENT
end
end end

@ -0,0 +1,15 @@
class Weapps::UpdateCourseForm
include ActiveModel::Model
attr_accessor :course
attr_accessor :name, :course_list_name, :credit
validates :name, presence: true
validates :course_list_name, presence: true
validate :course_name_prefix
def course_name_prefix
raise '课堂名称应以课程名称开头' unless name.index(course_list_name) && name.index(course_list_name) == 0
end
end

@ -14,6 +14,13 @@ class Weapps::CreateCourseService < ApplicationService
course.school_id = course.teacher&.school_id course.school_id = course.teacher&.school_id
course.is_public = 0 course.is_public = 0
course.credit = params[:credit].blank? ? nil : params[:credit] course.credit = params[:credit].blank? ? nil : params[:credit]
course_list = CourseList.find_by(name: params[:course_list_name].to_s.strip)
if course_list
course.course_list_id = course_list.id
else
new_course_list = CourseList.create!(name: params[:course_list_name].to_s.strip, user_id: course.tea_id, is_admin: 0)
course.course_list_id = new_course_list.id
end
course.save! course.save!
course.generate_invite_code course.generate_invite_code

@ -0,0 +1,31 @@
class Weapps::UpdateCourseService < ApplicationService
attr_reader :course, :params
def initialize(course, params)
@course = course
@params = params
end
def call
Weapps::UpdateCourseForm.new(form_params).validate!
ActiveRecord::Base.transaction do
course.name = params[:name].to_s.strip
course.credit = params[:credit].blank? ? nil : params[:credit]
course_list = CourseList.find_by(name: params[:course_list_name].to_s.strip)
if course_list
course.course_list_id = course_list.id
else
new_course_list = CourseList.create!(name: params[:course_list_name].to_s.strip, user_id: course.tea_id, is_admin: 0)
course.course_list_id = new_course_list.id
end
course.save!
end
end
private
def form_params
params.merge(course: course)
end
end

@ -0,0 +1,2 @@
json.(@course, :id, :name, :credit)
json.course_list_name @course.course_list&.name

@ -58,81 +58,94 @@ class ModulationModal_exercise extends Component {
Inputsvals Inputsvals
} = this.state; } = this.state;
let re = /^[0-9]+.?[0-9]*$/;//判断字符串是否为数字 //判断正整数 /^[1-9]+[0-9]*]*$/ let re = /^[0-9]+.?[0-9]*$/;//判断字符串是否为数字 //判断正整数 /^[1-9]+[0-9]*]*$/
let res= /^\-[1-9][0-9]*$/; //判断字符串是负整数
if (subool === false) { if (subool === false) {
let subools=false;
let suboolss=false;
//不是总分模式 //不是总分模式
if (Inputsval === undefined || Inputsval === null || Inputsval === "") { if (Inputsval === undefined || Inputsval === null || Inputsval === "") {
this.setState({ this.setState({
Inputsval: "", Inputsval: "",
Inputsvaltype: true, Inputsvaltype: true,
Inputsvaltest: "请填写分数", Inputsvaltest: "主观题成绩不能为空",
}) })
return subools=true;
} }
//判断主观题 //判断主观题
if(subools===false){
var nubmer = Inputsval;
if (!re.test(nubmer)&&!res.test(nubmer)) {
this.setState({
Inputsval: Inputsval,
Inputsvaltype: true,
Inputsvaltest: "请输入0-100的分数",
})
subools=true;
}
var nubmer = Inputsval;
if (!re.test(nubmer)) {
this.setState({
Inputsval: Inputsval,
Inputsvaltype: true,
Inputsvaltest: "请输入0-100的分数",
})
return;
} }
if(subools===false){
if (0 > parseFloat(Inputsval)) { if (0 > parseFloat(Inputsval)) {
this.setState({ this.setState({
Inputsval: Inputsval, Inputsval: Inputsval,
Inputsvaltype: true, Inputsvaltype: true,
Inputsvaltest: "成绩不能小于零", Inputsvaltest: "主观题成绩不能小于零",
}) })
return; subools=true;
} else if (parseFloat(Inputsval) > this.props.subjective_score) { } else if (parseFloat(Inputsval) > this.props.subjective_score) {
this.setState({ this.setState({
Inputsval: Inputsval, Inputsval: Inputsval,
Inputsvaltype: true, Inputsvaltype: true,
Inputsvaltest: `成绩不能大于${this.props.subjective_score}`, Inputsvaltest: `主观题成绩不能大于主观题总分值${this.props.subjective_score}`,
}) })
return; subools=true;
}
} }
//判断客观题 //判断客观题
if (Inputsvals === undefined || Inputsvals === null || Inputsvals === "") { if (Inputsvals === undefined || Inputsvals === null || Inputsvals === "") {
this.setState({ this.setState({
Inputsvals: "", Inputsvals: "",
Inputsvaltypes: true, Inputsvaltypes: true,
Inputsvaltests: "请填写分数", Inputsvaltests: "客观题成绩不能为空",
}) })
return suboolss=true;
} }
var nubmers = Inputsvals;
if (!re.test(nubmers)) { if(suboolss===false){
this.setState({ var nubmers = Inputsvals;
Inputsvals: "", if (!re.test(nubmers)&&!res.test(nubmers)) {
Inputsvaltypes: true, this.setState({
Inputsvaltests: "请输入0-100的分数", Inputsvals: "",
}) Inputsvaltypes: true,
return; Inputsvaltests: "请输入0-100的分数",
})
suboolss=true;
}
} }
if(suboolss===false){
if (0 > parseFloat(Inputsvals)) { if (0 > parseFloat(Inputsvals)) {
this.setState({ this.setState({
Inputsvals: Inputsvals, Inputsvals: Inputsvals,
Inputsvaltypes: true, Inputsvaltypes: true,
Inputsvaltests: "请输入0-100的分数", Inputsvaltests: "客观题成绩不能小于零",
}) })
return; suboolss=true;
} else if (parseFloat(Inputsvals) > this.props.objective_score) { } else if (parseFloat(Inputsvals) > this.props.objective_score) {
this.setState({ this.setState({
Inputsvals: Inputsvals, Inputsvals: Inputsvals,
Inputsvaltypes: true, Inputsvaltypes: true,
Inputsvaltests: `成绩不能大于${this.props.objective_score}`, Inputsvaltests: `客观题成绩不能大于客观题总分值${this.props.objective_score}`,
}) })
return; suboolss=true;
}
}
if(subools===true ||suboolss===true){
return;
} }
} else { } else {
debugger debugger
@ -143,14 +156,14 @@ class ModulationModal_exercise extends Component {
this.setState({ this.setState({
Inputsval: "", Inputsval: "",
Inputsvaltype: true, Inputsvaltype: true,
Inputsvaltest: "请填写分数", Inputsvaltest: "总成绩不能为空",
}) })
return return
} }
//判断主观题 //判断主观题
var nubmer = Inputsval; var nubmer = Inputsval;
if (!re.test(nubmer)) { if (!re.test(nubmer)&&!res.test(nubmer)) {
this.setState({ this.setState({
Inputsval: Inputsval, Inputsval: Inputsval,
Inputsvaltype: true, Inputsvaltype: true,
@ -164,14 +177,14 @@ class ModulationModal_exercise extends Component {
this.setState({ this.setState({
Inputsval: Inputsval, Inputsval: Inputsval,
Inputsvaltype: true, Inputsvaltype: true,
Inputsvaltest: "成绩不能小于零", Inputsvaltest: "成绩不能小于零",
}) })
return; return;
} else if (parseFloat(Inputsval) > this.props.subjective_score) { } else if (parseFloat(Inputsval) > this.props.subjective_score) {
this.setState({ this.setState({
Inputsval: Inputsval, Inputsval: Inputsval,
Inputsvaltype: true, Inputsvaltype: true,
Inputsvaltest: `成绩不能大于${this.props.subjective_score}`, Inputsvaltest: `成绩不能大于总分值${this.props.subjective_score}`,
}) })
return; return;
} }
@ -181,12 +194,12 @@ class ModulationModal_exercise extends Component {
this.setState({ this.setState({
Inputsvals: "", Inputsvals: "",
Inputsvaltypes: true, Inputsvaltypes: true,
Inputsvaltests: "请填写分数", Inputsvaltests: "总成绩不能为空",
}) })
return return
} }
var nubmers = Inputsvals; var nubmers = Inputsvals;
if (!re.test(nubmers)) { if (!re.test(nubmers)&&!res.test(nubmers)) {
this.setState({ this.setState({
Inputsvals: "", Inputsvals: "",
Inputsvaltypes: true, Inputsvaltypes: true,
@ -199,14 +212,14 @@ class ModulationModal_exercise extends Component {
this.setState({ this.setState({
Inputsvals: Inputsvals, Inputsvals: Inputsvals,
Inputsvaltypes: true, Inputsvaltypes: true,
Inputsvaltests: "请输入0-100的分数", Inputsvaltests: "总成绩不能小于零",
}) })
return; return;
} else if (parseFloat(Inputsvals) > this.props.objective_score) { } else if (parseFloat(Inputsvals) > this.props.objective_score) {
this.setState({ this.setState({
Inputsvals: Inputsvals, Inputsvals: Inputsvals,
Inputsvaltypes: true, Inputsvaltypes: true,
Inputsvaltests: `成绩不能大于${this.props.objective_score}`, Inputsvaltests: `成绩不能大于总分值${this.props.objective_score}`,
}) })
return; return;
} }
@ -316,7 +329,7 @@ class ModulationModal_exercise extends Component {
<div className="mexertwo" style={{ <div className="mexertwo" style={{
marginTop: "20px", marginTop: "20px",
}}> }}>
<p className="mexeheigth2">主观题成绩:</p> <p className="mexeheigth2 mr10">主观题成绩:</p>
<Input <Input
className={Inputsvaltype === true ? "borerinput myinputnumbers bor-reds" : "myinputnumbers"} className={Inputsvaltype === true ? "borerinput myinputnumbers bor-reds" : "myinputnumbers"}
style={{ style={{
@ -335,7 +348,7 @@ class ModulationModal_exercise extends Component {
<p style={{ <p style={{
color: "#DD1717", color: "#DD1717",
width: "77%", width: "77%",
marginLeft: "75px", marginLeft: "82px",
marginTop: "10px", marginTop: "10px",
}}>{Inputsvaltest}</p> }}>{Inputsvaltest}</p>
: "" : ""
@ -362,7 +375,7 @@ class ModulationModal_exercise extends Component {
marginTop: "20px", marginTop: "20px",
}}> }}>
<p className="mexeheigth2">客观题成绩:</p> <p className="mexeheigth2 mr10">客观题成绩:</p>
<Input <Input
className={Inputsvaltypes === true ? "borerinput myinputnumbers bor-reds" : "myinputnumbers"} className={Inputsvaltypes === true ? "borerinput myinputnumbers bor-reds" : "myinputnumbers"}
style={{ style={{
@ -382,7 +395,7 @@ class ModulationModal_exercise extends Component {
<p style={{ <p style={{
color: "#DD1717", color: "#DD1717",
width: "77%", width: "77%",
marginLeft: "75px", marginLeft: "82px",
marginTop: "10px", marginTop: "10px",
}}>{Inputsvaltests}</p> }}>{Inputsvaltests}</p>
: "" : ""

Loading…
Cancel
Save