添加用户得数统计功能

帖子内的踩顶横排
This commit is contained in:
z9hang 2014-06-13 16:09:43 +08:00
parent 621346268f
commit eae3918074
13 changed files with 208 additions and 73 deletions

View File

@ -9,6 +9,7 @@ class PraiseTreadController < ApplicationController
if request.get? if request.get?
@obj_id = params[:obj_id] @obj_id = params[:obj_id]
@obj_type = params[:obj_type] @obj_type = params[:obj_type]
@horizontal = params[:horizontal]
@obj = find_object_by_type_and_id(@obj_type,@obj_id) @obj = find_object_by_type_and_id(@obj_type,@obj_id)
praise_tread_plus(@obj_type,@obj_id,1) praise_tread_plus(@obj_type,@obj_id,1)
end end
@ -44,6 +45,7 @@ class PraiseTreadController < ApplicationController
if request.get? if request.get?
@obj_id = params[:obj_id] @obj_id = params[:obj_id]
@obj_type = params[:obj_type] @obj_type = params[:obj_type]
@horizontal = params[:horizontal]
@obj = find_object_by_type_and_id(@obj_type,@obj_id) @obj = find_object_by_type_and_id(@obj_type,@obj_id)
praise_tread_plus(@obj_type,@obj_id,0) praise_tread_plus(@obj_type,@obj_id,0)
end end

View File

@ -4,7 +4,7 @@ class PraiseTread < ActiveRecord::Base
belongs_to :praise_tread_object, polymorphic: true belongs_to :praise_tread_object, polymorphic: true
before_save :be_user_score before_save :be_user_score
def find_object_by_type_and_id(type,id) def self.find_object_by_type_and_id(type,id)
@obj = nil @obj = nil
case type case type
when 'User' when 'User'
@ -29,12 +29,12 @@ class PraiseTread < ActiveRecord::Base
def be_user_score def be_user_score
#踩贴吧或讨论区帖子 #踩贴吧或讨论区帖子
if self.new_record? && self.praise_or_tread == 0 && (self.praise_tread_object_type == 'Memo' || self.praise_tread_object_type == 'Message') if self.new_record? && self.praise_or_tread == 0 && (self.praise_tread_object_type == 'Memo' || self.praise_tread_object_type == 'Message')
obj = find_object_by_type_and_id(self.praise_tread_object_type,praise_tread_object_id) obj = PraiseTread.find_object_by_type_and_id(self.praise_tread_object_type,praise_tread_object_id)
target_user = obj.author target_user = obj.author
UserScore.skill(:treaded_by_user, User.current,target_user, { praise_tread_id: self.id }) UserScore.skill(:treaded_by_user, User.current,target_user, { praise_tread_id: self.id })
#顶贴吧或讨论区帖子 #顶贴吧或讨论区帖子
elsif self.new_record? && self.praise_or_tread == 1 && (self.praise_tread_object_type == 'Memo' || self.praise_tread_object_type == 'Message') elsif self.new_record? && self.praise_or_tread == 1 && (self.praise_tread_object_type == 'Memo' || self.praise_tread_object_type == 'Message')
obj = find_object_by_type_and_id(self.praise_tread_object_type,praise_tread_object_id) obj = PraiseTread.find_object_by_type_and_id(self.praise_tread_object_type,praise_tread_object_id)
target_user = obj.author target_user = obj.author
UserScore.skill(:praised_by_user, User.current,target_user,{ praise_tread_id: self.id }) UserScore.skill(:praised_by_user, User.current,target_user,{ praise_tread_id: self.id })
#更新用户等级 #更新用户等级

View File

@ -15,7 +15,7 @@
</div> </div>
<span id="praise_tread" style="float: right"> <span id="praise_tread" style="float: right">
<%= render :partial => "/praise_tread/praise_tread", <%= render :partial => "/praise_tread/praise_tread",
:locals => {:obj => @contest,:show_flag => true,:user_id =>User.current.id}%> :locals => {:obj => @contest,:show_flag => true,:user_id =>User.current.id,:horizontal => false}%>
</span> </span>
</span> </span>
</div> </div>

View File

@ -10,7 +10,7 @@
<% column_content = ( query.inline_columns.map {|column| "#{column_content_new(column, issue)}"}) %> <% column_content = ( query.inline_columns.map {|column| "#{column_content_new(column, issue)}"}) %>
<!-- 在这里添加赞和踩--> <!-- 在这里添加赞和踩-->
<span id="praise_tread" style="float: right"> <%= render :partial => "/praise_tread/praise_tread",:locals => {:obj => issue,:show_flag => true,:user_id =>User.current.id}%> </span> <span id="praise_tread" style="float: right"> <%= render :partial => "/praise_tread/praise_tread",:locals => {:obj => issue,:show_flag => true,:user_id =>User.current.id,:horizontal => false}%> </span>
<% if issue.tracker_id == 1 %> <% if issue.tracker_id == 1 %>
<%= image_tag("/images/task.png", :class => "img-tag-issues") %> <%= image_tag("/images/task.png", :class => "img-tag-issues") %>

View File

@ -33,7 +33,7 @@
<!-- 顶和踩 在这里添加 --> <!-- 顶和踩 在这里添加 -->
<span id="praise_tread" style="float: right"> <span id="praise_tread" style="float: right">
<%= render :partial => "/praise_tread/praise_tread",:locals => {:obj => @issue,:show_flag => true,:user_id =>User.current.id}%> <%= render :partial => "/praise_tread/praise_tread",:locals => {:obj => @issue,:show_flag => true,:user_id =>User.current.id,:horizontal => false}%>
</span> </span>
<p class="author"> <p class="author">

View File

@ -1,6 +1,6 @@
<div class="lz"> <div class="lz">
<!-- 在这里添加赞和踩--> <!-- 在这里添加赞和踩-->
<span id="praise_tread" style="float: right"> <%= render :partial => "/praise_tread/praise_tread",:locals => {:obj => @memo,:show_flag => true,:user_id =>User.current.id}%> </span> <span id="praise_tread" style="float: right"> <%= render :partial => "/praise_tread/praise_tread",:locals => {:obj => @memo,:show_flag => true,:user_id =>User.current.id,:horizontal => true}%> </span>
<div class="lz-left"> <div class="lz-left">
<div><%= link_to image_tag(url_to_avatar(@memo.author), :class => "avatar"), user_path(@memo.author) %></div> <div><%= link_to image_tag(url_to_avatar(@memo.author), :class => "avatar"), user_path(@memo.author) %></div>
<p class="clearfix"><%=link_to @memo.author.name, user_path(@memo.author) %></p> <p class="clearfix"><%=link_to @memo.author.name, user_path(@memo.author) %></p>

View File

@ -61,7 +61,7 @@
<div class="lz"> <div class="lz">
<!-- 在这里添加赞和踩--> <!-- 在这里添加赞和踩-->
<span id="praise_tread" style="float: right"> <%= render :partial => "/praise_tread/praise_tread",:locals => {:obj => @topic,:show_flag => true,:user_id =>User.current.id}%> </span> <span id="praise_tread" style="float: right"> <%= render :partial => "/praise_tread/praise_tread",:locals => {:obj => @topic,:show_flag => true,:user_id =>User.current.id,:horizontal => true}%> </span>
<div class="contextual"> <div class="contextual">
<%= watcher_link(@topic, User.current) %> <%= watcher_link(@topic, User.current) %>
<%= link_to( <%= link_to(

View File

@ -1,57 +1,101 @@
<!-- get_praise_num(obj,1)函数中 1代表返回顶得次数 0返回踩的次数 --> <!-- get_praise_num(obj,1)函数中 1代表返回顶得次数 0返回踩的次数 -->
<% if User.current.logged? %> <% if User.current.logged? %>
<div id="praise_tread_<%= obj.id %>" style="float:right;"> <% if horizontal %>
<!-- 横排 -->
<div id="praise_tread_<%= obj.id %>" style="float:right;">
<% @is_valuate = is_praise_or_tread(obj,user_id)%> <% @is_valuate = is_praise_or_tread(obj,user_id)%>
<% if @is_valuate.size > 0 %> <!-- 评价过 1代表赞 0代表踩 --> <% if @is_valuate.size > 0 %> <!-- 评价过 1代表赞 0代表踩 -->
<% @flag = @is_valuate.first.praise_or_tread %> <% @flag = @is_valuate.first.praise_or_tread %>
<% if @flag == 1 %> <!-- 顶过 --><!-- modified by bai --> <% if @flag == 1 %> <!-- 顶过 --><!-- modified by bai -->
<table style="line-height: 1px"> <table style="line-height: 1px">
<tr> <tr>
<td ><%= image_tag "/images/praise_tread/praise_false.png" , weight:"22px", height:"22px",:title => l(:label_issue_praise_over) %></td> <td ><%= image_tag "/images/praise_tread/praise_false.png" , weight:"22px", height:"22px",:title => l(:label_issue_praise_over) %></td>
</tr> <td align="center"><strong class="font_small_watch"><%= get_praise_num(obj)%></strong></td>
<tr> <td><%= image_tag "/images/praise_tread/tread_false.png",weight:"22px", height:"22px",:title => l(:label_issue_appraise_over) %></td>
<td align="center"><strong class="font_small_watch"><%= get_praise_num(obj)%></strong></td> </tr>
</tr> </table>
<tr>
<td><%= image_tag "/images/praise_tread/tread_false.png",weight:"22px", height:"22px",:title => l(:label_issue_appraise_over) %></td>
</tr>
</table>
<% elsif @flag == 0 %> <!-- 踩过 0-->
<table style="line-height: 1px">
<tr>
<td > <%= image_tag "/images/praise_tread/praise_false.png",weight:"22px", height:"22px", :title => l(:label_issue_appraise_over) %></td>
</tr>
<tr>
<td align="center"><strong class="font_small_watch"><%= get_praise_num(obj)%></strong></td>
</tr>
<tr>
<td><%= image_tag "/images/praise_tread/tread_false.png",weight:"22px", height:"22px",:title => l(:label_issue_tread_over) %> </td>
</tr>
</table>
<% end %>
<% else %> <% elsif @flag == 0 %> <!-- 踩过 0-->
<table style="line-height: 1px">
<tr>
<td > <%= link_to image_tag("/images/praise_tread/praise_true.png",weight:"22px", height:"22px",:title => l(:label_issue_praise)),
:controller=>"praise_tread",:action=>"praise_plus",:remote=>true,:obj_id => obj.id,:obj_type => obj.class%> </td>
</tr>
<tr>
<td align="center"><strong class="font_small_watch"><%= get_praise_num(obj)%></strong></td>
</tr>
<tr>
<td> <%= link_to image_tag("/images/praise_tread/tread_true.png",weight:"22px", height:"22px",:title => l(:label_issue_tread)),:controller=>"praise_tread",
:action=>"tread_plus",:remote=>true,:obj_id => obj.id,:obj_type => obj.class %></td>
</tr>
</table>
<!-- end -->
<% end %>
</div>
<% end %> <table style="line-height: 1px">
<tr>
<td > <%= image_tag "/images/praise_tread/praise_false.png",weight:"22px", height:"22px", :title => l(:label_issue_appraise_over) %></td>
<td align="center"><strong class="font_small_watch"><%= get_praise_num(obj)%></strong></td>
<td><%= image_tag "/images/praise_tread/tread_false.png",weight:"22px", height:"22px",:title => l(:label_issue_tread_over) %> </td>
</tr>
</table>
<% end %>
<% else %>
<table style="line-height: 1px">
<tr>
<td > <%= link_to image_tag("/images/praise_tread/praise_true.png",weight:"22px", height:"22px",:title => l(:label_issue_praise)),
:controller=>"praise_tread",:action=>"praise_plus",:remote=>true,:obj_id => obj.id,:obj_type => obj.class,:horizontal => horizontal %> </td>
<td align="center"><strong class="font_small_watch"><%= get_praise_num(obj)%></strong></td>
<td> <%= link_to image_tag("/images/praise_tread/tread_true.png",weight:"22px", height:"22px",:title => l(:label_issue_tread)),:controller=>"praise_tread",
:action=>"tread_plus",:remote=>true,:obj_id => obj.id,:obj_type => obj.class,:horizontal => horizontal %></td>
</tr>
</table>
<!-- end -->
<% end %>
</div>
<% else %>
<!-- 竖排 -->
<div id="praise_tread_<%= obj.id %>" style="float:right;">
<% @is_valuate = is_praise_or_tread(obj,user_id)%>
<% if @is_valuate.size > 0 %> <!-- 评价过 1代表赞 0代表踩 -->
<% @flag = @is_valuate.first.praise_or_tread %>
<% if @flag == 1 %> <!-- 顶过 --><!-- modified by bai -->
<table style="line-height: 1px">
<tr>
<td ><%= image_tag "/images/praise_tread/praise_false.png" , weight:"22px", height:"22px",:title => l(:label_issue_praise_over) %></td>
</tr>
<tr>
<td align="center"><strong class="font_small_watch"><%= get_praise_num(obj)%></strong></td>
</tr>
<tr>
<td><%= image_tag "/images/praise_tread/tread_false.png",weight:"22px", height:"22px",:title => l(:label_issue_appraise_over) %></td>
</tr>
</table>
<% elsif @flag == 0 %> <!-- 踩过 0-->
<table style="line-height: 1px">
<tr>
<td > <%= image_tag "/images/praise_tread/praise_false.png",weight:"22px", height:"22px", :title => l(:label_issue_appraise_over) %></td>
</tr>
<tr>
<td align="center"><strong class="font_small_watch"><%= get_praise_num(obj)%></strong></td>
</tr>
<tr>
<td><%= image_tag "/images/praise_tread/tread_false.png",weight:"22px", height:"22px",:title => l(:label_issue_tread_over) %> </td>
</tr>
</table>
<% end %>
<% else %>
<table style="line-height: 1px">
<tr>
<td > <%= link_to image_tag("/images/praise_tread/praise_true.png",weight:"22px", height:"22px",:title => l(:label_issue_praise)),
:controller=>"praise_tread",:action=>"praise_plus",:remote=>true,:obj_id => obj.id,:obj_type => obj.class ,:horizontal => horizontal %> </td>
</tr>
<tr>
<td align="center"><strong class="font_small_watch"><%= get_praise_num(obj)%></strong></td>
</tr>
<tr>
<td> <%= link_to image_tag("/images/praise_tread/tread_true.png",weight:"22px", height:"22px",:title => l(:label_issue_tread)),:controller=>"praise_tread",
:action=>"tread_plus",:remote=>true,:obj_id => obj.id,:obj_type => obj.class ,:horizontal => horizontal %></td>
</tr>
</table>
<!-- end -->
<% end %>
</div>
<% end %>
<% end %>

View File

@ -1,3 +1,3 @@
$('#praise_tread').html('<%= j( $('#praise_tread').html('<%= j(
render :partial => "/praise_tread/praise_tread",:locals => {:obj => @obj,:show_flag => false,:user_id => User.current.id} render :partial => "/praise_tread/praise_tread",:locals => {:obj => @obj,:show_flag => false,:user_id => User.current.id,:horizontal=>@horizontal}
)%>'); )%>');

View File

@ -1,4 +1,4 @@
$('#praise_tread_<%= @obj.id %>').html('<%= j( $('#praise_tread_<%= @obj.id %>').html('<%= j(
render :partial => "/praise_tread/praise_tread",:locals => {:obj => @obj,:user_id => User.current.id} render :partial => "/praise_tread/praise_tread",:locals => {:obj => @obj,:user_id => User.current.id,:horizontal => @horizontal}
)%>'); )%>');

View File

@ -1,5 +1,5 @@
$('#praise_tread_<%= @obj.id %>').html('<%= j( $('#praise_tread_<%= @obj.id %>').html('<%= j(
render :partial => "/praise_tread/praise_tread",:locals => {:obj => @obj,:user_id => User.current.id} render :partial => "/praise_tread/praise_tread",:locals => {:obj => @obj,:user_id => User.current.id,:horizontal => @horizontal}
)%>'); )%>');

View File

@ -14,47 +14,136 @@ namespace :user_score do
Message.includes(:author).where("parent_id IS NULL").all.each do |m| Message.includes(:author).where("parent_id IS NULL").all.each do |m|
users[m.author.id] = users[m.author.id].to_i + 2 users[m.author.id] = users[m.author.id].to_i + 2
end end
puts ":post_message calculate Completed. users count: #{users.count}" puts ":post_message calculate Completed. collaboration users count: #{users.count}"
# 对缺陷的留言 # 对缺陷的留言
Journal.includes(:user).all.each do |j| Journal.includes(:user).all.each do |j|
users[j.user.id] = users[j.user.id].to_i + 1 users[j.user.id] = users[j.user.id].to_i + 1
end end
puts ":post_issue calculate Completed. users count: #{users.count}" puts ":post_issue calculate Completed. collaboration users count: #{users.count}"
# 更改一次缺陷状态 # 更改一次缺陷状态
Journal.joins(:details, :user).where("#{JournalDetail.table_name}.prop_key = 'status_id'").each do |j| Journal.joins(:details, :user).where("#{JournalDetail.table_name}.prop_key = 'status_id'").each do |j|
users[j.user.id] = users[j.user.id].to_i + 1 users[j.user.id] = users[j.user.id].to_i + 1
end end
puts ":change_issue_status calculate Completed. users count: #{users.count}" puts ":change_issue_status calculate Completed. collaboration users count: #{users.count}"
# 对留言的回复 # 对留言的回复
JournalsForMessage.includes(:user).where("m_parent_id IS NOT NULL").each do |jfm| JournalsForMessage.includes(:user).where("m_parent_id IS NOT NULL").each do |jfm|
users[jfm.user.id] = users[jfm.user.id].to_i + 1 users[jfm.user.id] = users[jfm.user.id].to_i + 1
end end
puts ":reply_message calculate Completed. users count: #{users.count}" puts ":reply_message calculate Completed. collaboration users count: #{users.count}"
# 对帖子的回复 # 对帖子的回复
Message.includes(:author).where("parent_id IS NOT NULL").each do |m| Message.includes(:author).where("parent_id IS NOT NULL").each do |m|
users[m.author.id] = users[m.author.id].to_i + 1 users[m.author.id] = users[m.author.id].to_i + 1
end end
puts ":reply_posting calculate Completed. users count: #{users.count}" puts ":reply_posting calculate Completed. collaboration users count: #{users.count}"
users.each do |user_id, score| users.each do |user_id, score|
UserScore.find_or_create_by_user_id(user_id).update_attribute(:collaboration, score) UserScore.find_or_create_by_user_id(user_id).update_attribute(:collaboration, score)
end end
puts "=== UserScore#collaboration calculate Completed. users count: #{users.count}" puts "=== UserScore#collaboration calculate Completed. collaboration users count: #{users.count}"
users.clear users.clear
# influence 影响力得分 # influence 影响力得分
# ... #关注
users_influence = {}
Watcher.includes(:watchable).where("watchable_type = 'Principal'").all.each do |w|
users_influence[w.watchable.id] = users_influence[w.watchable.id].to_i + 2
end
puts ":followed_by calculate Completed. influence users count: #{users_influence.count}"
users_influence.each do |user_id, score|
UserScore.find_or_create_by_user_id(user_id).update_attribute(:influence, score)
end
puts "=== UserScore#influence calculate Completed. influence users count: #{users_influence.count}"
# skill 技术得分 # skill 技术得分
# ... # 顶踩帖
users_skill = {}
PraiseTread.where("praise_tread_object_type = 'Memo' || praise_tread_object_type = 'Message'").all.each do |pt|
obj = PraiseTread.find_object_by_type_and_id(pt.praise_tread_object_type, pt.praise_tread_object_id)
if obj.nil?
next
end
target_user = obj.author
level = pt.user.get_level
if pt.praise_or_tread == 0
#踩帖
users_skill[pt.user.id] = users_skill[pt.user.id].to_i - 2 #踩别人帖-2分
if level == 1
users_skill[target_user.id] = users_skill[target_user.id].to_i - 2 #帖子被一级会员踩-2分 add praise_tread
elsif level == 2
users_skill[target_user.id] = users_skill[target_user.id].to_i - 4 #帖子被二级会员踩-4分 add praise_tread
elsif level == 3
users_skill[target_user.id] = users_skill[target_user.id].to_i - 6 #帖子被三级会员踩-6分 add praise_tread
end
elsif pt.praise_or_tread == 1
#顶贴
if level == 1
users_skill[target_user.id] = users_skill[target_user.id].to_i + 4 #帖子被一级会员顶+4分 add praise_tread
elsif level == 2
users_skill[target_user.id] = users_skill[target_user.id].to_i + 6 #帖子被二级会员顶+6分 add praise_tread
elsif level == 3
users_skill[target_user.id] = users_skill[target_user.id].to_i + 8 #帖子被三级会员顶+8分 add praise_tread
end
end
end
puts ":praised_by_user and :treaded_by_user calculate Completed. skill users count: #{users_skill.count}"
users_skill.each do |user_id, score|
UserScore.find_or_create_by_user_id(user_id).update_attribute(:skill, score)
end
puts "=== UserScore#skill calculate Completed. skill users count: #{users_skill.count}"
# active 项目贡献得分 # active 项目贡献得分
# ... users_active = {}
# 提交代码
Changeset.includes(:user).all.each do |changeset|
if changeset.user.nil?
next
end
users_active[changeset.user.id] = users_active[changeset.user.id].to_i + 4
end
puts ":push_code calculate Completed. active users count: #{users_active.count}"
#提交文档
Document.includes(:user).all.each do |document|
if document.user.nil?
next
end
users_active[document.user.id] = users_active[document.user.id].to_i + 4
end
puts ":push_document calculate Completed. active users count: #{users_active.count}"
#提交附件
Attachment.includes(:author).all.each do |attachment|
#if attachment.container_id_changed?
# type = attachment.container_type
# types = %w|Document News Version Project Issue Message WikiPage|
# if types.include?(type)
if attachment.author.nil?
next
end
users_active[attachment.author.id] = users_active[attachment.author.id].to_i + 4
# end
#end
end
puts ":push_file calculate Completed. active users count: #{users_active.count}"
#更新完成度
Journal.joins(:details, :user).where("#{JournalDetail.table_name}.prop_key = 'done_ratio'").each do |j|
users_active[j.user.id] = users_active[j.user.id].to_i + 2
end
puts ":update_issue_ratio calculate Completed. active users count: #{users_active.count}"
#发布缺陷
Issue.includes(:author).all.each do |issue|
users_active[issue.author.id] = users_active[issue.author.id].to_i + 4
end
puts ":post_issue calculate Completed. active users count: #{users_active.count}"
users_active.each do |user_id, score|
UserScore.find_or_create_by_user_id(user_id).update_attribute(:active, score)
end
puts "=== UserScore#active calculate Completed. active users count: #{users_active.count}"
end end
end end

View File

@ -1449,7 +1449,7 @@ div.square {
overflow: hidden; overflow: hidden;
width: .6em; height: .6em; width: .6em; height: .6em;
} }
.contextual {float:right; white-space: nowrap; line-height:1.4em;/*margin-top:5px;*/ padding-left: 10px; font-size:0.9em;} .contextual {float:right; white-space: nowrap; line-height:1.4em;/*margin-top:5px;*/ padding-left: 10px;padding-right: 10px;padding-top: 5px; font-size:0.9em;}
.contextual input, .contextual select {font-size:0.9em;} .contextual input, .contextual select {font-size:0.9em;}
.message .contextual { margin-top: 0; } .message .contextual { margin-top: 0; }