diff options
author | Eric Davis <edavis@littlestreamsoftware.com> | 2009-10-21 22:34:39 +0000 |
---|---|---|
committer | Eric Davis <edavis@littlestreamsoftware.com> | 2009-10-21 22:34:39 +0000 |
commit | e615266e9a036811c7f73a471ba48b5bbe27adfe (patch) | |
tree | 83458d985c737f3cd898278d1066015eac395547 /app | |
parent | 29301c8a381aa5995a0ce2e10ad91f210dc6464f (diff) | |
download | redmine-e615266e9a036811c7f73a471ba48b5bbe27adfe.tar.gz redmine-e615266e9a036811c7f73a471ba48b5bbe27adfe.zip |
Changed the Timelogs to use both the Systemwide and Project specific TimeEntryActivities
* Added Project#activities to return all the Systemwide and Project specific
activities, excluding Systemwide ones that are overridden.
* Added some tests for TimelogHelper.
#4077
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2948 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app')
-rw-r--r-- | app/helpers/timelog_helper.rb | 12 | ||||
-rw-r--r-- | app/models/enumeration.rb | 2 | ||||
-rw-r--r-- | app/models/project.rb | 20 |
3 files changed, 30 insertions, 4 deletions
diff --git a/app/helpers/timelog_helper.rb b/app/helpers/timelog_helper.rb index 0c3e7e6b6..178929161 100644 --- a/app/helpers/timelog_helper.rb +++ b/app/helpers/timelog_helper.rb @@ -29,10 +29,16 @@ module TimelogHelper # Returns a collection of activities for a select field. time_entry # is optional and will be used to check if the selected TimeEntryActivity # is active. - def activity_collection_for_select_options(time_entry=nil) - activities = TimeEntryActivity.active + def activity_collection_for_select_options(time_entry=nil, project=nil) + project ||= @project + if project.nil? + activities = TimeEntryActivity.active + else + activities = project.activities + end + collection = [] - if time_entry && !time_entry.activity.active? + if time_entry && time_entry.activity && !time_entry.activity.active? collection << [ "--- #{l(:actionview_instancetag_blank_option)} ---", '' ] else collection << [ "--- #{l(:actionview_instancetag_blank_option)} ---", '' ] unless activities.detect(&:is_default) diff --git a/app/models/enumeration.rb b/app/models/enumeration.rb index 2d27d2f86..bdb6ddd25 100644 --- a/app/models/enumeration.rb +++ b/app/models/enumeration.rb @@ -62,7 +62,7 @@ class Enumeration < ActiveRecord::Base named_scope :active, lambda { { - :conditions => {:active => true}, + :conditions => {:active => true, :project_id => nil}, :order => 'position' } } diff --git a/app/models/project.rb b/app/models/project.rb index f9030bdf2..6e397b776 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -20,6 +20,7 @@ class Project < ActiveRecord::Base STATUS_ACTIVE = 1 STATUS_ARCHIVED = 9 + has_many :time_entry_activities, :conditions => {:active => true } # Specific overidden Activities has_many :members, :include => :user, :conditions => "#{User.table_name}.type='User' AND #{User.table_name}.status=#{User::STATUS_ACTIVE}" has_many :member_principals, :class_name => 'Member', :include => :principal, @@ -155,6 +156,17 @@ class Project < ActiveRecord::Base statements.empty? ? base_statement : "((#{base_statement}) AND (#{statements.join(' OR ')}))" end + # Returns all the Systemwide and project specific activities + def activities + overridden_activity_ids = self.time_entry_activities.collect(&:parent_id) + + if overridden_activity_ids.empty? + return TimeEntryActivity.active + else + return system_activities_and_project_overrides + end + end + # Returns a :conditions SQL string that can be used to find the issues associated with this project. # # Examples: @@ -446,4 +458,12 @@ private def allowed_actions @actions_allowed ||= allowed_permissions.inject([]) { |actions, permission| actions += Redmine::AccessControl.allowed_actions(permission) }.flatten end + + # Returns the systemwide activities merged with the project specific overrides + def system_activities_and_project_overrides + return TimeEntryActivity.active. + find(:all, + :conditions => ["id NOT IN (?)", self.time_entry_activities.collect(&:parent_id)]) + + self.time_entry_activities + end end |