From 5833ba9f81f0384e5b7f5a9d322adb1c5199e3d8 Mon Sep 17 00:00:00 2001 From: Eric Davis Date: Wed, 21 Oct 2009 22:34:45 +0000 Subject: Added a Activities tab to Project Settings * Changed Project#activities to allow getting inactive Activities also: * Changed the Enumeration#all named_scope to exclude project specific Activities * Changed the Project has_many time_entry_activities to include all by default and provided an #active method to filter them to active ones only * Split Project#activities to two methods and gave it a parameter that is used to determine if inactive activities are included (default is no) * Added a reset button to delete all project specific activities. * Added ProjectsController#reset_activities to remove the project specific activities * Added a HTTP DELETE route for reset_activities * Changed the permissions for managing project activities to have access to the ProjectsController#reset_activities action * Added a way to bulk save Project specific Activities in ProjectsController * #save_activities will save all the changed activities, including update the existing records * Added helper methods to the controller which will be refactored later * Allow the same TimeEntryActivity names on different projects #4077 git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2949 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/models/enumeration.rb | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) (limited to 'app/models/enumeration.rb') diff --git a/app/models/enumeration.rb b/app/models/enumeration.rb index bdb6ddd25..f219a4c7c 100644 --- a/app/models/enumeration.rb +++ b/app/models/enumeration.rb @@ -25,7 +25,7 @@ class Enumeration < ActiveRecord::Base before_destroy :check_integrity validates_presence_of :name - validates_uniqueness_of :name, :scope => [:type] + validates_uniqueness_of :name, :scope => [:type, :project_id] validates_length_of :name, :maximum => 30 # Backwards compatiblity named_scopes. @@ -58,7 +58,7 @@ class Enumeration < ActiveRecord::Base end # End backwards compatiblity named_scopes - named_scope :all, :order => 'position' + named_scope :all, :order => 'position', :conditions => { :project_id => nil } named_scope :active, lambda { { @@ -134,6 +134,32 @@ class Enumeration < ActiveRecord::Base def self.get_subclasses @@subclasses[Enumeration] end + + # Does the +new+ Hash override the previous Enumeration? + def self.overridding_change?(new, previous) + if (same_active_state?(new['active'], previous.active)) && same_custom_values?(new,previous) + return false + else + return true + end + end + + # Does the +new+ Hash have the same custom values as the previous Enumeration? + def self.same_custom_values?(new, previous) + previous.custom_field_values.each do |custom_value| + if custom_value.value != new["custom_field_values"][custom_value.custom_field_id.to_s] + return false + end + end + + return true + end + + # Are the new and previous fields equal? + def self.same_active_state?(new, previous) + new = (new == "1" ? true : false) + return new == previous + end private def check_integrity -- cgit v1.2.3