From 3b383dfa65f8c1dad4cee626eebb889e77099aad Mon Sep 17 00:00:00 2001 From: guange <8863824@gmail.com> Date: Mon, 27 Jun 2016 16:03:07 +0800 Subject: [PATCH] =?UTF-8?q?=E8=80=81=E5=B8=88=E8=AF=BE=E7=A8=8B=E7=95=8C?= =?UTF-8?q?=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .access_token | 2 +- Gemfile | 3 +- app/api/mobile/apis/courses.rb | 13 +- app/api/mobile/entities/exercise.rb | 8 ++ app/models/course.rb | 16 +-- app/services/courses_service.rb | 12 ++ public/assets/wechat/class_list.html | 19 ++- public/assets/wechat/myclass.html | 37 ++++- .../wechat/controllers/class_list.js | 7 +- .../javascripts/wechat/controllers/myclass.js | 126 ++++++++++++++---- public/stylesheets/weui/weixin.css | 14 +- 11 files changed, 203 insertions(+), 54 deletions(-) create mode 100644 app/api/mobile/entities/exercise.rb diff --git a/.access_token b/.access_token index ae71675eb..610b08d2e 100644 --- a/.access_token +++ b/.access_token @@ -1 +1 @@ -{"access_token":"_-LoF1vaOEfUwHI2E5iF7IOIyhvTQAhdkyrwp0ISL0q2Nqb8QMcO9K4Z_kNXxporFsN3xJxOdd8EcCPLVxxzqbBm02m9gmGdp_ENBf9K5nHcneKNTpdoIII7B-9FXHRwCYPaADAJFW","expires_in":7200,"got_token_at":1466770839} \ No newline at end of file +{"access_token":"oEEf8ZKAB8Y2G0o_xnTPkPJHKKk8iHkLC-f5ptvQ2nCMj9IpC86ivLD2-p38GfOkuG-HuQp3pWZqhs3NJXUMdPLWsr5k67hPZYuqg4ozLccx0xdLswapj0mn8ovZhK1tKIKiAFAOMO","expires_in":7200,"got_token_at":1467012449} \ No newline at end of file diff --git a/Gemfile b/Gemfile index 86f98629d..334f15853 100644 --- a/Gemfile +++ b/Gemfile @@ -4,14 +4,13 @@ unless RUBY_PLATFORM =~ /w32/ # unix-like only gem 'iconv' gem "rmagick", ">= 2.0.0" + gem 'certified' end gem 'net-ssh', '2.9.1' gem 'jenkins_api_client' gem 'nokogiri' -# gem 'certified' - gem 'wechat',path: 'lib/wechat' gem 'grack', path:'lib/grack' gem 'gitlab', path: 'lib/gitlab-cli' diff --git a/app/api/mobile/apis/courses.rb b/app/api/mobile/apis/courses.rb index 08b4dc98b..42303b63d 100644 --- a/app/api/mobile/apis/courses.rb +++ b/app/api/mobile/apis/courses.rb @@ -16,7 +16,7 @@ module Mobile get do authenticate! cs = CoursesService.new - courses = cs.course_list(params,current_user) + courses = cs.user_courses_list(current_user) present :data, courses, with: Mobile::Entities::Course present :status, 0 end @@ -385,7 +385,16 @@ module Mobile end - + desc '获取测验列表' + params do + requires :token, type:String + end + get ':course_id/exercises' do + authenticate! + exercises = Course.find(params[:course_id]).exercises + present :data,exercises,with:Mobile::Entities::Exercise + present :status,0 + end end end diff --git a/app/api/mobile/entities/exercise.rb b/app/api/mobile/entities/exercise.rb new file mode 100644 index 000000000..3218264fb --- /dev/null +++ b/app/api/mobile/entities/exercise.rb @@ -0,0 +1,8 @@ +module Mobile + module Entities + class Exercise < Grape::Entity + expose :exercise_name + expose :exercise_description + end + end +end diff --git a/app/models/course.rb b/app/models/course.rb index b623f1f5c..a562f91b7 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -94,6 +94,7 @@ class Course < ActiveRecord::Base acts_as_customizable + scope :not_deleted, lambda{where(is_delete: 0)} scope :all_course scope :active, lambda { where(:status => STATUS_ACTIVE) } scope :status, lambda {|arg| where(arg.blank? ? nil : {:status => arg.to_i}) } @@ -459,22 +460,17 @@ class Course < ActiveRecord::Base # 延迟生成邀请码 def invite_code - code = read_attribute[:invite_code] - if !code || code.size < 5 - code = generate_invite_code - end - return code + return generate_invite_code end # 生成邀请码 CODES = %W(2 3 4 5 6 7 8 9 A B C D E F G H J K L N M O P Q R S T U V W X Y Z) def generate_invite_code - code = invite_code - if !invite_code || invite_code.size <5 - self.invite_code = CODES.sample(5).join - return generate_invite_code if Course.where(invite_code: invite_code).present? + code = read_attribute(:invite_code) + if !code || code.size <5 + code = CODES.sample(5).join + return generate_invite_code if Course.where(invite_code: code).present? save! && reload - code = invite_code end code end diff --git a/app/services/courses_service.rb b/app/services/courses_service.rb index 60c053997..dce3e1f18 100644 --- a/app/services/courses_service.rb +++ b/app/services/courses_service.rb @@ -32,6 +32,18 @@ class CoursesService course_list end + + def user_courses_list(current_user) + courses = current_user.courses.not_deleted + courses.inject([]) {|course_list, course| + course_list << {:course => course,:img_url => url_to_avatar(course), + :current_user_is_member => current_user.member_of_course?(course), + :current_user_is_teacher => is_course_teacher(current_user,course), + course_student_num: searchStudent(course).count + } + } + end + #搜索课程 def search_course params,current_user courses_all = Course.all_course diff --git a/public/assets/wechat/class_list.html b/public/assets/wechat/class_list.html index b436a4bf2..a449279f8 100644 --- a/public/assets/wechat/class_list.html +++ b/public/assets/wechat/class_list.html @@ -1,10 +1,21 @@ -
+
+
课程列表
未命名课程
+ + +
\ No newline at end of file diff --git a/public/assets/wechat/myclass.html b/public/assets/wechat/myclass.html index 30a8b9083..dc575dc64 100644 --- a/public/assets/wechat/myclass.html +++ b/public/assets/wechat/myclass.html @@ -2,11 +2,15 @@
{{course.name}}邀请码
-
课堂资源
-
-
+ + +
+ +
+
+
- +
@@ -14,10 +18,13 @@
-
-
{{r.filename}}
+ +
+
{{r.filename}}发送
+

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

-
+
授课老师
@@ -27,6 +34,22 @@
{{student.name}}
+
+ +
+
{{r.homework_name}}发送
+

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

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

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

+
+ + + +
diff --git a/public/javascripts/wechat/controllers/class_list.js b/public/javascripts/wechat/controllers/class_list.js index 73dffc9ec..81e485453 100644 --- a/public/javascripts/wechat/controllers/class_list.js +++ b/public/javascripts/wechat/controllers/class_list.js @@ -3,7 +3,7 @@ */ -app.controller('ClassListController', ['$scope','config','auth','$http', function($scope, config, auth, $http){ +app.controller('ClassListController', ['$scope','config','auth','$http','$location', function($scope, config, auth, $http, $location){ var vm = $scope; vm.courses = []; @@ -14,5 +14,10 @@ app.controller('ClassListController', ['$scope','config','auth','$http', functio } ); + vm.goClass = function(course_id){ + console.log(course_id); + $location.path("/myclass").search({id: course_id}); + } + }]); \ No newline at end of file diff --git a/public/javascripts/wechat/controllers/myclass.js b/public/javascripts/wechat/controllers/myclass.js index b689e0f55..815f6aa54 100644 --- a/public/javascripts/wechat/controllers/myclass.js +++ b/public/javascripts/wechat/controllers/myclass.js @@ -3,52 +3,126 @@ app.controller('MyClassController', ['$scope', 'config','$http', 'auth','$locati var vm = $scope; var courseid = $routeParams.id; + + + var getUsers = function(){ + if(vm.teachers.length<=0){ + $http.get(config.apiUrl + 'courses/teachers?token='+auth.token()+'&course_id='+courseid).then( + function(response) { + console.log(response.data); + vm.teachers = response.data.data; + } + ) + } + + if(vm.students.length<=0){ + $http.get(config.apiUrl + 'courses/students?token='+auth.token()+'&course_id='+courseid).then( + function(response) { + console.log(response.data); + vm.students = response.data.data; + } + ) + } + } + + var getResources = function(){ + if(vm.resources.length<=0){ + $http.post(config.apiUrl + "courses/"+courseid+"/attachments", + {token: auth.token(), name: ''} + ).then(function(response){ + vm.resources = response.data.data; + }); + } + } + + var getHomeworks = function(){ + if(vm.homeworks.length <=0){ + $http.get(config.apiUrl + "courses/homeworks/"+courseid+"?token="+auth.token()).then(function(response){ + vm.homeworks = response.data.data; + console.log(response.data); + }); + } + } + + var getExercises = function(){ + if(vm.exercises.length <=0){ + $http.get(config.apiUrl + "courses/"+courseid+"/exercises?token="+auth.token()).then(function(response){ + vm.exercises = response.data.data; + console.log(response.data); + }); + } + } + + + vm.isTeacher = false; vm.currentTab = 1; vm.tab = function(index){ vm.currentTab = index; - vm.searchText = ''; - console.log(vm.currentTab); - if(index == 2){ - if(vm.students.length<=0){ - $http.get(config.apiUrl + 'courses/students?token='+auth.token()+'&course_id='+courseid).then( - function(response) { - console.log(response.data); - vm.students = response.data.data; - } - ) + vm.searchText = ''; + + vm.showClassMate = false; + vm.showResources = false; + vm.showHomework = false; + vm.showTestcase = false; + + if(vm.isTeacher){ + if(index == 1){ //课件 + getResources(); + vm.showResources = true; + } else if(index==2){ //作业 + getHomeworks(); + vm.showHomework = true; + } else if(index==3){ //小测验 + getExercises(); + vm.showTestcase = true; + } else if(index==4){ //学生管理 + getUsers(); + vm.showClassMate = true; + } + + } else { + if(index == 2){ + getUsers(); + vm.showClassMate = true; + } else if(index==1){ + getResources(); + vm.showResources = true; } } } + + + + vm.course = {}; vm.students = []; vm.teachers = []; vm.resources = []; + vm.homeworks = []; + vm.exercises = []; vm.invite = function(){ $location.path("/invite_code").search({id: courseid}); }; - $http.post(config.apiUrl + "courses/"+courseid+"/attachments", - {token: auth.token(), name: ''} - ).then(function(response){ - vm.resources = response.data.data; - }); - $http.get(config.apiUrl+ 'courses/'+courseid+"?token="+auth.token()).then( - function(response){ + function(response) { console.log(response.data); - vm.course = response.data.data; + vm.course = response.data.data; + resetMenu(vm.course.current_user_is_teacher); + vm.tab(1); } ); - - if(vm.teachers.length<=0){ - $http.get(config.apiUrl + 'courses/teachers?token='+auth.token()+'&course_id='+courseid).then( - function(response) { - console.log(response.data); - vm.teachers = response.data.data; - } - ) + + var resetMenu = function(is_teacher){ + vm.isTeacher = is_teacher; + if(is_teacher){ + vm.menus = ["课件", "作业", "小测验", "学生管理"]; + } else { + vm.menus = ['课堂资源', "我的同学"]; + } + } }]); \ No newline at end of file diff --git a/public/stylesheets/weui/weixin.css b/public/stylesheets/weui/weixin.css index 955a7ab73..3360d81ee 100644 --- a/public/stylesheets/weui/weixin.css +++ b/public/stylesheets/weui/weixin.css @@ -74,7 +74,19 @@ a.underline {text-decoration:underline;} .bg-blue:not(.btn-disabled):active {background-color:#2780c2;} .btn-disabled {background-color:#ccc;} -/*背景色*/ + +/*tab*/ +.tab-wrap {position:relative; line-height:38px; display:flex; font-size:13px; background-color:#fff;} +.tab-wrap a {position:relative; display:block; flex:1;} +.tab-wrap a:first-child:after {display:none;} +.tab-wrap a:after {content:" "; position:absolute; left:0; top:0; width:1px; height:100%; border-left:1px solid #ccc; color:#707070;} +.weixin-tab {text-align:center; border-bottom:1px solid #ccc;} + +/*bottom-tab*/ +.bottom-tab-wrap {position:fixed; width:100%; bottom:0; line-height:38px; display:flex; font-size:13px; background-color:#fff;} +.bottom-tab-wrap a {display:block; flex:1; position:relative;} +.bottom-tab-wrap a:after {content:" "; position:absolute; left:0; top:0; width:1px; height:100%; border-left:1px solid #ccc; color:#707070;} + /*动态样式*/ .post-container {width:100%;}