Styling and refactor sorting methods and helpers

This commit is contained in:
Anna Anks Nowak
2019-01-02 20:55:57 +01:00
committed by Javi Martín
parent 3ab70ff0d8
commit e264490bca
2 changed files with 3 additions and 10 deletions

View File

@@ -5,18 +5,11 @@ module BudgetInvestmentsHelper
def link_to_investments_sorted_by(column)
sort_by = column.downcase
allowed_directions = %w[asc desc].freeze
default_direction = "desc"
current_direction = params[:direction]
if allowed_directions.include?(current_direction)
#select opposite direction
direction = allowed_directions.reject { |dir| dir == current_direction }.first
else
direction = default_direction
end
direction = params[:direction] == default_direction ? default_direction : "asc"
icon = direction == default_direction ? "icon-arrow-top" : "icon-arrow-down"
icon = direction == default_direction ? "icon-arrow-down" : "icon-arrow-top"
icon = sort_by == params[:sort_by] ? icon : ""
translation = t("admin.budget_investments.index.sort_by.#{sort_by}")

View File

@@ -144,7 +144,7 @@ class Budget
allowed_sort_option = SORTING_OPTIONS.select { |so| so[sorting_key]}.reduce
if allowed_sort_option.present?
direction = %w[asc desc].include?(params[:direction]) ? params[:direction] : "asc"
direction = params[:direction] == "desc" ? "desc" : "asc"
return order("#{allowed_sort_option[sorting_key]} #{direction}")
end
order(cached_votes_up: :desc).order(id: :desc)