diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb
index e7db204..815edb8 100644
--- a/app/controllers/projects_controller.rb
+++ b/app/controllers/projects_controller.rb
@@ -91,7 +91,7 @@ class ProjectsController < ApplicationController
@custom_fields = IssueCustomField.find(:all)
@issue_category ||= IssueCategory.new
@member ||= @project.members.new
- @roles = Role.find(:all)
+ @roles = Role.find(:all, :order => 'position')
@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) }
end
diff --git a/app/controllers/roles_controller.rb b/app/controllers/roles_controller.rb
index 9e26a69..6ac08a7 100644
--- a/app/controllers/roles_controller.rb
+++ b/app/controllers/roles_controller.rb
@@ -18,6 +18,9 @@
class RolesController < ApplicationController
layout 'base'
before_filter :require_admin
+
+ verify :method => :post, :only => [ :destroy, :move ],
+ :redirect_to => { :action => :list }
def index
list
@@ -25,7 +28,7 @@ class RolesController < ApplicationController
end
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?
end
@@ -62,6 +65,21 @@ class RolesController < ApplicationController
redirect_to :action => 'list'
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
@role = Role.find_by_id(params[:role_id])
@tracker = Tracker.find_by_id(params[:tracker_id])
@@ -77,7 +95,7 @@ class RolesController < ApplicationController
flash[:notice] = l(:notice_successful_update)
end
end
- @roles = Role.find :all
+ @roles = Role.find(:all, :order => 'position')
@trackers = Tracker.find :all
@statuses = IssueStatus.find(:all, :include => :workflows, :order => 'position')
end
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
index 14f8ecf..4ddbe05 100644
--- a/app/controllers/users_controller.rb
+++ b/app/controllers/users_controller.rb
@@ -80,7 +80,7 @@ class UsersController < ApplicationController
end
end
@auth_sources = AuthSource.find(:all)
- @roles = Role.find :all
+ @roles = Role.find(:all, :order => 'position')
@projects = Project.find(:all) - @user.projects
@membership ||= Member.new
end
diff --git a/app/models/role.rb b/app/models/role.rb
index aea402f..d00a2b2 100644
--- a/app/models/role.rb
+++ b/app/models/role.rb
@@ -20,6 +20,7 @@ class Role < ActiveRecord::Base
has_and_belongs_to_many :permissions
has_many :workflows, :dependent => :delete_all
has_many :members
+ acts_as_list
validates_presence_of :name
validates_uniqueness_of :name
diff --git a/app/views/projects/list_members.rhtml b/app/views/projects/list_members.rhtml
index 655abb2..d7b6c5b 100644
--- a/app/views/projects/list_members.rhtml
+++ b/app/views/projects/list_members.rhtml
@@ -1,10 +1,10 @@
<%=l(:label_member_plural)%>
<% members = @members.group_by {|m| m.role } %>
-<% members.each do |role, member| %>
+<% members.keys.sort{|x,y| x.position <=> y.position}.each do |role| %>
<%= role.name %>
-<% member.each do |m| %>
+<% members[role].each do |m| %>
- <%= link_to m.user.display_name, :controller => 'account', :action => 'show', :id => m.user %> (<%= format_date m.created_on %>)
<% end %>
diff --git a/app/views/projects/settings.rhtml b/app/views/projects/settings.rhtml
index 9299ce4..8a891c0 100644
--- a/app/views/projects/settings.rhtml
+++ b/app/views/projects/settings.rhtml
@@ -23,7 +23,7 @@
<%= l(:label_user) %> | <%= l(:label_role) %> | |
- <% 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? %>
<%= member.user.display_name %> |
diff --git a/app/views/roles/list.rhtml b/app/views/roles/list.rhtml
index 141d758..c6c4492 100644
--- a/app/views/roles/list.rhtml
+++ b/app/views/roles/list.rhtml
@@ -7,6 +7,7 @@
<%=l(:label_role)%> |
+ <%=l(:button_sort)%> |
|
@@ -14,6 +15,12 @@
">
<%= link_to role.name, :action => 'edit', :id => role %> |
+ <%= 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) %>
+ |
+
<%= button_to l(:button_delete), { :action => 'destroy', :id => role }, :confirm => l(:text_are_you_sure), :class => "button-small" %>
|
<% end %>
diff --git a/db/migrate/020_add_role_position.rb b/db/migrate/020_add_role_position.rb
new file mode 100644
index 0000000..3afa881
--- /dev/null
+++ b/db/migrate/020_add_role_position.rb
@@ -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
diff --git a/doc/CHANGELOG b/doc/CHANGELOG
index 34381a0..66d513e 100644
--- a/doc/CHANGELOG
+++ b/doc/CHANGELOG
@@ -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)
* 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
-* 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
* 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