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
This commit is contained in:
1 parent
e615266e9a
commit
5833ba9f81
12 files changed
+315
-19
No files matched your search
+72
-14
@@ -20,7 +20,12 @@ class Project < ActiveRecord::Base
|
||||
STATUS_ACTIVE = 1
|
||||
STATUS_ARCHIVED = 9
|
||||
|
||||
has_many :time_entry_activities, :conditions => {:active => true } # Specific overidden Activities
|
||||
# Specific overidden Activities
|
||||
has_many :time_entry_activities do
|
||||
def active
|
||||
find(:all, :conditions => {:active => true})
|
||||
end
|
||||
end
|
||||
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,
|
||||
@@ -156,14 +161,37 @@ 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
|
||||
# Returns the Systemwide and project specific activities
|
||||
def activities(include_inactive=false)
|
||||
if include_inactive
|
||||
return all_activities
|
||||
else
|
||||
return system_activities_and_project_overrides
|
||||
return active_activities
|
||||
end
|
||||
end
|
||||
|
||||
# Will build a new Project specific Activity or update an existing one
|
||||
def update_or_build_time_entry_activity(id, activity_hash)
|
||||
if activity_hash.respond_to?(:has_key?) && activity_hash.has_key?('parent_id')
|
||||
self.build_time_entry_activity_if_needed(activity_hash)
|
||||
else
|
||||
activity = project.time_entry_activities.find_by_id(id.to_i)
|
||||
activity.update_attributes(activity_hash) if activity
|
||||
end
|
||||
end
|
||||
|
||||
# Builds new activity
|
||||
def build_time_entry_activity_if_needed(activity)
|
||||
# Only new override activities are built
|
||||
if activity['parent_id']
|
||||
|
||||
parent_activity = TimeEntryActivity.find(activity['parent_id'])
|
||||
activity['name'] = parent_activity.name
|
||||
activity['position'] = parent_activity.position
|
||||
|
||||
if Enumeration.overridding_change?(activity, parent_activity)
|
||||
self.time_entry_activities.build(activity)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -459,11 +487,41 @@ private
|
||||
@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
|
||||
# Returns all the active Systemwide and project specific activities
|
||||
def active_activities
|
||||
overridden_activity_ids = self.time_entry_activities.active.collect(&:parent_id)
|
||||
|
||||
if overridden_activity_ids.empty?
|
||||
return TimeEntryActivity.active
|
||||
else
|
||||
return system_activities_and_project_overrides
|
||||
end
|
||||
end
|
||||
|
||||
# Returns all the Systemwide and project specific activities
|
||||
# (inactive and active)
|
||||
def all_activities
|
||||
overridden_activity_ids = self.time_entry_activities.collect(&:parent_id)
|
||||
|
||||
if overridden_activity_ids.empty?
|
||||
return TimeEntryActivity.all
|
||||
else
|
||||
return system_activities_and_project_overrides(true)
|
||||
end
|
||||
end
|
||||
|
||||
# Returns the systemwide active activities merged with the project specific overrides
|
||||
def system_activities_and_project_overrides(include_inactive=false)
|
||||
if include_inactive
|
||||
return TimeEntryActivity.all.
|
||||
find(:all,
|
||||
:conditions => ["id NOT IN (?)", self.time_entry_activities.collect(&:parent_id)]) +
|
||||
self.time_entry_activities
|
||||
else
|
||||
return TimeEntryActivity.active.
|
||||
find(:all,
|
||||
:conditions => ["id NOT IN (?)", self.time_entry_activities.active.collect(&:parent_id)]) +
|
||||
self.time_entry_activities.active
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in new issue
Block a user