From 6b09b7c2ae7917aa177b6698811da189db8ae25c Mon Sep 17 00:00:00 2001 From: Xinhui Date: Tue, 18 Apr 2017 11:58:14 +0200 Subject: Workbenches#show order referentials by validity periode Refs #3010 --- app/controllers/workbenches_controller.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'app/controllers/workbenches_controller.rb') 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 -- cgit v1.2.3