summaryrefslogtreecommitdiffstats
path: root/app/controllers
diff options
context:
space:
mode:
authorEric Davis <edavis@littlestreamsoftware.com>2009-05-30 23:30:36 +0000
committerEric Davis <edavis@littlestreamsoftware.com>2009-05-30 23:30:36 +0000
commit62e58f26b0c6905fc0b2d79ed278ac0e4f55d793 (patch)
tree6989cbc655e9ffee0db9b7558985cd77d28b0edb /app/controllers
parentfbfb34949677c41734531a552547fb216537999f (diff)
downloadredmine-62e58f26b0c6905fc0b2d79ed278ac0e4f55d793.tar.gz
redmine-62e58f26b0c6905fc0b2d79ed278ac0e4f55d793.zip
Changed Enumerations to use a Single Table Inheritance
* Added migrations to change Enumerations to an STI relationship * Added TimeEntryActivity model (STI) * Added DocumentCategory model (STI) * Added IssuePriority model (STI) * Added Enumeration#get_subclasses to get a list of the subclasses of Enumeration * Changed Enumeration to use the STI type field instead of the opt field * Changed Enumeration#opt to return the old opt values but with a deprecation warning. * Removed Enumeration::OPTIONS * Removed the dynamic named_scopes in favor of specific named_scopes. Kept for compatibility reasons. * Added Enumeration#default so each subclass can easily find it's default record. * Fixed Enumeration#default to use the STI scoping with a fake default scope for finding Enumeration's default. * Added a 'all' named scope for getting all records in order by position. * Added Deprecation warnings to the old named_scopes in Enumerations. * Moved various methods off of Enumeration and onto the concrete classes * Changed the EnumerationsController to use types * Updated the Enumeration list template * Added has_many relationships to the Enumeration STI classes. * Fixes for tests. #3007 git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2777 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/controllers')
-rw-r--r--app/controllers/documents_controller.rb2
-rw-r--r--app/controllers/enumerations_controller.rb16
-rw-r--r--app/controllers/issues_controller.rb10
-rw-r--r--app/controllers/reports_controller.rb6
-rw-r--r--app/controllers/timelog_controller.rb2
5 files changed, 21 insertions, 15 deletions
diff --git a/app/controllers/documents_controller.rb b/app/controllers/documents_controller.rb
index f5825e7c3..c2e08768f 100644
--- a/app/controllers/documents_controller.rb
+++ b/app/controllers/documents_controller.rb
@@ -53,7 +53,7 @@ class DocumentsController < ApplicationController
end
def edit
- @categories = Enumeration.document_categories
+ @categories = DocumentCategory.all
if request.post? and @document.update_attributes(params[:document])
flash[:notice] = l(:notice_successful_update)
redirect_to :action => 'show', :id => @document
diff --git a/app/controllers/enumerations_controller.rb b/app/controllers/enumerations_controller.rb
index ac55c421e..63965fae1 100644
--- a/app/controllers/enumerations_controller.rb
+++ b/app/controllers/enumerations_controller.rb
@@ -31,14 +31,19 @@ class EnumerationsController < ApplicationController
end
def new
- @enumeration = Enumeration.new(:opt => params[:opt])
+ begin
+ @enumeration = params[:type].constantize.new
+ rescue NameError
+ @enumeration = Enumeration.new
+ end
end
def create
@enumeration = Enumeration.new(params[:enumeration])
+ @enumeration.type = params[:enumeration][:type]
if @enumeration.save
flash[:notice] = l(:notice_successful_create)
- redirect_to :action => 'list', :opt => @enumeration.opt
+ redirect_to :action => 'list', :type => @enumeration.type
else
render :action => 'new'
end
@@ -50,9 +55,10 @@ class EnumerationsController < ApplicationController
def update
@enumeration = Enumeration.find(params[:id])
+ @enumeration.type = params[:enumeration][:type] if params[:enumeration][:type]
if @enumeration.update_attributes(params[:enumeration])
flash[:notice] = l(:notice_successful_update)
- redirect_to :action => 'list', :opt => @enumeration.opt
+ redirect_to :action => 'list', :type => @enumeration.type
else
render :action => 'edit'
end
@@ -65,12 +71,12 @@ class EnumerationsController < ApplicationController
@enumeration.destroy
redirect_to :action => 'index'
elsif params[:reassign_to_id]
- if reassign_to = Enumeration.find_by_opt_and_id(@enumeration.opt, params[:reassign_to_id])
+ if reassign_to = Enumeration.find_by_type_and_id(@enumeration.type, params[:reassign_to_id])
@enumeration.destroy(reassign_to)
redirect_to :action => 'index'
end
end
- @enumerations = Enumeration.values(@enumeration.opt) - [@enumeration]
+ @enumerations = Enumeration.find(:all, :conditions => ['type = (?)', @enumeration.type]) - [@enumeration]
#rescue
# flash[:error] = 'Unable to delete enumeration'
# redirect_to :action => 'index'
diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb
index 7fcf56e84..de5167651 100644
--- a/app/controllers/issues_controller.rb
+++ b/app/controllers/issues_controller.rb
@@ -113,7 +113,7 @@ class IssuesController < ApplicationController
@changesets.reverse! if User.current.wants_comments_in_reverse_order?
@allowed_statuses = @issue.new_statuses_allowed_to(User.current)
@edit_allowed = User.current.allowed_to?(:edit_issues, @project)
- @priorities = Enumeration.priorities
+ @priorities = IssuePriority.all
@time_entry = TimeEntry.new
respond_to do |format|
format.html { render :template => 'issues/show.rhtml' }
@@ -163,7 +163,7 @@ class IssuesController < ApplicationController
return
end
end
- @priorities = Enumeration.priorities
+ @priorities = IssuePriority.all
render :layout => !request.xhr?
end
@@ -173,7 +173,7 @@ class IssuesController < ApplicationController
def edit
@allowed_statuses = @issue.new_statuses_allowed_to(User.current)
- @priorities = Enumeration.priorities
+ @priorities = IssuePriority.all
@edit_allowed = User.current.allowed_to?(:edit_issues, @project)
@time_entry = TimeEntry.new
@@ -237,7 +237,7 @@ class IssuesController < ApplicationController
def bulk_edit
if request.post?
status = params[:status_id].blank? ? nil : IssueStatus.find_by_id(params[:status_id])
- priority = params[:priority_id].blank? ? nil : Enumeration.find_by_id(params[:priority_id])
+ priority = params[:priority_id].blank? ? nil : IssuePriority.find_by_id(params[:priority_id])
assigned_to = (params[:assigned_to_id].blank? || params[:assigned_to_id] == 'none') ? nil : User.find_by_id(params[:assigned_to_id])
category = (params[:category_id].blank? || params[:category_id] == 'none') ? nil : @project.issue_categories.find_by_id(params[:category_id])
fixed_version = (params[:fixed_version_id].blank? || params[:fixed_version_id] == 'none') ? nil : @project.versions.find_by_id(params[:fixed_version_id])
@@ -415,7 +415,7 @@ class IssuesController < ApplicationController
@assignables << @issue.assigned_to if @issue && @issue.assigned_to && !@assignables.include?(@issue.assigned_to)
end
- @priorities = Enumeration.priorities.reverse
+ @priorities = IssuePriority.all.reverse
@statuses = IssueStatus.find(:all, :order => 'position')
@back = request.env['HTTP_REFERER']
diff --git a/app/controllers/reports_controller.rb b/app/controllers/reports_controller.rb
index 92bf530f0..d192a1955 100644
--- a/app/controllers/reports_controller.rb
+++ b/app/controllers/reports_controller.rb
@@ -37,7 +37,7 @@ class ReportsController < ApplicationController
render :template => "reports/issue_report_details"
when "priority"
@field = "priority_id"
- @rows = Enumeration.priorities
+ @rows = IssuePriority.all
@data = issues_by_priority
@report_title = l(:field_priority)
render :template => "reports/issue_report_details"
@@ -68,7 +68,7 @@ class ReportsController < ApplicationController
else
@trackers = @project.trackers
@versions = @project.versions.sort
- @priorities = Enumeration.priorities
+ @priorities = IssuePriority.all
@categories = @project.issue_categories
@assignees = @project.members.collect { |m| m.user }
@authors = @project.members.collect { |m| m.user }
@@ -130,7 +130,7 @@ private
p.id as priority_id,
count(i.id) as total
from
- #{Issue.table_name} i, #{IssueStatus.table_name} s, #{Enumeration.table_name} p
+ #{Issue.table_name} i, #{IssueStatus.table_name} s, #{IssuePriority.table_name} p
where
i.status_id=s.id
and i.priority_id=p.id
diff --git a/app/controllers/timelog_controller.rb b/app/controllers/timelog_controller.rb
index 60cc3916b..29ba49938 100644
--- a/app/controllers/timelog_controller.rb
+++ b/app/controllers/timelog_controller.rb
@@ -46,7 +46,7 @@ class TimelogController < ApplicationController
:klass => Tracker,
:label => :label_tracker},
'activity' => {:sql => "#{TimeEntry.table_name}.activity_id",
- :klass => Enumeration,
+ :klass => TimeEntryActivity,
:label => :label_activity},
'issue' => {:sql => "#{TimeEntry.table_name}.issue_id",
:klass => Issue,