点赞代码优化等

This commit is contained in:
txz 2016-04-07 09:26:24 +08:00
parent ec47fb1949
commit 8e1473a484
11 changed files with 87 additions and 64 deletions

View File

@ -30,7 +30,7 @@ module Mobile
all_count = activities.count
activities = activities.limit(10).offset(page * 10)
count = activities.count
present :data, activities, with: Mobile::Entities::Activity
present :data, activities, with: Mobile::Entities::Activity,user: user
present :all_count, all_count
present :count, count
present :page, page

View File

@ -130,6 +130,10 @@ module Mobile
act_expose :latest_update #最新更新时间
act_expose :course_project_name #课程/项目名字
act_expose :activity_type_name #课程问答区/项目缺陷等
expose :has_praise , if: lambda { |instance, options| options[:user] } do |instance, options|
current_user = options[:user]
false
end
end
end
end

View File

@ -9,13 +9,14 @@
<div class="post-main">
<div class="post-avatar fl"><img ng-src="{{replaceUrl(act.author.img_url)}}" width="45" height="45" class="border-radius" /></div>
<div class="post-title hidden mb5"><span class="c-grey3 f15 fb">{{act.subject|safeHtml}}</span></div>
<div class="post-title hidden"><a herf="javascript:void(0);" class="mr10">{{act.author.nickname}}</a>to<a herf="javascript:void(0);" class="ml10">{{act.course_project_name}}&nbsp;&nbsp;|&nbsp;&nbsp;{{act.activity_type_name}}</a></div>
<div class="post-title hidden"><a herf="javascript:void(0);" class="mr10">{{act.author.realname}}</a>to<a herf="javascript:void(0);" class="ml10">{{act.course_project_name}}&nbsp;&nbsp;|&nbsp;&nbsp;{{act.activity_type_name}}</a></div>
<div class="cl"></div>
<div class="post-content c-grey2 mt10">
<div class="post-all-content" ng-bind-html="act.description|safeHtml"></div>
<span class="mr15">迟交扣分:{{act.homework_common_detail.late_penalty}}分</span> 匿评开启时间:{{act.homework_common_detail.evaluation_start}}<br />
<span class="mr15">缺评扣分:{{act.homework_common_detail.absence_penalty}}分/作品</span> 匿评关闭时间:{{act.homework_common_detail.evaluation_end}}
</div>
<a>点击展开</a>
<a herf="javascript:void(0);" class="link-blue f13 fl mt5 post-more undis" style="text-decoration:underline">点击展开</a>
<div class="cl"></div>
<span class="c-grey f13 mt10 fl">{{act.latest_update}}</span>
@ -36,7 +37,7 @@
<div class="post-main">
<div class="post-avatar fl"><img ng-src="{{replaceUrl(act.author.img_url)}}" width="45" height="45" class="border-radius" /></div>
<div class="post-title hidden mb5"><span class="c-grey3 f15 fb">{{act.subject|safeHtml}}</span></div>
<div class="post-title hidden"><a herf="javascript:void(0);" class="mr10">{{act.author.nickname}}</a>to<a herf="javascript:void(0);" class="ml10">{{act.course_project_name}}&nbsp;&nbsp;|&nbsp;&nbsp;{{act.activity_type_name}}</a></div>
<div class="post-title hidden"><a herf="javascript:void(0);" class="mr10">{{act.author.realname}}</a>to<a herf="javascript:void(0);" class="ml10">{{act.course_project_name}}&nbsp;&nbsp;|&nbsp;&nbsp;{{act.activity_type_name}}</a></div>
<div class="cl"></div>
<div class="post-content c-grey2 mt10">
<div class="post-all-content" ng-bind-html="act.description|safeHtml"></div>
@ -48,7 +49,8 @@
</div>
<div class="post-interactive">
<div class="post-interactive-column c-grey2"><a href="javascript:void(0);" ng-href="#/course_notice/{{act.act_id}}" class="c-grey">回复 ({{act.reply_count}})</a></div>
<div class="post-interactive-column c-grey2">赞 ({{act.activity_praise_count}})</div>
<div class="post-interactive-column c-grey2" ng-if="{{act.has_praise}}">一赞 ({{act.activity_praise_count}})</div>
<div class="post-interactive-column c-grey2" ng-if="{{!act.has_praise}}">赞 ({{act.activity_praise_count}})</div>
</div>
</div>
</div>
@ -60,12 +62,12 @@
<div class="post-main">
<div class="post-avatar fl"><img ng-src="{{replaceUrl(act.author.img_url)}}" width="45" height="45" class="border-radius" /></div>
<div class="post-title hidden mb5"><span class="c-grey3 f15 fb">{{act.subject|safeHtml}}</span></div>
<div class="post-title fl mb10 hidden"><a herf="javascript:void(0);" class="mr10">{{act.author.nickname}}</a>to<a herf="javascript:void(0);" class="ml10">{{act.course_project_name}}&nbsp;&nbsp;|&nbsp;&nbsp;{{act.activity_type_name}}</a></div>
<div class="post-title fl mb10 hidden"><a herf="javascript:void(0);" class="mr10">{{act.author.realname}}</a>to<a herf="javascript:void(0);" class="ml10">{{act.course_project_name}}&nbsp;&nbsp;|&nbsp;&nbsp;{{act.activity_type_name}}</a></div>
<div class="cl"></div>
<div class="post-content c-grey2 mt10">
<div class="post-all-content" ng-bind-html="act.description|safeHtml"></div>
</div>
<a herf="javascript:void(0);" class="link-blue f13 fl mt5 post-more undis" style="text-decoration:underline;" ng-click="descToggle()">点击展开</a>
<a herf="javascript:void(0);" class="link-blue f13 fl mt5 post-more undis" style="text-decoration:underline;" ng-click="">点击展开</a>
<span class="c-grey f13 mt10 fl">{{act.latest_update}}</span>
<div class="cl"></div>
</div>
@ -83,7 +85,7 @@
<div class="post-wrapper">
<div class="post-main">
<div class="post-avatar fl"><img ng-src="{{replaceUrl(act.author.img_url)}}" width="45" height="45" class="border-radius" /></div>
<div class="post-title hidden mb5"><span class="c-grey3 f13 fb mr10">{{act.author.nickname}}</span>创建了<span class="c-grey3 f13 fb ml10">{{act.course_project_name}}</span></div>
<div class="post-title hidden mb5"><span class="c-grey3 f13 fb mr10">{{act.author.realname}}</span>创建了<span class="c-grey3 f13 fb ml10">{{act.course_project_name}}</span></div>
<div class="post-title hidden"><a herf="javascript:void(0);" class="mr10">{{act.latest_update}}</a></div>
<div class="cl"></div>
</div>
@ -101,7 +103,7 @@
<div class="post-main">
<div class="post-avatar fl"><img ng-src="{{replaceUrl(act.author.img_url)}}" width="45" height="45" class="border-radius" /></div>
<div class="post-title hidden mb5"><span class="c-grey3 f15 fb">{{act.subject|safeHtml}}</span></div>
<div class="post-title hidden"><a herf="javascript:void(0);" class="mr10">{{act.author.nickname}}</a>to<a herf="javascript:void(0);" class="ml10">{{act.course_project_name}}&nbsp;&nbsp;|&nbsp;&nbsp;{{act.activity_type_name}}</a></div>
<div class="post-title hidden"><a herf="javascript:void(0);" class="mr10">{{act.author.realname}}</a>to<a herf="javascript:void(0);" class="ml10">{{act.course_project_name}}&nbsp;&nbsp;|&nbsp;&nbsp;{{act.activity_type_name}}</a></div>
<div class="cl"></div>
<div class="post-content c-grey2 mt10">
<div class="post-all-content" ng-bind-html="act.description|safeHtml"></div>
@ -115,7 +117,8 @@
</div>
<div class="post-interactive">
<div class="post-interactive-column c-grey2"><a href="javascript:void(0);" ng-href="#/issues/{{act.act_id}}" class="c-grey"> 回复 ({{act.reply_count}})</a></div>
<div class="post-interactive-column c-grey2">赞 ({{act.activity_praise_count}})</div>
<div class="post-interactive-column c-grey2" ng-if="!act.has_praise" ng-click="addPraise(act);">一赞 ({{act.activity_praise_count}})</div>
<div class="post-interactive-column c-grey2" ng-if="act.has_praise">赞 ({{act.activity_praise_count}})</div>
</div>
</div>
</div>
@ -128,7 +131,7 @@
<div class="post-main">
<div class="post-avatar fl"><img ng-src="{{replaceUrl(act.author.img_url)}}" width="45" height="45" class="border-radius" /></div>
<div class="post-title hidden mb5"><span class="c-grey3 f15 fb">{{act.subject|safeHtml}}</span></div>
<div class="post-title hidden"><a herf="javascript:void(0);" class="mr10">{{act.author.nickname}}</a>to<a herf="javascript:void(0);" class="ml10">{{act.course_project_name}}&nbsp;&nbsp;|&nbsp;&nbsp;{{act.activity_type_name}}</a></div>
<div class="post-title hidden"><a herf="javascript:void(0);" class="mr10">{{act.author.realname}}</a>to<a herf="javascript:void(0);" class="ml10">{{act.course_project_name}}&nbsp;&nbsp;|&nbsp;&nbsp;{{act.activity_type_name}}</a></div>
<div class="cl"></div>
<div class="post-content c-grey2 mt10">
<div class="post-all-content" ng-bind-html="act.description|safeHtml"></div>
@ -153,7 +156,7 @@
<div class="post-wrapper">
<div class="post-main">
<div class="post-avatar fl"><img ng-src="{{replaceUrl(act.author.img_url)}}" width="45" height="45" class="border-radius" /></div>
<div class="post-title hidden mb5"><span class="c-grey3 f15 fb">{{act.author.nickname}}</span>创建了<span class="c-grey3 f15 fb">{{act.course_project_name}}</span></div>
<div class="post-title hidden mb5"><span class="c-grey3 f15 fb">{{act.author.realname}}</span>创建了<span class="c-grey3 f15 fb">{{act.course_project_name}}</span></div>
<div class="post-title hidden"><a herf="javascript:void(0);" class="mr10">{{act.latest_update}}</a></div>
<div class="cl"></div>
</div>
@ -166,7 +169,7 @@
<div class="post-wrapper">
<div class="post-main">
<div class="post-avatar fl"><img ng-src="{{replaceUrl(act.author.img_url)}}" width="45" height="45" class="border-radius" /></div>
<div class="post-title mb5 hidden"><a herf="javascript:void(0);" class="mr10">{{act.author.nickname}}</a> <span style="vertical-align:top;">给您留言了</span></div>
<div class="post-title mb5 hidden"><a herf="javascript:void(0);" class="mr10">{{act.author.realname}}</a> <span style="vertical-align:top;">给您留言了</span></div>
<div class="post-title hidden">{{act.latest_update}}</div>
<div class="cl"></div>
<div class="post-content c-grey2 mt10">
@ -189,7 +192,7 @@
<div class="post-main">
<div class="post-avatar fl"><img ng-src="{{replaceUrl(act.author.img_url)}}" width="45" height="45" class="border-radius" /></div>
<div class="post-title hidden mb5"><span class="c-grey3 f15 fb">{{act.subject|safeHtml}}</span></div>
<div class="post-title hidden"><a herf="javascript:void(0);" class="mr10">{{act.author.nickname}}</a>发表博客</div>
<div class="post-title hidden"><a herf="javascript:void(0);" class="mr10">{{act.author.realname}}</a>发表博客</div>
<div class="cl"></div>
<div class="post-content c-grey2 mt10">
<div class="post-all-content" ng-bind-html="act.description|safeHtml"></div>

View File

@ -5,7 +5,7 @@
<div class="post-main">
<div class="post-avatar fl"><img ng-src="{{blog.user.img_url}}" width="45" height="45" class="border-radius" /></div>
<div class="post-title hidden mb5"><span class="c-grey3 f15 fb">{{blog.title}}</span></div>
<div class="post-title hidden"><a herf="javascript:void(0);" class="mr10">{{blog.user.nickname}}</a>发表博客</div>
<div class="post-title hidden"><a herf="javascript:void(0);" class="mr10">{{blog.user.realname}}</a>发表博客</div>
<div class="cl"></div>
<div class="post-content" style="height:auto;">
<div class="post-all-content c-grey2 mt10">{{blog.content}}<br /></div>

View File

@ -5,7 +5,7 @@
<div class="post-main">
<div class="post-avatar fl"><img ng-src="{{discussion.user.img_url}}" width="45" height="45" class="border-radius" /></div>
<div class="post-title hidden mb5"><span class="c-grey3 f15 fb">{{discussion.subject}}</span></div>
<div class="post-title hidden"><a herf="javascript:void(0);" class="mr10">{{discussion.user.nickname}}</a>to<a herf="javascript:void(0);" class="ml10">{{discussion.course_project_name}}&nbsp;&nbsp;|&nbsp;&nbsp;课程问答区</a></div>
<div class="post-title hidden"><a herf="javascript:void(0);" class="mr10">{{discussion.user.realname}}</a>to<a herf="javascript:void(0);" class="ml10">{{discussion.course_project_name}}&nbsp;&nbsp;|&nbsp;&nbsp;课程问答区</a></div>
<div class="cl"></div>
<div class="post-content c-grey2 mt10" style="height:auto;">
<div class="post-all-content" ng-bind-html="discussion.content|safeHtml"></div>

View File

@ -5,7 +5,7 @@
<div class="post-main">
<div class="post-avatar fl"><img ng-src="{{news.author.img_url}}" width="45" height="45" class="border-radius" /></div>
<div class="post-title hidden mb5"><span class="c-grey3 f15 fb">{{news.title}}</span></div>
<div class="post-title hidden"><a herf="javascript:void(0);" class="mr10">{{news.author.nickname}}</a>to<a herf="javascript:void(0);" class="ml10">{{news.course_name}}&nbsp;&nbsp;|&nbsp;&nbsp;课程通知</a></div>
<div class="post-title hidden"><a herf="javascript:void(0);" class="mr10">{{news.author.realname}}</a>to<a herf="javascript:void(0);" class="ml10">{{news.course_name}}&nbsp;&nbsp;|&nbsp;&nbsp;课程通知</a></div>
<div class="cl"></div>
<div class="post-content c-grey2 mt10" style="height:auto;">
<div class="post-all-content" ng-bind-html="news.description|safeHtml"></div>

View File

@ -5,7 +5,7 @@
<div class="post-main">
<div class="post-avatar fl"><img ng-src="{{homework.author.img_url}}" width="45" height="45" class="border-radius" /></div>
<div class="post-title hidden mb5"><span class="c-grey3 f15 fb">{{homework.name}}</span></div>
<div class="post-title hidden"><a herf="javascript:void(0);" class="mr10">{{homework.author.nickname}}</a>to<a herf="javascript:void(0);" class="ml10">{{homework.course_name}}&nbsp;&nbsp;|&nbsp;&nbsp;课程作业</a></div>
<div class="post-title hidden"><a herf="javascript:void(0);" class="mr10">{{homework.author.realname}}</a>to<a herf="javascript:void(0);" class="ml10">{{homework.course_name}}&nbsp;&nbsp;|&nbsp;&nbsp;课程作业</a></div>
<div class="cl"></div>
<div class="post-content c-grey2 mt10" style="height:auto;">
<div class="post-all-content" ng-bind-html="homework.description|safeHtml"></div>

View File

@ -5,7 +5,7 @@
<div class="post-main">
<div class="post-avatar fl"><img ng-src="{{issue.author.img_url}}" width="45" height="45" class="border-radius" /></div>
<div class="post-title hidden mb5"><span class="c-grey3 f15 fb">{{issue.subject}}</span></div>
<div class="post-title hidden"><a herf="javascript:void(0);" class="mr10">{{issue.author.nickname}}</a>to<span class="ml10">{{issue.project_name}}&nbsp;&nbsp;|&nbsp;&nbsp;项目缺陷</span></div>
<div class="post-title hidden"><a herf="javascript:void(0);" class="mr10">{{issue.author.realname}}</a>to<span class="ml10">{{issue.project_name}}&nbsp;&nbsp;|&nbsp;&nbsp;项目缺陷</span></div>
<div class="cl"></div>
<div class="post-content" style="height:auto;">
<div class="post-all-content c-grey2 mt10" ng-bind-html="issue.description|safeHtml"></div>

View File

@ -3,7 +3,7 @@
<div class="post-wrapper">
<div class="post-main">
<div class="post-avatar fl"><img ng-src="{{message.user.img_url}}" width="45" height="45" class="border-radius" /></div>
<div class="post-title mb5 hidden"><a herf="javascript:void(0);" class="mr10">{{message.user.nickname}}</a><span style="vertical-align:top;">给您留言了</span><br /></div>
<div class="post-title mb5 hidden"><a herf="javascript:void(0);" class="mr10">{{message.user.realname}}</a><span style="vertical-align:top;">给您留言了</span><br /></div>
<div class="post-title hidden">{{message.created_on}}</div>
<div class="cl"></div>
<div class="post-content c-grey2 mt10" style="height:auto;">

View File

@ -5,7 +5,7 @@
<div class="post-main">
<div class="post-avatar fl"><img ng-src="{{discussion.user.img_url}}" width="45" height="45" class="border-radius" /></div>
<div class="post-title hidden mb5"><span class="c-grey3 f15 fb">{{discussion.subject}}</span></div>
<div class="post-title hidden"><a herf="javascript:void(0);" class="mr10">{{discussion.user.nickname}}</a>to<a herf="javascript:void(0);" class="ml10">{{discussion.course_project_name}}&nbsp;&nbsp;|&nbsp;&nbsp;项目讨论区</a></div>
<div class="post-title hidden"><a herf="javascript:void(0);" class="mr10">{{discussion.user.realname}}</a>to<a herf="javascript:void(0);" class="ml10">{{discussion.course_project_name}}&nbsp;&nbsp;|&nbsp;&nbsp;项目讨论区</a></div>
<div class="cl"></div>
<div class="post-content c-grey2 mt10" style="height:auto;">
<div class="post-all-content" ng-bind-html="discussion.content|safeHtml"></div>

View File

@ -10,7 +10,7 @@ app.factory('auth', function($http,$routeParams, $cookies, $q){
var _openid = '';
if(debug===true){
_openid = "2";
_openid = "1";
}
var getOpenId = function() {
@ -67,7 +67,6 @@ app.controller('ActivityController',function($scope, $http, auth, rms){
}
console.log("ActivityController load");
$scope.activities = rms.get("activities") || [];
$scope.page = 1;
@ -91,47 +90,20 @@ app.controller('ActivityController',function($scope, $http, auth, rms){
}
);
$scope.addPraise = function(act){
act.activity_praise_count += 1;
act.has_praise = true;
//$http
}
$scope.loadActData = loadActData;
var descToggle = function(){
$(".post-all-content").each(function(){
var postHeight = $(this).height();
if (postHeight > 90){
$(this).parent().next().css("display","block");
$(this).parent().next().toggle(function(){
$(this).text("点击隐藏");
$(this).prev().css("height",postHeight);
},function(){
$(this).text("点击展开");
$(this).prev().css("height",90);
});
}
});
}
$scope.descToggle = descToggle;
});
app.controller('IssueController', function($scope, $http, $routeParams, auth){
$scope.formData = {comment: ''};
var loadData = function(id){
$http({
method: 'GET',
url: apiUrl+ "issues/"+id,
}).then(function successCallback(response) {
console.log(response.data);
$scope.issue = response.data.data;
}, function errorCallback(response) {
});
}
loadData($routeParams.id);
$scope.addIssueReply = function(data){
app.factory('common', function($http, auth){
var addCommonReply = function(id, type, data, cb){
console.log(data.comment);
if(!data.comment || data.comment.length<=0){
@ -139,22 +111,66 @@ app.controller('IssueController', function($scope, $http, $routeParams, auth){
}
var userInfo = {
type: "Issue",
type: type,
content: data.comment,
openid: auth.openid(),
openid: auth.openid()
};
$http({
method: 'POST',
url: apiUrl+ "new_comment/"+$routeParams.id,
data: userInfo,
url: apiUrl+ "new_comment/"+id,
data: userInfo
}).then(function successCallback(response) {
alert("提交成功");
$scope.formData = {comment: ''};
loadData($routeParams.id);
if(typeof cb === 'function'){
cb();
}
}, function errorCallback(response) {
});
};
var loadCommonData = function(id, type){
return $http({
method: 'GET',
url: apiUrl+ type + "/"+id
})
};
return {addCommonReply: addCommonReply, loadCommonData: loadCommonData};
});
app.controller('IssueController', function($scope, $http, $routeParams, auth, common){
$scope.formData = {comment: ''};
var loadData = function(id){
common.loadCommonData(id, 'issues').then(function successCallback(response) {
console.log(response.data);
$scope.issue = response.data.data;
}, function errorCallback(response) {
});
}
loadData($routeParams.id);
$scope.addIssueReply = function(data){
console.log("add issue reply");
common.addCommonReply($routeParams.id, 'Issue', data, function(){
$scope.formData = {comment: ''};
loadData($routeParams.id);
});
};
});
app.controller('HomeworkController', function($scope, $http, $routeParams, auth){