From c7beefa55696603454667dd3e4efdecb57427ff1 Mon Sep 17 00:00:00 2001 From: fanqiang <316257774@qq.com> Date: Tue, 27 Aug 2013 11:09:34 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=94=A8=E6=88=B7=E6=B4=BB?= =?UTF-8?q?=E5=8A=A8=E9=A1=B5=E9=9D=A2=EF=BC=8C=E6=B7=BB=E5=8A=A0=E4=BA=86?= =?UTF-8?q?=E8=BF=87=E6=BB=A4=E5=8A=9F=E8=83=BD=E3=80=82=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E7=95=99=E8=A8=80=E4=B8=AD=E5=BC=95=E7=94=A8=E5=92=8C=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E5=8A=9F=E8=83=BD=E7=9A=84=E6=98=BE=E7=A4=BA=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/users_controller.rb | 50 ++++++++++++---- app/helpers/users_helper.rb | 28 +++++++++ app/models/user.rb | 8 +++ app/views/bids/_history.html.erb | 13 +++-- app/views/layouts/base_users.html.erb | 6 +- app/views/users/show.html.erb | 82 ++++++++++++++++++++++++++- app/views/words/_message.html.erb | 6 +- 7 files changed, 169 insertions(+), 24 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 751d497ca..ce62f3423 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -215,18 +215,48 @@ class UsersController < ApplicationController # @activity_pages = Paginator.new @activity_count, @limit, params['page'] # @offset ||= @activity_pages.offset # @events_by_day_ = @events.slice(@offset,@limit) - if @user == User.current + case params[:type] + when "1" + if @user == User.current + activity = Activity.where('user_id = ?', User.current.id).order('id desc') + @offset, @limit = api_offset_and_limit({:limit => 10}) + @activity_count = activity.count + @activity_pages = Paginator.new @activity_count, @limit, params['page'] + @offset ||= @activity_pages.offset + @activity = activity.offset(@offset).limit(@limit) + @state = 1 + end + when "2" + message = [] + if @user == User.current + message = JournalsForMessage.reference_message(@user.id) + message += Journal.reference_message(@user.id) + end + @offset, @limit = api_offset_and_limit({:limit => 10}) + @activity_count = message.size + @info_pages = Paginator.new @activity_count, @limit, params['page'] + @offset ||= @info_pages.offset + + messages = message.sort {|x,y| y.created_on <=> x.created_on } + + @message = messages[@offset, @limit] + @state = 2 + else + if @user == User.current watcher = User.watched_by(@user) watcher.push(User.current) activity = Activity.where('user_id in (?)', watcher).order('id desc') - else + else activity = Activity.where('user_id = ?', @user.id).order('id desc') + end + @offset, @limit = api_offset_and_limit({:limit => 10}) + @activity_count = activity.count + @activity_pages = Paginator.new @activity_count, @limit, params['page'] + @offset ||= @activity_pages.offset + @activity = activity.offset(@offset).limit(@limit) + @state = 0 end - @offset, @limit = api_offset_and_limit({:limit => 10}) - @activity_count = activity.count - @activity_pages = Paginator.new @activity_count, @limit, params['page'] - @offset ||= @activity_pages.offset - @activity = activity.offset(@offset).limit(@limit) + #Modified by nie unless User.current.admin? @@ -249,10 +279,10 @@ class UsersController < ApplicationController def info message = [] - if @user == User.current - + if @user == User.current message = JournalsForMessage.reference_message(@user.id) - message += Journal.reference_message(@user.id) end + message += Journal.reference_message(@user.id) + end @offset, @limit = api_offset_and_limit({:limit => 10}) @info_count = message.size @info_pages = Paginator.new @info_count, @limit, params['page'] diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb index 8a2ab765f..491112b82 100644 --- a/app/helpers/users_helper.rb +++ b/app/helpers/users_helper.rb @@ -62,5 +62,33 @@ module UsersHelper end # added by fq + # + + def show_activity(state) + content = ''.html_safe + case state + when 0 + s = content_tag('span', "所有动态", :class => "current-page") + content << content_tag('li', s) + content << content_tag('li', link_to("只看自己", {:controller => 'users', :action => 'show', :type => 1})) + content << content_tag('li', link_to("所有反馈", {:controller => 'users', :action => 'show', :type => 2})) + when 1 + s = content_tag('span', "只看自己", :class => "current-page") + content << content_tag('li', link_to("所有动态", {:controller => 'users', :action => 'show'})) + content << content_tag('li', s, :class => "current-page") + content << content_tag('li', link_to("所有反馈", {:controller => 'users', :action => 'show', :type => 2})) + when 2 + s = content_tag('span', "所有反馈", :class => "current-page") + content << content_tag('li', link_to("所有动态", {:controller => 'users', :action => 'show'})) + content << content_tag('li', link_to("只看自己", {:controller => 'users', :action => 'show', :type => 1})) + content << content_tag('li', s, :class => "current-page") + end + content_tag('div', content, :class => "pagination") + end end diff --git a/app/models/user.rb b/app/models/user.rb index 21e1664e1..5e6c0963b 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -84,6 +84,7 @@ class User < Principal has_many :new_jours, :as => :jour, :class_name => 'JournalsForMessage', :conditions => "status=1" has_many :journal_replies has_many :activities + has_many :acts, :class_name => 'Activity', :as => :act, :dependent => :destroy ##### ######added by nie @@ -128,6 +129,9 @@ class User < Principal before_create :set_mail_notification before_save :update_hashed_password before_destroy :remove_references_before_destroy + # added by fq + after_create :act_as_activity + # end scope :in_group, lambda {|group| group_id = group.is_a?(Group) ? group.id : group.to_i @@ -665,6 +669,10 @@ class User < Principal end private + + def act_as_activity + self.acts << Activity.new(:user_id => self.id) + end # Removes references that are not handled by associations # Things that are not deleted are reassociated with the anonymous user diff --git a/app/views/bids/_history.html.erb b/app/views/bids/_history.html.erb index 494511e54..577685e01 100644 --- a/app/views/bids/_history.html.erb +++ b/app/views/bids/_history.html.erb @@ -11,14 +11,14 @@ <% if journals.size >0 %> -<% remove_allowed = (User.current.id == journals.first.jour_id) %> + <% for journal in journals%>
<%= link_to image_tag(url_to_avatar(journal.user), :class => "avatar"), user_path(journal.user), :class => "avatar" %> - + @@ -26,17 +26,18 @@ <% if @user==User.current|| User.current.admin? %> - + <%= link_to("删除", {:controller => 'bids', :action => 'destroy', :object_id => journal, :id => bid},:confirm => l(:label_delete_confirm), + :remote => true, :method => 'delete', :class => "delete", :confirm => l(:text_are_you_sure), :title => l(:button_delete)) %> <% else %> -
<%=link_to journal.user, user_path(journal.user)%> <%= l(:label_respond_requirement) %><%= link_to "##{journal.indice}", respond_path(bid), :class => "journal-link" %> <%=link_to journal.user, user_path(journal.user)%> <%= l(:label_respond_requirement) %>

<%= textilizable journal.notes%>

<%= l(:label_bids_published) %> <%= time_tag(journal.created_on).html_safe %> <%= l(:label_bids_published_ago) %><%= link_to(image_tag('comment.png'), {:controller => 'bids', :action => 'new', :id => bid, :journal_id => journal}, :remote => true, + <%= link_to("引用", {:controller => 'bids', :action => 'new', :id => bid, :journal_id => journal}, :remote => true, :method => 'post', :title => l(:button_quote))%> - <%= link_to(image_tag('delete.png'), {:controller => 'bids', :action => 'destroy', :object_id => journal, :id => bid},:confirm => l(:label_delete_confirm), - :remote => true, :method => 'delete', :class => "delete", :confirm => l(:text_are_you_sure), :title => l(:button_delete)) if remove_allowed || journal.user_id == User.current.id %><%= link_to(image_tag('comment.png'), {:controller => 'bids', :action => 'new', :id => bid, :journal_id => journal}, :remote => true, + <%= link_to("引用", {:controller => 'bids', :action => 'new', :id => bid, :journal_id => journal}, :remote => true, :method => 'post', :title => l(:button_quote))%> <% end %>
+
<% end %> <% end %> diff --git a/app/views/layouts/base_users.html.erb b/app/views/layouts/base_users.html.erb index 635120f85..ddd2b8370 100644 --- a/app/views/layouts/base_users.html.erb +++ b/app/views/layouts/base_users.html.erb @@ -123,11 +123,9 @@
- <% if @user == User.current %> - <%= render_menu :user_menu_self %> - <%else%> + <%= render_menu :user_menu %> - <%end%> +
<%= yield %> <%= call_hook :view_layouts_base_content %> diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index 30abc6503..cfe367feb 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -1,3 +1,7 @@ +<% if User.current.id == @user.id%> +<%= show_activity @state%> +<% end %> +<% unless @state == 2%> <% unless @activity.empty? %>
<% @activity.each do |e| %> @@ -75,6 +79,23 @@ <%= textilizable act.content %>

+ + +
+ <% when 'Principal' %> + + <% if e.user == User.current%> + <%= link_to("#{l(:label_i)}", user_path(e.user_id)) %>新建了用户 + <% else %> + <%= link_to(h(e.user), user_path(e.user_id)) %>新建了用户 + <% end %> + + + +

+ +

+
@@ -142,4 +163,63 @@ <%= l(:label_user_activities_other) %>

<% end %> -<% end %> \ No newline at end of file +<% end %> +<% else %> + +<% unless @message.empty? %> +
+ <% @message.each do |e| -%> + + + + + + +
<%= link_to image_tag(url_to_avatar(e.user), :class => "avatar"), user_path(e.user), :class => "avatar" %> + + + + + + + + + + + + +
<%= link_to(h(e.user), user_path(e.user)) %> + <% if e.instance_of?(JournalsForMessage)%> + <% if e.reply_id == User.current.id%> + <%if e.jour_type == 'Bid'%> + <%= l(:label_in_bids)%><%= link_to(e.jour.name, respond_path(e.jour))%><%= l(:label_quote_my_words) %> + <% else %> + <%= l(:label_in_users)%><%= link_to(e.jour.firstname, feedback_path(e.jour))%><%= l(:label_quote_my_words) %> + <% end %> + <% else %> + <%= l(:label_about_requirement) %><%= link_to(e.jour.name, respond_path(e.jour_id))%><%= l(:label_have_respond) %> + <% end %> + <% else %> + <% if e.journal_reply.nil? || e.journal_reply.reply_id != User.current.id %> + <%= l(:label_about_issue) %><%= link_to(e.issue.subject, issue_path(e.journalized_id))%><%= l(:label_have_respond) %> + + <% else %> + <%= l(:label_in_issues)%><%= link_to(e.issue.subject, issue_path(e.issue))%><%= l(:label_quote_my_words) %> + <% end %> + <% end %>
+

+ <%= textilizable e.notes %> +

<%= format_time e.created_on %>
+ <% end %> +
+ +<% else %> +

<%= l(:label_no_user_respond_you) %>

+<% end %> + + +<% end %> diff --git a/app/views/words/_message.html.erb b/app/views/words/_message.html.erb index a8fbb98cc..d8f3666b2 100644 --- a/app/views/words/_message.html.erb +++ b/app/views/words/_message.html.erb @@ -21,12 +21,12 @@ <%= format_time journal.created_on %> <% if @user == User.current %> - <%= link_to(image_tag('comment.png'), {:controller => 'words', :action => 'new', :id => user, :journal_id => journal}, :remote => true, + <%= link_to("引用", {:controller => 'words', :action => 'new', :id => user, :journal_id => journal}, :remote => true, :method => 'post', :title => l(:button_quote))%> - <%= link_to(image_tag('delete.png'), {:controller => 'words', :action => 'destroy', :object_id => journal, :user_id => user}, + <%= link_to("删除", {:controller => 'words', :action => 'destroy', :object_id => journal, :user_id => user}, :remote => true, :confirm => l(:text_are_you_sure), :method => 'delete', :class => "delete", :title => l(:button_delete)) if remove_allowed || journal.jour_id == User.current.id %> <% else %> - <%= link_to(image_tag('comment.png'), {:controller => 'words', :action => 'new', :id => user, :journal_id => journal}, :remote => true, + <%= link_to("引用", {:controller => 'words', :action => 'new', :id => user, :journal_id => journal}, :remote => true, :method => 'post', :title => l(:button_quote))%> <% end %>