From de32745eefcfdfd9979a0fef1d5618867876075f Mon Sep 17 00:00:00 2001 From: ouyangxuhua Date: Mon, 16 Nov 2015 15:02:57 +0800 Subject: [PATCH] =?UTF-8?q?1.=E5=B0=86=E9=A1=B9=E7=9B=AE=E5=8A=A8=E6=80=81?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E8=BF=81=E7=A7=BB=E8=87=B3=E7=BB=84=E7=BB=87?= =?UTF-8?q?=E5=8A=A8=E6=80=81=EF=BC=9B=202.=E5=9C=A8=E7=BB=84=E7=BB=87?= =?UTF-8?q?=E5=8A=A8=E6=80=81=E4=B8=AD=EF=BC=8C=E6=8C=89=E6=97=B6=E9=97=B4?= =?UTF-8?q?=E5=80=92=E6=8E=92=E6=98=BE=E7=A4=BA=E7=BB=84=E7=BB=87=E5=8A=A8?= =?UTF-8?q?=E6=80=81=EF=BC=9B=203.=E5=A2=9E=E5=8A=A0=E6=88=91=E7=9A=84?= =?UTF-8?q?=E7=BB=84=E7=BB=87=E4=B8=AD=E6=90=9C=E7=B4=A2=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/organizations_controller.rb | 20 +++---- app/controllers/users_controller.rb | 14 +++++ app/models/forge_activity.rb | 12 +++- .../organizations/_org_activities.html.erb | 56 +++++++++++++++++++ app/views/organizations/show.html.erb | 44 ++------------- app/views/organizations/show.js.erb | 7 +-- app/views/users/_show_user_org.html.erb | 39 +++++++++++++ app/views/users/search_user_orgs.html.erb | 1 + app/views/users/search_user_orgs.js.erb | 2 + app/views/users/user_organizations.html.erb | 46 ++++++++------- config/routes.rb | 1 + ...copy_forge_activities_to_org_activities.rb | 16 ++++++ 12 files changed, 183 insertions(+), 75 deletions(-) create mode 100644 app/views/organizations/_org_activities.html.erb create mode 100644 app/views/users/_show_user_org.html.erb create mode 100644 app/views/users/search_user_orgs.html.erb create mode 100644 app/views/users/search_user_orgs.js.erb create mode 100644 db/migrate/20151116020842_copy_forge_activities_to_org_activities.rb diff --git a/app/controllers/organizations_controller.rb b/app/controllers/organizations_controller.rb index b75742164..6a1030adc 100644 --- a/app/controllers/organizations_controller.rb +++ b/app/controllers/organizations_controller.rb @@ -55,22 +55,22 @@ class OrganizationsController < ApplicationController def show if @organization.is_public? || User.current.admin? || User.current.member_of_org?(@organization) @organization = Organization.find(params[:id]) - @org_activities = OrgActivity.where('container_id =? and container_type =? ', - @organization.id, 'Organization ').order('updated_at desc').page(params[:page]).per(10) - @org_activities_count = OrgActivity.where('container_id =? and container_type =? ', - @organization.id, 'Organization ').order('updated_at desc').count project_ids = @organization.projects.map(&:id) << 0 - @org_project_activties = ForgeActivity.where("project_id in (#{project_ids.join(',')}) and forge_act_type in('Issue','Message','ProjectCreateInfo')").order("updated_at desc").page(params[:page] || 1).per(10) - @org_project_activties_count = ForgeActivity.where('project_id in (?)',project_ids.join(',')).count + @org_activities = OrgActivity.where("(container_id =? and container_type =?) or (container_type ='Project' and container_id in (#{project_ids.join(',')}))", + @organization.id, 'Organization').order('updated_at desc').page(params[:page] || 1).per(10) + @org_activities_count = OrgActivity.where("(container_id =? and container_type =?) or (container_type ='Project' and container_id in (#{project_ids.join(',')}))" , + @organization.id, 'Organization ').count + # @org_project_activties = ForgeActivity.where("project_id in (#{project_ids.join(',')}) and forge_act_type in('Issue','Message','ProjectCreateInfo')").order("updated_at desc").page(params[:page] || 1).per(10) + # @org_project_activties_count = ForgeActivity.where('project_id in (?)',project_ids.join(',')).count #@org_activities = paginateHelper @org_activities, 10 @page = params[:page] + respond_to do |format| + format.html + format.js + end else render_403 end - respond_to do |format| - format.html - format.js - end end def update diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 273d48ccf..776e6b7d5 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1918,6 +1918,20 @@ class UsersController < ApplicationController end end + def search_user_orgs + name="" + if !params[:search_orgs].nil? + name = params[:search_orgs].strip + end + name = "%"+name+"%" + @orgs = User.current.organizations.where("name like ?", name) + @user = User.current + respond_to do |format| + format.html {render :layout => 'static_base'} + format.js + end + end + private def find_user diff --git a/app/models/forge_activity.rb b/app/models/forge_activity.rb index c4f13c6d0..8a94f1019 100644 --- a/app/models/forge_activity.rb +++ b/app/models/forge_activity.rb @@ -20,7 +20,7 @@ class ForgeActivity < ActiveRecord::Base validates :forge_act_id,presence: true validates :forge_act_type, presence: true has_many :user_acts, :class_name => 'UserAcivity',:as =>:act - after_save :add_user_activity + after_save :add_user_activity, :add_org_activity before_destroy :destroy_user_activity #在个人动态里面增加当前动态 @@ -45,6 +45,16 @@ class ForgeActivity < ActiveRecord::Base end end + def add_org_activity + OrgActivity.create(:user_id => self.user_id, + :org_act_id => self.forge_act_id, + :org_act_type => self.forge_act_type, + :container_id => self.project_id, + :container_type => 'Project', + :created_at => self.created_at, + :updated_at => self.updated_at) + end + def destroy_user_activity user_activity = UserActivity.where("act_type = '#{self.forge_act_type.to_s}' and act_id = '#{self.forge_act_id}'") user_activity.destroy_all diff --git a/app/views/organizations/_org_activities.html.erb b/app/views/organizations/_org_activities.html.erb new file mode 100644 index 000000000..cb69738b6 --- /dev/null +++ b/app/views/organizations/_org_activities.html.erb @@ -0,0 +1,56 @@ +<% unless org_activities.nil? %> + <% org_activities.each do |act| %> + <% if act.container_type == 'Organization' %> + <% if act.org_act_type == 'CreateOrganization' %> +
+
+ +
+
<%= link_to User.find(act.user_id), user_path(act.user_id) %>  创建了 <%= Organization.find(act.org_act_id).name %> + | 组织
+
创建时间:<%= format_activity_day(act.created_at) %> <%= format_time(act.created_at, false) %>
+
+
+
+
+ <% end %> + <% if act.org_act_type == 'OrgDocumentComment' && act.org_act_id != @organization.home_id %> + + <%= render :partial => 'show_org_document', :locals => {:document => act.org_act} %> + <% end %> + <% end %> + <% if act.container_type == 'Project' %> + <% case act.org_act_type.to_s %> + <% when 'Issue' %> + <%= render :partial => 'organizations/org_project_issue', :locals => {:activity => Issue.find(act.org_act_id),:user_activity_id =>act.id} %> + <% when 'Message' %> + <%= render :partial => 'organizations/project_message', :locals => {:activity => Message.find(act.org_act_id),:user_activity_id =>act.id} %> + <%# when 'ProjectCreateInfo'%> + <%#= render :partial => 'organizations/project_create', :locals => {:activity => act,:user_activity_id =>act.id} %> + <% end %> + <% end %> + <% end %> + + <%#= pagination_links_full @obj_pages, @obj_count, :per_page_links => false, :remote => false, :flag => true%> + +<% end %> + +<% if org_act_count == 10 %> +
展开更多<%=link_to "", organization_path(org,:page => page.to_i + 1),:id => "more_org_activities_link",:remote => "true",:class => "none" %>
+ <%#= link_to "点击展开更多",user_activities_path(@user.id,:type => type,:page => page),:id => "show_more_activities",:remote => "true",:class => "loadMore mt10 f_grey"%> +<% end%> + + \ No newline at end of file diff --git a/app/views/organizations/show.html.erb b/app/views/organizations/show.html.erb index 0b624d479..a85ffa687 100644 --- a/app/views/organizations/show.html.erb +++ b/app/views/organizations/show.html.erb @@ -30,49 +30,15 @@ init_activity_KindEditor_data(<%= @organization.home_id%>, null, "87%"); }); - <%= render :partial => 'show_org_document', :locals => {:document => OrgDocumentComment.find(@organization.home_id), :home_id => @organization.home_id} %> <% end %> - <% unless @org_activities.nil? %> - <% @org_activities.each do |act| %> - <% if act.org_act_type == 'CreateOrganization' %> -
-
- -
-
<%= link_to User.find(act.user_id), user_path(act.user_id) %>  创建了 <%= Organization.find(act.org_act_id).name %> - | 组织
-
创建时间:<%= format_activity_day(act.created_at) %> <%= format_time(act.created_at, false) %>
-
-
-
-
- <% end %> - <% if act.org_act_type == 'OrgDocumentComment' && act.org_act_id != @organization.home_id %> - - <%= render :partial => 'show_org_document', :locals => {:document => act.org_act} %> - <% end %> - <% end %> - - <%#= pagination_links_full @obj_pages, @obj_count, :per_page_links => false, :remote => false, :flag => true%> - - <% end %> +<%= render :partial => 'organizations/org_activities', + :locals => {:org_activities =>@org_activities, + :page=>@page, + :org => @organization, + :org_act_count=>@org_activities.count}%> - <%# @org_project_activties.each do |org_act|%> - <%= render :partial => 'organizations/org_project_activities', - :locals => {:org_project_activties =>@org_project_activties, - :page=>@page, - :org => @organization, - :org_act_count=>@org_activities.count, - :pro_act_count=>@org_project_activties.count}%> - <%# end %> diff --git a/app/views/organizations/show.js.erb b/app/views/organizations/show.js.erb index b0a447910..ee405d73c 100644 --- a/app/views/organizations/show.js.erb +++ b/app/views/organizations/show.js.erb @@ -1,7 +1,6 @@ -$("#show_more_activities").replaceWith("<%= escape_javascript( render :partial => 'organizations/org_project_activities', - :locals => {:org_project_activties =>@org_project_activties, +$("#show_more_activities").replaceWith("<%= escape_javascript( render :partial => 'organizations/org_activities', + :locals => {:org_activities =>@org_activities, :page=>@page, :org => @organization, - :org_act_count=>@org_activities.count, - :pro_act_count=>@org_project_activties.count} )%>"); + :org_act_count=>@org_activities.count} )%>"); diff --git a/app/views/users/_show_user_org.html.erb b/app/views/users/_show_user_org.html.erb new file mode 100644 index 000000000..e753092fa --- /dev/null +++ b/app/views/users/_show_user_org.html.erb @@ -0,0 +1,39 @@ +<%= stylesheet_link_tag 'pleft','header','new_user','repository','org', 'project' %> +<%#= stylesheet_link_tag 'pleft','prettify','jquery/jquery-ui-1.9.2','header','new_user','repository','org' %> +
+
+
+
+ 组织列表 + + <%= form_tag url_for(:controller => 'users', :action => 'search_user_orgs', :id => User.current.id), :method => 'get', :id => "search_org_form", :class=>"resourcesSearchloadBox", :style=>"float:right; margin-top:-5px;" do %> + + + + 搜索 + <% end %> +
+
+
+ <% orgs.each do |org| %> +
+
+ <%= link_to image_tag(url_to_avatar(org), :width => '78', :height => '78', :alt => '组织logo'), organization_path(org), :class => "linkGrey2" %> +
+
+
+ <%= link_to org.name, organization_path(org), :class => 'f16 linkBlue' %> +
+
<%= org.description %>
+
创建者:<%= link_to User.find(org.creator_id), user_path(org.creator_id), :class => 'linkGrey2', :target => '_blank' %>
+ +
您的身份:<%= User.current.admin_of_org?(org) ? "组织管理员" : "组织成员" %>
+
+ +
+
+ <% end %> +
+
+
+
\ No newline at end of file diff --git a/app/views/users/search_user_orgs.html.erb b/app/views/users/search_user_orgs.html.erb new file mode 100644 index 000000000..1a921d38e --- /dev/null +++ b/app/views/users/search_user_orgs.html.erb @@ -0,0 +1 @@ +<%= render :partial => 'show_user_org', :locals => {:orgs => @orgs} %> \ No newline at end of file diff --git a/app/views/users/search_user_orgs.js.erb b/app/views/users/search_user_orgs.js.erb new file mode 100644 index 000000000..7184a29c5 --- /dev/null +++ b/app/views/users/search_user_orgs.js.erb @@ -0,0 +1,2 @@ + +//$("#org_list").replaceWith("<%#= escape_javascript(render :partial => 'show_user_org', :locals => {:orgs => @orgs}) %>") \ No newline at end of file diff --git a/app/views/users/user_organizations.html.erb b/app/views/users/user_organizations.html.erb index 50fa03bbe..e2a24b2aa 100644 --- a/app/views/users/user_organizations.html.erb +++ b/app/views/users/user_organizations.html.erb @@ -1,4 +1,4 @@ -<%= stylesheet_link_tag 'pleft','header','new_user','repository','org' %> +<%= stylesheet_link_tag 'pleft','header','new_user','repository','org', 'project' %> <%#= stylesheet_link_tag 'pleft','prettify','jquery/jquery-ui-1.9.2','header','new_user','repository','org' %>
@@ -6,30 +6,34 @@
组织列表 - - - - + <%= form_tag url_for(:controller => 'users', :action => 'search_user_orgs', :id => User.current.id), :method => 'get', :id => "search_org_form", :class=>"resourcesSearchloadBox", :style=>"float:right; margin-top:-5px;" do %> + + + + 搜索 + <% end %>
- <% @orgs.each do |org| %> -
-
- <%= link_to image_tag(url_to_avatar(org), :width => '78', :height => '78', :alt => '组织logo'), organization_path(org), :class => "linkGrey2" %> -
-
-
- <%= link_to org.name, organization_path(org), :class => 'f16 linkBlue' %> +
+ <% @orgs.each do |org| %> +
+
+ <%= link_to image_tag(url_to_avatar(org), :width => '78', :height => '78', :alt => '组织logo'), organization_path(org), :class => "linkGrey2" %>
-
<%= org.description %>
-
创建者:<%= link_to User.find(org.creator_id), user_path(org.creator_id), :class => 'linkGrey2', :target => '_blank' %>
- -
您的身份:<%= User.current.admin_of_org?(org) ? "组织管理员" : "组织成员" %>
+
+
+ <%= link_to org.name, organization_path(org), :class => 'f16 linkBlue' %> +
+
<%= org.description %>
+
创建者:<%= link_to User.find(org.creator_id), user_path(org.creator_id), :class => 'linkGrey2', :target => '_blank' %>
+ +
您的身份:<%= User.current.admin_of_org?(org) ? "组织管理员" : "组织成员" %>
+
+ +
- -
-
- <% end %> + <% end %> +
\ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 0f05c3521..69134e666 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -444,6 +444,7 @@ RedmineApp::Application.routes.draw do get 'dealwith_apply_request' get 'store_selected_resource' get 'user_organizations' + get 'search_user_orgs' # end end #resources :blogs diff --git a/db/migrate/20151116020842_copy_forge_activities_to_org_activities.rb b/db/migrate/20151116020842_copy_forge_activities_to_org_activities.rb new file mode 100644 index 000000000..95c4ed5bf --- /dev/null +++ b/db/migrate/20151116020842_copy_forge_activities_to_org_activities.rb @@ -0,0 +1,16 @@ +class CopyForgeActivitiesToOrgActivities < ActiveRecord::Migration + def up + ForgeActivity.all.each do |forge_act| + OrgActivity.create(:user_id => forge_act.user_id, + :org_act_id => forge_act.forge_act_id, + :org_act_type => forge_act.forge_act_type, + :container_id => forge_act.project_id, + :container_type => 'Project', + :created_at => forge_act.created_at, + :updated_at => forge_act.updated_at) + end + end + + def down + end +end