diff --git a/.access_token b/.access_token index 610b08d2e..2fb2e740f 100644 --- a/.access_token +++ b/.access_token @@ -1 +1 @@ -{"access_token":"oEEf8ZKAB8Y2G0o_xnTPkPJHKKk8iHkLC-f5ptvQ2nCMj9IpC86ivLD2-p38GfOkuG-HuQp3pWZqhs3NJXUMdPLWsr5k67hPZYuqg4ozLccx0xdLswapj0mn8ovZhK1tKIKiAFAOMO","expires_in":7200,"got_token_at":1467012449} \ No newline at end of file +{"access_token":"m8kGwb7G0laM6-0uHmPtxETR6WJk5PgR37te_h8aBwgqGXkml2ZZAvPUBldmzF5hDZsQBHEn8PUACSL60eDKlCWigwwUJReK2wB4UbXIc1UA-rrkpHuWl84H3rcswtlvHENjAHAZWF","expires_in":7200,"got_token_at":1467472907} \ No newline at end of file diff --git a/app/api/mobile/apis/courses.rb b/app/api/mobile/apis/courses.rb index 42303b63d..cb1db09d8 100644 --- a/app/api/mobile/apis/courses.rb +++ b/app/api/mobile/apis/courses.rb @@ -107,7 +107,7 @@ module Mobile status = cs.join_course({role: "10", openid: params[:openid], invite_code: params[:invite_code]}, current_user) { status: status[:state], - messsge:CoursesService::JoinCourseError.message(status[:state]) + message:CoursesService::JoinCourseError.message(status[:state]) } end diff --git a/app/api/mobile/apis/resources.rb b/app/api/mobile/apis/resources.rb index fca94a642..c2fcfa754 100644 --- a/app/api/mobile/apis/resources.rb +++ b/app/api/mobile/apis/resources.rb @@ -46,10 +46,26 @@ module Mobile end + desc '发送资源' + params do + requires :token, type: String + requires :course_ids, type: Array[Integer] + requires :send_id, type: Integer + end + post 'send' do + authenticate! + + rs = ResourcesService.new + ori, flag, save_message = rs.send_resource_to_course(params) + if flag + present :status, 0 + else + {status: -1, message: save_message.first} + end + end + end - - end end end \ No newline at end of file diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index b7972ff6f..3bf582e23 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1977,44 +1977,8 @@ class UsersController < ApplicationController def add_exist_file_to_course @flag = true if params[:send_id].present? - send_id = params[:send_id] - @ori = Attachment.find_by_id(send_id) - course_ids = params[:course_ids] - if course_ids.nil? - @flag = false - end - unless course_ids.nil? - course_ids.each do |id| - next if @ori.blank? - @exist = false - Course.find(id).attachments.each do |att| #如果课程中包含该资源 - if att.id == @ori.id || (!att.copy_from.nil? && !@ori.copy_from.nil? && att.copy_from == @ori.copy_from) || att.copy_from == @ori.id || att.id == @ori.copy_from - att.created_on = Time.now - att.save - @exist = true - break - end - end - next if @exist - attach_copied_obj = @ori.copy - attach_copied_obj.tag_list.add(@ori.tag_list) # tag关联 - attach_copied_obj.container = Course.find(id) - attach_copied_obj.created_on = Time.now - attach_copied_obj.author_id = User.current.id - attach_copied_obj.is_public = 0 - attach_copied_obj.copy_from = @ori.copy_from.nil? ? @ori.id : @ori.copy_from #发送要添加copy_from - if attach_copied_obj.attachtype == nil - attach_copied_obj.attachtype = 4 - end - if attach_copied_obj.save - # 更新引用次数 - quotes = @ori.quotes.to_i + 1 - @ori.update_attribute(:quotes, quotes) unless @ori.nil? - @ori.forwards << Forward.new(:to_type => attach_copied_obj.class.name, :to_id => attach_copied_obj.id,:created_at => Time.now) - end - @save_message = attach_copied_obj.errors.full_messages - end - end + rs = ResourcesService.new + @ori, @flag, @save_message = rs.send_resource_to_course(params) elsif params[:send_ids].present? send_ids = params[:send_ids].split(",") course_ids = params[:course_ids] diff --git a/app/services/courses_service.rb b/app/services/courses_service.rb index dce3e1f18..e6143caec 100644 --- a/app/services/courses_service.rb +++ b/app/services/courses_service.rb @@ -324,7 +324,7 @@ class CoursesService 1, '密码错误', 2, '课程已过期 请联系课程管理员重启课程。', 3, '您已经加入了课程', - 4, '您加入的课程不存在', + 4, '您的邀请码不正确', 5, '您还未登录', 6, '申请成功,请等待审核完毕', 7, '您已经发送过申请了,请耐心等待', diff --git a/app/services/resources_service.rb b/app/services/resources_service.rb new file mode 100644 index 000000000..827fc3efd --- /dev/null +++ b/app/services/resources_service.rb @@ -0,0 +1,53 @@ +#coding=utf-8 + +class ResourcesService + + #发送资源到课程 + def send_resource_to_course params + send_id = params[:send_id] + @ori = Attachment.find_by_id(send_id) + course_ids = params[:course_ids] + @flag = false + unless course_ids.nil? + course_ids.each do |id| + next if @ori.blank? + @exist = false + Course.find(id).attachments.each do |att| #如果课程中包含该资源 + if att.id == @ori.id || (!att.copy_from.nil? && !@ori.copy_from.nil? && att.copy_from == @ori.copy_from) || att.copy_from == @ori.id || att.id == @ori.copy_from + att.created_on = Time.now + att.save + @exist = true + @flag = true + break + end + end + next if @exist + attach_copied_obj = @ori.copy + attach_copied_obj.tag_list.add(@ori.tag_list) # tag关联 + attach_copied_obj.container = Course.find(id) + attach_copied_obj.created_on = Time.now + attach_copied_obj.author_id = User.current.id + attach_copied_obj.is_public = 0 + attach_copied_obj.copy_from = @ori.copy_from.nil? ? @ori.id : @ori.copy_from #发送要添加copy_from + if attach_copied_obj.attachtype == nil + attach_copied_obj.attachtype = 4 + end + if attach_copied_obj.save + # 更新引用次数 + quotes = @ori.quotes.to_i + 1 + @ori.update_attribute(:quotes, quotes) unless @ori.nil? + @ori.forwards << Forward.new(:to_type => attach_copied_obj.class.name, :to_id => attach_copied_obj.id,:created_at => Time.now) + @flag = true + else + @flag = false + @save_message = attach_copied_obj.errors.full_messages + break + end + + end + end + + [@ori, @flag, @save_message] + end + +end \ No newline at end of file diff --git a/app/services/users_service.rb b/app/services/users_service.rb index 8df42fb41..ab1bb2ec4 100644 --- a/app/services/users_service.rb +++ b/app/services/users_service.rb @@ -319,4 +319,8 @@ class UsersService my_jours_arr end + + + + end diff --git a/app/views/wechats/user_activities.html.erb b/app/views/wechats/user_activities.html.erb index 7b7cb95e5..ab1d18a8d 100644 --- a/app/views/wechats/user_activities.html.erb +++ b/app/views/wechats/user_activities.html.erb @@ -50,6 +50,7 @@ + diff --git a/public/assets/wechat/activities.html b/public/assets/wechat/activities.html index f042daba7..ef3346e20 100644 --- a/public/assets/wechat/activities.html +++ b/public/assets/wechat/activities.html @@ -2,7 +2,11 @@
-
+ + +
我的动态
+ +
diff --git a/public/assets/wechat/class.html b/public/assets/wechat/class.html index dc575dc64..70dd64fad 100644 --- a/public/assets/wechat/class.html +++ b/public/assets/wechat/class.html @@ -20,7 +20,7 @@
-
{{r.filename}}发送
+
{{r.filename}}发送

暂无课件,
请登录Trustie网站,在PC浏览器中上传课件。

@@ -37,14 +37,14 @@
-
{{r.homework_name}}发送
+
{{r.homework_name}}

暂无作业,
请登录Trustie网站,在PC浏览器中上传作业。

-
{{r.exercise_name}}发送
+
{{r.exercise_name}}

暂无小测验,
请登录Trustie网站,在PC浏览器中上传小测验。

diff --git a/public/assets/wechat/class_list.html b/public/assets/wechat/class_list.html index 8ec8bcaa5..5c64b9a87 100644 --- a/public/assets/wechat/class_list.html +++ b/public/assets/wechat/class_list.html @@ -1,7 +1,7 @@
课程列表
-
未命名课程
+
未命名课程
\ No newline at end of file diff --git a/public/assets/wechat/myresource.html b/public/assets/wechat/myresource.html index 9d3bf0fda..dc4d6ea78 100644 --- a/public/assets/wechat/myresource.html +++ b/public/assets/wechat/myresource.html @@ -9,17 +9,17 @@
-
{{r.filename}}发送
+
{{r.filename}}发送

暂无课件,
请登录Trustie网站,在PC浏览器中上传课件。

-
{{r.homework_name}}发送
+
{{r.homework_name}}

暂无作业,
请登录Trustie网站,在PC浏览器中创建作业。

-
{{r.exercise_name}}发送
+
{{r.exercise_name}}

暂无测验,
请登录Trustie网站,在PC浏览器中创建测验。

diff --git a/public/assets/wechat/new_class.html b/public/assets/wechat/new_class.html index 2bb5d2aac..ab0fc96f6 100644 --- a/public/assets/wechat/new_class.html +++ b/public/assets/wechat/new_class.html @@ -3,5 +3,8 @@
课程
班级
+新增班级
- 完成 + 完成 + + +
diff --git a/public/assets/wechat/send_class_list.html b/public/assets/wechat/send_class_list.html new file mode 100644 index 000000000..4b8b8a27f --- /dev/null +++ b/public/assets/wechat/send_class_list.html @@ -0,0 +1,13 @@ + +
+
+ +
发送课程列表
+
未命名课程
+ + +
发送
+ +
diff --git a/public/assets/wechat/templates/loading.html b/public/assets/wechat/templates/loading.html new file mode 100644 index 000000000..8113a78c2 --- /dev/null +++ b/public/assets/wechat/templates/loading.html @@ -0,0 +1,21 @@ + +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

数据加载中

+
+
\ No newline at end of file diff --git a/public/javascripts/wechat/controllers/class.js b/public/javascripts/wechat/controllers/class.js index c2281be88..1cd69bb43 100644 --- a/public/javascripts/wechat/controllers/class.js +++ b/public/javascripts/wechat/controllers/class.js @@ -105,6 +105,10 @@ app.controller('ClassController', ['$scope', 'config','$http', 'auth','$location $location.path("/invite_code").search({id: courseid}); }; + vm.sendFile = function(r){ + $location.path("/send_class_list").search({id: r.id}); + } + $http.get(config.apiUrl+ 'courses/'+courseid+"?token="+auth.token()).then( function(response) { console.log(response.data); diff --git a/public/javascripts/wechat/controllers/class_list.js b/public/javascripts/wechat/controllers/class_list.js index 4484ff834..21da4aea9 100644 --- a/public/javascripts/wechat/controllers/class_list.js +++ b/public/javascripts/wechat/controllers/class_list.js @@ -3,28 +3,63 @@ */ -app.controller('ClassListController', ['$scope','config','auth','$http','$location', function($scope, config, auth, $http, $location){ - var vm = $scope; - vm.courses = []; +app.controller('ClassListController', ['$scope', 'config', 'auth', '$http', '$location', 'alertService', + function ($scope, config, auth, $http, $location, alertService) { + var vm = $scope; + vm.courses = []; - $http.get(config.apiUrl + "courses?token="+ auth.token() + "&per_page_count=10&page=1").then( - function(response){ - console.log(response.data); - vm.courses = response.data.data; + vm.alertService = alertService.create(); + + + var loadClassList = function () { + $http.get(config.apiUrl + "courses?token=" + auth.token() + "&per_page_count=10&page=1").then( + function (response) { + console.log(response.data); + vm.courses = response.data.data; + } + ); + }; + + loadClassList(); + + vm.goClass = function (course_id) { + console.log(course_id); + $location.path("/class").search({id: course_id}); } - ); - vm.goClass = function(course_id){ - console.log(course_id); - $location.path("/class").search({id: course_id}); - } + vm.newClass = function () { + $location.path("/new_class"); + } - vm.newClass = function(){ - $location.path("/new_class"); - } + vm.goResource = function () { + $location.path("/myresource"); + } - vm.goResource =function(){ - $location.path("/myresource"); - } + vm.joinClass = function () { + var code = window.prompt("请输入5位班级邀请码(不区分大小写)"); + if (code && code.length == 5) { + $http.post(config.apiUrl + "courses/join", { + token: auth.token(), + invite_code: code + }).then(function (response) { + console.log(response.data); + if (response.data.status != 0) { + vm.alertService.showMessage('错误', response.data.message); + } else { + vm.alertService.showMessage('提示', '加入课程成功'); + loadClassList(); + } + }); + } else { + if(code){ + vm.alertService.showMessage('错误', '邀请码格式不正确'); + } -}]); \ No newline at end of file + } + }; + + vm.onSetting = function () { + vm.alertService.showMessage('提示', '此功能正在开发中'); + } + + }]); \ No newline at end of file diff --git a/public/javascripts/wechat/controllers/myresource.js b/public/javascripts/wechat/controllers/myresource.js index 87b2a4d82..084205fbe 100644 --- a/public/javascripts/wechat/controllers/myresource.js +++ b/public/javascripts/wechat/controllers/myresource.js @@ -1,4 +1,4 @@ -app.controller('MyResourceController', ['$scope', '$http', 'auth', 'config', function($scope, $http, auth, config){ +app.controller('MyResourceController', ['$scope', '$http', 'auth', 'config', '$location', function($scope, $http, auth, config, $location){ var vm = $scope; vm.menus = ['课件', '作业', '测验']; @@ -27,4 +27,8 @@ app.controller('MyResourceController', ['$scope', '$http', 'auth', 'config', fun } vm.tab(1); + + vm.sendFile = function(r){ + $location.path("/send_class_list").search({id: r.id}); + } }] ); \ No newline at end of file diff --git a/public/javascripts/wechat/controllers/new_class.js b/public/javascripts/wechat/controllers/new_class.js index 488db31c6..c3c81eecd 100644 --- a/public/javascripts/wechat/controllers/new_class.js +++ b/public/javascripts/wechat/controllers/new_class.js @@ -1,12 +1,12 @@ -app.controller('NewClassController', ['$scope', '$http', 'auth', 'config', function($scope, $http, auth, config){ +app.controller('NewClassController', ['$scope', '$http', 'auth', 'config', 'alertService', function($scope, $http, auth, config, alertService){ var vm = $scope; - vm.resources = []; - vm.homeworks = []; - vm.exercises = []; + vm.alertService = alertService.create(); - + vm.newClass = function () { + vm.alertService.showMessage('提示', '此功能正在开发中'); + } }] ); \ No newline at end of file diff --git a/public/javascripts/wechat/controllers/send_class_list.js b/public/javascripts/wechat/controllers/send_class_list.js new file mode 100644 index 000000000..07d321ba2 --- /dev/null +++ b/public/javascripts/wechat/controllers/send_class_list.js @@ -0,0 +1,47 @@ +app.controller('SendClassListController', ['$scope', '$http','$routeParams', 'config','auth','alertService', function($scope, $http, $routeParams, config, auth, alertService){ + var vm = $scope; + var send_id = $routeParams.id; + + vm.alertService = alertService.create(); + vm.courses = []; + + var loadClassList = function () { + $http.get(config.apiUrl + "courses?token=" + auth.token() + "&per_page_count=10&page=1").then( + function (response) { + console.log(response.data); + vm.courses = response.data.data; + } + ); + }; + + loadClassList(); + + vm.selectCourse = function(course){ + if( typeof course.checked !== 'boolean' ) course.checked = false; + course.checked = !course.checked; + } + + vm.sendToCourses = function(){ + var course_ids = []; + + for(var i in vm.courses){ + if(vm.courses[i].checked){ + course_ids.push(vm.courses[i].id); + } + } + + $http.post(config.apiUrl + "resources/send", { + token: auth.token(), course_ids: course_ids, send_id: send_id + }).then(function(response){ + console.log(response.data); + if(response.data.status == 0){ + vm.alertService.showMessage('提示', '发送成功', function () { + window.history.back(); + }); + } else { + vm.alertService.showMessage('发送出错', response.data.message); + } + }) + } + +}]); \ No newline at end of file diff --git a/public/javascripts/wechat/directives/loading_spinner.js b/public/javascripts/wechat/directives/loading_spinner.js index 780056828..cea916997 100644 --- a/public/javascripts/wechat/directives/loading_spinner.js +++ b/public/javascripts/wechat/directives/loading_spinner.js @@ -1,7 +1,5 @@ -app.directive('loadingSpinner', ['$http', function ($http) { +app.directive('loadingSpinner', ['$http', 'config', function ($http, config) { return { - restrict: 'A', - replace: true, - template: '
加载中...
', + templateUrl: config.rootPath+ 'templates/loading.html', }; }]); diff --git a/public/javascripts/wechat/others/routes.js b/public/javascripts/wechat/others/routes.js index 80efa71e9..ea6dca05d 100644 --- a/public/javascripts/wechat/others/routes.js +++ b/public/javascripts/wechat/others/routes.js @@ -35,6 +35,7 @@ app.config(['$routeProvider',"$httpProvider", "$locationProvider",'config', func .when('/class_list', makeRoute('class_list.html', 'ClassListController')) .when('/myresource', makeRoute('myresource.html', 'MyResourceController')) .when('/invite_code', makeRoute('invite_code.html', 'InviteCodeController')) + .when('/send_class_list', makeRoute('send_class_list.html', 'SendClassListController')) .otherwise({ redirectTo: '/activites' });