From 434e031faa52e8105465a1f6efee410cffd2635b Mon Sep 17 00:00:00 2001 From: BrokenEagle Date: Sat, 8 Feb 2020 22:37:55 +0000 Subject: [PATCH] Add additional helper methods --- app/helpers/application_helper.rb | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index c7cd7d9d2..21b5e2b4c 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,11 +1,38 @@ require 'dtext' module ApplicationHelper + def listing_type(*fields, member_check: true, types: [:revert, :standard]) + (fields.reduce(false) { |acc, field| acc || params.dig(:search, field).present? } && (!member_check || CurrentUser.is_member?) ? types[0] : types[1]) + end + def diff_list_html(new, old, latest, ul_class: ["diff-list"], li_class: []) diff = SetDiff.new(new, old, latest) render "diff_list", diff: diff, ul_class: ul_class, li_class: li_class end + def diff_body_html(record, previous, field) + return h(record[field]).gsub(/\r?\n/, 'ΒΆ
').html_safe if previous.blank? + + pattern = Regexp.new('(?:<.+?>)|(?:\w+)|(?:[ \t]+)|(?:\r?\n)|(?:.+?)') + DiffBuilder.new(record[field], previous[field], pattern).build + end + + def status_diff_html(record) + previous = record.previous + + return "New" if previous.blank? + + statuses = [] + record.class.status_fields.each do |field, status| + if record.has_attribute?(field) + statuses += [status] if record[field] != previous[field] + else + statuses += [status] if record.send(field) + end + end + statuses.join("
").html_safe + end + def wordbreakify(string) lines = string.scan(/.{1,10}/) wordbreaked_string = lines.map {|str| h(str)}.join("")