This commit is contained in:
senluo 2014-06-16 19:42:43 +08:00
commit cde34e42bc
21 changed files with 286 additions and 113 deletions

View File

@ -74,19 +74,11 @@ GEM
mail (2.5.4) mail (2.5.4)
mime-types (~> 1.16) mime-types (~> 1.16)
treetop (~> 1.4.8) treetop (~> 1.4.8)
method_source (0.8.2)
mime-types (1.23) mime-types (1.23)
multi_json (1.7.6) multi_json (1.7.6)
mysql2 (0.3.11-x86-mingw32) mysql2 (0.3.11-x86-mingw32)
net-ldap (0.3.1) net-ldap (0.3.1)
polyglot (0.3.3) polyglot (0.3.3)
pry (0.9.12.6-x86-mingw32)
coderay (~> 1.0)
method_source (~> 0.8)
slop (~> 3.4)
win32console (~> 1.3)
pry-nav (0.2.3)
pry (~> 0.9.10)
rack (1.4.5) rack (1.4.5)
rack-cache (1.2) rack-cache (1.2)
rack (>= 0.4) rack (>= 0.4)
@ -121,7 +113,6 @@ GEM
railties (~> 3.2.0) railties (~> 3.2.0)
sass (>= 3.1.10) sass (>= 3.1.10)
tilt (~> 1.3) tilt (~> 1.3)
slop (3.5.0)
sprockets (2.2.2) sprockets (2.2.2)
hike (~> 1.2) hike (~> 1.2)
multi_json (~> 1.0) multi_json (~> 1.0)
@ -136,7 +127,6 @@ GEM
uglifier (1.0.3) uglifier (1.0.3)
execjs (>= 0.3.0) execjs (>= 0.3.0)
multi_json (>= 1.0.2) multi_json (>= 1.0.2)
win32console (1.3.2-x86-mingw32)
PLATFORMS PLATFORMS
x86-mingw32 x86-mingw32
@ -154,8 +144,6 @@ DEPENDENCIES
jquery-rails (~> 2.0.2) jquery-rails (~> 2.0.2)
mysql2 (~> 0.3.11) mysql2 (~> 0.3.11)
net-ldap (~> 0.3.1) net-ldap (~> 0.3.1)
pry
pry-nav
rack-mini-profiler! rack-mini-profiler!
rack-openid rack-openid
rails (= 3.2.13) rails (= 3.2.13)

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

@ -22,6 +22,33 @@ module WelcomeHelper
include CoursesHelper include CoursesHelper
include ProjectsHelper include ProjectsHelper
def get_timestamp(obj)
if obj.respond_to? :updated_on
:updated_on
elsif obj.respond_to? :updated_at
:updated_at
elsif obj.respond_to? :created_on
:created_on
elsif obj.respond_to? :created_at
:created_at
else
Time.now.to_i.to_s.to_sym
end
end
def cache_key_for_project(obj)
timestamp = get_timestamp(obj)
"welcome_index_project_ul_#{obj.class}_li_#{obj.id}_#{obj.__send__ timestamp}"
end
def cache_key_for_event(obj)
timestamp = get_timestamp(obj)
"welcome_index_event_ul_#{obj.class}_li_#{obj.id}_#{obj.__send__ timestamp}"
end
def cache_key_for_topic(obj)
timestamp = get_timestamp(obj)
"welcome_index_topic_ul_#{obj.class}_li_#{obj.id}_#{obj.__send__ timestamp}"
end
def welcome_join_in_course(project, user) def welcome_join_in_course(project, user)
if(user.logged? && if(user.logged? &&
!(course_endTime_timeout? project) && !(course_endTime_timeout? project) &&

View File

@ -302,6 +302,8 @@ class Changeset < ActiveRecord::Base
def be_user_score def be_user_score
if self.new_record? if self.new_record?
UserScore.project(:push_code, self.user, { changeset_id: self.id }) UserScore.project(:push_code, self.user, { changeset_id: self.id })
#更新用户等级
self.user.update_user_level
end end
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,14 +29,16 @@ 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_id == '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 })
#更新用户等级
target_user.update_user_level
end end
end end
end end

View File

@ -5,7 +5,7 @@ class ProjectInfo < ActiveRecord::Base
belongs_to :user belongs_to :user
validates_presence_of :project_id, :user_id validates_presence_of :project_id, :user_id
validates_uniqueness_of :project_id, :scope => :user_id validates_uniqueness_of :project_id, :scope => :user_id
after_save :update_user_level
def self.manager? (user_id, project) def self.manager? (user_id, project)
for project_info in project.project_infos for project_info in project.project_infos
if project_info.user_id == user_id if project_info.user_id == user_id
@ -14,4 +14,9 @@ class ProjectInfo < ActiveRecord::Base
end end
return false return false
end end
#更新用户等级
def update_user_level
self.user.update_user_level
end
end end

View File

@ -895,7 +895,7 @@ class User < Principal
#更新用户等级 - by zjc #更新用户等级 - by zjc
def update_user_level def update_user_level
user_level = UserLevels.new user_level = self.level.nil? ? UserLevels.new : self.level
user_level.user = self user_level.user = self
#判断user的等级 #判断user的等级

View File

@ -110,11 +110,11 @@ class UserScore < ActiveRecord::Base
current_user, target_user = get_users(current_user, target_user) current_user, target_user = get_users(current_user, target_user)
user_score = target_user.user_score_attr user_score = target_user.user_score_attr
case operate case operate
when :followed_by # current_user 关注了target_user when :followed_by # current_user 关注了target_user Add watcher
user_score.influence = user_score.influence.to_i + 2 user_score.influence = user_score.influence.to_i + 2
user_score.save user_score.save
Rails.logger.info "[UserScore#influence] ===> User: #{current_user} be followed. options => (#{options.to_s})" Rails.logger.info "[UserScore#influence] ===> User: #{current_user} be followed. options => (#{options.to_s})"
when :cancel_followed # current_uer 取消了对 target_user的关注 when :cancel_followed # current_uer 取消了对 target_user的关注 delete watcher
user_score.influence = user_score.influence.to_i - 2 user_score.influence = user_score.influence.to_i - 2
user_score.save user_score.save
Rails.logger.info "[UserScore#influence] ===> User: #{current_user} canceled followed. options => (#{options.to_s})" Rails.logger.info "[UserScore#influence] ===> User: #{current_user} canceled followed. options => (#{options.to_s})"
@ -144,7 +144,7 @@ class UserScore < ActiveRecord::Base
# when :treading # current_user 踩了 target_user 的帖子 # when :treading # current_user 踩了 target_user 的帖子
# Rails.logger.info "[UserScore#skill] ===> User: #{current_user} treading #{target_user}'s posting. options => (#{options.to_s})" # Rails.logger.info "[UserScore#skill] ===> User: #{current_user} treading #{target_user}'s posting. options => (#{options.to_s})"
when :treaded_by_user # current_user 踩了 target_user 的帖子 when :treaded_by_user # current_user 踩了 target_user 的帖子
current_user_score.skill = current_user_score.skill.to_i - 2 #踩别人的帖子减2分 current_user_score.skill = current_user_score.skill.to_i - 2 #踩别人的帖子减2分 add praise_tread
current_user_score.save current_user_score.save
if current_user.id == target_user.id if current_user.id == target_user.id
target_user.reload target_user.reload
@ -152,13 +152,13 @@ class UserScore < ActiveRecord::Base
end end
level = current_user.get_level level = current_user.get_level
if level == 1 if level == 1
target_user_score.skill = target_user_score.skill.to_i - 2 #帖子被一级会员踩-2分 target_user_score.skill = target_user_score.skill.to_i - 2 #帖子被一级会员踩-2分 add praise_tread
target_user_score.save target_user_score.save
elsif level == 2 elsif level == 2
target_user_score.skill = target_user_score.skill.to_i - 4 #帖子被二级会员踩-4分 target_user_score.skill = target_user_score.skill.to_i - 4 #帖子被二级会员踩-4分 add praise_tread
target_user_score.save target_user_score.save
elsif level == 3 elsif level == 3
target_user_score.skill = target_user_score.skill.to_i - 6 #帖子被三级会员踩-6分 target_user_score.skill = target_user_score.skill.to_i - 6 #帖子被三级会员踩-6分 add praise_tread
target_user_score.save target_user_score.save
end end
@ -166,13 +166,13 @@ class UserScore < ActiveRecord::Base
when :praised_by_user # current_user 顶了 target_user 的帖子 when :praised_by_user # current_user 顶了 target_user 的帖子
level = current_user.get_level level = current_user.get_level
if level == 1 if level == 1
target_user_score.skill = target_user_score.skill.to_i + 4 #帖子被一级会员顶+4分 target_user_score.skill = target_user_score.skill.to_i + 4 #帖子被一级会员顶+4分 add praise_tread
target_user_score.save target_user_score.save
elsif level == 2 elsif level == 2
target_user_score.skill = target_user_score.skill.to_i + 6 #帖子被二级会员顶+6分 target_user_score.skill = target_user_score.skill.to_i + 6 #帖子被二级会员顶+6分 add praise_tread
target_user_score.save target_user_score.save
elsif level == 3 elsif level == 3
target_user_score.skill = target_user_score.skill.to_i + 8 #帖子被三级会员顶+8分 target_user_score.skill = target_user_score.skill.to_i + 8 #帖子被三级会员顶+8分 add praise_tread
target_user_score.save target_user_score.save
end end
@ -200,7 +200,7 @@ class UserScore < ActiveRecord::Base
user_score = current_user.try(:user_score_attr) user_score = current_user.try(:user_score_attr)
return false if current_user.nil? return false if current_user.nil?
case operate case operate
when :push_code # current_user 提交了代码 when :push_code # current_user 提交了代码 changeset
user_score = user_score.active.to_i + 4 user_score = user_score.active.to_i + 4
user_score.save user_score.save
Rails.logger.debug "[UserScore#project] ===> User: [#{current_user.id},#{current_user.name}] pushed code one time. options => (#{options.to_s})" Rails.logger.debug "[UserScore#project] ===> User: [#{current_user.id},#{current_user.name}] pushed code one time. options => (#{options.to_s})"

View File

@ -11,6 +11,4 @@ fileSpan.find('a.remove-upload')
"href": '<%= j attachment_path(@attachment, :attachment_id => params[:attachment_id], :format => 'js') %>' "href": '<%= j attachment_path(@attachment, :attachment_id => params[:attachment_id], :format => 'js') %>'
}) })
.off('click'); .off('click');
var divattach = fileSpan.find('div.div_attachments');
divattach.html('<%= j(render :partial => 'tags/tagEx', :locals => {:obj => @attachment, :object_flag => "6"})%>');
<% end %> <% end %>

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,4 +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,: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

@ -54,7 +54,7 @@
<ul class="d-p-projectlist"> <ul class="d-p-projectlist">
<% projects = find_miracle_project(10, 3) %> <% projects = find_miracle_project(10, 3) %>
<% projects.map do |project| %> <% projects.map do |project| %>
<% cache "welcome_index_hotProject_ul_project_#{project.id}_li" do %> <% cache cache_key_for_project(project) do %>
<li style="position:relative;height:6em;" class='<%= cycle("odd", "even") %>'> <li style="position:relative;height:6em;" class='<%= cycle("odd", "even") %>'>
<div style="float: left;"> <div style="float: left;">
<%= image_tag(get_project_avatar(project), :class => "avatar-4") %> <%= image_tag(get_project_avatar(project), :class => "avatar-4") %>
@ -88,7 +88,7 @@
<div class="user-message-box-list" style="margin-top: 10px;"> <div class="user-message-box-list" style="margin-top: 10px;">
<%activities = find_all_activities%> <%activities = find_all_activities%>
<% activities.each do |event| %> <% activities.each do |event| %>
<% cache "welcome_index_userActivity_ul_event_#{event.class}_#{event.id}_li" do %> <% cache cache_key_for_event(event) do %>
<li style="display: block;height:60px; padding-bottom: 4px;"> <li style="display: block;height:60px; padding-bottom: 4px;">
<div class="inner-right" style="float: left; height: 100%; "> <div class="inner-right" style="float: left; height: 100%; ">
<%= image_tag url_to_avatar(event.event_author), :class => "avatar-3" %> <%= image_tag url_to_avatar(event.event_author), :class => "avatar-3" %>
@ -119,7 +119,7 @@
<div class="welcome-box-list-new memo_activity"> <div class="welcome-box-list-new memo_activity">
<% topics = find_new_forum_topics(7) %> <% topics = find_new_forum_topics(7) %>
<% topics.includes(:forum, :last_reply, :author).each do |topic|%> <% topics.includes(:forum, :last_reply, :author).each do |topic|%>
<% cache "welcome_index_memosActivity_ul_topic_#{topic.id}_li" do %> <% cache cache_key_for_topic(topic) do %>
<li class="message-brief-intro"> <li class="message-brief-intro">
<div class='memo_title text_nowrap'> <div class='memo_title text_nowrap'>
<%= link_to '['+topic.forum.name + ']',forum_path(topic.forum),:class => 'memo_Bar_title' %><%= link_to topic.subject.truncate(30, omission: '...'), topic.event_url,title: topic.subject %> <%= link_to '['+topic.forum.name + ']',forum_path(topic.forum),:class => 'memo_Bar_title' %><%= link_to topic.subject.truncate(30, omission: '...'), topic.event_url,title: topic.subject %>

View File

@ -4,9 +4,10 @@ task :user_score do
end end
namespace :user_score do namespace :user_score do
desc "calculating user score" desc "calculating user score"
# Rails.env = 'production' task :calculate => :environment do
task :calculate => :environment do puts "truncating table...#{Rails.env}"
UserScore.destroy_all
puts "loading..." puts "loading..."
# collaboration 协同得分 # collaboration 协同得分
users = {} users = {}
@ -14,47 +15,149 @@ 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| UserScore.transaction do
UserScore.find_or_create_by_user_id(user_id).update_attribute(:collaboration, score) users.each do |user_id, score|
UserScore.find_or_create_by_user_id(user_id).update_attribute(:collaboration, score)
end
end end
puts "=== UserScore#collaboration calculate Completed. users count: #{users.count}" puts "=== UserScore#collaboration calculate Completed. collaboration users count: #{users.count}"
puts ""
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}"
UserScore.transaction do
users_influence.each do |user_id, score|
UserScore.find_or_create_by_user_id(user_id).update_attribute(:influence, score)
end
end
puts "=== UserScore#influence calculate Completed. influence users count: #{users_influence.count}"
puts ""
# 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}"
UserScore.transaction do
users_skill.each do |user_id, score|
UserScore.find_or_create_by_user_id(user_id).update_attribute(:skill, score)
end
end
puts "=== UserScore#skill calculate Completed. skill users count: #{users_skill.count}"
puts ""
# 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}"
UserScore.transaction do
users_active.each do |user_id, score|
UserScore.find_or_create_by_user_id(user_id).update_attribute(:active, score)
end
end
puts "=== UserScore#active calculate Completed. active users count: #{users_active.count}"
puts ""
end end
end end
@ -62,11 +165,11 @@ desc "create tmp file, to test"
file 'tmp/test.yml' do file 'tmp/test.yml' do
require 'yaml' require 'yaml'
var = { var = {
:name => "name", :name => "name",
:age => "age", :age => "age",
:agent => "agent" :agent => "agent"
} }
File.open('tmp/test.yml', 'w') do |f| File.open('tmp/test.yml', 'w') do |f|
f.write YAML.dump({'conf' => var }) f.write YAML.dump({'conf' => var})
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; }
@ -1847,7 +1847,7 @@ a.remove-upload:hover {text-decoration:none !important;}
/*gcm upload file count and deleteall*/ /*gcm upload file count and deleteall*/
#upload_file_count #count {color:red; font-size:1.5em;} #upload_file_count #count {color:red; font-size:1.5em;}
span.add_attachment .remove_all {background:none;background: url(../images/delete.png) no-repeat 1px 50%; width:1px; display:inline-block;position:absolute;right:61px;text-decoration:none;} span.add_attachment .remove_all {background:none;background: url(../images/delete.png) no-repeat 1px 50%; width:1px; display:inline-block;position:absolute;right:10%;text-decoration:none;}
div.fileover { background-color: lavender; } div.fileover { background-color: lavender; }