Improve interface of change log table

The name of the changed field is translated, values are truncated so
descriptions with thousands of character would make this table huge and
impossible to read, dates are localized, and values like arrays and
booleans are displayed properly.
This commit is contained in:
Javi Martín
2019-11-03 16:31:24 +01:00
parent 04cd3b460e
commit 98e836ea83
8 changed files with 24 additions and 13 deletions

View File

@@ -0,0 +1,11 @@
module AuditsHelper
def truncate_audit_value(resource, field, value)
if value.is_a?(Array)
truncate(value.join(","), length: 50)
elsif resource.type_for_attribute(field.to_s).type == :boolean
resource.class.human_attribute_name("#{field}_#{value}")
else
truncate(value.to_s, length: 50)
end
end
end

View File

@@ -20,15 +20,15 @@
<% audit.audited_changes.each do |field, (old_value, new_value)| %>
<tr>
<td class="text-center"><%= audit.id %></td>
<td class="small"><%= field.capitalize %></td>
<td class="small"><%= sanitize(resource.class.human_attribute_name(field)) %></td>
<td class="small">
<div class="audit-value"><%= old_value %></div>
<div class="audit-value"><%= truncate_audit_value(resource, field, old_value) %></div>
</td>
<td class="small">
<div class="audit-value"><%= new_value %></div>
<div class="audit-value"><%= truncate_audit_value(resource, field, new_value) %></div>
</td>
<td class="small">
<%= audit.created_at.to_date %>
<%= l audit.created_at.to_date %>
</td>
<td class="small">
<%= audit.user&.name %>

View File

@@ -41,7 +41,7 @@
<div class="small-12 medium-4 column">
<p>
<strong><%= t("admin.budget_investments.show.selection.title") %></strong>:
<%= t("admin.budget_investments.show.selection.#{@investment.selected?}") %>
<%= @investment.class.human_attribute_name("selected_#{@investment.selected?}") %>
</p>
</div>
<div class="small-12 medium-4 column">

View File

@@ -161,6 +161,8 @@ en:
milestone_tag_list: "Milestone tags"
price_explanation: "Price explanation"
selected: "Mark as selected"
selected_true: "Selected"
selected_false: "Not selected"
unfeasibility_explanation: "Feasibility explanation"
valuation_finished: "Valuation finished"
valuator_ids: "Groups"

View File

@@ -241,8 +241,6 @@ en:
"false": Compatible
selection:
title: Selection
"true": Selected
"false": Not selected
winner:
title: Winner
"true": "Yes"
@@ -1592,7 +1590,7 @@ en:
edited_at: "Edited at"
edited_by: "Edited by"
actions: "Actions"
empty: "There are not changes logged"
empty: "There are no changes logged"
local_census_records:
index:
title: Manage local census

View File

@@ -163,6 +163,8 @@ es:
milestone_tag_list: "Etiquetas de Seguimiento"
price_explanation: "Informe de coste <small>(opcional, dato público)</small>"
selected: "Marcar como seleccionado"
selected_true: "Seleccionado"
selected_false: "No seleccionado"
unfeasibility_explanation: "Informe de inviabilidad <small>(en caso de que lo sea, dato público)</small>"
valuation_finished: "Informe finalizado"
valuator_ids: "Grupos"

View File

@@ -241,8 +241,6 @@ es:
"false": Compatible
selection:
title: Selección
"true": Seleccionado
"false": No seleccionado
winner:
title: Ganador
"true": "Si"

View File

@@ -27,7 +27,7 @@ describe "Admin change log" do
expect(page).to have_content(budget_investment.description)
expect(page).to have_content(budget_investment.author.name)
expect(page).to have_content(budget_investment.heading.name)
expect(page).to have_content("There are not changes logged")
expect(page).to have_content("There are no changes logged")
end
scenario "Changes" do
@@ -46,13 +46,13 @@ describe "Admin change log" do
expect(page).to have_content(budget_investment.description)
expect(page).to have_content(budget_investment.author.name)
expect(page).to have_content(budget_investment.heading.name)
expect(page).to have_content("There are not changes logged")
expect(page).to have_content("There are no changes logged")
click_link "Edit"
fill_in "Title", with: "test"
click_button "Update"
expect(page).not_to have_content("There are not changes logged")
expect(page).not_to have_content("There are no changes logged")
expect(page).to have_content("Change Log")
expect(page).to have_content("Title")
expect(page).to have_content("test")