Add alternate comparison types to versions

- The types are:
-- Previous: The default and the previously used type
-- Subsequent: Compares against the next version
-- Current: Compares against the current version
- Allow switching between comparison types in index and diff views
-- Have links vary depending upon current comparison type
This commit is contained in:
BrokenEagle
2020-03-17 07:23:42 +00:00
parent a95e57d938
commit e23ee170f5
41 changed files with 488 additions and 221 deletions

View File

@@ -5,37 +5,45 @@ module ApplicationHelper
(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)
def diff_list_html(this_list, other_list, ul_class: ["diff-list"], li_class: [])
diff = SetDiff.new(this_list, other_list)
render "diff_list", diff: diff, ul_class: ul_class, li_class: li_class
end
def diff_name_html(this_name, prev_name)
def diff_name_html(this_name, other_name)
pattern = Regexp.new('.')
DiffBuilder.new(this_name, prev_name, pattern).build
DiffBuilder.new(this_name, other_name, pattern).build
end
def diff_body_html(record, previous, field)
return h(record[field]).gsub(/\r?\n/, '<span class="paragraph-mark">¶</span><br>').html_safe if previous.blank?
def diff_body_html(record, other, field)
if record.blank? || other.blank?
diff_record = other.presence || record
return h(diff_record[field]).gsub(/\r?\n/, '<span class="paragraph-mark">¶</span><br>').html_safe
end
pattern = Regexp.new('(?:<.+?>)|(?:\w+)|(?:[ \t]+)|(?:\r?\n)|(?:.+?)')
DiffBuilder.new(record[field], previous[field], pattern).build
DiffBuilder.new(record[field], other[field], pattern).build
end
def status_diff_html(record)
previous = record.previous
def status_diff_html(record, type)
other = record.send(type)
return "New" if previous.blank?
if other.blank?
return type == "previous" ? "New" : ""
end
statuses = []
record.class.status_fields.each do |field, status|
if record.has_attribute?(field)
statuses += [status] if record[field] != previous[field]
statuses += [status] if record[field] != other[field]
else
statuses += [status] if record.send(field)
statuses += [status] if record.send(field, type)
end
end
statuses.join("<br>").html_safe
altered = record.updater_id != other.updater_id
%(<div class="version-statuses" data-altered="#{altered}">#{statuses.join("<br>")}</div>).html_safe
end
def wordbreakify(string)
@@ -44,6 +52,18 @@ module ApplicationHelper
raw(wordbreaked_string)
end
def version_type_links(params)
html = []
%w[previous subsequent current].each do |type|
if type == params[:type]
html << %(<span>#{type}</span>)
else
html << tag.li(link_to(type, params.except(:controller, :action).merge(type: type).permit!))
end
end
html.join(" | ").html_safe
end
def nav_link_to(text, url, **options)
klass = options.delete(:class)