diff options
Diffstat (limited to 'app')
| -rw-r--r-- | app/controllers/workbenches_controller.rb | 7 | ||||
| -rw-r--r-- | app/models/referential.rb | 2 | 
2 files changed, 6 insertions, 3 deletions
| diff --git a/app/controllers/workbenches_controller.rb b/app/controllers/workbenches_controller.rb index 1424fe03c..d621a28d7 100644 --- a/app/controllers/workbenches_controller.rb +++ b/app/controllers/workbenches_controller.rb @@ -37,10 +37,11 @@ class WorkbenchesController < BreadcrumbController    end    def sort_result collection -    col = (Workbench.find(params[:id]).referentials.column_names + %w{lines}).include?(params[:sort]) ? params[:sort] : 'name' +    col = (Workbench.find(params[:id]).referentials.column_names + %w{lines validity_period}).include?(params[:sort]) ? params[:sort] : 'name'      dir = %w[asc desc].include?(params[:direction]) ?  params[:direction] : 'asc' -    if col == "lines" -      collection.joins(:metadatas).group("referentials.id").order("sum(array_length(referential_metadata.line_ids,1)) #{dir}") + +    if ['lines', 'validity_period'].include?(col) +      collection.send("order_by_#{col}", dir)      else        collection.order("#{col} #{dir}")      end diff --git a/app/models/referential.rb b/app/models/referential.rb index 2c64a9a5c..50db32637 100644 --- a/app/models/referential.rb +++ b/app/models/referential.rb @@ -45,6 +45,8 @@ class Referential < ActiveRecord::Base    scope :ready, -> { where(ready: true) }    scope :in_periode, ->(periode) { where(id: referential_ids_in_periode(periode)) }    scope :include_metadatas_lines, ->(line_ids) { where('referential_metadata.line_ids && ARRAY[?]::bigint[]', line_ids) } +  scope :order_by_validity_period, ->(dir) { joins(:metadatas).order("unnest(periodes) #{dir}") } +  scope :order_by_lines, ->(dir) { joins(:metadatas).group("referentials.id").order("sum(array_length(referential_metadata.line_ids,1)) #{dir}") }    def lines      if metadatas.blank? | 
