diff --git a/app/api/mobile/apis/blog_comments.rb b/app/api/mobile/apis/blog_comments.rb index 01fd05c0f..5a064245a 100644 --- a/app/api/mobile/apis/blog_comments.rb +++ b/app/api/mobile/apis/blog_comments.rb @@ -7,8 +7,9 @@ module Mobile desc "get special topic" get ':id' do + user = UserWechat.find_by_openid(params[:openid]).user blog = BlogComment.find params[:id] - present :data, blog, with: Mobile::Entities::BlogComment + present :data, blog, with: Mobile::Entities::BlogComment,user: user present :status, 0 end end diff --git a/app/api/mobile/apis/issues.rb b/app/api/mobile/apis/issues.rb index 1815c85f3..b767bd768 100644 --- a/app/api/mobile/apis/issues.rb +++ b/app/api/mobile/apis/issues.rb @@ -8,8 +8,9 @@ module Mobile desc "get special issuse" get ':id' do + user = UserWechat.find_by_openid(params[:openid]).user issue = Issue.find params[:id] - present :data, issue, with: Mobile::Entities::Issue + present :data, issue, with: Mobile::Entities::Issue,user: user present :status, 0 end end diff --git a/app/api/mobile/apis/journal_for_messages.rb b/app/api/mobile/apis/journal_for_messages.rb index 648924912..15a571a82 100644 --- a/app/api/mobile/apis/journal_for_messages.rb +++ b/app/api/mobile/apis/journal_for_messages.rb @@ -7,8 +7,9 @@ module Mobile desc "get special journal" get ':id' do + user = UserWechat.find_by_openid(params[:openid]).user jour = JournalsForMessage.find params[:id] - present :data, jour, with: Mobile::Entities::Jours + present :data, jour, with: Mobile::Entities::Jours,user: user present :status, 0 end end diff --git a/app/api/mobile/apis/messages.rb b/app/api/mobile/apis/messages.rb index 5e2fb05b7..ae2f9a39c 100644 --- a/app/api/mobile/apis/messages.rb +++ b/app/api/mobile/apis/messages.rb @@ -7,8 +7,9 @@ module Mobile desc "get special topic" get ':id' do + user = UserWechat.find_by_openid(params[:openid]).user message = Message.find params[:id] - present :data, message, with: Mobile::Entities::Message + present :data, message, with: Mobile::Entities::Message,user: user present :status, 0 end end diff --git a/app/api/mobile/apis/newss.rb b/app/api/mobile/apis/newss.rb index 6f15ae2ee..8bdd460cc 100644 --- a/app/api/mobile/apis/newss.rb +++ b/app/api/mobile/apis/newss.rb @@ -7,8 +7,9 @@ module Mobile desc "get special news" get ':id' do + user = UserWechat.find_by_openid(params[:openid]).user news = News.find params[:id] - present :data, news, with: Mobile::Entities::News + present :data, news, with: Mobile::Entities::News,user: user present :status, 0 end end diff --git a/app/api/mobile/apis/whomeworks.rb b/app/api/mobile/apis/whomeworks.rb index 39a6faa68..a88d509a3 100644 --- a/app/api/mobile/apis/whomeworks.rb +++ b/app/api/mobile/apis/whomeworks.rb @@ -7,8 +7,9 @@ module Mobile desc "get one homework" get ':id' do + user = UserWechat.find_by_openid(params[:openid]).user homework = HomeworkCommon.find params[:id] - present :data, homework, with: Mobile::Entities::Whomework + present :data, homework, with: Mobile::Entities::Whomework,user: user present :status, 0 end end diff --git a/app/api/mobile/entities/activity.rb b/app/api/mobile/entities/activity.rb index 945601bd6..59127dedd 100644 --- a/app/api/mobile/entities/activity.rb +++ b/app/api/mobile/entities/activity.rb @@ -131,8 +131,11 @@ module Mobile act_expose :course_project_name #课程/项目名字 act_expose :activity_type_name #课程问答区/项目缺陷等 expose :has_praise , if: lambda { |instance, options| options[:user] } do |instance, options| + has_praise = false current_user = options[:user] - false + obj = PraiseTread.where("praise_tread_object_id=? and praise_tread_object_type=? and user_id=?",instance.act_id,instance.act_type.to_s,current_user.id) + has_praise = obj.empty? ? false : true + has_praise end end end diff --git a/app/api/mobile/entities/blog_comment.rb b/app/api/mobile/entities/blog_comment.rb index ac3fc3d9e..6961823d0 100644 --- a/app/api/mobile/entities/blog_comment.rb +++ b/app/api/mobile/entities/blog_comment.rb @@ -45,6 +45,13 @@ module Mobile c.children end end + expose :has_praise , if: lambda { |instance, options| options[:user] } do |instance, options| + has_praise = false + current_user = options[:user] + obj = PraiseTread.where("praise_tread_object_id=? and praise_tread_object_type=? and user_id=?",instance.id,instance.class.to_s,current_user.id) + has_praise = obj.empty? ? false : true + has_praise + end end end end \ No newline at end of file diff --git a/app/api/mobile/entities/issue.rb b/app/api/mobile/entities/issue.rb index d0bb0fa0d..e64248353 100644 --- a/app/api/mobile/entities/issue.rb +++ b/app/api/mobile/entities/issue.rb @@ -49,6 +49,13 @@ module Mobile f.journals.where("notes is not null and notes != ''") end end + expose :has_praise , if: lambda { |instance, options| options[:user] } do |instance, options| + has_praise = false + current_user = options[:user] + obj = PraiseTread.where("praise_tread_object_id=? and praise_tread_object_type=? and user_id=?",instance.id,instance.class.to_s,current_user.id) + has_praise = obj.empty? ? false : true + has_praise + end end end end \ No newline at end of file diff --git a/app/api/mobile/entities/jours.rb b/app/api/mobile/entities/jours.rb index 9d4d85f7a..87bbd0184 100644 --- a/app/api/mobile/entities/jours.rb +++ b/app/api/mobile/entities/jours.rb @@ -51,6 +51,13 @@ module Mobile f.children end end + expose :has_praise , if: lambda { |instance, options| options[:user] } do |instance, options| + has_praise = false + current_user = options[:user] + obj = PraiseTread.where("praise_tread_object_id=? and praise_tread_object_type=? and user_id=?",instance.id,instance.class.to_s,current_user.id) + has_praise = obj.empty? ? false : true + has_praise + end end end end diff --git a/app/api/mobile/entities/message.rb b/app/api/mobile/entities/message.rb index d182e5965..7a00b5725 100644 --- a/app/api/mobile/entities/message.rb +++ b/app/api/mobile/entities/message.rb @@ -52,6 +52,13 @@ module Mobile c.children end end + expose :has_praise , if: lambda { |instance, options| options[:user] } do |instance, options| + has_praise = false + current_user = options[:user] + obj = PraiseTread.where("praise_tread_object_id=? and praise_tread_object_type=? and user_id=?",instance.id,instance.class.to_s,current_user.id) + has_praise = obj.empty? ? false : true + has_praise + end end end end \ No newline at end of file diff --git a/app/api/mobile/entities/news.rb b/app/api/mobile/entities/news.rb index d1ec9c5c3..85504a280 100644 --- a/app/api/mobile/entities/news.rb +++ b/app/api/mobile/entities/news.rb @@ -73,8 +73,13 @@ module Mobile f.send(:comments) end end - - + expose :has_praise , if: lambda { |instance, options| options[:user] } do |instance, options| + has_praise = false + current_user = options[:user] + obj = PraiseTread.where("praise_tread_object_id=? and praise_tread_object_type=? and user_id=?",instance.id,instance.class.to_s,current_user.id) + has_praise = obj.empty? ? false : true + has_praise + end end end end \ No newline at end of file diff --git a/app/api/mobile/entities/whomework.rb b/app/api/mobile/entities/whomework.rb index b24c50aa2..76b88ec6f 100644 --- a/app/api/mobile/entities/whomework.rb +++ b/app/api/mobile/entities/whomework.rb @@ -67,6 +67,13 @@ module Mobile f.journals_for_messages end end + expose :has_praise , if: lambda { |instance, options| options[:user] } do |instance, options| + has_praise = false + current_user = options[:user] + obj = PraiseTread.where("praise_tread_object_id=? and praise_tread_object_type=? and user_id=?",instance.id,instance.class.to_s,current_user.id) + has_praise = obj.empty? ? false : true + has_praise + end end end end \ No newline at end of file diff --git a/public/assets/wechat/activities.html b/public/assets/wechat/activities.html index 2db18be26..39da65ce4 100644 --- a/public/assets/wechat/activities.html +++ b/public/assets/wechat/activities.html @@ -116,7 +116,7 @@
回复 ({{act.reply_count}})
-
一赞 ({{act.activity_praise_count}})
+
已赞 ({{act.activity_praise_count}})
赞 ({{act.activity_praise_count}})
diff --git a/public/assets/wechat/blog_detail.html b/public/assets/wechat/blog_detail.html index 5c1d6bf22..1fc92eabb 100644 --- a/public/assets/wechat/blog_detail.html +++ b/public/assets/wechat/blog_detail.html @@ -16,7 +16,8 @@
回复 ({{blog.comments_count}})
-
({{blog.blog_praise_count}})
+
已赞 ({{blog.blog_praise_count}})
+
赞 ({{blog.blog_praise_count}})
diff --git a/public/assets/wechat/course_discussion.html b/public/assets/wechat/course_discussion.html index 13ae823c3..2c2c210a9 100644 --- a/public/assets/wechat/course_discussion.html +++ b/public/assets/wechat/course_discussion.html @@ -16,7 +16,8 @@
回复 ({{discussion.replies_count}})
-
({{discussion.message_praise_count}})
+
已赞 ({{discussion.message_praise_count}})
+
赞 ({{discussion.message_praise_count}})
diff --git a/public/assets/wechat/course_notice.html b/public/assets/wechat/course_notice.html index 3881d96f1..eccd91848 100644 --- a/public/assets/wechat/course_notice.html +++ b/public/assets/wechat/course_notice.html @@ -16,7 +16,8 @@
回复 ({{news.comments_count}})
-
({{news.news_praise_count}})
+
已赞 ({{news.news_praise_count}})
+
赞 ({{news.news_praise_count}})
diff --git a/public/assets/wechat/homework_detail.html b/public/assets/wechat/homework_detail.html index 072678ba1..98992da59 100644 --- a/public/assets/wechat/homework_detail.html +++ b/public/assets/wechat/homework_detail.html @@ -18,7 +18,8 @@
回复 ({{homework.whomework_journal_count}})
-
({{homework.whomework_praise_count}})
+
已赞 ({{homework.whomework_praise_count}})
+
赞 ({{homework.whomework_praise_count}})
diff --git a/public/assets/wechat/issue_detail.html b/public/assets/wechat/issue_detail.html index ea3fd06be..0fb443e67 100644 --- a/public/assets/wechat/issue_detail.html +++ b/public/assets/wechat/issue_detail.html @@ -18,7 +18,8 @@
回复 ({{issue.journals_count}})
-
({{issue.issue_praise_count}})
+
已赞 ({{issue.issue_praise_count}})
+
赞 ({{issue.issue_praise_count}})
diff --git a/public/assets/wechat/jour_message_detail.html b/public/assets/wechat/jour_message_detail.html index 857498f0a..893d693c8 100644 --- a/public/assets/wechat/jour_message_detail.html +++ b/public/assets/wechat/jour_message_detail.html @@ -13,7 +13,8 @@
回复 ({{message.reply_count}})
-
({{message.message_praise_count}})
+
已赞 ({{message.message_praise_count}})
+
赞 ({{message.message_praise_count}})
diff --git a/public/assets/wechat/project_discussion.html b/public/assets/wechat/project_discussion.html index d868e0d03..62d6dc728 100644 --- a/public/assets/wechat/project_discussion.html +++ b/public/assets/wechat/project_discussion.html @@ -16,7 +16,8 @@
回复 ({{discussion.replies_count}})
-
({{discussion.message_praise_count}})
+
已赞 ({{discussion.message_praise_count}})
+
赞 ({{discussion.message_praise_count}})
diff --git a/public/javascripts/wechat/app.js b/public/javascripts/wechat/app.js index dc926574d..a31bf8c22 100644 --- a/public/javascripts/wechat/app.js +++ b/public/javascripts/wechat/app.js @@ -135,7 +135,7 @@ app.factory('common', function($http, auth){ var loadCommonData = function(id, type){ return $http({ method: 'GET', - url: apiUrl+ type + "/"+id + url: apiUrl+ type + "/" + id }) }; @@ -155,238 +155,126 @@ app.controller('IssueController', function($scope, $http, $routeParams, auth, co $scope.issue = response.data.data; }, function errorCallback(response) { }); - } + }; loadData($routeParams.id); $scope.addIssueReply = function(data){ - console.log("add issue reply"); + console.log(data.comment); common.addCommonReply($routeParams.id, 'Issue', data, function(){ $scope.formData = {comment: ''}; loadData($routeParams.id); }); }; - - - - }); -app.controller('HomeworkController', function($scope, $http, $routeParams, auth){ +app.controller('HomeworkController', function($scope, $http, $routeParams, auth, common){ $scope.formData = {comment: ''}; var loadData = function(id){ - $http({ - method: 'GET', - url: apiUrl+ "whomeworks/"+id, - }).then(function successCallback(response) { + common.loadCommonData(id, 'whomeworks').then(function successCallback(response) { console.log(response.data); $scope.homework = response.data.data; - }, function errorCallback(response) { }); - } + }; loadData($routeParams.id); - $scope.addHomeworkReply = function(data){ console.log(data.comment); - - if(!data.comment || data.comment.length<=0){ - return; - } - - var userInfo = { - type: "HomeworkCommon", - content: data.comment, - openid: auth.openid(), - }; - - $http({ - method: 'POST', - url: apiUrl+ "new_comment/"+$routeParams.id, - data: userInfo, - }).then(function successCallback(response) { - alert("提交成功"); + common.addCommonReply($routeParams.id, 'HomeworkCommon', data, function(){ $scope.formData = {comment: ''}; loadData($routeParams.id); - }, function errorCallback(response) { }); - } + }; }); -app.controller('CourseNoticeController', function($scope, $http, $routeParams, auth){ +app.controller('CourseNoticeController', function($scope, $http, $routeParams, auth, common){ $scope.formData = {comment: ''}; var loadData = function(id){ - $http({ - method: 'GET', - url: apiUrl+ "newss/"+id, - }).then(function successCallback(response) { + common.loadCommonData(id, 'newss').then(function successCallback(response) { console.log(response.data); $scope.news = response.data.data; - }, function errorCallback(response) { }); - }; + } loadData($routeParams.id); - $scope.addNoticeReply = function(data){ console.log(data.comment); - - if(!data.comment || data.comment.length<=0){ - return; - } - - var userInfo = { - type: "News", - content: data.comment, - openid: auth.openid(), - }; - - $http({ - method: 'POST', - url: apiUrl+ "new_comment/"+$routeParams.id, - data: userInfo, - }).then(function successCallback(response) { - alert("提交成功"); + common.addCommonReply($routeParams.id, 'News', data, function(){ $scope.formData = {comment: ''}; loadData($routeParams.id); - }, function errorCallback(response) { }); } }); -app.controller('CourseDiscussionController', function($scope, $http, $routeParams, auth){ +app.controller('DiscussionController', function($scope, $http, $routeParams, auth, common){ $scope.formData = {comment: ''}; var loadData = function(id){ - $http({ - method: 'GET', - url: apiUrl+ "messages/"+id, - }).then(function successCallback(response) { + common.loadCommonData(id, 'messages').then(function successCallback(response) { console.log(response.data); $scope.discussion = response.data.data; - }, function errorCallback(response) { }); - }; + } loadData($routeParams.id); - $scope.addDiscussionReply = function(data){ console.log(data.comment); - - if(!data.comment || data.comment.length<=0){ - return; - } - - var userInfo = { - type: "Message", - content: data.comment, - openid: auth.openid(), - }; - - $http({ - method: 'POST', - url: apiUrl+ "new_comment/"+$routeParams.id, - data: userInfo, - }).then(function successCallback(response) { - alert("提交成功"); + common.addCommonReply($routeParams.id, 'Message', data, function(){ $scope.formData = {comment: ''}; loadData($routeParams.id); - }, function errorCallback(response) { }); } }); -app.controller('JournalsController', function($scope, $http, $routeParams, auth){ +app.controller('JournalsController', function($scope, $http, $routeParams, auth, common){ $scope.formData = {comment: ''}; var loadData = function(id){ - $http({ - method: 'GET', - url: apiUrl+ "journal_for_messages/"+id, - }).then(function successCallback(response) { + common.loadCommonData(id, 'journal_for_messages').then(function successCallback(response) { console.log(response.data); $scope.message = response.data.data; }, function errorCallback(response) { }); - }; + } loadData($routeParams.id); - $scope.addJournalReply = function(data){ console.log(data.comment); - - if(!data.comment || data.comment.length<=0){ - return; - } - - var userInfo = { - type: "JournalsForMessage", - content: data.comment, - openid: auth.openid(), - }; - - $http({ - method: 'POST', - url: apiUrl+ "new_comment/"+$routeParams.id, - data: userInfo, - }).then(function successCallback(response) { - alert("提交成功"); + common.addCommonReply($routeParams.id, 'JournalsForMessage', data, function(){ $scope.formData = {comment: ''}; loadData($routeParams.id); - }, function errorCallback(response) { }); } }); -app.controller('BlogController', function($scope, $http, $routeParams, auth){ +app.controller('BlogController', function($scope, $http, $routeParams, auth, common){ $scope.formData = {comment: ''}; var loadData = function(id){ - $http({ - method: 'GET', - url: apiUrl+ "blog_comments/"+id, - }).then(function successCallback(response) { + common.loadCommonData(id, 'blog_comments').then(function successCallback(response) { console.log(response.data); $scope.blog = response.data.data; }, function errorCallback(response) { }); - }; + } loadData($routeParams.id); - $scope.addBlogReply = function(data){ console.log(data.comment); - - if(!data.comment || data.comment.length<=0){ - return; - } - - var userInfo = { - type: "BlogComment", - content: data.comment, - openid: auth.openid(), - }; - - $http({ - method: 'POST', - url: apiUrl+ "new_comment/"+$routeParams.id, - data: userInfo, - }).then(function successCallback(response) { - alert("提交成功"); + common.addCommonReply($routeParams.id, 'BlogComment', data, function(){ $scope.formData = {comment: ''}; loadData($routeParams.id); - }, function errorCallback(response) { }); } }); @@ -441,7 +329,7 @@ app.config(['$routeProvider',function ($routeProvider) { }) .when('/project_discussion/:id', { templateUrl: 'project_discussion.html', - controller: 'CourseDiscussionController' + controller: 'DiscussionController' }) .when('/homework/:id', { templateUrl: 'homework_detail.html', @@ -453,7 +341,7 @@ app.config(['$routeProvider',function ($routeProvider) { }) .when('/course_discussion/:id', { templateUrl: 'course_discussion.html', - controller: 'CourseDiscussionController' + controller: 'DiscussionController' }) .when('/journal_for_message/:id', { templateUrl: 'jour_message_detail.html',