##// END OF EJS Templates
Custom fields can now be reordered....
Jean-Philippe Lang -
r888:5944696b6d43
parent child
Show More
@@ -0,0 +1,15
1 class AddCustomFieldsPosition < ActiveRecord::Migration
2 def self.up
3 add_column(:custom_fields, :position, :integer, :default => 1)
4 CustomField.find(:all).group_by(&:type).each_value do |fields|
5 fields.each_with_index do |field, i|
6 # do not call model callbacks
7 CustomField.update_all "position = #{i+1}", {:id => field.id}
8 end
9 end
10 end
11
12 def self.down
13 remove_column :custom_fields, :position
14 end
15 end
@@ -45,7 +45,7 class CustomFieldsController < ApplicationController
45 end
45 end
46 if request.post? and @custom_field.save
46 if request.post? and @custom_field.save
47 flash[:notice] = l(:notice_successful_create)
47 flash[:notice] = l(:notice_successful_create)
48 redirect_to :action => 'list', :tab => @custom_field.type
48 redirect_to :action => 'list', :tab => @custom_field.class.name
49 end
49 end
50 @trackers = Tracker.find(:all, :order => 'position')
50 @trackers = Tracker.find(:all, :order => 'position')
51 end
51 end
@@ -57,14 +57,29 class CustomFieldsController < ApplicationController
57 @custom_field.trackers = params[:tracker_ids] ? Tracker.find(params[:tracker_ids]) : []
57 @custom_field.trackers = params[:tracker_ids] ? Tracker.find(params[:tracker_ids]) : []
58 end
58 end
59 flash[:notice] = l(:notice_successful_update)
59 flash[:notice] = l(:notice_successful_update)
60 redirect_to :action => 'list', :tab => @custom_field.type
60 redirect_to :action => 'list', :tab => @custom_field.class.name
61 end
61 end
62 @trackers = Tracker.find(:all, :order => 'position')
62 @trackers = Tracker.find(:all, :order => 'position')
63 end
63 end
64
64
65 def move
66 @custom_field = CustomField.find(params[:id])
67 case params[:position]
68 when 'highest'
69 @custom_field.move_to_top
70 when 'higher'
71 @custom_field.move_higher
72 when 'lower'
73 @custom_field.move_lower
74 when 'lowest'
75 @custom_field.move_to_bottom
76 end if params[:position]
77 redirect_to :action => 'list', :tab => @custom_field.class.name
78 end
79
65 def destroy
80 def destroy
66 @custom_field = CustomField.find(params[:id]).destroy
81 @custom_field = CustomField.find(params[:id]).destroy
67 redirect_to :action => 'list', :tab => @custom_field.type
82 redirect_to :action => 'list', :tab => @custom_field.class.name
68 rescue
83 rescue
69 flash[:error] = "Unable to delete custom field"
84 flash[:error] = "Unable to delete custom field"
70 redirect_to :action => 'list'
85 redirect_to :action => 'list'
@@ -80,7 +80,7 class IssuesController < ApplicationController
80 end
80 end
81
81
82 def show
82 def show
83 @custom_values = @issue.custom_values.find(:all, :include => :custom_field)
83 @custom_values = @issue.custom_values.find(:all, :include => :custom_field, :order => "#{CustomField.table_name}.position")
84 @journals = @issue.journals.find(:all, :include => [:user, :details], :order => "#{Journal.table_name}.created_on ASC")
84 @journals = @issue.journals.find(:all, :include => [:user, :details], :order => "#{Journal.table_name}.created_on ASC")
85 @status_options = @issue.status.find_new_statuses_allowed_to(logged_in_user.role_for_project(@project), @issue.tracker) if logged_in_user
85 @status_options = @issue.status.find_new_statuses_allowed_to(logged_in_user.role_for_project(@project), @issue.tracker) if logged_in_user
86 respond_to do |format|
86 respond_to do |format|
@@ -56,15 +56,15 class ProjectsController < ApplicationController
56
56
57 # Add a new project
57 # Add a new project
58 def add
58 def add
59 @custom_fields = IssueCustomField.find(:all)
59 @custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position")
60 @root_projects = Project.find(:all, :conditions => "parent_id IS NULL AND status = #{Project::STATUS_ACTIVE}")
60 @root_projects = Project.find(:all, :conditions => "parent_id IS NULL AND status = #{Project::STATUS_ACTIVE}")
61 @project = Project.new(params[:project])
61 @project = Project.new(params[:project])
62 @project.enabled_module_names = Redmine::AccessControl.available_project_modules
62 @project.enabled_module_names = Redmine::AccessControl.available_project_modules
63 if request.get?
63 if request.get?
64 @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project) }
64 @custom_values = ProjectCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| CustomValue.new(:custom_field => x, :customized => @project) }
65 else
65 else
66 @project.custom_fields = CustomField.find(params[:custom_field_ids]) if params[:custom_field_ids]
66 @project.custom_fields = CustomField.find(params[:custom_field_ids]) if params[:custom_field_ids]
67 @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)) }
67 @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)) }
68 @project.custom_values = @custom_values
68 @project.custom_values = @custom_values
69 if @project.save
69 if @project.save
70 @project.enabled_module_names = params[:enabled_modules]
70 @project.enabled_module_names = params[:enabled_modules]
@@ -76,7 +76,7 class ProjectsController < ApplicationController
76
76
77 # Show @project
77 # Show @project
78 def show
78 def show
79 @custom_values = @project.custom_values.find(:all, :include => :custom_field)
79 @custom_values = @project.custom_values.find(:all, :include => :custom_field, :order => "#{CustomField.table_name}.position")
80 @members_by_role = @project.members.find(:all, :include => [:user, :role], :order => 'position').group_by {|m| m.role}
80 @members_by_role = @project.members.find(:all, :include => [:user, :role], :order => 'position').group_by {|m| m.role}
81 @subprojects = @project.active_children
81 @subprojects = @project.active_children
82 @news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC")
82 @news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC")
@@ -92,7 +92,7 class ProjectsController < ApplicationController
92 @custom_fields = IssueCustomField.find(:all)
92 @custom_fields = IssueCustomField.find(:all)
93 @issue_category ||= IssueCategory.new
93 @issue_category ||= IssueCategory.new
94 @member ||= @project.members.new
94 @member ||= @project.members.new
95 @custom_values ||= ProjectCustomField.find(:all).collect { |x| @project.custom_values.find_by_custom_field_id(x.id) || CustomValue.new(:custom_field => x) }
95 @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) }
96 @repository ||= @project.repository
96 @repository ||= @project.repository
97 @wiki ||= @project.wiki
97 @wiki ||= @project.wiki
98 end
98 end
@@ -102,7 +102,7 class ProjectsController < ApplicationController
102 if request.post?
102 if request.post?
103 @project.custom_fields = IssueCustomField.find(params[:custom_field_ids]) if params[:custom_field_ids]
103 @project.custom_fields = IssueCustomField.find(params[:custom_field_ids]) if params[:custom_field_ids]
104 if params[:custom_fields]
104 if params[:custom_fields]
105 @custom_values = ProjectCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @project, :value => params["custom_fields"][x.id.to_s]) }
105 @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]) }
106 @project.custom_values = @custom_values
106 @project.custom_values = @custom_values
107 end
107 end
108 @project.attributes = params[:project]
108 @project.attributes = params[:project]
@@ -52,13 +52,13 class UsersController < ApplicationController
52 def add
52 def add
53 if request.get?
53 if request.get?
54 @user = User.new(:language => Setting.default_language)
54 @user = User.new(:language => Setting.default_language)
55 @custom_values = UserCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @user) }
55 @custom_values = UserCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| CustomValue.new(:custom_field => x, :customized => @user) }
56 else
56 else
57 @user = User.new(params[:user])
57 @user = User.new(params[:user])
58 @user.admin = params[:user][:admin] || false
58 @user.admin = params[:user][:admin] || false
59 @user.login = params[:user][:login]
59 @user.login = params[:user][:login]
60 @user.password, @user.password_confirmation = params[:password], params[:password_confirmation] unless @user.auth_source_id
60 @user.password, @user.password_confirmation = params[:password], params[:password_confirmation] unless @user.auth_source_id
61 @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)) }
61 @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)) }
62 @user.custom_values = @custom_values
62 @user.custom_values = @custom_values
63 if @user.save
63 if @user.save
64 Mailer.deliver_account_information(@user, params[:password]) if params[:send_information]
64 Mailer.deliver_account_information(@user, params[:password]) if params[:send_information]
@@ -72,13 +72,13 class UsersController < ApplicationController
72 def edit
72 def edit
73 @user = User.find(params[:id])
73 @user = User.find(params[:id])
74 if request.get?
74 if request.get?
75 @custom_values = UserCustomField.find(:all).collect { |x| @user.custom_values.find_by_custom_field_id(x.id) || CustomValue.new(:custom_field => x) }
75 @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) }
76 else
76 else
77 @user.admin = params[:user][:admin] if params[:user][:admin]
77 @user.admin = params[:user][:admin] if params[:user][:admin]
78 @user.login = params[:user][:login] if params[:user][:login]
78 @user.login = params[:user][:login] if params[:user][:login]
79 @user.password, @user.password_confirmation = params[:password], params[:password_confirmation] unless params[:password].nil? or params[:password].empty? or @user.auth_source_id
79 @user.password, @user.password_confirmation = params[:password], params[:password_confirmation] unless params[:password].nil? or params[:password].empty? or @user.auth_source_id
80 if params[:custom_fields]
80 if params[:custom_fields]
81 @custom_values = UserCustomField.find(:all).collect { |x| CustomValue.new(:custom_field => x, :customized => @user, :value => params["custom_fields"][x.id.to_s]) }
81 @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]) }
82 @user.custom_values = @custom_values
82 @user.custom_values = @custom_values
83 end
83 end
84 if @user.update_attributes(params[:user])
84 if @user.update_attributes(params[:user])
@@ -17,6 +17,7
17
17
18 class CustomField < ActiveRecord::Base
18 class CustomField < ActiveRecord::Base
19 has_many :custom_values, :dependent => :delete_all
19 has_many :custom_values, :dependent => :delete_all
20 acts_as_list :scope => 'type = \'#{self.class}\''
20 serialize :possible_values
21 serialize :possible_values
21
22
22 FIELD_FORMATS = { "string" => { :name => :label_string, :order => 1 },
23 FIELD_FORMATS = { "string" => { :name => :label_string, :order => 1 },
@@ -51,6 +52,10 class CustomField < ActiveRecord::Base
51 end
52 end
52 end
53 end
53
54
55 def <=>(field)
56 position <=> field.position
57 end
58
54 # to move in project_custom_field
59 # to move in project_custom_field
55 def self.for_all
60 def self.for_all
56 find(:all, :conditions => ["is_for_all=?", true])
61 find(:all, :conditions => ["is_for_all=?", true])
@@ -36,7 +36,13 class Project < ActiveRecord::Base
36 has_one :repository, :dependent => :destroy
36 has_one :repository, :dependent => :destroy
37 has_many :changesets, :through => :repository
37 has_many :changesets, :through => :repository
38 has_one :wiki, :dependent => :destroy
38 has_one :wiki, :dependent => :destroy
39 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'
39 # Custom field for the project issues
40 has_and_belongs_to_many :custom_fields,
41 :class_name => 'IssueCustomField',
42 :order => "#{CustomField.table_name}.position",
43 :join_table => "#{table_name_prefix}custom_fields_projects#{table_name_suffix}",
44 :association_foreign_key => 'custom_field_id'
45
40 acts_as_tree :order => "name", :counter_cache => true
46 acts_as_tree :order => "name", :counter_cache => true
41
47
42 acts_as_searchable :columns => ['name', 'description'], :project_key => 'id'
48 acts_as_searchable :columns => ['name', 'description'], :project_key => 'id'
@@ -19,10 +19,11
19 <th><%=l(:field_is_for_all)%></th>
19 <th><%=l(:field_is_for_all)%></th>
20 <th><%=l(:label_used_by)%></th>
20 <th><%=l(:label_used_by)%></th>
21 <% end %>
21 <% end %>
22 <th><%=l(:button_sort)%></th>
22 <th width="10%"></th>
23 <th width="10%"></th>
23 </tr></thead>
24 </tr></thead>
24 <tbody>
25 <tbody>
25 <% for custom_field in (@custom_fields_by_type[type] || []) %>
26 <% for custom_field in (@custom_fields_by_type[type] || []).sort %>
26 <tr class="<%= cycle("odd", "even") %>">
27 <tr class="<%= cycle("odd", "even") %>">
27 <td><%= link_to custom_field.name, :action => 'edit', :id => custom_field %></td>
28 <td><%= link_to custom_field.name, :action => 'edit', :id => custom_field %></td>
28 <td align="center"><%= l(CustomField::FIELD_FORMATS[custom_field.field_format][:name]) %></td>
29 <td align="center"><%= l(CustomField::FIELD_FORMATS[custom_field.field_format][:name]) %></td>
@@ -31,6 +32,12
31 <td align="center"><%= image_tag 'true.png' if custom_field.is_for_all? %></td>
32 <td align="center"><%= image_tag 'true.png' if custom_field.is_for_all? %></td>
32 <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>
33 <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>
33 <% end %>
34 <% end %>
35 <td align="center" style="width:15%;">
36 <%= 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) %>
37 <%= 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) %> -
38 <%= 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) %>
39 <%= 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) %>
40 </td>
34 <td align="center">
41 <td align="center">
35 <%= button_to l(:button_delete), { :action => 'destroy', :id => custom_field }, :confirm => l(:text_are_you_sure), :class => "button-small" %>
42 <%= button_to l(:button_delete), { :action => 'destroy', :id => custom_field }, :confirm => l(:text_are_you_sure), :class => "button-small" %>
36 </td>
43 </td>
General Comments 0
You need to be logged in to leave comments. Login now