From cf27fe8839822b460ac1f4a5f5cd3e2866ac9a41 Mon Sep 17 00:00:00 2001 From: "sylor_huang@126.com" Date: Wed, 18 Mar 2020 15:32:54 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=B7=A5=E5=8D=95=E7=9A=84?= =?UTF-8?q?=E8=AF=84=E8=AE=BA=E4=BF=AE=E6=94=B9=E5=86=85=E5=AE=B9=E5=90=8E?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E8=AE=B0=E5=BD=95=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/journal.rb | 238 +++++++++++++++++++++--------------------- 1 file changed, 120 insertions(+), 118 deletions(-) diff --git a/app/models/journal.rb b/app/models/journal.rb index 01c10de..b943bd4 100644 --- a/app/models/journal.rb +++ b/app/models/journal.rb @@ -19,127 +19,129 @@ class Journal < ApplicationRecord details = self.journal_details.select(:property, :prop_key, :old_value, :value).pluck(:property, :prop_key, :old_value, :value) if details.size > 0 details.each do |de| - if de[0] == "attr" - content = "" - else - content = "附件" - end - old_value = de[2] - value = de[3] - if de[1].to_i > 0 - prop_name = "" - else - prop_name = I18n.t("journal_detail.#{de[1]}") - case de[1] - when "is_private" - old_value = I18n.t("journal_detail.#{de[2]}") - value = I18n.t("journal_detail.#{de[3]}") - when "assigned_to_id" - u = User.select(:id, :login, :lastname, :firstname, :nickname) - old_value = de[2].to_i > 0 ? u.find_by_id(de[2]).try(:show_real_name) : "" - assign_user = de[3].to_i > 0 ? u.find_by_id(de[3]) : "" - if assign_user.present? - value = assign_user.try(:show_real_name) - else - value = "" - end - - when "tracker_id" - t = Tracker.select(:id, :name) - old_value = de[2].to_i > 0 ? t.find_by_id(de[2]).try(:name) : "" - tracker_name = de[3].to_i > 0 ? t.find_by_id(de[3]) : "" - if tracker_name - value = tracker_name.try(:name) - else - value = "" - end - - when "status_id" - t = IssueStatus.select(:id, :name) - old_value = de[2].to_i > 0 ? t.find_by_id(de[2]).try(:name) : "" - type_name = de[3].to_i > 0 ? t.find_by_id(de[3]) : "" - if type_name - value = type_name.try(:name) - else - value = "" - end - when "priority_id" - t = IssuePriority.select(:id, :name) - old_value = de[2].to_i > 0 ? t.find_by_id(de[2]).try(:name): "" - type_name = de[3].to_i > 0 ? t.find_by_id(de[3]) : "" - if type_name - value = type_name.try(:name) - else - value = "" - end - when "issue_tags_value" - t = IssueTag.select(:id, :name) - old_value = de[2].to_i > 0 ? t.where(id: de[2].split(",")).select(:id,:name,:color).as_json : "" - if de[3].present? - value = t.where(id: de[3].split(",")).select(:id,:name,:color).as_json - else - value = "" - end - when "fixed_version_id" - t = Version.select(:id, :name) - old_value = de[2].to_i > 0 ? t.find_by_id(de[2]).try(:name) : "" - type_name = de[3].to_i > 0 ? t.find_by_id(de[3]) : "" - if type_name - value = type_name.try(:name) - else - value = "" - end - when "end_time" - t = IssueTime.select(:id, :start_time, :end_time) - type_name = de[2].to_i > 0 ? t.find_by_id(de[2]) : "" - if type_name.present? - old_value = "停止工作" - d_value = type_name.end_time.to_i - type_name.start_time.to_i - value = "#{Time.at(d_value).utc.strftime('%H h %M min %S s')}" - else - old_value = "停止工作" - value = "" - end - when "issue_depend" - t = Issue.select(:id,:subject ) - type_name = de[3].present? ? t&.find_by_id(de[3]) : "" - if type_name.present? - old_value = "增加依赖" - value = { - id: de[3], - name: type_name.try(:subject) - } - else - old_value = "增加依赖" - value = "" - end - when "destroy_issue_depend" - t = Issue.select(:id,:subject ) - type_name = de[3].present? ? t&.find_by_id(de[3]) : "" - if type_name.present? - old_value = "删除依赖" - value = { - id: de[3], - name: type_name.try(:subject) - } - else - old_value = "删除依赖" - value = "" - end - when "done_ratio" - old_value = "#{de[2]}%" - value = "#{de[3]}%" + unless de[1] == "description" + if de[0] == "attr" + content = "" else - old_value = de[2] - value = de[3] + content = "附件" end + old_value = de[2] + value = de[3] + if de[1].to_i > 0 + prop_name = "" + else + prop_name = I18n.t("journal_detail.#{de[1]}") + case de[1] + when "is_private" + old_value = I18n.t("journal_detail.#{de[2]}") + value = I18n.t("journal_detail.#{de[3]}") + when "assigned_to_id" + u = User.select(:id, :login, :lastname, :firstname, :nickname) + old_value = de[2].to_i > 0 ? u.find_by_id(de[2]).try(:show_real_name) : "" + assign_user = de[3].to_i > 0 ? u.find_by_id(de[3]) : "" + if assign_user.present? + value = assign_user.try(:show_real_name) + else + value = "" + end + + when "tracker_id" + t = Tracker.select(:id, :name) + old_value = de[2].to_i > 0 ? t.find_by_id(de[2]).try(:name) : "" + tracker_name = de[3].to_i > 0 ? t.find_by_id(de[3]) : "" + if tracker_name + value = tracker_name.try(:name) + else + value = "" + end + + when "status_id" + t = IssueStatus.select(:id, :name) + old_value = de[2].to_i > 0 ? t.find_by_id(de[2]).try(:name) : "" + type_name = de[3].to_i > 0 ? t.find_by_id(de[3]) : "" + if type_name + value = type_name.try(:name) + else + value = "" + end + when "priority_id" + t = IssuePriority.select(:id, :name) + old_value = de[2].to_i > 0 ? t.find_by_id(de[2]).try(:name): "" + type_name = de[3].to_i > 0 ? t.find_by_id(de[3]) : "" + if type_name + value = type_name.try(:name) + else + value = "" + end + when "issue_tags_value" + t = IssueTag.select(:id, :name) + old_value = de[2].to_i > 0 ? t.where(id: de[2].split(",")).select(:id,:name,:color).as_json : "" + if de[3].present? + value = t.where(id: de[3].split(",")).select(:id,:name,:color).as_json + else + value = "" + end + when "fixed_version_id" + t = Version.select(:id, :name) + old_value = de[2].to_i > 0 ? t.find_by_id(de[2]).try(:name) : "" + type_name = de[3].to_i > 0 ? t.find_by_id(de[3]) : "" + if type_name + value = type_name.try(:name) + else + value = "" + end + when "end_time" + t = IssueTime.select(:id, :start_time, :end_time) + type_name = de[2].to_i > 0 ? t.find_by_id(de[2]) : "" + if type_name.present? + old_value = "停止工作" + d_value = type_name.end_time.to_i - type_name.start_time.to_i + value = "#{Time.at(d_value).utc.strftime('%H h %M min %S s')}" + else + old_value = "停止工作" + value = "" + end + when "issue_depend" + t = Issue.select(:id,:subject ) + type_name = de[3].present? ? t&.find_by_id(de[3]) : "" + if type_name.present? + old_value = "增加依赖" + value = { + id: de[3], + name: type_name.try(:subject) + } + else + old_value = "增加依赖" + value = "" + end + when "destroy_issue_depend" + t = Issue.select(:id,:subject ) + type_name = de[3].present? ? t&.find_by_id(de[3]) : "" + if type_name.present? + old_value = "删除依赖" + value = { + id: de[3], + name: type_name.try(:subject) + } + else + old_value = "删除依赖" + value = "" + end + when "done_ratio" + old_value = "#{de[2]}%" + value = "#{de[3]}%" + else + old_value = de[2] + value = de[3] + end + end + prop_hash = { + detail: (content + prop_name), + old_value: old_value, + value: value + } + send_details.push(prop_hash) end - prop_hash = { - detail: (content + prop_name), - old_value: old_value, - value: value - } - send_details.push(prop_hash) end end end