From f9612ca63fa8f6e6c08a8c9deb3c9f52ae7873ac Mon Sep 17 00:00:00 2001 From: z9hang Date: Sat, 21 Jun 2014 15:34:10 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E5=AE=9E=E6=97=B6=E5=88=B7=E6=96=B0?= =?UTF-8?q?=EF=BC=88ajax=E8=BD=AE=E8=AF=A2=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/users_controller.rb | 7 ++++++- app/views/layouts/base_users.html.erb | 27 +++++++++++++++++++++------ app/views/users/_user_score.html.erb | 6 ++++++ app/views/users/update_score.js.erb | 2 ++ config/routes.rb | 1 + 5 files changed, 36 insertions(+), 7 deletions(-) create mode 100644 app/views/users/_user_score.html.erb create mode 100644 app/views/users/update_score.js.erb diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 494b8333..e0845ae2 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -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 diff --git a/app/views/layouts/base_users.html.erb b/app/views/layouts/base_users.html.erb index 895f83bb..f07169d5 100644 --- a/app/views/layouts/base_users.html.erb +++ b/app/views/layouts/base_users.html.erb @@ -16,7 +16,25 @@ <%= call_hook :view_layouts_base_html_head %> <%= yield :header_tags -%> + + +
@@ -97,12 +115,9 @@ - <%= 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;') %> +
+ <%= render :partial => 'users/user_score', :locals => {:user => @user}%> +
diff --git a/app/views/users/_user_score.html.erb b/app/views/users/_user_score.html.erb new file mode 100644 index 00000000..836daa17 --- /dev/null +++ b/app/views/users/_user_score.html.erb @@ -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') %> \ No newline at end of file diff --git a/app/views/users/update_score.js.erb b/app/views/users/update_score.js.erb new file mode 100644 index 00000000..f3d3f492 --- /dev/null +++ b/app/views/users/update_score.js.erb @@ -0,0 +1,2 @@ +$('#score_div').html('<%= escape_javascript(render(:partial => 'users/user_score', + :locals => {:user => @user} )) %>'); \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index fb0bd55a..9d577559 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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] From 9d9bc76af423d4d0231b7f370cdccc832e21102b Mon Sep 17 00:00:00 2001 From: z9hang Date: Sat, 21 Jun 2014 17:06:08 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E5=AE=9A=E6=97=B6=E5=88=B7=E6=96=B0?= =?UTF-8?q?=E5=88=86=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/layouts/base_users.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/layouts/base_users.html.erb b/app/views/layouts/base_users.html.erb index f07169d5..948a7e3f 100644 --- a/app/views/layouts/base_users.html.erb +++ b/app/views/layouts/base_users.html.erb @@ -35,7 +35,7 @@ - +
From f16bec924c8e05b1628da9335943154140114e4f Mon Sep 17 00:00:00 2001 From: z9hang Date: Mon, 23 Jun 2014 09:27:21 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E5=A4=84=E7=90=86undefined=20method=20`upd?= =?UTF-8?q?ate=5Fuser=5Flevel'=20for=20nil:NilClass=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/changeset.rb | 2 +- app/models/praise_tread.rb | 2 +- app/models/project_info.rb | 2 +- app/models/user.rb | 57 ---------------------------------- app/models/user_levels.rb | 63 ++++++++++++++++++++++++++++++++++++++ lib/tasks/userscore.rake | 2 +- 6 files changed, 67 insertions(+), 61 deletions(-) diff --git a/app/models/changeset.rb b/app/models/changeset.rb index 6c22455a..6763963c 100644 --- a/app/models/changeset.rb +++ b/app/models/changeset.rb @@ -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 diff --git a/app/models/praise_tread.rb b/app/models/praise_tread.rb index b18b569d..f36441cf 100644 --- a/app/models/praise_tread.rb +++ b/app/models/praise_tread.rb @@ -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 diff --git a/app/models/project_info.rb b/app/models/project_info.rb index 4cb984b0..d22bf7cf 100644 --- a/app/models/project_info.rb +++ b/app/models/project_info.rb @@ -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 diff --git a/app/models/user.rb b/app/models/user.rb index 111213c7..ba996fe8 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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 diff --git a/app/models/user_levels.rb b/app/models/user_levels.rb index eb8dd37e..900d1803 100644 --- a/app/models/user_levels.rb +++ b/app/models/user_levels.rb @@ -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 \ No newline at end of file diff --git a/lib/tasks/userscore.rake b/lib/tasks/userscore.rake index 43b8bed4..7bfec13b 100644 --- a/lib/tasks/userscore.rake +++ b/lib/tasks/userscore.rake @@ -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分 From 773b7288289eff50b4fc66cec06d2cf14cf982fc Mon Sep 17 00:00:00 2001 From: z9hang Date: Mon, 23 Jun 2014 11:17:42 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E4=BF=AE=E6=94=B9=EF=BC=9A=E8=87=AA?= =?UTF-8?q?=E5=B7=B1=E4=B8=8D=E8=83=BD=E8=B8=A9=E6=88=96=E9=A1=B6=E8=87=AA?= =?UTF-8?q?=E5=B7=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/praise_tread_controller.rb | 10 ++- app/views/praise_tread/_praise_tread.html.erb | 70 +++++++++++++------ config/locales/zh.yml | 2 + 3 files changed, 58 insertions(+), 24 deletions(-) diff --git a/app/controllers/praise_tread_controller.rb b/app/controllers/praise_tread_controller.rb index 368b901f..acfd785d 100644 --- a/app/controllers/praise_tread_controller.rb +++ b/app/controllers/praise_tread_controller.rb @@ -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 diff --git a/app/views/praise_tread/_praise_tread.html.erb b/app/views/praise_tread/_praise_tread.html.erb index 8d2545f9..2b859cf7 100644 --- a/app/views/praise_tread/_praise_tread.html.erb +++ b/app/views/praise_tread/_praise_tread.html.erb @@ -29,15 +29,26 @@ <% 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 %>
+ <% if user_id == obj.author_id %> + + + + + + +
<%= image_tag "/images/praise_tread/praise_true.png" , weight:"22px", height:"22px",:title => l(:label_issue_not_praise_over) %><%= get_praise_num(obj)%><%= image_tag "/images/praise_tread/tread_true.png",weight:"22px", height:"22px",:title => l(:label_issue_not_treed_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,: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 %>
@@ -80,20 +91,35 @@ <% end %> <% else %> + <% if user_id == obj.author_id %> + + + + + + + + + + + +
<%= image_tag "/images/praise_tread/praise_true.png",weight:"22px", height:"22px", :title => l(:label_issue_not_praise_over) %>
<%= get_praise_num(obj)%>
<%= image_tag "/images/praise_tread/tread_true.png",weight:"22px", height:"22px",:title => l(:label_issue_not_tread_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 ,: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 %> - - - - - - - - - - -
<%= 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 %>
diff --git a/config/locales/zh.yml b/config/locales/zh.yml index af7af96f..c500481e 100644 --- a/config/locales/zh.yml +++ b/config/locales/zh.yml @@ -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: 只能评价一次哦!