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

dev_home
SylorHuang 5 years ago
commit 5f62d10009

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

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

Loading…
Cancel
Save