Commit 671a0fa1 authored by Jean-Philippe Lang's avatar Jean-Philippe Lang

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
parent 99f006f2
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
<h2><%=l(:label_member_plural)%></h2>
<% 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>
<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>
<% end %>
</ul>
......
......@@ -23,7 +23,7 @@
<table class="list">
<thead><th><%= l(:label_user) %></th><th><%= l(:label_role) %></th><th></th></thead>
<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? %>
<tr class="<%= cycle 'odd', 'even' %>">
<td><%= member.user.display_name %></td>
......
......@@ -7,12 +7,19 @@
<table class="list">
<thead><tr>
<th><%=l(:label_role)%></th>
<th><%=l(:button_sort)%></th>
<th></th>
</tr></thead>
<tbody>
<% for role in @roles %>
<tr class="<%= cycle("odd", "even") %>">
<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">
<%= button_to l(:button_delete), { :action => 'destroy', :id => role }, :confirm => l(:text_are_you_sure), :class => "button-small" %>
</tr>
......
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
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment