Fix sorting links for non-English languages

We were assuming the translation and the column name were related.
This commit is contained in:
Javi Martín
2019-01-10 15:05:04 +01:00
parent 3fd7b3d216
commit ee2f970e03
4 changed files with 7 additions and 18 deletions

View File

@@ -4,23 +4,22 @@ module BudgetInvestmentsHelper
end
def link_to_investments_sorted_by(column)
sort_by = column.downcase
current_direction = params[:direction].downcase if params[:direction]
direction = set_direction(current_direction)
icon = set_sorting_icon(direction, sort_by)
icon = set_sorting_icon(direction, column)
translation = t("admin.budget_investments.index.sort_by.#{sort_by}")
translation = t("admin.budget_investments.index.list.#{column}")
link_to(
"#{translation} <span class=\"#{icon}\"></span>".html_safe,
admin_budget_budget_investments_path(sort_by: sort_by, direction: direction)
admin_budget_budget_investments_path(sort_by: column, direction: direction)
)
end
def set_sorting_icon(direction, sort_by)
icon = direction == "desc" ? "icon-arrow-top" : "icon-arrow-down"
icon = sort_by == params[:sort_by] ? icon : ""
icon = sort_by.to_s == params[:sort_by] ? icon : ""
end
def set_direction(current_direction)

View File

@@ -26,9 +26,9 @@
<table class="table-for-mobile">
<thead>
<tr>
<th><%= link_to_investments_sorted_by t("admin.budget_investments.index.list.id") %></th>
<th class="small-3"><%= link_to_investments_sorted_by t("admin.budget_investments.index.list.title") %></th>
<th><%= link_to_investments_sorted_by t("admin.budget_investments.index.list.supports") %></th>
<th><%= link_to_investments_sorted_by :id %></th>
<th class="small-3"><%= link_to_investments_sorted_by :title %></th>
<th><%= link_to_investments_sorted_by :supports %></th>
<th><%= t("admin.budget_investments.index.list.admin") %></th>
<th>
<%= t("admin.budget_investments.index.list.valuation_group") %>

View File

@@ -176,11 +176,6 @@ en:
tags_filter_all: All tags
advanced_filters: Advanced filters
placeholder: Search projects
sort_by:
placeholder: Sort by
id: ID
title: Title
supports: Supports
filters:
all: All
without_admin: Without assigned admin

View File

@@ -176,11 +176,6 @@ es:
tags_filter_all: Todas las etiquetas
advanced_filters: Filtros avanzados
placeholder: Buscar proyectos
sort_by:
placeholder: Ordenar por
id: ID
title: Título
supports: Apoyos
filters:
all: Todos
without_admin: Sin administrador