diff --git a/app/controllers/praise_tread_controller.rb b/app/controllers/praise_tread_controller.rb index 53c74519b..97cf3cdac 100644 --- a/app/controllers/praise_tread_controller.rb +++ b/app/controllers/praise_tread_controller.rb @@ -9,6 +9,7 @@ class PraiseTreadController < ApplicationController if request.get? @obj_id = params[:obj_id] @obj_type = params[:obj_type] + @horizontal = params[:horizontal] @obj = find_object_by_type_and_id(@obj_type,@obj_id) praise_tread_plus(@obj_type,@obj_id,1) end @@ -44,6 +45,7 @@ class PraiseTreadController < ApplicationController if request.get? @obj_id = params[:obj_id] @obj_type = params[:obj_type] + @horizontal = params[:horizontal] @obj = find_object_by_type_and_id(@obj_type,@obj_id) praise_tread_plus(@obj_type,@obj_id,0) end diff --git a/app/models/praise_tread.rb b/app/models/praise_tread.rb index 577391ae9..11d68157b 100644 --- a/app/models/praise_tread.rb +++ b/app/models/praise_tread.rb @@ -4,7 +4,7 @@ class PraiseTread < ActiveRecord::Base belongs_to :praise_tread_object, polymorphic: true 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 case type when 'User' @@ -29,12 +29,12 @@ class PraiseTread < ActiveRecord::Base 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') - 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 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') - 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 UserScore.skill(:praised_by_user, User.current,target_user,{ praise_tread_id: self.id }) #更新用户等级 diff --git a/app/views/contests/show_contest.html.erb b/app/views/contests/show_contest.html.erb index 67414b0c8..c379bc668 100644 --- a/app/views/contests/show_contest.html.erb +++ b/app/views/contests/show_contest.html.erb @@ -15,7 +15,7 @@ <%= 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}%> diff --git a/app/views/issues/_list.html.erb b/app/views/issues/_list.html.erb index 2b17b4fb1..dd3487258 100644 --- a/app/views/issues/_list.html.erb +++ b/app/views/issues/_list.html.erb @@ -10,7 +10,7 @@ <% column_content = ( query.inline_columns.map {|column| "#{column_content_new(column, issue)}"}) %> - <%= 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}%> <% if issue.tracker_id == 1 %> <%= image_tag("/images/task.png", :class => "img-tag-issues") %> diff --git a/app/views/issues/show.html.erb b/app/views/issues/show.html.erb index d261957c6..8e6ad803c 100644 --- a/app/views/issues/show.html.erb +++ b/app/views/issues/show.html.erb @@ -33,7 +33,7 @@ - <%= 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}%>

diff --git a/app/views/memos/show.html.erb b/app/views/memos/show.html.erb index 06bdb5bf3..5ffcedacc 100644 --- a/app/views/memos/show.html.erb +++ b/app/views/memos/show.html.erb @@ -1,6 +1,6 @@

- <%= render :partial => "/praise_tread/praise_tread",:locals => {:obj => @memo,:show_flag => true,:user_id =>User.current.id}%> + <%= render :partial => "/praise_tread/praise_tread",:locals => {:obj => @memo,:show_flag => true,:user_id =>User.current.id,:horizontal => true}%>
<%= link_to image_tag(url_to_avatar(@memo.author), :class => "avatar"), user_path(@memo.author) %>

<%=link_to @memo.author.name, user_path(@memo.author) %>

diff --git a/app/views/messages/show.html.erb b/app/views/messages/show.html.erb index 92b62cb60..aeae4c7ab 100644 --- a/app/views/messages/show.html.erb +++ b/app/views/messages/show.html.erb @@ -61,7 +61,7 @@
- <%= render :partial => "/praise_tread/praise_tread",:locals => {:obj => @topic,:show_flag => true,:user_id =>User.current.id}%> + <%= render :partial => "/praise_tread/praise_tread",:locals => {:obj => @topic,:show_flag => true,:user_id =>User.current.id,:horizontal => true}%>
<%= watcher_link(@topic, User.current) %> <%= link_to( diff --git a/app/views/praise_tread/_praise_tread.html.erb b/app/views/praise_tread/_praise_tread.html.erb index 5fee2a593..8d2545f91 100644 --- a/app/views/praise_tread/_praise_tread.html.erb +++ b/app/views/praise_tread/_praise_tread.html.erb @@ -1,57 +1,101 @@ <% if User.current.logged? %> -
+ <% if horizontal %> + +
- <% @is_valuate = is_praise_or_tread(obj,user_id)%> - <% if @is_valuate.size > 0 %> - <% @flag = @is_valuate.first.praise_or_tread %> - <% if @flag == 1 %> - - - - - - - - - - - -
<%= image_tag "/images/praise_tread/praise_false.png" , weight:"22px", height:"22px",:title => l(:label_issue_praise_over) %>
<%= get_praise_num(obj)%>
<%= image_tag "/images/praise_tread/tread_false.png",weight:"22px", height:"22px",:title => l(:label_issue_appraise_over) %>
- - <% elsif @flag == 0 %> - - - - - - - - - - - - -
<%= image_tag "/images/praise_tread/praise_false.png",weight:"22px", height:"22px", :title => l(:label_issue_appraise_over) %>
<%= get_praise_num(obj)%>
<%= image_tag "/images/praise_tread/tread_false.png",weight:"22px", height:"22px",:title => l(:label_issue_tread_over) %>
- <% end %> + <% @is_valuate = is_praise_or_tread(obj,user_id)%> + <% if @is_valuate.size > 0 %> + <% @flag = @is_valuate.first.praise_or_tread %> + <% if @flag == 1 %> + + + + + + +
<%= image_tag "/images/praise_tread/praise_false.png" , weight:"22px", height:"22px",:title => l(:label_issue_praise_over) %><%= get_praise_num(obj)%><%= image_tag "/images/praise_tread/tread_false.png",weight:"22px", height:"22px",:title => l(:label_issue_appraise_over) %>
- <% else %> - - - - - - - - - - - -
<%= 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%>
<%= get_praise_num(obj)%>
<%= 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 %>
- - <% end %> -
+ <% elsif @flag == 0 %> -<% end %> + + + + + + +
<%= image_tag "/images/praise_tread/praise_false.png",weight:"22px", height:"22px", :title => l(:label_issue_appraise_over) %><%= get_praise_num(obj)%><%= image_tag "/images/praise_tread/tread_false.png",weight:"22px", height:"22px",:title => l(:label_issue_tread_over) %>
+ <% end %> + + <% else %> + + + + + + + +
<%= 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 %> <%= get_praise_num(obj)%> <%= 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 %>
+ + <% end %> +
+ + <% else %> + +
+ + <% @is_valuate = is_praise_or_tread(obj,user_id)%> + <% if @is_valuate.size > 0 %> + <% @flag = @is_valuate.first.praise_or_tread %> + <% if @flag == 1 %> + + + + + + + + + + + +
<%= image_tag "/images/praise_tread/praise_false.png" , weight:"22px", height:"22px",:title => l(:label_issue_praise_over) %>
<%= get_praise_num(obj)%>
<%= image_tag "/images/praise_tread/tread_false.png",weight:"22px", height:"22px",:title => l(:label_issue_appraise_over) %>
+ + <% elsif @flag == 0 %> + + + + + + + + + + + + +
<%= image_tag "/images/praise_tread/praise_false.png",weight:"22px", height:"22px", :title => l(:label_issue_appraise_over) %>
<%= get_praise_num(obj)%>
<%= image_tag "/images/praise_tread/tread_false.png",weight:"22px", height:"22px",:title => l(:label_issue_tread_over) %>
+ <% end %> + + <% else %> + + + + + + + + + + + +
<%= 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 %>
<%= get_praise_num(obj)%>
<%= 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 %>
+ + <% end %> +
+ <% end %> + <% end %> diff --git a/app/views/praise_tread/praise_minus.js.erb b/app/views/praise_tread/praise_minus.js.erb index 74f7d6bfe..ab298ba2e 100644 --- a/app/views/praise_tread/praise_minus.js.erb +++ b/app/views/praise_tread/praise_minus.js.erb @@ -1,3 +1,3 @@ $('#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} )%>'); diff --git a/app/views/praise_tread/praise_plus.js.erb b/app/views/praise_tread/praise_plus.js.erb index c2584dcd2..d56ff0e68 100644 --- a/app/views/praise_tread/praise_plus.js.erb +++ b/app/views/praise_tread/praise_plus.js.erb @@ -1,4 +1,4 @@ $('#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} )%>'); diff --git a/app/views/praise_tread/tread_plus.js.erb b/app/views/praise_tread/tread_plus.js.erb index 89efec2dc..1104440ec 100644 --- a/app/views/praise_tread/tread_plus.js.erb +++ b/app/views/praise_tread/tread_plus.js.erb @@ -1,5 +1,5 @@ $('#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} )%>'); diff --git a/lib/tasks/userscore.rake b/lib/tasks/userscore.rake index eefca6d7a..144b9c9b9 100644 --- a/lib/tasks/userscore.rake +++ b/lib/tasks/userscore.rake @@ -14,47 +14,136 @@ namespace :user_score do Message.includes(:author).where("parent_id IS NULL").all.each do |m| users[m.author.id] = users[m.author.id].to_i + 2 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| users[j.user.id] = users[j.user.id].to_i + 1 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| users[j.user.id] = users[j.user.id].to_i + 1 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| users[jfm.user.id] = users[jfm.user.id].to_i + 1 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| users[m.author.id] = users[m.author.id].to_i + 1 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| UserScore.find_or_create_by_user_id(user_id).update_attribute(:collaboration, score) end - puts "=== UserScore#collaboration calculate Completed. users count: #{users.count}" + puts "=== UserScore#collaboration calculate Completed. collaboration users count: #{users.count}" users.clear # 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 技术得分 - # ... + # 顶踩帖 + 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 项目贡献得分 - # ... + 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 diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css index f5a21da5f..6bf8fc2da 100644 --- a/public/stylesheets/application.css +++ b/public/stylesheets/application.css @@ -1449,7 +1449,7 @@ div.square { overflow: hidden; 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;} .message .contextual { margin-top: 0; }