From 04a2effceec5c8b07b230a51fd90cc5bb5bc2cc3 Mon Sep 17 00:00:00 2001 From: yuanke <249218296@qq.com> Date: Sun, 18 Sep 2016 16:12:38 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E5=A2=9E=E5=8A=A0=E5=88=86?= =?UTF-8?q?=E7=8F=AD=E7=9B=B8=E5=85=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/mobile/apis/courses.rb | 30 ++++++++++---- app/services/courses_service.rb | 8 +++- public/assets/wechat/join_class.html | 2 + public/assets/wechat/join_classgroup.html | 32 +++++++++++++++ .../wechat/controllers/join_class.js | 8 +++- .../wechat/controllers/join_classgroup.js | 39 +++++++++++++++++++ public/javascripts/wechat/others/routes.js | 1 + 7 files changed, 111 insertions(+), 9 deletions(-) create mode 100644 public/assets/wechat/join_classgroup.html create mode 100644 public/javascripts/wechat/controllers/join_classgroup.js diff --git a/app/api/mobile/apis/courses.rb b/app/api/mobile/apis/courses.rb index 57feff084..f0e4c867d 100644 --- a/app/api/mobile/apis/courses.rb +++ b/app/api/mobile/apis/courses.rb @@ -118,20 +118,18 @@ module Mobile roles_ids << "10" end + go_course_group = 0 + if roles_ids.length <= 0 {status:-1,message:"请至少选择一个角色"} else cs = CoursesService.new status = cs.join_course_roles({role: roles_ids, openid: params[:openid], invite_code: params[:invite_code]}, current_user) - if params[:student_flag] && status[:state] == 0 - #查询分班信息 - - - end - { status: status[:state], - message:CoursesService::JoinCourseError.message(status[:state]) + message:CoursesService::JoinCourseError.message(status[:state]), + go_coursegroup_flag:status[:go_coursegroup_flag], + course_id:status[:course_id] } end end @@ -756,6 +754,24 @@ module Mobile end out.merge(message: message) end + + desc '获取分班列表' + params do + requires :token, type:String + end + get ':course_id/course_groups' do + begin + authenticate! + course = Course.find(params[:course_id]) + groups = [] + groups = course.course_groups if course.course_groups + present :data,groups + present :status,0 + rescue + present :status,-1 + end + end + end end end diff --git a/app/services/courses_service.rb b/app/services/courses_service.rb index 5add9979d..182d1150f 100644 --- a/app/services/courses_service.rb +++ b/app/services/courses_service.rb @@ -565,6 +565,8 @@ class CoursesService #多个角色加入课程 def join_course_roles params,current_user course = Course.find_by_invite_code(params[:invite_code]) if params[:invite_code] + go_coursegroup_flag = 0 + course_id = 0 @state = 10 if course @@ -621,6 +623,8 @@ class CoursesService course.members << members StudentsForCourse.create(:student_id => current_user.id, :course_id => course.id) @state = 0 + go_coursegroup_flag = 1 if course.course_groups + course_id = course.id send_wechat_join_class_notice current_user,course,10,0 else is_stu = false @@ -630,6 +634,8 @@ class CoursesService course.members << members StudentsForCourse.create(:student_id => current_user.id, :course_id =>course.id) is_stu = true + go_coursegroup_flag = 1 if course.course_groups + course_id = course.id send_wechat_join_class_notice current_user,course,10,0 end #如果已经发送过消息了,那么就要给个提示 @@ -674,7 +680,7 @@ class CoursesService else @state = 4 end - {:state => @state,:course => course} + {:state => @state,:course => course,:go_coursegroup_flag => go_coursegroup_flag,:course_id=>course_id} end diff --git a/public/assets/wechat/join_class.html b/public/assets/wechat/join_class.html index ad43db3a7..4c81ff2e4 100644 --- a/public/assets/wechat/join_class.html +++ b/public/assets/wechat/join_class.html @@ -25,5 +25,7 @@ +
{{tip_1}}
+ diff --git a/public/assets/wechat/join_classgroup.html b/public/assets/wechat/join_classgroup.html new file mode 100644 index 000000000..6da2f1503 --- /dev/null +++ b/public/assets/wechat/join_classgroup.html @@ -0,0 +1,32 @@ +
+
+
+
欢迎加入班级
+
{{current_course.name}}
+
选择分班
+ + +
+ 提示 +
    +
  • 该班级存在分班信息,请选择属于您的小班
  • +
  • 老师可以在班级的成员管理页,对所有成员进行修改
  • +
  • 学生可以在班级的我的同学页,对自己进行修改
  • +
+
+ +
+ 取消 + 确定 +
+
+ + +
\ No newline at end of file diff --git a/public/javascripts/wechat/controllers/join_class.js b/public/javascripts/wechat/controllers/join_class.js index 006fa0b59..8f7647b12 100644 --- a/public/javascripts/wechat/controllers/join_class.js +++ b/public/javascripts/wechat/controllers/join_class.js @@ -55,10 +55,16 @@ app.controller('JoinClassController', ['$scope', '$http', 'auth', 'config', 'ale assistant_flag:vm.assistant, student_flag:vm.student }).then(function(response){ + console.log(response); if(response.data.status == 0){ vm.alertService.showMessage('提示', response.data.message,function(){ rms.save('syllabuses',[]); - $location.path("/class_list"); + if(response.data.go_coursegroup_flag == 0){ + $location.path("/class_list"); + } + else{ + $location.path("/join_classgroup").search({id: response.data.course_id}); + } }); } else { vm.alertService.showMessage('提示', response.data.message); diff --git a/public/javascripts/wechat/controllers/join_classgroup.js b/public/javascripts/wechat/controllers/join_classgroup.js new file mode 100644 index 000000000..504643817 --- /dev/null +++ b/public/javascripts/wechat/controllers/join_classgroup.js @@ -0,0 +1,39 @@ + + +app.controller('JoinClassGroupController', ['$scope', '$http', 'auth', 'config', 'alertService','$location','$routeParams','rms','wx','common', function($scope, $http, auth, config, alertService, $location,$routeParams, rms,wx,common){ + var vm = $scope; + + var course_id = $routeParams.id; + vm.alertService = alertService.create(); + + $http.get(config.apiUrl+ 'courses/'+course_id+"?token="+auth.token()).then( + function(response) { + console.log(response.data); + if (response.data.status == 0){ + vm.current_course = response.data.data; + console.log("courses"); + console.log(response.data.data); + } + else{ + vm.alertService.showMessage('提示', response.data.message); + } + if(!vm.current_course){ + vm.tip_1 = "该班级不存在或已被删除"; + } + } + ); + + if(vm.current_course){ + $http.get(config.apiUrl + 'courses/course_groups?token='+auth.token()+'&course_id='+course_id).then( + function(response) { + if(response.data.status == 0) { + vm.groups = response.data.groups; + } + else{ + vm.groups = []; + } + }); + } + + +}] ); \ No newline at end of file diff --git a/public/javascripts/wechat/others/routes.js b/public/javascripts/wechat/others/routes.js index e5c87d1ab..845995ec6 100644 --- a/public/javascripts/wechat/others/routes.js +++ b/public/javascripts/wechat/others/routes.js @@ -39,6 +39,7 @@ app.config(['$routeProvider',"$httpProvider", "$locationProvider",'config', func .when('/invite_code', {templateUrl: rootPath + 'invite_code.html', controller: 'InviteCodeController'}) .when('/send_class_list', makeRoute('send_class_list.html', 'SendClassListController')) .when('/join_class', makeRoute('join_class.html', 'JoinClassController')) + .when('/join_classgroup', makeRoute('join_classgroup.html', 'JoinClassGroupController')) .when('/review_class_member', makeRoute('review_class_member.html', 'ReviewClassMemberController')) .when('/class_publishnotice', makeRoute('class_publishnotice.html', 'ClassPublishNoticeController')) .when('/class_publishissue', makeRoute('class_publishissue.html', 'ClassPublishIssueController'))