修改新建项目显示,优化列表显示速度

This commit is contained in:
nieguanghui 2013-08-12 17:11:41 +08:00
parent edf2d39a06
commit c00575ce84
13 changed files with 107 additions and 55 deletions

View File

@ -14,7 +14,6 @@
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
class MembersController < ApplicationController
model_object Member
before_filter :find_model_object, :except => [:index, :create, :autocomplete]
@ -22,7 +21,6 @@ class MembersController < ApplicationController
before_filter :find_project_by_project_id, :only => [:index, :create, :autocomplete]
before_filter :authorize
accept_api_auth :index, :show, :create, :update, :destroy
def index
@offset, @limit = api_offset_and_limit
@member_count = @project.member_principals.count
@ -49,17 +47,32 @@ class MembersController < ApplicationController
def create
members = []
project_info = []
if params[:membership]
if params[:membership][:user_ids]
attrs = params[:membership].dup
user_ids = attrs.delete(:user_ids)
user_ids.each do |user_id|
members << Member.new(:role_ids => params[:membership][:role_ids], :user_id => user_id)
## added by nie
if params[:membership][:role_ids][0] == "3"
project_info << ProjectInfo.new(:user_id => user_id, :project_id => @project.id)
# ProjectInfo.create(:name => "test", :user_id => 123)
end
## end
end
else
members << Member.new(:role_ids => params[:membership][:role_ids], :user_id => params[:membership][:user_id])
## added by nie
if params[:membership][:role_ids][0] == "3"
project_info << Project_info.new(:role_ids => params[:membership][:role_ids], :user_id => params[:membership][:user_id])
end
## end
end
@project.members << members
@project.members << members
# added by nie
@project.project_infos << project_info
# end
end
respond_to do |format|
@ -79,7 +92,21 @@ class MembersController < ApplicationController
def update
if params[:membership]
@member.role_ids = params[:membership][:role_ids]
#added by nie
if params[:membership][:role_ids][0] == "3"
@projectInfo = ProjectInfo.new(:user_id => @member.user_id, :project_id => @project.id)
@projectInfo.save
else
user_admin = ProjectInfo.where("user_id = ? and project_id = ?", @member.user_id, @project.id)
if user_admin.size > 0
user_admin.each do |user|
user.destroy
end
end
end
end
saved = @member.save
respond_to do |format|
format.html { redirect_to_settings_in_projects }
@ -96,7 +123,13 @@ class MembersController < ApplicationController
def destroy
if request.delete? && @member.deletable?
@member.destroy
@member.destroy
end
user_admin = ProjectInfo.where("user_id = ? and project_id = ?", @member.user_id, @project.id)
if user_admin.size > 0
user_admin.each do |user|
user.destroy
end
end
respond_to do |format|
format.html { redirect_to_settings_in_projects }

View File

@ -50,7 +50,6 @@ class ProjectsController < ApplicationController
helper :members
helper :activities
helper :documents
helper :watchers
### added by william
@ -85,8 +84,18 @@ class ProjectsController < ApplicationController
# @project_pages = Paginator.new @project_count, @limit, params['page']
# @offset ||= @project_pages.offset
# @projects = Project.visible.offset(@offset).limit(@limit).order('lft').all
@offset, @limit = api_offset_and_limit({:limit => 10})
@projects = Project.visible
# @projects.each do |project|
# @admin = project.users_by_role[Role.find(3)]
# unless @admin.nil?
# @admin.each do |user|
# ProjectInfo.create(:user_id => user.id, :project_id => project.id)
# end
#
# end
# end
@projects = Project.visible.like(params[:name]) if params[:name].present?
@project_count = @projects.count
@project_pages = Paginator.new @project_count, @limit, params['page']

View File

@ -2,7 +2,6 @@
class TagsController < ApplicationController
before_filter :require_admin,:only => :show
include ProjectsHelper
include IssuesHelper
include UsersHelper
@ -10,7 +9,6 @@ class TagsController < ApplicationController
$selected_tags = Array.new
$related_tags = Array.new
def index
$selected_tags = []
@ -26,17 +24,13 @@ class TagsController < ApplicationController
@users_results = get_users_by_tag($selected_tags)
@obj_id = params[:obj_id]
@show_flag = params[:object_flag]
case @show_flag
case params[:object_flag]
when '1' then
@obj = User.find_by_id(@obj_id)
when '2' then
@obj = Project.find_by_id(@obj_id)
when '3' then
@obj = Issue.find_by_id(@obj_id)
when '4' then
@obj = Bid.find_by_id(@obj_id)
else
@obj = nil
end
@ -80,9 +74,4 @@ class TagsController < ApplicationController
end
def show_all
@tags = ActsAsTaggableOn::Tag.find(:all)
@tags = @tags.to_a
end
end

View File

@ -51,6 +51,9 @@ class Project < ActiveRecord::Base
has_one :repository, :conditions => ["is_default = ?", true]
has_many :repositories, :dependent => :destroy
has_many :changesets, :through => :repository
#ADDED BY NIE
has_many :project_infos, :dependent => :destroy
#end
has_one :wiki, :dependent => :destroy
# Custom field for the project issues
has_and_belongs_to_many :issue_custom_fields,

View File

@ -0,0 +1,8 @@
class ProjectInfo < ActiveRecord::Base
attr_accessible :project_id, :user_id
belongs_to :project
belongs_to :user
validates_presence_of :project_id, :user_id
validates_uniqueness_of :project_id, :scope => :user_id
end

View File

@ -85,6 +85,9 @@ class User < Principal
has_many :activities
#####
######added by nie
has_many :project_infos, :dependent => :destroy
#####
scope :logged, lambda { where("#{User.table_name}.status <> #{STATUS_ANONYMOUS}") }
scope :status, lambda {|arg| where(arg.blank? ? nil : {:status => arg.to_i}) }

View File

@ -26,9 +26,9 @@
<div class="add-info">
<div class="main-language">
<%= content_tag('span', "#{l(:default_role_manager)}: ") %>
<% @admin = @project.users_by_role[Role.find(3)]%>
<% unless @admin.nil?%>
<%= content_tag('a', @admin.sort.collect{|u| link_to_user u}.join(", ").html_safe) %>
<% @admin = @project.project_infos%>
<% if @admin.size > 0 %>
<%= content_tag('a', @admin.collect{|u| link_to(u.user.name, user_path(u.user_id))}.join(", ").html_safe) %>
<% end %>
</div>
<div class="licences">

View File

@ -2,13 +2,16 @@
<%= auto_discovery_link_tag(:atom, {:action => 'index', :format => 'atom', :key => User.current.rss_key}) %>
<% end %>
<div class="contextual" style="padding-top:10px;padding-right:10px;">
<%= link_to(l(:label_project_new), {:controller => 'projects', :action => 'new'}, :class => 'icon icon-add') if User.current.allowed_to?(:add_project, nil, :global => true) %>
</div>
<%= form_tag(projects_path, :method => :get) do %>
<div class="project-search-block">
<span><%=l(:label_project_plural)%></span>
<span style="margin-left:0px"><%=l(:label_project_plural)%></span>
<span class="contextual" style="font-size: 12px; float: none; vertical-align: center; margin-left: 100px">
<%= link_to(l(:label_project_new), {:controller => 'projects', :action => 'new'}, :class => 'icon icon-add') if User.current.allowed_to?(:add_project, nil, :global => true) %>
</span>
<div class="project-search">
<%= text_field_tag 'name', params[:name], :size => 30 %>
<%= submit_tag l(:label_search), :class => "small", :name => nil %>

View File

@ -1,21 +1,4 @@
<style type="text/css">
.tags_left{
width: 30%;
float:left;
}
.tags_right{
padding-top:18px;
width: 68%;
float:right;
}
</style>
<script type="text/javascript" language="JavaScript">
function show_selector(var id){
$('.issues')
}
</script>
<div class="tags_left">
<div class="splitcontentleft">
<ul>
<li>
Selected Tags
@ -32,18 +15,17 @@
</ul>
</div>
<div class="tags_right">
<div class="splitcontentright">
<h2>Search Results</h2>
<div id="filter-menu" align="right">
<%= toggle_link "Project", 'projects' %> (<%= @users_tags_num %>) |
<%= toggle_link "User", 'users' %> (<%= @projects_tags_num %>)|
<%= toggle_link "Issue", 'issues' %> (<%= @issues_tags_num %>)|
<%= link_to "Bid",:action => "index"%> ()|
<%= link_to "All",:action => "index"%> |
<%= link_to "Issue",:action => "index"%>(<%= @issues_tags_num %>)|
<%= link_to "Project",:action => "index"%>(<%= @projects_tags_num %>) |
<%= link_to "User",:action => "index"%>(<%= @users_tags_num %>)
</div>
<div id="show_results">
<!-- 显示规则 0 全部显示 1显示users 2显示projects 3显示issues 4显示需求-->
<%= render :partial => "tag_search_results",:locals => {:issues_results => @issues_results,
:projects_results => @projects_results,:users_results => @users_results,:show_flag => @show_flag } %>
:projects_results => @projects_results,:users_results => @users_results }%>
</div>
</div>

View File

@ -87,7 +87,9 @@
<div class="autoscroll">
<% for user in @users -%>
<% unless user.id == 1%>
<div class="well">
<%= content_tag "p", "#{format_date(user.created_on)}#{l(:label_member_since)}", :class => "float_right member_since" %>
<%= image_tag "/images/time_member.png", :class => "img_member_time"%>
<!-- <%= get_avatar?(user) ? (link_to image_tag(avatar_image(user), :class => 'avatar'), user_path(user), :class => "avatar") : (link_to image_tag("/images/12_50.png", :class => 'avatar'), user_path(user), :class => "avatar") %> -->
@ -111,6 +113,7 @@
</div>
</div>
<% end -%>
<% end -%>
</div>
<div class="pagination">
<ul>

View File

@ -435,8 +435,8 @@ RedmineApp::Application.routes.draw do
match 'bids/:id', :controller => 'bids', :action => 'show', :as => 'respond'
######added by nie
match 'tags/show_projects_tags',:to => 'tags#show_projects_tags'
########### added by liuping
match 'tags/add_tag',:to => 'tags#add_tag',:as=>"add_tag"
match 'tags/delete_tag',:to => 'tags#delete_tag',:as=>"add_tag"

View File

@ -0,0 +1,10 @@
class CreateProjectInfos < ActiveRecord::Migration
def change
create_table :project_infos do |t|
t.string :name
t.integer :project_id
t.integer :user_id
t.timestamps
end
end
end

View File

@ -0,0 +1,9 @@
class DeleteNameFromProjectInfo < ActiveRecord::Migration
def up
remove_column :project_infos, :name
end
def down
add_column :project_infos, :name, :string
end
end