From 52d4d36097da17d2ea3decd65921b4861f4238ba Mon Sep 17 00:00:00 2001
From: guange <8863824@gmail.com>
Date: Fri, 24 Jun 2016 09:01:12 +0800
Subject: [PATCH] =?UTF-8?q?=E9=82=80=E8=AF=B7=E7=A0=81=E9=A1=B5=E9=9D=A2?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.gitignore | 1 +
Gemfile | 2 +-
app/api/mobile/apis/courses.rb | 1 +
app/api/mobile/entities/course.rb | 1 +
app/controllers/wechats_controller.rb | 7 ++++
app/views/wechats/user_activities.html.erb | 4 ++
public/assets/wechat/invite_code.html | 15 +++++++
public/assets/wechat/myclass.html | 17 +++++---
public/javascripts/wechat/app.js | 2 +-
.../wechat/controllers/invite_code.js | 18 +++++++++
.../javascripts/wechat/controllers/myclass.js | 40 ++++++++++++++++++-
public/javascripts/wechat/others/routes.js | 1 +
12 files changed, 99 insertions(+), 10 deletions(-)
create mode 100644 public/assets/wechat/invite_code.html
create mode 100644 public/javascripts/wechat/controllers/invite_code.js
diff --git a/.gitignore b/.gitignore
index ba7890841..dbc349c80 100644
--- a/.gitignore
+++ b/.gitignore
@@ -34,3 +34,4 @@ vendor/cache
/config/initializers/gitlab_config.rb
1234567
public/javascripts/wechat/node_modules/
+.ruby-version
diff --git a/Gemfile b/Gemfile
index d392c6561..a8131fb3f 100644
--- a/Gemfile
+++ b/Gemfile
@@ -81,7 +81,7 @@ group :assets do
gem 'coffee-rails', '~> 3.2.1'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
- gem 'therubyracer', :platforms => :ruby
+ # gem 'therubyracer', :platforms => :ruby
gem 'uglifier', '>= 1.0.3'
end
diff --git a/app/api/mobile/apis/courses.rb b/app/api/mobile/apis/courses.rb
index de2e48c8e..58d4a4f8c 100644
--- a/app/api/mobile/apis/courses.rb
+++ b/app/api/mobile/apis/courses.rb
@@ -196,6 +196,7 @@ module Mobile
end
route_param :id do
get do
+ authenticate!
cs = CoursesService.new
course = cs.show_course(params,(current_user.nil? ? User.find(2):current_user))
#course = Course.find(params[:id])
diff --git a/app/api/mobile/entities/course.rb b/app/api/mobile/entities/course.rb
index 50812b349..fc5c95ef5 100644
--- a/app/api/mobile/entities/course.rb
+++ b/app/api/mobile/entities/course.rb
@@ -45,6 +45,7 @@ module Mobile
course_expose :tea_id
course_expose :term
course_expose :time
+ course_expose :invite_code
course_expose :updated_at
course_expose :course_student_num
expose :teacher, using: Mobile::Entities::User do |c, opt|
diff --git a/app/controllers/wechats_controller.rb b/app/controllers/wechats_controller.rb
index d6ab11f92..75a8bac92 100644
--- a/app/controllers/wechats_controller.rb
+++ b/app/controllers/wechats_controller.rb
@@ -260,7 +260,14 @@ class WechatsController < ActionController::Base
unless open_id
render 'wechats/open_wechat', layout: nil and return
end
+ if params[:state] == 'myclass'
+ @course_id = params[:id];
+ end
+
session[:wechat_openid] = open_id
+ if params[:code]
+ redirect_to "/wechat/user_activities##{@path}?id=#{params[:id]}" and return
+ end
render 'wechats/user_activities', layout: nil
end
diff --git a/app/views/wechats/user_activities.html.erb b/app/views/wechats/user_activities.html.erb
index b5bd82fc5..2b4ebc703 100644
--- a/app/views/wechats/user_activities.html.erb
+++ b/app/views/wechats/user_activities.html.erb
@@ -16,6 +16,9 @@
window.g_debug = false; //调试标志,如果在本地请置为true
window.apiUrl = '/api/v1/';
window.g_redirect_path = '<%= @path %>';
+ <% if @course_id %>
+ window.g_courseid = <%= @course_id %>;
+ <% end %>
@@ -34,6 +37,7 @@
+
diff --git a/public/assets/wechat/invite_code.html b/public/assets/wechat/invite_code.html
new file mode 100644
index 000000000..116dad8da
--- /dev/null
+++ b/public/assets/wechat/invite_code.html
@@ -0,0 +1,15 @@
+
+
+
+
{{course.name}}
+
+
邀请码:{{course.invite_code}}
+
+
+
+
分享邀请码
+
1.将此页面分享给好友,邀请好友加入班级
+ 2.通过微信扫一扫加入班级
+ 3.输入邀请码加入班级
+
+
\ No newline at end of file
diff --git a/public/assets/wechat/myclass.html b/public/assets/wechat/myclass.html
index 25d29008a..f12364130 100644
--- a/public/assets/wechat/myclass.html
+++ b/public/assets/wechat/myclass.html
@@ -1,5 +1,6 @@
-
分布式计算环境A班邀请码
+
+
{{course.name}}邀请码
@@ -10,7 +11,7 @@
@@ -23,10 +24,14 @@
授课老师
-
jacknudt
+
+
+
{{teacher.realname}}教辅
+
我的同学
-
jingquan教辅
-
yuanke
-
sasameimei
+
+
{{student.realname}}
+
+
diff --git a/public/javascripts/wechat/app.js b/public/javascripts/wechat/app.js
index ea2bdf318..00d6bf3bc 100644
--- a/public/javascripts/wechat/app.js
+++ b/public/javascripts/wechat/app.js
@@ -9,7 +9,7 @@ app.constant('config', {
app.run(['$rootScope', 'auth', '$location', '$routeParams', function($rootScope, auth, $location, $routeParams){
- if(g_redirect_path && g_redirect_path.length>0){
+ if(g_redirect_path && g_redirect_path.length>1){
$location.path(g_redirect_path);
g_redirect_path = null;
}
diff --git a/public/javascripts/wechat/controllers/invite_code.js b/public/javascripts/wechat/controllers/invite_code.js
new file mode 100644
index 000000000..b21653b1e
--- /dev/null
+++ b/public/javascripts/wechat/controllers/invite_code.js
@@ -0,0 +1,18 @@
+/**
+ * Created by guange on 16/6/22.
+ */
+
+
+app.controller('InviteCodeController', ['$scope','$http', '$routeParams','config','auth', function($scope, $http, $routeParams, config, auth){
+ var vm = $scope;
+
+ vm.course = {};
+ var courseid = $routeParams.id;
+ $http.get(config.apiUrl+ 'courses/'+courseid+"?token="+auth.token()).then(
+ function(response){
+ console.log(response.data);
+ vm.course = response.data.data;
+ }
+ );
+
+}]);
diff --git a/public/javascripts/wechat/controllers/myclass.js b/public/javascripts/wechat/controllers/myclass.js
index cb5cf9037..bf864ab88 100644
--- a/public/javascripts/wechat/controllers/myclass.js
+++ b/public/javascripts/wechat/controllers/myclass.js
@@ -1,11 +1,47 @@
-app.controller('MyClassController', ['$scope', function($scope){
+app.controller('MyClassController', ['$scope', 'config','$http', 'auth','$location','$routeParams', function($scope, config, $http, auth, $location, $routeParams){
var vm = $scope;
+ var courseid = $routeParams.id;
vm.currentTab = 1;
vm.tab = function(index){
vm.currentTab = index;
- console.log(vm.currentTab);
+ 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.course = {};
+ vm.students = [];
+ vm.teachers = [];
+
+ vm.invite = function(){
+ $location.path("/invite_code").search({id: courseid});
+ };
+
+ $http.get(config.apiUrl+ 'courses/'+courseid+"?token="+auth.token()).then(
+ function(response){
+ console.log(response.data);
+ vm.course = response.data.data;
+ }
+ );
+
+
+ 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;
+ }
+ )
}
}]);
\ No newline at end of file
diff --git a/public/javascripts/wechat/others/routes.js b/public/javascripts/wechat/others/routes.js
index 7fa5e6d74..3fa7ca6df 100644
--- a/public/javascripts/wechat/others/routes.js
+++ b/public/javascripts/wechat/others/routes.js
@@ -32,6 +32,7 @@ app.config(['$routeProvider',"$httpProvider", "$locationProvider",'config', func
.when('/blog_comment/:id', makeRoute('blog_detail.html', 'BlogController'))
.when('/add_class', makeRoute('add_class.html', 'AddClassController'))
.when('/myclass', makeRoute('myclass.html', 'MyClassController'))
+ .when('/invite_code', makeRoute('invite_code.html', 'InviteCodeController'))
.otherwise({
redirectTo: '/activites'
});