From bb62ba40b78b09312f8c6429cfb81d26b8fac670 Mon Sep 17 00:00:00 2001 From: yuanke <249218296@qq.com> Date: Fri, 8 Jul 2016 16:23:07 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=BE=AE=E4=BF=A1=E6=9D=83?= =?UTF-8?q?=E9=99=90=E9=97=AE=E9=A2=98=E3=80=81=E7=AE=A1=E7=90=86=E8=AF=BE?= =?UTF-8?q?=E7=A8=8B=E7=95=8C=E9=9D=A2=E7=AD=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/mobile/apis/courses.rb | 8 +- app/api/mobile/apis/syllabuses.rb | 43 +++++++- app/api/mobile/entities/course.rb | 1 + app/api/mobile/entities/syllabus.rb | 1 + app/services/syllabuses_service.rb | 99 ++++++++++++++++++- public/assets/wechat/class_list.html | 2 +- public/assets/wechat/edit_class.html | 4 +- .../wechat/controllers/class_list.js | 13 ++- .../wechat/controllers/edit_class.js | 32 ++++-- public/stylesheets/weui/weixin.css | 1 + 10 files changed, 182 insertions(+), 22 deletions(-) diff --git a/app/api/mobile/apis/courses.rb b/app/api/mobile/apis/courses.rb index 917a396e2..301417781 100644 --- a/app/api/mobile/apis/courses.rb +++ b/app/api/mobile/apis/courses.rb @@ -403,12 +403,12 @@ module Mobile post ':course_id/del' do authenticate! c = Course.find(params[:course_id]) - if c.members.count > 1 - {status: -1, message: '已经有成员加入,不能删除'} - else + # if c.members.count > 1 + # {status: -1, message: '已经有成员加入,不能删除'} + # else c.delete! present :status,0 - end + # end end diff --git a/app/api/mobile/apis/syllabuses.rb b/app/api/mobile/apis/syllabuses.rb index 47989155e..682929a90 100644 --- a/app/api/mobile/apis/syllabuses.rb +++ b/app/api/mobile/apis/syllabuses.rb @@ -25,11 +25,32 @@ module Mobile get ':id' do authenticate! + ss = SyllabusesService.new + sy = ::Syllabus.find(params[:id]) + + sy = ss.judge_can_setting(sy,current_user) + present :data, sy, with: Mobile::Entities::Syllabus present :status, 0 end + desc "获取新建大纲的权限" + params do + requires :token, type: String + end + post 'auth' do + authenticate! + + auth = 0 + + if (current_user.user_extensions && current_user.user_extensions.identity == 0 && current_user.allowed_to?(:add_course, nil, :global => true)) + auth = 1 + end + + present :auth, auth + end + desc "新建大纲" params do requires :token, type: String @@ -53,12 +74,30 @@ module Mobile end + desc '编辑大纲' + params do + requires :token, type: String + requires :title, type: String, desc: '大纲标题' + # requires :add_courses, type: Array[String], desc: '课程名' + # requires :modify_courses, type: Array[Integer,String], desc: '课程名' + end + post ':id/edit' do + authenticate! + ss = SyllabusesService.new + + #修改课程大纲 + status = ss.edit(current_user, params) + + if status == -1 + {status:status, message: '修改课程信息失败' } + else + present :status, status + end + end end - - end end end \ No newline at end of file diff --git a/app/api/mobile/entities/course.rb b/app/api/mobile/entities/course.rb index ea74058f4..d44869a60 100644 --- a/app/api/mobile/entities/course.rb +++ b/app/api/mobile/entities/course.rb @@ -52,6 +52,7 @@ module Mobile course_expose :updated_at course_expose :course_student_num course_expose :member_count + course_expose :can_setting expose :teacher, using: Mobile::Entities::User do |c, opt| if c.is_a? ::Course c.teacher diff --git a/app/api/mobile/entities/syllabus.rb b/app/api/mobile/entities/syllabus.rb index bb39fa4f6..4f97dd868 100644 --- a/app/api/mobile/entities/syllabus.rb +++ b/app/api/mobile/entities/syllabus.rb @@ -5,6 +5,7 @@ module Mobile expose :title expose :id + expose :can_setting expose :courses, using: Mobile::Entities::Course end diff --git a/app/services/syllabuses_service.rb b/app/services/syllabuses_service.rb index 530c550ed..04dc801fb 100644 --- a/app/services/syllabuses_service.rb +++ b/app/services/syllabuses_service.rb @@ -5,21 +5,70 @@ class SyllabusesService include ApplicationHelper include CoursesHelper + def judge_can_setting(sy,user) + sy[:can_setting] = sy[:user_id] == user.id ? true : false + + sy.courses.each do |c| + c[:can_setting] = false + + member = c.members.where("user_id=#{user.id} and course_id=#{c.id}")[0] + roleName = member.roles[0].name if member + + if roleName && (roleName == "TeachingAsistant" || roleName == "Teacher" ) + c[:can_setting] = true + end + + if c.tea_id == user.id + c[:can_setting] = true + end + end + + sy + end #获取指定用户的课程大纲 def user_syllabus(user) courses = CoursesService.new.user_courses_list(user) - other = Syllabus.new(title: '未命名课程') + other = Syllabus.new(title: '未命名课程',user_id: user.id) courses.each do |c| other.courses << c[:course] unless c[:course].syllabus end - user.syllabuses.each do |syllabus| - syllabus.courses = syllabus.courses.not_deleted + # user.syllabuses.each do |syllabus| + # syllabus.courses = syllabus.courses.not_deleted + # end + # + # user.syllabuses.to_a << other + + courses = user.courses.not_deleted + syllabus_ids = courses.empty? ? '(-1)' : "(" + courses.map{|course| !course.syllabus_id.nil? && course.syllabus_id}.join(",") + ")" + syllabuses = Syllabus.where("id in #{syllabus_ids} or user_id = #{user.id}").order("updated_at desc") + syllabuses.to_a << other + + #管理权限 can_setting + syllabuses.each do |s| + + s = judge_can_setting(s,user) + + # s[:can_setting] = s.user_id == user.id ? true : false + # s.courses.each do |c| + # c[:can_setting] = false + # + # member = c.members.where("user_id=#{user.id} and course_id=#{c.id}")[0] + # roleName = member.roles[0].name if member + # + # if roleName && (roleName == "TeachingAsistant" || roleName == "Teacher" ) + # c[:can_setting] = true + # end + # + # if c.tea_id == user.id + # c[:can_setting] = true + # end + # end end - user.syllabuses.to_a << other + syllabuses end def after_create_course(course, user) @@ -56,9 +105,49 @@ class SyllabusesService end end - + sy[:can_setting] = true sy end + #修改课程大纲的名称、班级名称、新增班级 + def edit(user, option) + courses = [] + status = -1 + syllabus_id = option[:id] + + sy = Syllabus.where("id=?",option[:id]).first + + if sy && sy.user_id == user.id + syllabus_title = option[:title] + + sy.title = syllabus_title + + #修改班级名称 + modify_courses = option[:modify_courses] + modify_courses.each do |c| + course = Course.where("id=?",c.id).first + + if course && course.tea_id == user.id + course.name = c.name + !course.save + end + end + + #新增班级 + add_courses = option[:add_courses] + add_courses.each do |c| + course = ::Course.new(c) + course.name = add_courses + course.tea_id = user.id + course.syllabus_id = sy.id + course.update_default_value + course.is_public = 0 + course.save! + after_create_course(course, user) + end + status = 0 + end + status + end end \ No newline at end of file diff --git a/public/assets/wechat/class_list.html b/public/assets/wechat/class_list.html index 7c0af4a1a..c1e1a2123 100644 --- a/public/assets/wechat/class_list.html +++ b/public/assets/wechat/class_list.html @@ -3,7 +3,7 @@