Document · Versions

<% if params[:document_id] %>

<%= link_to(@document.title, admin_document_path(@document)) %> · <%= @document.versions.count %> versions

<% end %> <%- @document.versions.reverse.each_with_index do |version, index| %> <%- end %>
Version Change Time Ago
<%= @document.versions.count - index %> <%- # Current Document %> <%- if index == 0 %> <%- current = @document.json_attributes %> <%- previous = version&.previous&.reify&.json_attributes %> <%- diff = ::Hashdiff.diff(previous,current) %> <%- changeset = version.changeset.except(:json_attributes).collect{ |change| ["+", change[0], change[1][1]] }.flatten %> <%- diff << changeset %> <%- diff.each do |d| %> <%- next if d[0] == '~' %> <%- end %> <%- # Previous Document with another previous one %> <%- elsif version.previous && version.previous.reify %> <%- current = version.reify&.json_attributes %> <%- previous = version.previous.reify&.json_attributes %> <%- diff = ::Hashdiff.diff(previous,current) %> <%- changeset = version.changeset.except(:json_attributes).collect{ |change| ["+", change[0], change[1][1]] }.flatten %> <%- diff << changeset %> <%- diff.each do |d| %> <%- next if d[0] == '~' %> <%- end %> <%- # Very first Document %> <% else %> <%- current = version.changeset %> <%- previous = {} %> <%- diff = ::Hashdiff.diff(previous,current) %> <%- changeset = version.changeset.except(:json_attributes, :updated_at).collect{ |change| ["+", change[0], change[1][1]] }.flatten %> <%- diff.each do |d| %> <%- next if d[0] == '~' %> <%- next if d[2] == [""] %> <%- next if d[2].nil? %> <%- end %> <%- end %>
Operator Field Change
<%= d[0] %> <%= d[1] %> <%= d[2] %> <%= d[3] %>
<%= d[0] %> <%= d[1] %> <%- if d[2].kind_of?(Document::Reference) %> <%= d[2].category %> — <%= d[2].value %> <%- else %> <%= d[2] %> <%- end %> <%= d[3] %>
<%= d[0] %> <%= d[1] %> <%- if d[2].kind_of?(Document::Reference) %> <%= d[2].category %> — <%= d[2].value %> <%- else %> <%= d[2] %> <%- end %>
<%= time_ago_in_words(version.created_at) %>