From 8f7c6f49b7547181d484522429ec566359b3167a Mon Sep 17 00:00:00 2001 From: cxt Date: Wed, 6 Apr 2016 14:56:09 +0800 Subject: [PATCH 1/3] =?UTF-8?q?api=E7=9A=84=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/api_helper.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/helpers/api_helper.rb b/app/helpers/api_helper.rb index 28a8f74e4..bd7ba8751 100644 --- a/app/helpers/api_helper.rb +++ b/app/helpers/api_helper.rb @@ -412,7 +412,7 @@ module ApiHelper #课程动态的更新 def update_course_activity_api type, id - course_activity = CourseActivity.where("course_act_type=? and course_act_id =?", type.to_s, id).first + course_activity = CourseActivity.where("course_act_type=? and course_act_id =?", type.to_s, id.to_i).first if course_activity course_activity.updated_at = Time.now course_activity.save @@ -420,7 +420,7 @@ module ApiHelper end #首页动态更新 def update_user_activity_api type, id - user_activity = UserActivity.where("act_type=? and act_id =?", type.to_s, id).first + user_activity = UserActivity.where("act_type=? and act_id =?", type.to_s, id.to_i).first if user_activity user_activity.updated_at = Time.now user_activity.save @@ -428,7 +428,7 @@ module ApiHelper end #项目动态更新 def update_forge_activity_api type, id - forge_activity = ForgeActivity.where("forge_act_type=? and forge_act_id=?", type.to_s, id).first + forge_activity = ForgeActivity.where("forge_act_type=? and forge_act_id=?", type.to_s, id.to_i).first if forge_activity forge_activity.updated_at = Time.now forge_activity.save @@ -436,7 +436,7 @@ module ApiHelper end #组织动态更新 def update_org_activity_api type , id - org_activity = OrgActivity.where("org_act_type=? and org_act_id =?", type.to_s, id).first + org_activity = OrgActivity.where("org_act_type=? and org_act_id =?", type.to_s, id.to_i).first if org_activity org_activity.updated_at = Time.now org_activity.save @@ -444,7 +444,7 @@ module ApiHelper end #个人动态更新 def update_principal_activity_api type, id - principal_activity = PrincipalActivity.where("principal_act_type=? and principal_act_id =?", type.to_s, id).first + principal_activity = PrincipalActivity.where("principal_act_type=? and principal_act_id =?", type.to_s, id.to_i).first if principal_activity principal_activity.updated_at = Time.now principal_activity.save From 70c2c9cc9f9137b10f9d61646993f74e86384885 Mon Sep 17 00:00:00 2001 From: guange <8863824@gmail.com> Date: Wed, 6 Apr 2016 15:19:18 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E6=8A=8Aactivities=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E5=AD=98=E8=B5=B7=E6=9D=A5,=E9=98=B2=E6=AD=A2=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E6=97=B6=E9=A1=B5=E9=9D=A2=E5=8F=98=E7=A9=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/javascripts/wechat/app.js | 84 +++++++++++++++++++------------- 1 file changed, 49 insertions(+), 35 deletions(-) diff --git a/public/javascripts/wechat/app.js b/public/javascripts/wechat/app.js index 5a18a2e35..09440b4bf 100644 --- a/public/javascripts/wechat/app.js +++ b/public/javascripts/wechat/app.js @@ -1,41 +1,41 @@ var app = angular.module('wechat', ['ngRoute','ngCookies']); var apiUrl = 'http://wechat.trustie.net/api/v1/'; -var debug = false; //调试标志,如果在本地请置为true +var debug = true; //调试标志,如果在本地请置为true -app.factory('auth', function($http,$routeParams, $cookies){ +app.factory('auth', function($http,$routeParams, $cookies, $q){ var _openid = ''; if(debug===true){ _openid = "oCnvgvz8R7QheXE-R9Kkr39j8Ndg"; } - var getOpenId = function(cb) { + var getOpenId = function() { + var deferred = $q.defer(); if (typeof _openid !== 'undefined' && _openid.length > 0) { - cb(_openid); - return; - } - var code = $routeParams.code; - $http({ - url: '/wechat/get_open_id', - data: {code: code}, - method: 'POST' - }).then(function successCallback(response) { - _openid = response.data.openid; - if(typeof _openid !== 'undefined' && _openid.length>0){ - if(debug !== true){ //如果是生产环境,就存到cookies中 - $cookies.put("openid", _openid); - } - } else { - if(debug!==true){//考虑从cookies中取出 - _openid = $cookies.get('openid'); + deferred.resolve(_openid); + } else { + var code = $routeParams.code; + $http({ + url: '/wechat/get_open_id', + data: {code: code}, + method: 'POST' + }).then(function successCallback(response) { + _openid = response.data.openid; + if(typeof _openid !== 'undefined' && _openid.length>0){ + if(debug !== true){ //如果是生产环境,就存到cookies中 + $cookies.put("openid", _openid); + } + } else { + if(debug!==true){//考虑从cookies中取出 + _openid = $cookies.get('openid'); + } } - } - - cb(_openid); - }, function errorCallback(response) { - cb(null); - }); - + deferred.resolve(_openid); + }, function errorCallback(response) { + deferred.reject(response); + }); + } + return deferred.promise; }; var openid = function(){ return _openid; @@ -43,14 +43,27 @@ app.factory('auth', function($http,$routeParams, $cookies){ return {getOpenId: getOpenId, openid: openid}; }); -app.controller('ActivityController',function($scope, $http, auth){ +app.factory('rms', function(){ + var _saveStorage = {}; + var save = function(key, value){ + _saveStorage[key] = value; + }; + + var get = function(key){ + return _saveStorage[key]; + } + + return {save: save, get: get}; +}); + +app.controller('ActivityController',function($scope, $http, auth, rms){ $scope.repaceUrl = function(url){ return "http://www.trustie.net/" + url; } console.log("ActivityController load"); - $scope.activities = []; + $scope.activities = rms.get("activities") || []; $scope.page = 1; var loadActData = function(page){ @@ -61,17 +74,18 @@ app.controller('ActivityController',function($scope, $http, auth){ data: {openid: auth.openid(), page: page}, }).then(function successCallback(response) { $scope.activities = $scope.activities.concat(response.data.data); + rms.save('activities', $scope.activities); }, function errorCallback(response) { }); } - - auth.getOpenId(function(oid){ - if(!oid){ - alert("获取openid出错"); - } else { + auth.getOpenId().then( + function successCallback(response){ loadActData($scope.page); + }, function errorCallback(response) { + alert("获取openid出错:"+response); } - }); + ); + $scope.loadActData = loadActData; From 42bd2dcfc5f1c0aaa2a4d75cb82dc3dc7f91e71a Mon Sep 17 00:00:00 2001 From: guange <8863824@gmail.com> Date: Wed, 6 Apr 2016 15:23:48 +0800 Subject: [PATCH 3/3] Merge branch 'weixin_guange' of https://git.trustie.net/jacknudt/trustieforge into weixin_guange # Conflicts: # public/javascripts/wechat/app.js --- public/javascripts/wechat/app.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/javascripts/wechat/app.js b/public/javascripts/wechat/app.js index f3c86e966..c0104b358 100644 --- a/public/javascripts/wechat/app.js +++ b/public/javascripts/wechat/app.js @@ -1,6 +1,6 @@ var app = angular.module('wechat', ['ngRoute','ngCookies']); var apiUrl = 'http://wechat.trustie.net/api/v1/'; -var debug = true; //调试标志,如果在本地请置为true +var debug = false; //调试标志,如果在本地请置为true if(debug===true){ apiUrl = 'http://localhost:3000/api/v1/';