From 671a0fa10161ead2ec0fef888710cf7d872b2f61 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Wed, 31 Jan 2007 20:57:01 +0000 Subject: [PATCH] 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 --- app/controllers/projects_controller.rb | 2 +- app/controllers/roles_controller.rb | 22 ++++++++++++++++++++-- app/controllers/users_controller.rb | 2 +- app/models/role.rb | 1 + app/views/projects/list_members.rhtml | 4 ++-- app/views/projects/settings.rhtml | 2 +- app/views/roles/list.rhtml | 7 +++++++ db/migrate/020_add_role_position.rb | 10 ++++++++++ doc/CHANGELOG | 2 +- 9 files changed, 44 insertions(+), 8 deletions(-) create mode 100644 db/migrate/020_add_role_position.rb diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index e7db204ed..815edb87d 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 9e26a6996..6ac08a767 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 14f8ecff3..4ddbe0548 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 aea402f46..d00a2b218 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 655abb280..d7b6c5bcb 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 %>

diff --git a/app/views/projects/settings.rhtml b/app/views/projects/settings.rhtml index 9299ce49c..8a891c010 100644 --- a/app/views/projects/settings.rhtml +++ b/app/views/projects/settings.rhtml @@ -23,7 +23,7 @@ - <% 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? %> diff --git a/app/views/roles/list.rhtml b/app/views/roles/list.rhtml index 141d75873..c6c4492b3 100644 --- a/app/views/roles/list.rhtml +++ b/app/views/roles/list.rhtml @@ -7,12 +7,19 @@
<%= l(:label_user) %><%= l(:label_role) %>
<%= member.user.display_name %>
+ <% for role in @roles %> "> + diff --git a/db/migrate/020_add_role_position.rb b/db/migrate/020_add_role_position.rb new file mode 100644 index 000000000..3afa88193 --- /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 34381a04a..66d513e65 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
<%=l(:label_role)%><%=l(:button_sort)%>
<%= 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" %>