aboutsummaryrefslogtreecommitdiffstats
path: root/app/controllers
diff options
context:
space:
mode:
authorZog2018-04-19 16:38:15 +0200
committerJohan Van Ryseghem2018-04-27 11:17:19 +0200
commite8e029da36b493827820289f8db50645eb939806 (patch)
tree0e6fa62311641733673f4a53fa3e00c362b90b45 /app/controllers
parentc5f45f2a57b225503506c89df6b2a53a84028223 (diff)
downloadchouette-core-e8e029da36b493827820289f8db50645eb939806.tar.bz2
Refs #6572; Update filters on referentials list
Diffstat (limited to 'app/controllers')
-rw-r--r--app/controllers/workbenches_controller.rb47
1 files changed, 36 insertions, 11 deletions
diff --git a/app/controllers/workbenches_controller.rb b/app/controllers/workbenches_controller.rb
index 35438eaaf..43415ff60 100644
--- a/app/controllers/workbenches_controller.rb
+++ b/app/controllers/workbenches_controller.rb
@@ -5,7 +5,7 @@ class WorkbenchesController < ChouetteController
defaults resource_class: Workbench
include PolicyChecker
-
+
respond_to :html, except: :destroy
def index
@@ -50,7 +50,7 @@ class WorkbenchesController < ChouetteController
end
def sort_result collection
- col = (Workbench.find(params[:id]).referentials.column_names + %w{lines validity_period}).include?(params[:sort]) ? params[:sort] : 'name'
+ col = (Referential.column_names + %w{lines validity_period}).include?(params[:sort]) ? params[:sort] : 'name'
dir = %w[asc desc].include?(params[:direction]) ? params[:direction] : 'asc'
if ['lines', 'validity_period'].include?(col)
@@ -75,16 +75,41 @@ class WorkbenchesController < ChouetteController
# Fake ransack filter
def ransack_status scope
- archived = !params[:q]['archived_at_not_null'].to_i.zero?
- unarchived = !params[:q]['archived_at_null'].to_i.zero?
-
- # Both status checked, means no filter
- return scope unless archived || unarchived
- return scope if archived && unarchived
+ sql = scope.to_sql
+ filters = []
+ (params[:q] && params[:q][:state] || {}).each do |k, v|
+ if v == "1"
+
+ # We get the specific part of the SQL QUERY
+ # It looks a bit weird, bu this way we don't have to duplicate the
+ # logic of the scopes
+ filter_sql = scope.send(k).to_sql
+ j = 0
+ while filter_sql[j] == sql[j]
+ j += 1
+ end
+ i = j
+ while filter_sql[j] != sql[i]
+ j += 1
+ end
+
+ filter_sql = filter_sql[i..j]
+ filter_sql = filter_sql.strip
+ filter_sql = filter_sql.gsub /^AND\s*/i, ''
+ filters << filter_sql
+ end
+ end
- scope = scope.where(archived_at: nil) if unarchived
- scope = scope.where("archived_at is not null") if archived
- scope
+ # archived = !params[:q]['archived_at_not_null'].to_i.zero?
+ # unarchived = !params[:q]['archived_at_null'].to_i.zero?
+ #
+ # # Both status checked, means no filter
+ # return scope unless archived || unarchived
+ # return scope if archived && unarchived
+ #
+ # scope = scope.where(archived_at: nil) if unarchived
+ # scope = scope.where("archived_at is not null") if archived
+ scope.where filters.map{|f| "(#{f})"}.join('OR')
end
# Ignore archived_at_not_null/archived_at_null managed by ransack_status scope