From 60dc0e72cf8c93116f7e4b0738b476c8dd51508c Mon Sep 17 00:00:00 2001 From: yuanke <249218296@qq.com> Date: Fri, 15 Jul 2016 16:46:27 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E6=88=91=E6=88=91=E7=9A=84?= =?UTF-8?q?=E8=B5=84=E6=BA=90=E6=9B=B4=E5=A4=9A=E6=8C=89=E9=92=AE=E6=98=BE?= =?UTF-8?q?=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/mobile/apis/resources.rb | 36 ++++- app/views/wechats/user_activities.html.erb | 50 +++---- public/assets/wechat/myresource.html | 9 ++ .../wechat/controllers/myresource.js | 135 +++++++++++++++--- 4 files changed, 180 insertions(+), 50 deletions(-) diff --git a/app/api/mobile/apis/resources.rb b/app/api/mobile/apis/resources.rb index 16531940f..d5823d5b4 100644 --- a/app/api/mobile/apis/resources.rb +++ b/app/api/mobile/apis/resources.rb @@ -8,13 +8,23 @@ module Mobile desc '获取所有课件' params do requires :token, type: String + requires :page, type: Integer end - get do + post do authenticate! + page = params[:page] ? params[:page] : 0 + rs = ResourcesService.new # data = current_user.course_attachments data = rs.all_course_attachments current_user + all_count = data.count + data = data.limit(10).offset(page * 10) + count = data.count + present :data, data, with: Mobile::Entities::Attachment,user: current_user + present :all_count, all_count + present :count, count + present :page, page present :status, 0 end @@ -24,14 +34,24 @@ module Mobile desc '获取所有作业' params do requires :token, type: String + requires :page, type: Integer end - get 'homeworks' do + post 'homeworks' do authenticate! + page = params[:page] ? params[:page] : 0 + rs = ResourcesService.new homeworks = rs.all_homework_commons current_user + all_count = homeworks.count + homeworks = homeworks.limit(10).offset(page * 10) + count = homeworks.count + present :data, homeworks, with: Mobile::Entities::Homework,user: current_user + present :all_count, all_count + present :count, count + present :page, page present :status, 0 end @@ -39,13 +59,23 @@ module Mobile desc '获取所有测验' params do requires :token, type: String + requires :page, type: Integer end - get 'exercies' do + post 'exercises' do authenticate! + page = params[:page] ? params[:page] : 0 + rs = ResourcesService.new exercises = rs.all_exercises current_user + all_count = exercises.count + exercises = exercises.limit(10).offset(page * 10) + count = exercises.count + present :data, exercises, with: Mobile::Entities::Exercise,user: current_user + present :all_count, all_count + present :count, count + present :page, page present :status, 0 end diff --git a/app/views/wechats/user_activities.html.erb b/app/views/wechats/user_activities.html.erb index 5e86d32d1..cb9f4095a 100644 --- a/app/views/wechats/user_activities.html.erb +++ b/app/views/wechats/user_activities.html.erb @@ -28,31 +28,31 @@ - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/public/assets/wechat/myresource.html b/public/assets/wechat/myresource.html index e91185968..0782aeb3b 100644 --- a/public/assets/wechat/myresource.html +++ b/public/assets/wechat/myresource.html @@ -15,6 +15,9 @@ {{r.filename}}发送
大小:{{r.attafile_size}}
+
+
更多
+

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

@@ -22,6 +25,9 @@
{{r.homework_name}}发送
+
+
更多
+

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

@@ -29,6 +35,9 @@
{{r.exercise_name}}发送
+
+
更多
+

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

diff --git a/public/javascripts/wechat/controllers/myresource.js b/public/javascripts/wechat/controllers/myresource.js index b371ee8cc..802982266 100644 --- a/public/javascripts/wechat/controllers/myresource.js +++ b/public/javascripts/wechat/controllers/myresource.js @@ -1,37 +1,128 @@ -app.controller('MyResourceController', ['$scope', '$http', 'auth', 'config', '$location', function($scope, $http, auth, config, $location){ +app.controller('MyResourceController', ['$scope', '$http', 'auth', 'config', '$location', 'rms', function($scope, $http, auth, config, $location,rms){ var vm = $scope; vm.menus = ['课件', '作业', '测验']; - vm.resources = null; - vm.homeworks = null; - vm.exercise = null; + vm.resources = []; + vm.homeworks = []; + vm.exercise = []; + + 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){ + $location.path("/send_class_list").search({id: r.id}); + } + + vm.loadResourceData = function (index,page){ + if(index == 1){ + vm.page = page; + $http({ + method: 'POST', + url: apiUrl+ "resources", + data: {token: auth.token(), page: page} + }).then(function successCallback(response) { + if(response.data.page >0) { + vm.resources = vm.resources.concat(response.data.data); + } else { + vm.resources = response.data.data; + } + + rms.save("resources", vm.resources); + vm.has_more = (response.data.count + response.data.page * 10) < response.data.all_count; + rms.save('has_more', vm.has_more); + rms.save('page', response.data.page); + + console.log(response.data); + + }, function errorCallback(response) { + }); + + } + else if(index==2 ){ + vm.homework_page = page; + $http({ + method: 'POST', + url: apiUrl+ "resources/homeworks", + data: {token: auth.token(), page: page} + }).then(function successCallback(response) { + if(response.data.page >0) { + vm.homeworks = vm.homeworks.concat(response.data.data); + } else { + vm.homeworks = response.data.data; + } + + rms.save("homeworks", vm.homeworks); + vm.homework_has_more = (response.data.count + response.data.page * 10) < response.data.all_count; + rms.save('homework_has_more', vm.has_more); + rms.save('homework_page', response.data.page); + + console.log(response.data); + + }, function errorCallback(response) { + }); + } + else if(index==3 ){ + vm.exercise_page = page; + $http({ + method: 'POST', + url: apiUrl+ "resources/exercises", + data: {token: auth.token(), page: page} + }).then(function successCallback(response) { + if(response.data.page >0) { + vm.exercise = vm.exercise.concat(response.data.data); + } else { + vm.exercise = response.data.data; + } + + rms.save("exercise", vm.exercise); + vm.exercise_has_more = (response.data.count + response.data.page * 10) < response.data.all_count; + rms.save('exercise_has_more', vm.exercise_has_more); + rms.save('exercise_page', response.data.page); + + console.log(response.data); + + }, function errorCallback(response) { + }); + } + } + vm.tab = function(index){ vm.currentTab = index; vm.searchText = ""; - if(index==1 && (!vm.resources || vm.resources.length <= 0 )){ - $http.get(config.apiUrl + "resources?token="+auth.token()).then(function(response){ - console.log(response.data); - vm.resources = response.data.data; - }); - } else if(index==2 && (!vm.homeworks || vm.homeworks.length <= 0) ){ - $http.get(config.apiUrl + "resources/homeworks?token="+auth.token()).then(function(response){ - console.log(response.data); - vm.homeworks = response.data.data; - }); - } else if(index==3 && (!vm.exercise || vm.exercise.length <= 0) ){ - $http.get(config.apiUrl + "resources/exercies?token="+auth.token()).then(function(response){ - console.log(response.data); - vm.exercise = response.data.data; - }); + + switch(index){ + //ALL + case 1: + if(vm.resources.length<=0){ + vm.loadResourceData(index,0); + } + break; + //homework + case 2: + if(vm.homeworks.length<=0){ + vm.loadResourceData(index,0); + } + break; + //exercise + case 3: + if(vm.exercise.length<=0){ + vm.loadResourceData(index,0); + } + break; } } vm.tab(1); - vm.sendFile = function(r){ - $location.path("/send_class_list").search({id: r.id}); - } }] );