From cf9aa1272721debb1434af3ff0a1ef41dfbb00cf Mon Sep 17 00:00:00 2001 From: william Date: Mon, 12 Aug 2013 14:50:54 +0800 Subject: [PATCH] =?UTF-8?q?1.=E9=87=8D=E6=96=B0=E5=AE=9A=E4=B9=89=E4=BA=86?= =?UTF-8?q?=E9=A1=B6=E5=92=8C=E8=B8=A9=E5=BE=97=E8=A7=84=E5=88=99=EF=BC=9A?= =?UTF-8?q?=20=E5=AF=B9=E4=BA=8E=E4=B8=BA=E8=AF=84=E4=BB=B7=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98=EF=BC=8C=E5=90=8C=E6=97=B6=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E9=A1=B6=E5=92=8C=E8=B8=A9=E7=9A=84=E6=95=B0=E5=AD=97=EF=BC=8C?= =?UTF-8?q?=E5=B9=B6=E4=B8=94=E6=95=B0=E5=AD=97=E7=9A=84=E2=80=9C+?= =?UTF-8?q?=E2=80=9D=E2=80=9C-=E2=80=9D=E6=A0=87=E6=88=90=E9=BB=91?= =?UTF-8?q?=E8=89=B2=EF=BC=9B=20=E5=AF=B9=E4=BA=8E=E8=AF=84=E4=BB=B7?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98=EF=BC=8C=E5=A6=82=E6=9E=9C=E8=AF=84?= =?UTF-8?q?=E4=BB=B7=E6=98=AF=E9=A1=B6=EF=BC=8C=E5=88=99=E5=8F=AA=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E6=89=80=E6=9C=89=E9=A1=B6=E7=9A=84=E6=AC=A1=E6=95=B0?= =?UTF-8?q?=EF=BC=9B=E5=8F=8D=E4=B9=8B=EF=BC=8C=E4=BA=A6=E7=84=B6=EF=BC=9B?= =?UTF-8?q?=202.=E5=9C=A8=E9=97=AE=E9=A2=98=E5=88=97=E8=A1=A8=E4=B8=AD?= =?UTF-8?q?=E4=B9=9F=E6=B7=BB=E5=8A=A0=E4=BA=86=E9=A1=B6=E5=92=8C=E8=B8=A9?= =?UTF-8?q?=E7=9A=84=E5=8A=9F=E8=83=BD=EF=BC=9B=203.=E5=AF=B9=E4=BA=8E?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E5=88=97=E8=A1=A8=E7=9A=84=E6=8F=8F=E8=BF=B0?= =?UTF-8?q?=EF=BC=8C=E5=9C=A8=E6=8F=8F=E8=BF=B0=E5=86=85=E5=AE=B9=E5=89=8D?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=86=E2=80=9C=E6=8F=8F=E8=BF=B0=EF=BC=9A?= =?UTF-8?q?=E2=80=9D=EF=BC=8C=20=E6=89=80=E4=BB=A5=E4=B8=BA=E7=A9=BA?= =?UTF-8?q?=E7=9A=84=E6=83=85=E5=86=B5=E4=B8=8B=EF=BC=8C=E8=AF=A5=E5=A4=84?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E5=8D=A0=E4=BD=8D=E4=BE=9D=E7=84=B6=E5=AD=98?= =?UTF-8?q?=E5=9C=A8=EF=BC=8C=E4=BD=BF=E5=88=97=E8=A1=A8=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E7=BB=9F=E4=B8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/praise_tread_controller.rb | 25 ++++--- app/controllers/users_controller.rb | 4 +- app/helpers/praise_tread_helper.rb | 15 ++-- app/models/praise_tread_cache.rb | 9 ++- app/views/issues/_list.html.erb | 20 ++++-- app/views/issues/show.html.erb | 11 +-- app/views/praise_tread/_praise_tread.html.erb | 71 ++++++++++++++----- app/views/praise_tread/praise_plus.js.erb | 3 +- 8 files changed, 109 insertions(+), 49 deletions(-) diff --git a/app/controllers/praise_tread_controller.rb b/app/controllers/praise_tread_controller.rb index 41b167ed0..48574bcad 100644 --- a/app/controllers/praise_tread_controller.rb +++ b/app/controllers/praise_tread_controller.rb @@ -1,10 +1,17 @@ class PraiseTreadController < ApplicationController + + accept_api_auth :tread_plus,:praise_plus + before_filter :require_login,:only => [:praise_plus,:tread_plus] + def praise_plus @obj = nil + # @is_in_list = nil if request.get? @obj_id = params[:obj_id] @obj_type = params[:obj_type] - @obj = praise_tread_plus(@obj_type,@obj_id,1) + @obj = find_object_by_type_and_id(@obj_type,@obj_id) + # @is_in_list = params[:is_in_list] + praise_tread_plus(@obj_type,@obj_id,1) end end @@ -34,10 +41,13 @@ class PraiseTreadController < ApplicationController def tread_plus @obj = nil + # @is_in_list = nil if request.get? @obj_id = params[:obj_id] @obj_type = params[:obj_type] - @obj = praise_tread_plus(@obj_type,@obj_id,0) + @obj = find_object_by_type_and_id(@obj_type,@obj_id) + # @is_in_list = params[:is_in_list] + praise_tread_plus(@obj_type,@obj_id,0) end end @@ -79,14 +89,11 @@ class PraiseTreadController < ApplicationController #再创建或更新praise_tread_cache表 @ptc = PraiseTreadCache.find_by_object_id_and_object_type(id,type) @ptc = @ptc.nil? ? PraiseTreadCache.new : @ptc - @ptc.object_id = id.to_i - @ptc.object_type = type - @ptc.save - @ptc.plus(1) + @ptc.object_id = id.to_i + @ptc.object_type = type + @ptc.save + @ptc.plus(flag,1) end - - @obj = find_object_by_type_and_id(type,id) - respond_to do |format| format.html format.js diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 0e005690e..02d23e174 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -28,10 +28,10 @@ class UsersController < ApplicationController before_filter :require_admin, :except => [:show, :index,:tag_save, :user_projects, :user_newfeedback, :user_comments, :watch_bids, :info, :user_watchlist, :user_fanslist,:edit] before_filter :find_user, :only => [:user_fanslist, :user_watchlist, :show, :edit, :update, :destroy, :edit_membership, :destroy_membership, :user_activities, :user_projects, :user_newfeedback, :user_comments, :watch_bids, :info] - accept_api_auth :index, :show, :create, :update, :destroy + accept_api_auth :index, :show, :create, :update, :destroy,:tag_save #william - before_filter :require_login,:only=>[:tag_save] + before_filter :require_login,:only => :tag_save helper :sort diff --git a/app/helpers/praise_tread_helper.rb b/app/helpers/praise_tread_helper.rb index 1aa49d3ab..26e4e5f4c 100644 --- a/app/helpers/praise_tread_helper.rb +++ b/app/helpers/praise_tread_helper.rb @@ -9,14 +9,19 @@ module PraiseTreadHelper end #end - def get_praise_num(object) - @obj_type = object.class.name.underscore + def get_praise_num(object,flag) + @obj_type = object.class @obj_id = object.id @record = PraiseTreadCache.find_by_object_id_and_object_type(@obj_id,@obj_type) if @record - return @record.praise_num - else - return 0 + case flag + when 1 + return @record.praise_num.nil? ? 0 : @record.praise_num + when 0 + return @record.tread_num.nil? ? 0 : @record.tread_num + end + else + return 0 end end diff --git a/app/models/praise_tread_cache.rb b/app/models/praise_tread_cache.rb index 330e197cf..739b45876 100644 --- a/app/models/praise_tread_cache.rb +++ b/app/models/praise_tread_cache.rb @@ -1,8 +1,13 @@ class PraiseTreadCache < ActiveRecord::Base attr_accessible :object_id,:object_type,:praise_num,:tread_num - def plus(num) - self.update_attribute(:praise_num, self.praise_num.to_i + num) + def plus(flag,num) + case flag + when 0 + self.update_attribute(:tread_num, self.tread_num.to_i + num) + when 1 + self.update_attribute(:praise_num, self.praise_num.to_i + num) + end end def minus(num) diff --git a/app/views/issues/_list.html.erb b/app/views/issues/_list.html.erb index e174b01bc..53a6681db 100644 --- a/app/views/issues/_list.html.erb +++ b/app/views/issues/_list.html.erb @@ -72,23 +72,27 @@
  • "> <% column_content = ( query.inline_columns.map {|column| "#{column_content_new(column, issue)}"}) %> + + <%= render :partial => "/praise_tread/praise_tread", + :locals => {:obj => issue,:user_id =>User.current.id}%> + <% if issue.tracker.name == 'Bug' %> <%= image_tag("/images/task.png", :class => "img-tag-issues") %> <% end %> <% if issue.tracker.name == '任务'%> <%= image_tag("/images/issues.png", :class => "img-tag-issues") %> <% end %> +
  • diff --git a/app/views/issues/show.html.erb b/app/views/issues/show.html.erb index 8305cd18d..2917bdf4a 100644 --- a/app/views/issues/show.html.erb +++ b/app/views/issues/show.html.erb @@ -23,7 +23,12 @@
    <%= render_issue_subject_with_tree(@issue) %> -
    + + + +<%= render :partial => "/praise_tread/praise_tread", + :locals => {:obj => @issue,:user_id =>User.current.id}%> +

    <%= authoring @issue.created_on, @issue.author %>. <% if @issue.created_on != @issue.updated_on %> @@ -34,10 +39,6 @@

    <%= render :partial => 'layouts/tag', :locals => {:obj => @issue,:object_flag => "3" }%>
    - - <%= render :partial => "/praise_tread/praise_tread", - :locals => {:obj => @issue,:user_id =>User.current.id}%> - <%= issue_fields_rows do |rows| rows.left l(:field_status), h(@issue.status.name), :class => 'status' diff --git a/app/views/praise_tread/_praise_tread.html.erb b/app/views/praise_tread/_praise_tread.html.erb index ebd48bf6b..4ed2328cf 100644 --- a/app/views/praise_tread/_praise_tread.html.erb +++ b/app/views/praise_tread/_praise_tread.html.erb @@ -1,22 +1,57 @@ - - <% @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_true.png") %> <%= get_praise_num(obj)%> <%= image_tag("/images/praise_tread/tread_false.png") %> + +
    - <% elsif @flag == 0 %> - <%= image_tag("/images/praise_tread/praise_false.png") %> <%= get_praise_num(obj)%> <%= image_tag("/images/praise_tread/tread_true.png") %> - <% 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_true.png") %>
    +<%= get_praise_num(obj,1)%>
    <%= image_tag("/images/praise_tread/tread_false.png") %>
    + <% elsif @flag == 0 %> + + + + + + + + + + + +
    <%= image_tag("/images/praise_tread/praise_false.png") %>
    -<%= get_praise_num(obj,0)%>
    <%= image_tag("/images/praise_tread/tread_true.png") %>
    + <% end %> - <% else %> + <% else %> + + + + + + + + + + + + + + + +
    <%= link_to image_tag("/images/praise_tread/praise_false.png"), + :controller=>"praise_tread",:action=>"praise_plus",:remote=>true,:obj_id => obj.id,:obj_type => obj.class%>
    +<%= get_praise_num(obj,1)%>
    ---
    -<%= get_praise_num(obj,0)%>
    <%= link_to image_tag("/images/praise_tread/tread_false.png"),:controller=>"praise_tread", + :action=>"tread_plus",:remote=>true,:obj_id => obj.id,:obj_type => obj.class %>
    - <%= link_to image_tag("/images/praise_tread/praise_false.png"), - :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_false.png"),:controller=>"praise_tread", - :action=>"tread_plus",:remote=>true,:obj_id => obj.id,:obj_type => obj.class %> - - <% end %> - + <% end %> + diff --git a/app/views/praise_tread/praise_plus.js.erb b/app/views/praise_tread/praise_plus.js.erb index 5020bb3c9..c2584dcd2 100644 --- a/app/views/praise_tread/praise_plus.js.erb +++ b/app/views/praise_tread/praise_plus.js.erb @@ -1,3 +1,4 @@ -$('#praise_tread').html('<%= j( + +$('#praise_tread_<%= @obj.id %>').html('<%= j( render :partial => "/praise_tread/praise_tread",:locals => {:obj => @obj,:user_id => User.current.id} )%>');