diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2017-01-18 14:49:57 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2017-01-18 14:49:57 +0000 |
commit | 6fabc106964a6e33eb5f0cf779856a6b24451692 (patch) | |
tree | 8d0fd29250ca7588c7d8e332c44df4018f486968 /app | |
parent | 3a21dc6912ab6f0426dc5a59c68c571447bf9bef (diff) | |
download | redmine-6fabc106964a6e33eb5f0cf779856a6b24451692.tar.gz redmine-6fabc106964a6e33eb5f0cf779856a6b24451692.zip |
Add warning when loosing data from custom fields when bulk editing issues (#22600).
git-svn-id: http://svn.redmine.org/redmine/trunk@16224 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/issues_controller.rb | 19 | ||||
-rw-r--r-- | app/models/custom_field_value.rb | 8 | ||||
-rw-r--r-- | app/views/issues/bulk_edit.html.erb | 7 |
3 files changed, 34 insertions, 0 deletions
diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index 1b6a82aa4..0f66f27fb 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -213,6 +213,16 @@ class IssuesController < ApplicationController edited_issues = Issue.where(:id => @issues.map(&:id)).to_a + @values_by_custom_field = {} + edited_issues.each do |issue| + issue.custom_field_values.each do |c| + if c.value_present? + @values_by_custom_field[c.custom_field] ||= [] + @values_by_custom_field[c.custom_field] << issue.id + end + end + end + @allowed_projects = Issue.allowed_target_projects if params[:issue] @target_project = @allowed_projects.detect {|p| p.id.to_s == params[:issue][:project_id].to_s} @@ -244,6 +254,15 @@ class IssuesController < ApplicationController end end + edited_issues.each do |issue| + issue.custom_field_values.each do |c| + if c.value_present? && @values_by_custom_field[c.custom_field] + @values_by_custom_field[c.custom_field].delete(issue.id) + end + end + end + @values_by_custom_field.delete_if {|k,v| v.blank?} + @custom_fields = edited_issues.map{|i|i.editable_custom_fields}.reduce(:&).select {|field| field.format.bulk_edit_supported} @assignables = target_projects.map(&:assignable_users).reduce(:&) @versions = target_projects.map {|p| p.shared_versions.open}.reduce(:&) diff --git a/app/models/custom_field_value.rb b/app/models/custom_field_value.rb index 38cffc0e6..eea09b289 100644 --- a/app/models/custom_field_value.rb +++ b/app/models/custom_field_value.rb @@ -52,6 +52,14 @@ class CustomFieldValue @value = custom_field.set_custom_field_value(self, v) end + def value_present? + if value.is_a?(Array) + value.any?(&:present?) + else + value.present? + end + end + def validate_value custom_field.validate_custom_value(self).each do |message| customized.errors.add(:base, custom_field.name + ' ' + message) diff --git a/app/views/issues/bulk_edit.html.erb b/app/views/issues/bulk_edit.html.erb index 29b4881c7..23817f875 100644 --- a/app/views/issues/bulk_edit.html.erb +++ b/app/views/issues/bulk_edit.html.erb @@ -186,6 +186,13 @@ </fieldset> </div> +<% if @values_by_custom_field.present? %> +<div class="flash warning"> + <%= l(:warning_fields_cleared_on_bulk_edit) %>:<br /> + <%= safe_join(@values_by_custom_field.map {|field, ids| content_tag "span", "#{field.name} (#{ids.size})"}, ', ') %> +</div> +<% end %> + <p> <% if @copy %> <%= hidden_field_tag 'copy', '1' %> |