Custom fields can now be reordered.
git-svn-id: http://redmine.rubyforge.org/svn/trunk@901 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
a727f0d25a
commit
5944696b6d
@ -45,7 +45,7 @@ class CustomFieldsController < ApplicationController
|
|||||||
end
|
end
|
||||||
if request.post? and @custom_field.save
|
if request.post? and @custom_field.save
|
||||||
flash[:notice] = l(:notice_successful_create)
|
flash[:notice] = l(:notice_successful_create)
|
||||||
redirect_to :action => 'list', :tab => @custom_field.type
|
redirect_to :action => 'list', :tab => @custom_field.class.name
|
||||||
end
|
end
|
||||||
@trackers = Tracker.find(:all, :order => 'position')
|
@trackers = Tracker.find(:all, :order => 'position')
|
||||||
end
|
end
|
||||||
@ -57,14 +57,29 @@ class CustomFieldsController < ApplicationController
|
|||||||
@custom_field.trackers = params[:tracker_ids] ? Tracker.find(params[:tracker_ids]) : []
|
@custom_field.trackers = params[:tracker_ids] ? Tracker.find(params[:tracker_ids]) : []
|
||||||
end
|
end
|
||||||
flash[:notice] = l(:notice_successful_update)
|
flash[:notice] = l(:notice_successful_update)
|
||||||
redirect_to :action => 'list', :tab => @custom_field.type
|
redirect_to :action => 'list', :tab => @custom_field.class.name
|
||||||
end
|
end
|
||||||
@trackers = Tracker.find(:all, :order => 'position')
|
@trackers = Tracker.find(:all, :order => 'position')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def move
|
||||||
|
@custom_field = CustomField.find(params[:id])
|
||||||
|
case params[:position]
|
||||||
|
when 'highest'
|
||||||
|
@custom_field.move_to_top
|
||||||
|
when 'higher'
|
||||||
|
@custom_field.move_higher
|
||||||
|
when 'lower'
|
||||||
|
@custom_field.move_lower
|
||||||
|
when 'lowest'
|
||||||
|
@custom_field.move_to_bottom
|
||||||
|
end if params[:position]
|
||||||
|
redirect_to :action => 'list', :tab => @custom_field.class.name
|
||||||
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
@custom_field = CustomField.find(params[:id]).destroy
|
@custom_field = CustomField.find(params[:id]).destroy
|
||||||
redirect_to :action => 'list', :tab => @custom_field.type
|
redirect_to :action => 'list', :tab => @custom_field.class.name
|
||||||
rescue
|
rescue
|
||||||
flash[:error] = "Unable to delete custom field"
|
flash[:error] = "Unable to delete custom field"
|
||||||
redirect_to :action => 'list'
|
redirect_to :action => 'list'
|
||||||
|
@ -80,7 +80,7 @@ class IssuesController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
@custom_values = @issue.custom_values.find(:all, :include => :custom_field)
|
@custom_values = @issue.custom_values.find(:all, :include => :custom_field, :order => "#{CustomField.table_name}.position")
|
||||||
@journals = @issue.journals.find(:all, :include => [:user, :details], :order => "#{Journal.table_name}.created_on ASC")
|
@journals = @issue.journals.find(:all, :include => [:user, :details], :order => "#{Journal.table_name}.created_on ASC")
|
||||||
@status_options = @issue.status.find_new_statuses_allowed_to(logged_in_user.role_for_project(@project), @issue.tracker) if logged_in_user
|
@status_options = @issue.status.find_new_statuses_allowed_to(logged_in_user.role_for_project(@project), @issue.tracker) if logged_in_user
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
|
@ -56,15 +56,15 @@ class ProjectsController < ApplicationController
|
|||||||
|
|
||||||
# Add a new project
|
# Add a new project
|
||||||
def add
|
def add
|
||||||
@custom_fields = IssueCustomField.find(:all)
|
@custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position")
|
||||||
@root_projects = Project.find(:all, :conditions => "parent_id IS NULL AND status = #{Project::STATUS_ACTIVE}")
|
@root_projects = Project.find(:all, :conditions => "parent_id IS NULL AND status = #{Project::STATUS_ACTIVE}")
|
||||||
@project = Project.new(params[:project])
|
@project = Project.new(params[:project])
|
||||||
@project.enabled_module_names = Redmine::AccessControl.available_project_modules
|
@project.enabled_module_names = Redmine::AccessControl.available_project_modules
|
||||||
if request.get?
|
if request.get?
|
||||||
@custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project) }
|
@custom_values = ProjectCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| CustomValue.new(:custom_field => x, :customized => @project) }
|
||||||
else
|
else
|
||||||
@project.custom_fields = CustomField.find(params[:custom_field_ids]) if params[:custom_field_ids]
|
@project.custom_fields = CustomField.find(params[:custom_field_ids]) if params[:custom_field_ids]
|
||||||
@custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => (params[:custom_fields] ? params["custom_fields"][x.id.to_s] : nil)) }
|
@custom_values = ProjectCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => (params[:custom_fields] ? params["custom_fields"][x.id.to_s] : nil)) }
|
||||||
@project.custom_values = @custom_values
|
@project.custom_values = @custom_values
|
||||||
if @project.save
|
if @project.save
|
||||||
@project.enabled_module_names = params[:enabled_modules]
|
@project.enabled_module_names = params[:enabled_modules]
|
||||||
@ -76,7 +76,7 @@ class ProjectsController < ApplicationController
|
|||||||
|
|
||||||
# Show @project
|
# Show @project
|
||||||
def show
|
def show
|
||||||
@custom_values = @project.custom_values.find(:all, :include => :custom_field)
|
@custom_values = @project.custom_values.find(:all, :include => :custom_field, :order => "#{CustomField.table_name}.position")
|
||||||
@members_by_role = @project.members.find(:all, :include => [:user, :role], :order => 'position').group_by {|m| m.role}
|
@members_by_role = @project.members.find(:all, :include => [:user, :role], :order => 'position').group_by {|m| m.role}
|
||||||
@subprojects = @project.active_children
|
@subprojects = @project.active_children
|
||||||
@news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC")
|
@news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC")
|
||||||
@ -92,7 +92,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
|
||||||
@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, :order => "#{CustomField.table_name}.position").collect { |x| @project.custom_values.find_by_custom_field_id(x.id) || CustomValue.new(:custom_field => x) }
|
||||||
@repository ||= @project.repository
|
@repository ||= @project.repository
|
||||||
@wiki ||= @project.wiki
|
@wiki ||= @project.wiki
|
||||||
end
|
end
|
||||||
@ -102,7 +102,7 @@ class ProjectsController < ApplicationController
|
|||||||
if request.post?
|
if request.post?
|
||||||
@project.custom_fields = IssueCustomField.find(params[:custom_field_ids]) if params[:custom_field_ids]
|
@project.custom_fields = IssueCustomField.find(params[:custom_field_ids]) if params[:custom_field_ids]
|
||||||
if params[:custom_fields]
|
if params[:custom_fields]
|
||||||
@custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => params["custom_fields"][x.id.to_s]) }
|
@custom_values = ProjectCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => params["custom_fields"][x.id.to_s]) }
|
||||||
@project.custom_values = @custom_values
|
@project.custom_values = @custom_values
|
||||||
end
|
end
|
||||||
@project.attributes = params[:project]
|
@project.attributes = params[:project]
|
||||||
|
@ -52,13 +52,13 @@ class UsersController < ApplicationController
|
|||||||
def add
|
def add
|
||||||
if request.get?
|
if request.get?
|
||||||
@user = User.new(:language => Setting.default_language)
|
@user = User.new(:language => Setting.default_language)
|
||||||
@custom_values = UserCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @user) }
|
@custom_values = UserCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| CustomValue.new(:custom_field => x, :customized => @user) }
|
||||||
else
|
else
|
||||||
@user = User.new(params[:user])
|
@user = User.new(params[:user])
|
||||||
@user.admin = params[:user][:admin] || false
|
@user.admin = params[:user][:admin] || false
|
||||||
@user.login = params[:user][:login]
|
@user.login = params[:user][:login]
|
||||||
@user.password, @user.password_confirmation = params[:password], params[:password_confirmation] unless @user.auth_source_id
|
@user.password, @user.password_confirmation = params[:password], params[:password_confirmation] unless @user.auth_source_id
|
||||||
@custom_values = UserCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @user, :value => (params[:custom_fields] ? params["custom_fields"][x.id.to_s] : nil)) }
|
@custom_values = UserCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| CustomValue.new(:custom_field => x, :customized => @user, :value => (params[:custom_fields] ? params["custom_fields"][x.id.to_s] : nil)) }
|
||||||
@user.custom_values = @custom_values
|
@user.custom_values = @custom_values
|
||||||
if @user.save
|
if @user.save
|
||||||
Mailer.deliver_account_information(@user, params[:password]) if params[:send_information]
|
Mailer.deliver_account_information(@user, params[:password]) if params[:send_information]
|
||||||
@ -72,13 +72,13 @@ class UsersController < ApplicationController
|
|||||||
def edit
|
def edit
|
||||||
@user = User.find(params[:id])
|
@user = User.find(params[:id])
|
||||||
if request.get?
|
if request.get?
|
||||||
@custom_values = UserCustomField.find(:all).collect { |x| @user.custom_values.find_by_custom_field_id(x.id) || CustomValue.new(:custom_field => x) }
|
@custom_values = UserCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| @user.custom_values.find_by_custom_field_id(x.id) || CustomValue.new(:custom_field => x) }
|
||||||
else
|
else
|
||||||
@user.admin = params[:user][:admin] if params[:user][:admin]
|
@user.admin = params[:user][:admin] if params[:user][:admin]
|
||||||
@user.login = params[:user][:login] if params[:user][:login]
|
@user.login = params[:user][:login] if params[:user][:login]
|
||||||
@user.password, @user.password_confirmation = params[:password], params[:password_confirmation] unless params[:password].nil? or params[:password].empty? or @user.auth_source_id
|
@user.password, @user.password_confirmation = params[:password], params[:password_confirmation] unless params[:password].nil? or params[:password].empty? or @user.auth_source_id
|
||||||
if params[:custom_fields]
|
if params[:custom_fields]
|
||||||
@custom_values = UserCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @user, :value => params["custom_fields"][x.id.to_s]) }
|
@custom_values = UserCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| CustomValue.new(:custom_field => x, :customized => @user, :value => params["custom_fields"][x.id.to_s]) }
|
||||||
@user.custom_values = @custom_values
|
@user.custom_values = @custom_values
|
||||||
end
|
end
|
||||||
if @user.update_attributes(params[:user])
|
if @user.update_attributes(params[:user])
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
class CustomField < ActiveRecord::Base
|
class CustomField < ActiveRecord::Base
|
||||||
has_many :custom_values, :dependent => :delete_all
|
has_many :custom_values, :dependent => :delete_all
|
||||||
|
acts_as_list :scope => 'type = \'#{self.class}\''
|
||||||
serialize :possible_values
|
serialize :possible_values
|
||||||
|
|
||||||
FIELD_FORMATS = { "string" => { :name => :label_string, :order => 1 },
|
FIELD_FORMATS = { "string" => { :name => :label_string, :order => 1 },
|
||||||
@ -51,6 +52,10 @@ class CustomField < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def <=>(field)
|
||||||
|
position <=> field.position
|
||||||
|
end
|
||||||
|
|
||||||
# to move in project_custom_field
|
# to move in project_custom_field
|
||||||
def self.for_all
|
def self.for_all
|
||||||
find(:all, :conditions => ["is_for_all=?", true])
|
find(:all, :conditions => ["is_for_all=?", true])
|
||||||
|
@ -36,7 +36,13 @@ class Project < ActiveRecord::Base
|
|||||||
has_one :repository, :dependent => :destroy
|
has_one :repository, :dependent => :destroy
|
||||||
has_many :changesets, :through => :repository
|
has_many :changesets, :through => :repository
|
||||||
has_one :wiki, :dependent => :destroy
|
has_one :wiki, :dependent => :destroy
|
||||||
has_and_belongs_to_many :custom_fields, :class_name => 'IssueCustomField', :join_table => "#{table_name_prefix}custom_fields_projects#{table_name_suffix}", :association_foreign_key => 'custom_field_id'
|
# Custom field for the project issues
|
||||||
|
has_and_belongs_to_many :custom_fields,
|
||||||
|
:class_name => 'IssueCustomField',
|
||||||
|
:order => "#{CustomField.table_name}.position",
|
||||||
|
:join_table => "#{table_name_prefix}custom_fields_projects#{table_name_suffix}",
|
||||||
|
:association_foreign_key => 'custom_field_id'
|
||||||
|
|
||||||
acts_as_tree :order => "name", :counter_cache => true
|
acts_as_tree :order => "name", :counter_cache => true
|
||||||
|
|
||||||
acts_as_searchable :columns => ['name', 'description'], :project_key => 'id'
|
acts_as_searchable :columns => ['name', 'description'], :project_key => 'id'
|
||||||
|
@ -19,10 +19,11 @@
|
|||||||
<th><%=l(:field_is_for_all)%></th>
|
<th><%=l(:field_is_for_all)%></th>
|
||||||
<th><%=l(:label_used_by)%></th>
|
<th><%=l(:label_used_by)%></th>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
<th><%=l(:button_sort)%></th>
|
||||||
<th width="10%"></th>
|
<th width="10%"></th>
|
||||||
</tr></thead>
|
</tr></thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<% for custom_field in (@custom_fields_by_type[type] || []) %>
|
<% for custom_field in (@custom_fields_by_type[type] || []).sort %>
|
||||||
<tr class="<%= cycle("odd", "even") %>">
|
<tr class="<%= cycle("odd", "even") %>">
|
||||||
<td><%= link_to custom_field.name, :action => 'edit', :id => custom_field %></td>
|
<td><%= link_to custom_field.name, :action => 'edit', :id => custom_field %></td>
|
||||||
<td align="center"><%= l(CustomField::FIELD_FORMATS[custom_field.field_format][:name]) %></td>
|
<td align="center"><%= l(CustomField::FIELD_FORMATS[custom_field.field_format][:name]) %></td>
|
||||||
@ -31,6 +32,12 @@
|
|||||||
<td align="center"><%= image_tag 'true.png' if custom_field.is_for_all? %></td>
|
<td align="center"><%= image_tag 'true.png' if custom_field.is_for_all? %></td>
|
||||||
<td align="center"><%= custom_field.projects.count.to_s + ' ' + lwr(:label_project, custom_field.projects.count) if custom_field.is_a? IssueCustomField and !custom_field.is_for_all? %></td>
|
<td align="center"><%= custom_field.projects.count.to_s + ' ' + lwr(:label_project, custom_field.projects.count) if custom_field.is_a? IssueCustomField and !custom_field.is_for_all? %></td>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
<td align="center" style="width:15%;">
|
||||||
|
<%= link_to image_tag('2uparrow.png', :alt => l(:label_sort_highest)), {:action => 'move', :id => custom_field, :position => 'highest'}, :method => :post, :title => l(:label_sort_highest) %>
|
||||||
|
<%= link_to image_tag('1uparrow.png', :alt => l(:label_sort_higher)), {:action => 'move', :id => custom_field, :position => 'higher'}, :method => :post, :title => l(:label_sort_higher) %> -
|
||||||
|
<%= link_to image_tag('1downarrow.png', :alt => l(:label_sort_lower)), {:action => 'move', :id => custom_field, :position => 'lower'}, :method => :post, :title => l(:label_sort_lower) %>
|
||||||
|
<%= link_to image_tag('2downarrow.png', :alt => l(:label_sort_lowest)), {:action => 'move', :id => custom_field, :position => 'lowest'}, :method => :post, :title => l(:label_sort_lowest) %>
|
||||||
|
</td>
|
||||||
<td align="center">
|
<td align="center">
|
||||||
<%= button_to l(:button_delete), { :action => 'destroy', :id => custom_field }, :confirm => l(:text_are_you_sure), :class => "button-small" %>
|
<%= button_to l(:button_delete), { :action => 'destroy', :id => custom_field }, :confirm => l(:text_are_you_sure), :class => "button-small" %>
|
||||||
</td>
|
</td>
|
||||||
|
15
db/migrate/078_add_custom_fields_position.rb
Normal file
15
db/migrate/078_add_custom_fields_position.rb
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
class AddCustomFieldsPosition < ActiveRecord::Migration
|
||||||
|
def self.up
|
||||||
|
add_column(:custom_fields, :position, :integer, :default => 1)
|
||||||
|
CustomField.find(:all).group_by(&:type).each_value do |fields|
|
||||||
|
fields.each_with_index do |field, i|
|
||||||
|
# do not call model callbacks
|
||||||
|
CustomField.update_all "position = #{i+1}", {:id => field.id}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.down
|
||||||
|
remove_column :custom_fields, :position
|
||||||
|
end
|
||||||
|
end
|
Loading…
x
Reference in New Issue
Block a user