diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 5dcb934fe..c89167aa3 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -65,14 +65,14 @@ class ProjectsController < ApplicationController def new @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position") - @trackers = Tracker.all + @trackers = Tracker.sorted.all @project = Project.new @project.safe_attributes = params[:project] end def create @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position") - @trackers = Tracker.all + @trackers = Tracker.sorted.all @project = Project.new @project.safe_attributes = params[:project] @@ -105,7 +105,7 @@ class ProjectsController < ApplicationController def copy @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position") - @trackers = Tracker.all + @trackers = Tracker.sorted.all @root_projects = Project.find(:all, :conditions => "parent_id IS NULL AND status = #{Project::STATUS_ACTIVE}", :order => 'name') @@ -175,7 +175,7 @@ class ProjectsController < ApplicationController @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position") @issue_category ||= IssueCategory.new @member ||= @project.members.new - @trackers = Tracker.all + @trackers = Tracker.sorted.all @wiki ||= @project.wiki end diff --git a/app/controllers/trackers_controller.rb b/app/controllers/trackers_controller.rb index 7dd88f5e4..a67583c16 100644 --- a/app/controllers/trackers_controller.rb +++ b/app/controllers/trackers_controller.rb @@ -29,7 +29,7 @@ class TrackersController < ApplicationController render :action => "index", :layout => false if request.xhr? } format.api { - @trackers = Tracker.all + @trackers = Tracker.sorted.all } end end diff --git a/app/models/project.rb b/app/models/project.rb index aad320b33..1b8f30db3 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -121,7 +121,7 @@ class Project < ActiveRecord::Base self.enabled_module_names = Setting.default_projects_modules end if !initialized.key?('trackers') && !initialized.key?('tracker_ids') - self.trackers = Tracker.all + self.trackers = Tracker.sorted.all end end diff --git a/app/models/tracker.rb b/app/models/tracker.rb index d489d6d45..ce34f782c 100644 --- a/app/models/tracker.rb +++ b/app/models/tracker.rb @@ -32,7 +32,8 @@ class Tracker < ActiveRecord::Base validates_uniqueness_of :name validates_length_of :name, :maximum => 30 - scope :named, lambda {|arg| { :conditions => ["LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip]}} + scope :sorted, order("#{table_name}.position ASC") + scope :named, lambda {|arg| where("LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip)} def to_s; name end @@ -40,10 +41,6 @@ class Tracker < ActiveRecord::Base position <=> tracker.position end - def self.all - find(:all, :order => 'position') - end - # Returns an array of IssueStatus that are used # in the tracker's workflows def issue_statuses @@ -63,6 +60,6 @@ class Tracker < ActiveRecord::Base private def check_integrity - raise "Can't delete tracker" if Issue.find(:first, :conditions => ["tracker_id=?", self.id]) + raise Exception.new("Can't delete tracker") if Issue.where(:tracker_id => self.id).any? end end diff --git a/app/models/workflow.rb b/app/models/workflow.rb index 059d2c1ee..5c1ef5dea 100644 --- a/app/models/workflow.rb +++ b/app/models/workflow.rb @@ -50,7 +50,7 @@ class Workflow < ActiveRecord::Base target_trackers = [target_trackers].flatten.compact target_roles = [target_roles].flatten.compact - target_trackers = Tracker.all if target_trackers.empty? + target_trackers = Tracker.sorted.all if target_trackers.empty? target_roles = Role.all if target_roles.empty? target_trackers.each do |target_tracker| diff --git a/app/views/custom_fields/_form.html.erb b/app/views/custom_fields/_form.html.erb index 84f08457e..afc15b53c 100644 --- a/app/views/custom_fields/_form.html.erb +++ b/app/views/custom_fields/_form.html.erb @@ -89,7 +89,7 @@ function toggle_custom_field_format() { when "IssueCustomField" %>