diff --git a/app/api/mobile/apis/courses.rb b/app/api/mobile/apis/courses.rb index caabad198..aa1e573ed 100644 --- a/app/api/mobile/apis/courses.rb +++ b/app/api/mobile/apis/courses.rb @@ -200,8 +200,13 @@ module Mobile # course = Course.find(params[:id]) cs = CoursesService.new course = cs.show_course(params,current_user) - present :data, course, with: Mobile::Entities::Course,user: current_user - { status: 0} + + if course[:course][:is_delete] == 1 + {status:-1, message: '该班级不存在或已被删除啦' } + else + present :data, course, with: Mobile::Entities::Course,user: current_user + present :status, 0 + end end end diff --git a/app/api/mobile/apis/resources.rb b/app/api/mobile/apis/resources.rb index d5823d5b4..ebfef7f2d 100644 --- a/app/api/mobile/apis/resources.rb +++ b/app/api/mobile/apis/resources.rb @@ -85,12 +85,26 @@ module Mobile requires :token, type: String requires :course_ids, type: Array[Integer] requires :send_id, type: Integer + requires :send_type, type: Integer end post 'send' do authenticate! rs = ResourcesService.new - ori, flag, save_message = rs.send_resource_to_course(current_user,params) + + ori = nil + flag = false + save_message = nil + + case params[:send_type] + when 1 + ori, flag, save_message = rs.send_resource_to_course(current_user,params) + when 2 + ori, flag, save_message = rs.send_homework_to_course(current_user,params) + when 3 + ori, flag, save_message = rs.send_exercise_to_course(current_user,params) + end + if flag present :status, 0 else diff --git a/app/services/resources_service.rb b/app/services/resources_service.rb index bc97437e4..b56da8ad3 100644 --- a/app/services/resources_service.rb +++ b/app/services/resources_service.rb @@ -49,6 +49,125 @@ class ResourcesService [@ori, @flag, @save_message] end + def send_homework_to_course user,params + homework = HomeworkCommon.find params[:send_id].to_i + @ori = homework + course_ids = params[:course_ids] + @flag = false + unless course_ids.nil? + course_ids.each do |course_id| + course = Course.find course_id.to_i + new_homework = HomeworkCommon.new + new_homework.name = homework.name + new_homework.user_id = user.id + new_homework.description = homework.description + new_homework.homework_type = homework.homework_type + new_homework.late_penalty = homework.late_penalty + new_homework.course_id = course.id + new_homework.teacher_priority = homework.teacher_priority + new_homework.anonymous_comment = homework.anonymous_comment + new_homework.quotes = 0 + new_homework.is_open = homework.is_open + homework.attachments.each do |attachment| + att = attachment.copy + att.container_id = nil + att.container_type = nil + att.copy_from = attachment.id + att.save + new_homework.attachments << att + end + homework_detail_manual = homework.homework_detail_manual + homework_detail_programing = homework.homework_detail_programing + homework_detail_group = homework.homework_detail_group + if homework_detail_manual + new_homework.homework_detail_manual = HomeworkDetailManual.new + new_homework_detail_manual = new_homework.homework_detail_manual + new_homework_detail_manual.ta_proportion = homework_detail_manual.ta_proportion + new_homework_detail_manual.comment_status = 0 + new_homework_detail_manual.evaluation_num = homework_detail_manual.evaluation_num + new_homework_detail_manual.absence_penalty = homework_detail_manual.absence_penalty + end + if homework_detail_programing + new_homework.homework_detail_programing = HomeworkDetailPrograming.new + new_homework.homework_detail_programing.ta_proportion = homework_detail_programing.ta_proportion + new_homework.homework_detail_programing.language = homework_detail_programing.language + homework.homework_tests.each_with_index do |homework_test| + new_homework.homework_tests << HomeworkTest.new( + input: homework_test.input, + output: homework_test.output + ) + end + end + + if homework_detail_group + new_homework.homework_detail_group = HomeworkDetailGroup.new + new_homework.homework_detail_group.min_num = homework_detail_group.min_num + new_homework.homework_detail_group.max_num = homework_detail_group.max_num + new_homework.homework_detail_group.base_on_project = homework_detail_group.base_on_project + end + if new_homework.save + new_homework_detail_manual.save if new_homework_detail_manual + new_homework.homework_detail_programing.save if new_homework.homework_detail_programing + new_homework.homework_detail_group.save if new_homework.homework_detail_group + @flag = true + else + @flag = false + @save_message = new_homework.errors.full_messages + break + end + homework.update_column(:quotes, homework.quotes+1) + end + end + [@ori, @flag, @save_message] + end + + def send_exercise_to_course user,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.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 + # 我的资源-课件 已发布的 def all_course_attachments user diff --git a/public/assets/wechat/class.html b/public/assets/wechat/class.html index c328ed226..2f9af6554 100644 --- a/public/assets/wechat/class.html +++ b/public/assets/wechat/class.html @@ -56,5 +56,5 @@ - + diff --git a/public/assets/wechat/myresource.html b/public/assets/wechat/myresource.html index c89f39684..28fc69cc3 100644 --- a/public/assets/wechat/myresource.html +++ b/public/assets/wechat/myresource.html @@ -12,7 +12,7 @@
- {{r.filename}}发送
+ {{r.filename}}发送
大小:{{r.attafile_size}}
@@ -22,7 +22,7 @@ 请登录Trustie网站,在PC浏览器中上传课件。

-
{{r.homework_name}}发送
+
{{r.homework_name}}发送
@@ -32,7 +32,7 @@ 请登录Trustie网站,在PC浏览器中创建作业。

-
{{r.exercise_name}}发送
+
{{r.exercise_name}}发送
diff --git a/public/javascripts/wechat/controllers/class.js b/public/javascripts/wechat/controllers/class.js index 87703b681..cf2a3ee88 100644 --- a/public/javascripts/wechat/controllers/class.js +++ b/public/javascripts/wechat/controllers/class.js @@ -1,4 +1,4 @@ -app.controller('ClassController', ['$scope', 'config','$http', 'auth','$location','$routeParams', function($scope, config, $http, auth, $location, $routeParams){ +app.controller('ClassController', ['$scope', 'config','$http', 'auth','$location','$routeParams','alertService', function($scope, config, $http, auth, $location, $routeParams,alertService){ var vm = $scope; var courseid = $routeParams.id; @@ -97,15 +97,14 @@ app.controller('ClassController', ['$scope', 'config','$http', 'auth','$location } } - - - vm.course = {}; vm.students = []; vm.teachers = []; vm.resources = []; vm.homeworks = []; vm.exercises = []; + + vm.alertService = alertService.create(); vm.invite = function(){ $location.path("/invite_code").search({id: courseid}); @@ -118,9 +117,16 @@ app.controller('ClassController', ['$scope', 'config','$http', 'auth','$location $http.get(config.apiUrl+ 'courses/'+courseid+"?token="+auth.token()).then( function(response) { console.log(response.data); - vm.course = response.data.data; - resetMenu(vm.course.current_user_is_teacher); - vm.tab(1); + + if (response.data.status == 0){ + vm.course = response.data.data; + resetMenu(vm.course.current_user_is_teacher); + vm.tab(1); + } + else{ + vm.alertService.showMessage('提示', response.data.message); + } + } ); diff --git a/public/javascripts/wechat/controllers/myresource.js b/public/javascripts/wechat/controllers/myresource.js index fb564cde8..15428bb34 100644 --- a/public/javascripts/wechat/controllers/myresource.js +++ b/public/javascripts/wechat/controllers/myresource.js @@ -10,21 +10,30 @@ app.controller('MyResourceController', ['$scope', '$http', 'auth', 'config', '$l vm.homeworks_tag = false; vm.exercises_tag = false; + //课件 vm.page = rms.get('page') || 0; vm.resources = rms.get("resources") || []; vm.has_more = rms.get("has_more"); + //作业 vm.homework_page = rms.get('homework_page') || 0; vm.homeworks = rms.get("homeworks") || []; vm.homework_has_more = rms.get("homework_has_more"); + //测验 vm.exercise_page = rms.get('exercise_page') || 0; vm.exercise = rms.get("exercise") || []; vm.exercise_has_more = rms.get("exercise_has_more"); vm.searchText = ""; - vm.sendFile = function(r){ + //发送类别 1课件 2作业 3测验 + vm.myresource_sendIndex = rms.get('myresource_sendIndex') || 1; + + vm.sendFile = function(r,index){ + vm.myresource_sendIndex = index; + rms.save('myresource_sendIndex',index); + $location.path("/send_class_list").search({id: r.id}); } diff --git a/public/javascripts/wechat/controllers/send_class_list.js b/public/javascripts/wechat/controllers/send_class_list.js index 16875af9f..c80943e39 100644 --- a/public/javascripts/wechat/controllers/send_class_list.js +++ b/public/javascripts/wechat/controllers/send_class_list.js @@ -2,6 +2,9 @@ app.controller('SendClassListController', ['$scope', '$http','$routeParams', 'co var vm = $scope; var send_id = $routeParams.id; + //发送类别 1课件 2作业 3测验 + vm.myresource_sendIndex = rms.get('myresource_sendIndex') || 1; + vm.alertService = alertService.create(); vm.syllabuses = []; @@ -39,7 +42,7 @@ app.controller('SendClassListController', ['$scope', '$http','$routeParams', 'co } $http.post(config.apiUrl + "resources/send", { - token: auth.token(), course_ids: course_ids, send_id: send_id + token: auth.token(), course_ids: course_ids, send_id: send_id,send_type:vm.myresource_sendIndex }).then(function(response){ console.log(response.data); if(response.data.status == 0){