1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
| # This file is a part of Redmine Checklists (redmine_checklists) plugin,
# issue checklists management plugin for Redmine
#
# Copyright (C) 2011-2015 Kirill Bezrukov
# http://www.redminecrm.com/
#
# redmine_checklists is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# redmine_checklists is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with redmine_checklists. If not, see <http://www.gnu.org/licenses/>.
module RedmineChecklists
module Patches
module IssuesHelperPatch
def self.included(base)
base.send(:include, InstanceMethods)
base.class_eval do
unloadable
alias_method_chain :details_to_strings, :checklists
alias_method_chain :render_email_issue_attributes, :checklists if Redmine::VERSION.to_s <= '2.4' && Redmine::VERSION.to_s >= '2.2'
end
end
module InstanceMethods
def render_email_issue_attributes_with_checklists(issue, html = false)
journal = issue.journals.order(:id).last
return render_email_issue_attributes_without_checklists(issue, html) unless journal
details = journal.details
return render_email_issue_attributes_without_checklists(issue, html) unless details
checklist_details = details.select{ |x| x.prop_key == 'checklist'}
return render_email_issue_attributes_without_checklists(issue, html) unless checklist_details.any?
return render_email_issue_attributes_without_checklists(issue, html) + details_to_strings_with_checklists(checklist_details, !html).join(html ? "<br/>".html_safe : "\n")
end
def details_to_strings_with_checklists(details, no_html = false, options = {})
details_checklist, details_other = details.partition{ |x| x.prop_key == 'checklist' }
details_checklist.map do |detail|
result = []
diff = Hash.new([])
if Checklist.old_format?(detail)
result << "<b>#{l(:label_checklist_item)}</b> #{l(:label_checklist_changed_from)} #{detail.old_value} #{l(:label_checklist_changed_to)} #{detail.value}"
else
diff = JournalChecklistHistory.new(detail.old_value, detail.value).diff
end
if diff[:removed].any?
diff[:removed].each do |item|
result << "<b>#{l(:label_checklist_item)}</b> #{l(:label_checklist_deleted)} (<strike><i>#{item[:subject]}</i></strike>)"
end
end
if diff[:renamed].any?
diff[:renamed].each do |was, became|
result << "<b>#{l(:label_checklist_item)}</b> #{l(:label_checklist_changed_from)} <i>#{was}</i> #{l(:label_checklist_changed_to)} <i>#{became}</i>"
end
end
if diff[:added].any?
diff[:added].each do |item|
result << "<b>#{l(:label_checklist_item)}</b> <input type='checkbox' #{item.is_done ? 'checked' : '' } disabled> <i>#{item[:subject]}</i> #{l(:label_checklist_added)}"
end
end
if diff[:done].any?
diff[:done].each do |item|
result << "<b>#{l(:label_checklist_item)}</b> <input type='checkbox' #{item.is_done ? 'checked' : '' } disabled> <i>#{item[:subject]}</i> #{l(:label_checklist_done)}"
end
end
if diff[:undone].any?
diff[:undone].each do |item|
result << "<b>#{l(:label_checklist_item)}</b> <input type='checkbox' #{item.is_done ? 'checked' : '' } disabled> <i>#{item[:subject]}</i> #{l(:label_checklist_undone)}"
end
end
result = result.join('</li><li>').html_safe
result = nil if result.blank?
if result && no_html
result = result.gsub /<\/li><li>/, "\n"
result = result.gsub /<input type='checkbox'[^c^>]*checked[^>]*>/, '[x]'
result = result.gsub /<input type='checkbox'[^c^>]*>/, '[ ]'
result = result.gsub /<[^>]*>/, ''
end
result
end.compact + details_to_strings_without_checklists(details_other, no_html, options)
end
end
end
end
end
unless IssuesHelper.included_modules.include?(RedmineChecklists::Patches::IssuesHelperPatch)
IssuesHelper.send(:include, RedmineChecklists::Patches::IssuesHelperPatch)
end |
Partager