diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2016-10-23 11:31:20 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2016-10-23 11:31:20 +0000 |
commit | eb023bdcce2bd6d9ec3b1d37aa09e436c5ee8149 (patch) | |
tree | 352efa51b7e99d469ac3121eb531b58715609b30 /app/models/version.rb | |
parent | f94711ea8c9998a6a6af74370fdc02c9c25208cb (diff) | |
download | redmine-eb023bdcce2bd6d9ec3b1d37aa09e436c5ee8149.tar.gz redmine-eb023bdcce2bd6d9ec3b1d37aa09e436c5ee8149.zip |
Add option to set a new version as default directly from New Version page (#24011).
git-svn-id: http://svn.redmine.org/redmine/trunk@15922 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/models/version.rb')
-rw-r--r-- | app/models/version.rb | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/app/models/version.rb b/app/models/version.rb index 98d1c6ac0..2b82f7c5b 100644 --- a/app/models/version.rb +++ b/app/models/version.rb @@ -19,6 +19,7 @@ class Version < ActiveRecord::Base include Redmine::SafeAttributes after_update :update_issues_from_sharing_change + after_save :update_default_project_version before_destroy :nullify_projects_default_version belongs_to :project @@ -65,6 +66,7 @@ class Version < ActiveRecord::Base 'wiki_page_title', 'status', 'sharing', + 'default_project_version', 'custom_field_values', 'custom_fields' @@ -82,6 +84,12 @@ class Version < ActiveRecord::Base project.present? && project.attachments_deletable?(usr) end + alias :base_reload :reload + def reload(*args) + @default_project_version = nil + base_reload(*args) + end + def start_date @start_date ||= fixed_issues.minimum('start_date') end @@ -263,6 +271,18 @@ class Version < ActiveRecord::Base fixed_issues.empty? && !referenced_by_a_custom_field? end + def default_project_version + if @default_project_version.nil? + project.present? && project.default_version == self + else + @default_project_version + end + end + + def default_project_version=(arg) + @default_project_version = (arg == '1' || arg == true) + end + private def load_issue_counts @@ -291,6 +311,12 @@ class Version < ActiveRecord::Base end end + def update_default_project_version + if @default_project_version && project.present? + project.update_columns :default_version_id => id + end + end + # Returns the average estimated time of assigned issues # or 1 if no issue has an estimated time # Used to weight unestimated issues in progress calculation |