Merge branch 'szzh' of http://repository.trustie.net/xianbo/trustie2 into szzh
This commit is contained in:
commit
d0843861ce
|
@ -11,7 +11,10 @@ class PraiseTreadController < ApplicationController
|
|||
@obj_type = params[:obj_type]
|
||||
@horizontal = params[:horizontal].downcase == "false" ? false:true
|
||||
@obj = find_object_by_type_and_id(@obj_type,@obj_id)
|
||||
praise_tread_plus(@obj_type,@obj_id,1)
|
||||
unless @obj.author_id == User.current.id
|
||||
praise_tread_plus(@obj_type,@obj_id,1)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -47,7 +50,10 @@ class PraiseTreadController < ApplicationController
|
|||
@obj_type = params[:obj_type]
|
||||
@horizontal = params[:horizontal].downcase == "false" ? false:true
|
||||
@obj = find_object_by_type_and_id(@obj_type,@obj_id)
|
||||
praise_tread_plus(@obj_type,@obj_id,0)
|
||||
unless @obj.author_id == User.current.id
|
||||
praise_tread_plus(@obj_type,@obj_id,0)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ class UsersController < ApplicationController
|
|||
before_filter :require_admin, :except => [:show, :index, :search, :tag_save, :tag_saveEx,:user_projects, :user_newfeedback, :user_comments, :watch_bids, :watch_contests, :info,
|
||||
:user_watchlist, :user_fanslist,:update, :user_courses, :user_homeworks, :watch_projects, :show_score, :topic_score_index, :project_score_index,
|
||||
:activity_score_index, :influence_score_index, :score_index,:show_new_score, :topic_new_score_index, :project_new_score_index,
|
||||
:activity_new_score_index, :influence_new_score_index, :score_new_index]
|
||||
:activity_new_score_index, :influence_new_score_index, :score_new_index,:update_score]
|
||||
#edit has been deleted by huang, 2013-9-23
|
||||
before_filter :find_user, :only => [:user_fanslist, :user_watchlist, :show, :edit, :update, :destroy, :edit_membership, :user_courses,
|
||||
:user_homeworks, :destroy_membership, :user_activities, :user_projects, :user_newfeedback, :user_comments,
|
||||
|
@ -792,6 +792,11 @@ class UsersController < ApplicationController
|
|||
def score_new_index
|
||||
|
||||
end
|
||||
|
||||
def update_score
|
||||
@user = User.find(params[:id])
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def find_user
|
||||
|
|
|
@ -302,7 +302,7 @@ class Changeset < ActiveRecord::Base
|
|||
def be_user_score
|
||||
UserScore.project(:push_code, self.user,self, { changeset_id: self.id })
|
||||
#更新用户等级
|
||||
self.user.update_user_level
|
||||
UserLevels.update_user_level(self.user)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -38,7 +38,7 @@ class PraiseTread < ActiveRecord::Base
|
|||
target_user = obj.author
|
||||
UserScore.skill(:praised_by_user, User.current,target_user,self,{ praise_tread_id: self.id })
|
||||
#更新用户等级
|
||||
target_user.update_user_level
|
||||
UserLevels.update_user_level(target_user)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -17,6 +17,6 @@ class ProjectInfo < ActiveRecord::Base
|
|||
|
||||
#更新用户等级
|
||||
def update_user_level
|
||||
self.user.update_user_level
|
||||
UserLevels.update_user_level(self.user)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -885,63 +885,6 @@ class User < Principal
|
|||
end
|
||||
end
|
||||
|
||||
#获取user的等级 -by zjc
|
||||
def get_level
|
||||
if self.level.nil?
|
||||
update_user_level
|
||||
end
|
||||
self.level.level
|
||||
end
|
||||
|
||||
#更新用户等级 - by zjc
|
||||
def update_user_level
|
||||
user_level = self.level.nil? ? UserLevels.new : self.level
|
||||
user_level.user = self
|
||||
|
||||
#判断user的等级
|
||||
pis = self.project_infos #ProjectInfo.find_all_by_user_id(self.id)
|
||||
isManager = false;
|
||||
pis.each do |pi|
|
||||
#判断是否为项目管理员
|
||||
if self.allowed_to?({:controller => "projects", :action => "edit"}, pi.project)
|
||||
isManager = true;
|
||||
end
|
||||
end
|
||||
has_effective_praise_count = false;
|
||||
self.messages.each do |message|
|
||||
if message.parent_id.nil?
|
||||
ptcs = PraiseTreadCache.find_all_by_object_id(message.id)
|
||||
ptcs.each do |ptc|
|
||||
if ptc.object_type == 'Message' && ptc.praise_num.to_i > 5
|
||||
has_effective_praise_count = true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
if !has_effective_praise_count
|
||||
self.memos do |memo|
|
||||
if memo.parent_id.nil?
|
||||
ptcs = PraiseTreadCache.find_all_by_object_id(memo.id)
|
||||
ptcs.each do |ptc|
|
||||
if ptc.object_type == 'Memo' && ptc.praise_num > 5
|
||||
has_effective_praise_count = true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if isManager || self.changesets.count > 100
|
||||
user_level.level = 3
|
||||
elsif (self.changesets.count > 1 && self.changesets.count <= 100) || has_effective_praise_count
|
||||
user_level.level = 2
|
||||
else
|
||||
user_level.level = 1
|
||||
end
|
||||
user_level.save
|
||||
self.reload
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def validate_password_length
|
||||
|
|
|
@ -2,4 +2,67 @@
|
|||
class UserLevels < ActiveRecord::Base
|
||||
attr_accessible :user_id, :level
|
||||
belongs_to :user
|
||||
|
||||
#获取user的等级 -by zjc
|
||||
def get_level(user)
|
||||
unless user.nil?
|
||||
if user.level.nil?
|
||||
UserLevels.update_user_level(user)
|
||||
end
|
||||
user.level.level
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
#更新用户的等级 -by zjc
|
||||
def self.update_user_level(user)
|
||||
unless user.nil?
|
||||
user_level = user.level.nil? ? UserLevels.new : user.level
|
||||
user_level.user = user
|
||||
|
||||
#判断user的等级
|
||||
pis = user.project_infos #ProjectInfo.find_all_by_user_id(self.id)
|
||||
isManager = false;
|
||||
pis.each do |pi|
|
||||
#判断是否为项目管理员
|
||||
if user.allowed_to?({:controller => "projects", :action => "edit"}, pi.project)
|
||||
isManager = true;
|
||||
end
|
||||
end
|
||||
has_effective_praise_count = false;
|
||||
user.messages.each do |message|
|
||||
if message.parent_id.nil?
|
||||
ptcs = PraiseTreadCache.find_all_by_object_id(message.id)
|
||||
ptcs.each do |ptc|
|
||||
if ptc.object_type == 'Message' && ptc.praise_num.to_i > 5
|
||||
has_effective_praise_count = true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
if !has_effective_praise_count
|
||||
user.memos do |memo|
|
||||
if memo.parent_id.nil?
|
||||
ptcs = PraiseTreadCache.find_all_by_object_id(memo.id)
|
||||
ptcs.each do |ptc|
|
||||
if ptc.object_type == 'Memo' && ptc.praise_num > 5
|
||||
has_effective_praise_count = true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if isManager || user.changesets.count > 100
|
||||
user_level.level = 3
|
||||
elsif (user.changesets.count > 1 && user.changesets.count <= 100) || has_effective_praise_count
|
||||
user_level.level = 2
|
||||
else
|
||||
user_level.level = 1
|
||||
end
|
||||
user_level.save
|
||||
user.reload
|
||||
end
|
||||
|
||||
end
|
||||
end
|
|
@ -16,8 +16,26 @@
|
|||
<%= call_hook :view_layouts_base_html_head %>
|
||||
<!-- page specific tags -->
|
||||
<%= yield :header_tags -%>
|
||||
<script type="text/javascript">
|
||||
function startXMLHttp()
|
||||
{
|
||||
$.ajax({
|
||||
url: '<%= update_score_user_path(:format => 'js') %>',
|
||||
type: 'get',
|
||||
data: 'id=<%= @user.id %>',
|
||||
remote: true
|
||||
}) ;
|
||||
}
|
||||
|
||||
function t()
|
||||
{
|
||||
setInterval("startXMLHttp()",5000);
|
||||
}
|
||||
</script>
|
||||
|
||||
</head>
|
||||
<body class="<%= h body_css_classes %>">
|
||||
<!--加上 onload="Javascript:t()" 开始定时刷新分数 -->
|
||||
<body class="<%= h body_css_classes %>" onload="Javascript:t()">
|
||||
<div id="wrapper">
|
||||
<div id="wrapper2">
|
||||
<div id="wrapper3">
|
||||
|
@ -97,12 +115,9 @@
|
|||
|
||||
<!-- modified by zjc 新得分显示 -->
|
||||
<tr><td class="score">
|
||||
<%= l(:label_user_grade)%>:
|
||||
<%= link_to(format("%.2f" , @user.user_score_attr.total_score).to_f, {:controller => 'users',
|
||||
:action => 'show_new_score',
|
||||
:remote => true,
|
||||
:id => @user.id
|
||||
}, :style => 'color :#E8770D;') %>
|
||||
<div id="score_div">
|
||||
<%= render :partial => 'users/user_score', :locals => {:user => @user}%>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<!-- end -->
|
||||
|
|
|
@ -29,15 +29,26 @@
|
|||
|
||||
<% 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>
|
||||
<% if user_id == obj.author_id %>
|
||||
<table style="line-height: 1px">
|
||||
<tr>
|
||||
<td ><%= image_tag "/images/praise_tread/praise_true.png" , weight:"22px", height:"22px",:title => l(:label_issue_not_praise_over) %></td>
|
||||
<td align="center"><strong class="font_small_watch"><%= get_praise_num(obj)%></strong></td>
|
||||
<td><%= image_tag "/images/praise_tread/tread_true.png",weight:"22px", height:"22px",:title => l(:label_issue_not_treed_over) %></td>
|
||||
</tr>
|
||||
</table>
|
||||
<% 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 -->
|
||||
<% end %>
|
||||
</div>
|
||||
|
@ -80,20 +91,35 @@
|
|||
<% end %>
|
||||
|
||||
<% else %>
|
||||
<% if user_id == obj.author_id %>
|
||||
<table style="line-height: 1px">
|
||||
<tr>
|
||||
<td > <%= image_tag "/images/praise_tread/praise_true.png",weight:"22px", height:"22px", :title => l(:label_issue_not_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_true.png",weight:"22px", height:"22px",:title => l(:label_issue_not_tread_over) %> </td>
|
||||
</tr>
|
||||
</table>
|
||||
<% 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 %>
|
||||
|
||||
<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>
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
<%= l(:label_user_grade)%>:
|
||||
<%= link_to(format("%.2f" , @user.user_score_attr.total_score).to_f, {:controller => 'users',
|
||||
:action => 'show_new_score',
|
||||
:remote => true,
|
||||
:id => user.id
|
||||
}, :style => 'color :#E8770D;',:id => 'user_score') %>
|
|
@ -0,0 +1,2 @@
|
|||
$('#score_div').html('<%= escape_javascript(render(:partial => 'users/user_score',
|
||||
:locals => {:user => @user} )) %>');
|
|
@ -1537,6 +1537,8 @@ zh:
|
|||
label_issue_tread: 烂问题,踩!
|
||||
label_issue_praise_over: 我刚才顶过了~
|
||||
label_issue_tread_over: 我刚才踩过了~
|
||||
label_issue_not_praise_over: 不能顶自己~
|
||||
label_issue_not_treed_over: 不能踩自己~
|
||||
#end
|
||||
label_goto: 前往>>
|
||||
label_issue_appraise_over: 只能评价一次哦!
|
||||
|
|
|
@ -238,6 +238,7 @@ RedmineApp::Application.routes.draw do
|
|||
match 'activity_new_score_index', :to => 'users#activity_new_score_index', :via => :get
|
||||
match 'influence_new_score_index', :to => 'users#influence_new_score_index', :via => :get
|
||||
match 'score_new_index', :to => 'users#score_new_index', :via => :get
|
||||
match 'update_score', :to => 'users#update_score', :via => [:get,:post]
|
||||
|
||||
match 'show_projects_score', :to => 'projects#show_projects_score', :via => [:get, :post]
|
||||
match 'issue_score_index', :to => 'projects#issue_score_index', :via => [:get, :post]
|
||||
|
|
|
@ -75,7 +75,7 @@ namespace :user_score do
|
|||
next
|
||||
end
|
||||
target_user = obj.author
|
||||
level = pt.user.get_level
|
||||
level = UserLevels.get_level(pt.user)#pt.user.get_level
|
||||
if pt.praise_or_tread == 0
|
||||
#踩帖
|
||||
users_skill[pt.user.id] = users_skill[pt.user.id].to_i - 2 #踩别人帖-2分
|
||||
|
|
Loading…
Reference in New Issue