aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/controllers/stop_areas_controller.rb26
-rw-r--r--app/models/chouette/stop_area.rb20
-rw-r--r--app/views/referential_stop_areas/show.html.slim2
-rw-r--r--app/views/routes/show.html.slim2
-rw-r--r--app/views/stop_areas/_filters.html.slim6
-rw-r--r--app/views/stop_areas/index.html.slim2
-rw-r--r--app/views/stop_areas/show.html.slim2
7 files changed, 27 insertions, 33 deletions
diff --git a/app/controllers/stop_areas_controller.rb b/app/controllers/stop_areas_controller.rb
index c3d27cc6c..38363e8ef 100644
--- a/app/controllers/stop_areas_controller.rb
+++ b/app/controllers/stop_areas_controller.rb
@@ -120,7 +120,6 @@ class StopAreasController < ChouetteController
def collection
scope = parent.present? ? parent.stop_areas : referential.stop_areas
- scope = ransack_status(scope) if params[:q] && params[:q][:status_eq_any]
@q = scope.search(params[:q])
if sort_column && sort_direction
@@ -206,29 +205,4 @@ class StopAreasController < ChouetteController
] + permitted_custom_fields_params(Chouette::StopArea.custom_fields(stop_area_referential.workgroup))
params.require(:stop_area).permit(fields)
end
-
- # Fake ransack filter
- def ransack_status scope
- status_param = params[:q][:status_eq_any].reject(&:blank?)
- params[:q].delete :status_eq_any
-
- return scope unless status_param
- return scope if status_param.empty? || status_param.length == 3
-
-
- @status = Hash.new do |hash|
- hash[:status_eq_any] = {
- in_creation: status_param.include?('in_creation'),
- confirmed: status_param.include?('confirmed'),
- deactivated: status_param.include?('deactivated'),
- }
- end
-
- scope = Chouette::StopArea.where(
- "confirmed_at #{(@status[:status_eq_any][:confirmed] || @status[:status_eq_any][:deactivated]) ? "IS NOT NULL" : "IS NULL"}
- AND deleted_at #{@status[:status_eq_any][:deactivated] ? "IS NOT NULL" : "IS NULL"}"
- )
-
- scope
- end
end
diff --git a/app/models/chouette/stop_area.rb b/app/models/chouette/stop_area.rb
index b933e1944..479407469 100644
--- a/app/models/chouette/stop_area.rb
+++ b/app/models/chouette/stop_area.rb
@@ -383,6 +383,26 @@ module Chouette
end
end
+ def self.ransackable_scopes(auth_object = nil)
+ [:by_status]
+ end
+
+
+ def self.by_status(*statuses)
+ return Chouette::StopArea.all if statuses.reject(&:blank?).length == 3 || statuses.reject(&:blank?).empty?
+
+ status = {
+ in_creation: statuses.include?('in_creation'),
+ confirmed: statuses.include?('confirmed'),
+ deactivated: statuses.include?('deactivated'),
+ }
+
+ Chouette::StopArea.where(
+ "confirmed_at #{status[:confirmed] ? "IS NOT NULL" : "IS NULL"}
+ AND deleted_at #{status[:deactivated] ? "IS NOT NULL" : "IS NULL"}"
+ )
+ end
+
def activated?
!!(deleted_at.nil? && confirmed_at)
end
diff --git a/app/views/referential_stop_areas/show.html.slim b/app/views/referential_stop_areas/show.html.slim
index beee0383f..06096bbaa 100644
--- a/app/views/referential_stop_areas/show.html.slim
+++ b/app/views/referential_stop_areas/show.html.slim
@@ -7,7 +7,7 @@
.col-lg-6.col-md-6.col-sm-12.col-xs-12
= definition_list t('metadatas'),
{ t('id_reflex') => @stop_area.try(:user_objectid),
- Chouette::StopArea.tmf(:status) => stop_area_status(@stop_area),
+ Chouette::StopArea.tmf(:status) => stop_area_status(@stop_area.status),
Chouette::StopArea.tmf(:comment) => @stop_area.try(:comment),
Chouette::StopArea.tmf(:stop_area_type) => t("area_types.label.#{@stop_area.stop_area_type}"),
Chouette::StopArea.tmf(:registration_number) => @stop_area.registration_number,
diff --git a/app/views/routes/show.html.slim b/app/views/routes/show.html.slim
index 2218bd85f..615913faa 100644
--- a/app/views/routes/show.html.slim
+++ b/app/views/routes/show.html.slim
@@ -36,7 +36,7 @@
TableBuilderHelper::Column.new( \
key: :status, \
name: Chouette::StopArea.tmf('status'), \
- attribute: Proc.new { |s| stop_area_status(s.try(:stop_area)) } \
+ attribute: Proc.new { |s| stop_area_status(s.try(:stop_area).try(:status) ) } \
), \
TableBuilderHelper::Column.new( \
key: :zip_code, \
diff --git a/app/views/stop_areas/_filters.html.slim b/app/views/stop_areas/_filters.html.slim
index 2bc59ce75..88ed6a772 100644
--- a/app/views/stop_areas/_filters.html.slim
+++ b/app/views/stop_areas/_filters.html.slim
@@ -16,9 +16,9 @@
= f.label Chouette::StopArea.tmf('area_type'), required: false, class: 'control-label'
= f.input :area_type_eq_any, checked: params[:q] && params[:q][:area_type_eq_any], collection: Chouette::AreaType.options, as: :check_boxes, label: false, label_method: lambda{|w| ("<span>" + w[0] + "</span>").html_safe}, required: false, wrapper_html: { class: 'checkbox_list' }
- .form-group.togglable class=filter_item_class(@status, :status_eq_any)
- = f.label Chouette::StopArea.tmf('state'), required: false, class: 'control-label'
- = f.input :status_eq_any, checked: lambda { |w| @status.try(:[], :status_eq_any).try(:[], w)}, collection: [:in_creation, :confirmed, :deactivated], as: :check_boxes, label: false, label_method: lambda{|w| ("<span>" + stop_area_status(w) + "</span>").html_safe}, required: false, wrapper_html: { class: 'checkbox_list' }
+ .form-group.togglable class=filter_item_class(params[:q], :by_status)
+ = f.label Chouette::StopArea.tmf('status'), required: false, class: 'control-label'
+ = f.input :by_status, checked: params[:q] && params[:q][:by_status], collection: [:in_creation, :confirmed, :deactivated], as: :check_boxes, label: false, label_method: lambda{|w| ("<span>" + stop_area_status(w) + "</span>").html_safe}, required: false, wrapper_html: { class: 'checkbox_list' }
.actions
= link_to t('actions.erase'), @workbench, class: 'btn btn-link'
diff --git a/app/views/stop_areas/index.html.slim b/app/views/stop_areas/index.html.slim
index 62b873c36..e5ca82ee2 100644
--- a/app/views/stop_areas/index.html.slim
+++ b/app/views/stop_areas/index.html.slim
@@ -33,7 +33,7 @@
), \
TableBuilderHelper::Column.new( \
key: :status, \
- attribute: Proc.new { |s| stop_area_status(s) } \
+ attribute: Proc.new { |s| stop_area_status(s.status) } \
), \
TableBuilderHelper::Column.new( \
key: :zip_code, \
diff --git a/app/views/stop_areas/show.html.slim b/app/views/stop_areas/show.html.slim
index c10d22bfb..c1965c161 100644
--- a/app/views/stop_areas/show.html.slim
+++ b/app/views/stop_areas/show.html.slim
@@ -21,7 +21,7 @@
Chouette::StopArea.tmf('city_name') => @stop_area.city_name,
Chouette::StopArea.tmf('country_code') => @stop_area.country_code.presence || '-',
Chouette::StopArea.tmf('time_zone') => @stop_area.time_zone.presence || '-',
- Chouette::StopArea.tmf('status') => stop_area_status(@stop_area),
+ Chouette::StopArea.tmf('status') => stop_area_status(@stop_area.status),
Chouette::StopArea.tmf('comment') => @stop_area.try(:comment),
})
- @stop_area.custom_fields.each do |code, field|