added the ability to set the sort order for roles

git-svn-id: http://redmine.rubyforge.org/svn/trunk@208 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2007-01-31 20:57:01 +00:00
parent 99f006f2c9
commit 671a0fa101
9 changed files with 44 additions and 8 deletions

View File

@ -91,7 +91,7 @@ class ProjectsController < ApplicationController
@custom_fields = IssueCustomField.find(:all) @custom_fields = IssueCustomField.find(:all)
@issue_category ||= IssueCategory.new @issue_category ||= IssueCategory.new
@member ||= @project.members.new @member ||= @project.members.new
@roles = Role.find(:all) @roles = Role.find(:all, :order => 'position')
@users = User.find_active(:all) - @project.users @users = User.find_active(:all) - @project.users
@custom_values ||= ProjectCustomField.find(:all).collect { |x| @project.custom_values.find_by_custom_field_id(x.id) || CustomValue.new(:custom_field => x) } @custom_values ||= ProjectCustomField.find(:all).collect { |x| @project.custom_values.find_by_custom_field_id(x.id) || CustomValue.new(:custom_field => x) }
end end

View File

@ -18,6 +18,9 @@
class RolesController < ApplicationController class RolesController < ApplicationController
layout 'base' layout 'base'
before_filter :require_admin before_filter :require_admin
verify :method => :post, :only => [ :destroy, :move ],
:redirect_to => { :action => :list }
def index def index
list list
@ -25,7 +28,7 @@ class RolesController < ApplicationController
end end
def list def list
@role_pages, @roles = paginate :roles, :per_page => 10 @role_pages, @roles = paginate :roles, :per_page => 10, :order => "position"
render :action => "list", :layout => false if request.xhr? render :action => "list", :layout => false if request.xhr?
end end
@ -62,6 +65,21 @@ class RolesController < ApplicationController
redirect_to :action => 'list' redirect_to :action => 'list'
end end
def move
@role = Role.find(params[:id])
case params[:position]
when 'highest'
@role.move_to_top
when 'higher'
@role.move_higher
when 'lower'
@role.move_lower
when 'lowest'
@role.move_to_bottom
end if params[:position]
redirect_to :action => 'list'
end
def workflow def workflow
@role = Role.find_by_id(params[:role_id]) @role = Role.find_by_id(params[:role_id])
@tracker = Tracker.find_by_id(params[:tracker_id]) @tracker = Tracker.find_by_id(params[:tracker_id])
@ -77,7 +95,7 @@ class RolesController < ApplicationController
flash[:notice] = l(:notice_successful_update) flash[:notice] = l(:notice_successful_update)
end end
end end
@roles = Role.find :all @roles = Role.find(:all, :order => 'position')
@trackers = Tracker.find :all @trackers = Tracker.find :all
@statuses = IssueStatus.find(:all, :include => :workflows, :order => 'position') @statuses = IssueStatus.find(:all, :include => :workflows, :order => 'position')
end end

View File

@ -80,7 +80,7 @@ class UsersController < ApplicationController
end end
end end
@auth_sources = AuthSource.find(:all) @auth_sources = AuthSource.find(:all)
@roles = Role.find :all @roles = Role.find(:all, :order => 'position')
@projects = Project.find(:all) - @user.projects @projects = Project.find(:all) - @user.projects
@membership ||= Member.new @membership ||= Member.new
end end

View File

@ -20,6 +20,7 @@ class Role < ActiveRecord::Base
has_and_belongs_to_many :permissions has_and_belongs_to_many :permissions
has_many :workflows, :dependent => :delete_all has_many :workflows, :dependent => :delete_all
has_many :members has_many :members
acts_as_list
validates_presence_of :name validates_presence_of :name
validates_uniqueness_of :name validates_uniqueness_of :name

View File

@ -1,10 +1,10 @@
<h2><%=l(:label_member_plural)%></h2> <h2><%=l(:label_member_plural)%></h2>
<% members = @members.group_by {|m| m.role } %> <% members = @members.group_by {|m| m.role } %>
<% members.each do |role, member| %> <% members.keys.sort{|x,y| x.position <=> y.position}.each do |role| %>
<h3><%= role.name %></h3> <h3><%= role.name %></h3>
<ul> <ul>
<% member.each do |m| %> <% members[role].each do |m| %>
<li><%= link_to m.user.display_name, :controller => 'account', :action => 'show', :id => m.user %> (<%= format_date m.created_on %>)</li> <li><%= link_to m.user.display_name, :controller => 'account', :action => 'show', :id => m.user %> (<%= format_date m.created_on %>)</li>
<% end %> <% end %>
</ul> </ul>

View File

@ -23,7 +23,7 @@
<table class="list"> <table class="list">
<thead><th><%= l(:label_user) %></th><th><%= l(:label_role) %></th><th></th></thead> <thead><th><%= l(:label_user) %></th><th><%= l(:label_role) %></th><th></th></thead>
<tbody> <tbody>
<% for member in @project.members.find(:all, :include => :user) %> <% @project.members.find(:all, :include => [:role, :user]).sort{|x,y| x.role.position <=> y.role.position}.each do |member| %>
<% unless member.new_record? %> <% unless member.new_record? %>
<tr class="<%= cycle 'odd', 'even' %>"> <tr class="<%= cycle 'odd', 'even' %>">
<td><%= member.user.display_name %></td> <td><%= member.user.display_name %></td>

View File

@ -7,12 +7,19 @@
<table class="list"> <table class="list">
<thead><tr> <thead><tr>
<th><%=l(:label_role)%></th> <th><%=l(:label_role)%></th>
<th><%=l(:button_sort)%></th>
<th></th> <th></th>
</tr></thead> </tr></thead>
<tbody> <tbody>
<% for role in @roles %> <% for role in @roles %>
<tr class="<%= cycle("odd", "even") %>"> <tr class="<%= cycle("odd", "even") %>">
<td><%= link_to role.name, :action => 'edit', :id => role %></td> <td><%= link_to role.name, :action => 'edit', :id => role %></td>
<td align="center">
<%= link_to image_tag('2uparrow.png', :alt => l(:label_sort_highest)), {:action => 'move', :id => role, :position => 'highest'}, :method => :post, :title => l(:label_sort_highest) %>
<%= link_to image_tag('1uparrow.png', :alt => l(:label_sort_higher)), {:action => 'move', :id => role, :position => 'higher'}, :method => :post, :title => l(:label_sort_higher) %> -
<%= link_to image_tag('1downarrow.png', :alt => l(:label_sort_lower)), {:action => 'move', :id => role, :position => 'lower'}, :method => :post, :title => l(:label_sort_lower) %>
<%= link_to image_tag('2downarrow.png', :alt => l(:label_sort_lowest)), {:action => 'move', :id => role, :position => 'lowest'}, :method => :post, :title => l(:label_sort_lowest) %>
</td>
<td align="center"> <td align="center">
<%= button_to l(:button_delete), { :action => 'destroy', :id => role }, :confirm => l(:text_are_you_sure), :class => "button-small" %> <%= button_to l(:button_delete), { :action => 'destroy', :id => role }, :confirm => l(:text_are_you_sure), :class => "button-small" %>
</tr> </tr>

View File

@ -0,0 +1,10 @@
class AddRolePosition < ActiveRecord::Migration
def self.up
add_column :roles, :position, :integer, :default => 1, :null => false
Role.find(:all).each_with_index {|role, i| role.update_attribute(:position, i+1)}
end
def self.down
remove_column :roles, :position
end
end

View File

@ -11,7 +11,7 @@ http://redmine.rubyforge.org/
* settings are now stored in the database and editable through the application in: Admin -> Settings (config_custom.rb is no longer used) * settings are now stored in the database and editable through the application in: Admin -> Settings (config_custom.rb is no longer used)
* mail notifications added when a document, a file or an attachment is added * mail notifications added when a document, a file or an attachment is added
* tooltips added on Gantt chart and calender to view the details of the issues * tooltips added on Gantt chart and calender to view the details of the issues
* ability to set the sort order for issue statuses * ability to set the sort order for roles, issue statuses
* added missing fields to csv export: priority, start date, due date, done ratio * added missing fields to csv export: priority, start date, due date, done ratio
* all icons replaced (new icons are based on GPL icon set: "KDE Crystal Diamond 2.5" -by paolino- and "kNeu! Alpha v0.1" -by Pablo Fabregat-) * all icons replaced (new icons are based on GPL icon set: "KDE Crystal Diamond 2.5" -by paolino- and "kNeu! Alpha v0.1" -by Pablo Fabregat-)
* added back "fixed version" field on issue screen and in filters * added back "fixed version" field on issue screen and in filters