diff --git a/app/api/mobile/apis/resources.rb b/app/api/mobile/apis/resources.rb index 6dfe8e599..9bd07a0d5 100644 --- a/app/api/mobile/apis/resources.rb +++ b/app/api/mobile/apis/resources.rb @@ -11,7 +11,9 @@ module Mobile end get do authenticate! - data = current_user.course_attachments + rs = ResourcesService.new + # data = current_user.course_attachments + data = rs.all_course_attachments current_user present :data, data, with: Mobile::Entities::Attachment present :status, 0 @@ -26,7 +28,8 @@ module Mobile get 'homeworks' do authenticate! - homeworks = current_user.homework_commons + rs = ResourcesService.new + homeworks = rs.all_homework_commons current_user present :data, homeworks, with: Mobile::Entities::Homework present :status, 0 @@ -40,7 +43,8 @@ module Mobile get 'exercies' do authenticate! - exercises = current_user.exercises + rs = ResourcesService.new + exercises = rs.all_exercises current_user present :data, exercises, with: Mobile::Entities::Exercise present :status, 0 end diff --git a/app/services/resources_service.rb b/app/services/resources_service.rb index a0fec585a..96034b4ce 100644 --- a/app/services/resources_service.rb +++ b/app/services/resources_service.rb @@ -50,4 +50,40 @@ class ResourcesService [@ori, @flag, @save_message] end + # 我的资源-课件 已发布的 + def all_course_attachments user + + courses = user.courses.not_deleted + + courses_ids = courses.empty? ? '(-1)' :"(" + courses.map(&:id).join(",") + ")" + + attchments = Attachment.where("(author_id = #{user.id} and is_publish = 1 and container_id in #{courses_ids} and container_type = 'Course') or (container_type = 'Course' and is_publish = 1 and container_id in #{courses_ids})" ).order("created_on desc") + + attchments + end + + # 我的资源-作业 已发布的 + def all_homework_commons user + + courses = user.courses.not_deleted + + courses_ids = courses.empty? ? '(-1)' :"(" + courses.map(&:id).join(",") + ")" + + homeworks = HomeworkCommon.where("course_id in #{courses_ids} and publish_time <= ?",Time.now.strftime("%Y-%m-%d")).order("created_at desc") + + homeworks + end + + # 我的资源-测验 已发布的 + def all_exercises user + + courses = user.courses.not_deleted + + courses_ids = courses.empty? ? '(-1)' :"(" + courses.map(&:id).join(",") + ")" + + exercises = Exercise.where("exercise_status <> 1 and course_id in #{courses_ids}").order("created_at desc") + + exercises + end + end \ 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 ef46fc4ba..5e9f339a1 100644 --- a/public/javascripts/wechat/controllers/new_class.js +++ b/public/javascripts/wechat/controllers/new_class.js @@ -1,6 +1,6 @@ -app.controller('NewClassController', ['$scope', '$http', 'auth', 'config', 'alertService','$location', function($scope, $http, auth, config, alertService, $location){ +app.controller('NewClassController', ['$scope', '$http', 'auth', 'config', 'alertService','$location','rms', function($scope, $http, auth, config, alertService, $location,rms){ var vm = $scope; vm.alertService = alertService.create(); @@ -40,7 +40,9 @@ app.controller('NewClassController', ['$scope', '$http', 'auth', 'config', 'aler vm.alertService.showMessage('出错了', response.data.message); } else { vm.alertService.showMessage('提示', '新建课程成功', function(){ - window.history.back(); +// window.history.back(); + rms.save('syllabuses',[]); + $location.path("/class_list"); }); } console.log(response.data.data);