aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlban Peignier2017-12-27 00:17:35 +0100
committerGitHub2017-12-27 00:17:35 +0100
commitce109f3b7ad1aefe1c120796c24535cd178f2af2 (patch)
treea021ac0f19eeeb09a912ca939e0efa13e910e3e8
parenteac95acb8e7a4ab51a778e206533947e5a8fff49 (diff)
parent3b4dc7713abfd6ade94c7f09a36a14fec103401b (diff)
downloadchouette-core-ce109f3b7ad1aefe1c120796c24535cd178f2af2.tar.bz2
Merge pull request #178 from af83/5382-all-stop-types-in-routes
Enable all area types for Stopareas in Routes. Refs #5382
-rw-r--r--app/assets/stylesheets/components/_tables.sass12
-rw-r--r--app/controllers/autocomplete_stop_areas_controller.rb9
-rw-r--r--app/javascript/routes/components/BSelect2.js23
-rw-r--r--app/policies/stop_area_policy.rb8
-rw-r--r--app/views/routes/show.html.slim2
-rw-r--r--spec/controllers/autocomplete_stop_areas_controller_spec.rb24
-rw-r--r--spec/support/controller_spec_helper.rb15
7 files changed, 84 insertions, 9 deletions
diff --git a/app/assets/stylesheets/components/_tables.sass b/app/assets/stylesheets/components/_tables.sass
index 178ec2f36..119a38c07 100644
--- a/app/assets/stylesheets/components/_tables.sass
+++ b/app/assets/stylesheets/components/_tables.sass
@@ -211,6 +211,18 @@
top: 50%
margin-top: -8px
+ .zdlp
+ background: url( image-path('map/zdlp.png') ) no-repeat left 50%
+ padding-left: 30px
+
+ .lda
+ background: url( image-path('map/lda.png') ) no-repeat left 50%
+ padding-left: 30px
+
+ .gdl
+ background: url( image-path('map/lda.png') ) no-repeat left 50%
+ padding-left: 30px
+
// select_toolbox
.select_toolbox
diff --git a/app/controllers/autocomplete_stop_areas_controller.rb b/app/controllers/autocomplete_stop_areas_controller.rb
index be1badff0..d82fa316a 100644
--- a/app/controllers/autocomplete_stop_areas_controller.rb
+++ b/app/controllers/autocomplete_stop_areas_controller.rb
@@ -17,13 +17,20 @@ class AutocompleteStopAreasController < ChouetteController
scope = scope.possible_parents if relation_parent?
scope = scope.possible_parents if relation_children?
end
+ if search_scope.present?
+ scope = StopAreaPolicy::Scope.new(current_user, scope).search_scope(search_scope)
+ end
args = [].tap{|arg| 4.times{arg << "%#{params[:q]}%"}}
@stop_areas = scope.where("unaccent(name) ILIKE unaccent(?) OR unaccent(city_name) ILIKE unaccent(?) OR registration_number ILIKE ? OR objectid ILIKE ?", *args).limit(50)
@stop_areas
end
def target_type?
- params.has_key?( :target_type)
+ params.has_key?(:target_type)
+ end
+
+ def search_scope
+ params[:scope]
end
def relation_parent?
diff --git a/app/javascript/routes/components/BSelect2.js b/app/javascript/routes/components/BSelect2.js
index 340d9df95..0d8d7787f 100644
--- a/app/javascript/routes/components/BSelect2.js
+++ b/app/javascript/routes/components/BSelect2.js
@@ -96,17 +96,26 @@ class BSelect2 extends Component{
data: function(params) {
return {
q: params.term,
- target_type: 'zdep'
+ scope: 'route_editor'
};
},
processResults: function(data, params) {
return {
- results: data.map(
- item => _.assign(
- {},
- item,
- { text: item.name + ", " + item.zip_code + " " + item.short_city_name + " <small><em>(" + item.user_objectid + ")</em></small>" }
- )
+ results: data.map(
+ function(item) {
+ var text = item.name;
+ if (item.zip_code || item.short_city_name) {
+ text += ","
+ }
+ if (item.zip_code) {
+ text += ` ${item.zip_code}`
+ }
+ if (item.short_city_name) {
+ text += ` ${item.short_city_name}`
+ }
+ text += ` <small><em>(${item.area_type.toUpperCase()}, ${item.user_objectid})</em></small>`;
+ return _.assign({}, item, { text: text });
+ }
)
};
},
diff --git a/app/policies/stop_area_policy.rb b/app/policies/stop_area_policy.rb
index e5921ef61..6db48b702 100644
--- a/app/policies/stop_area_policy.rb
+++ b/app/policies/stop_area_policy.rb
@@ -1,5 +1,13 @@
class StopAreaPolicy < ApplicationPolicy
class Scope < Scope
+ def search_scope scope_name
+ scope = resolve
+ if scope_name&.to_s == "route_editor"
+ scope = scope.where(area_type: 'zdep') unless user.organisation.has_feature?("route_stop_areas_all_types")
+ end
+ scope
+ end
+
def resolve
scope
end
diff --git a/app/views/routes/show.html.slim b/app/views/routes/show.html.slim
index 3adf3e2f6..2b4ebf159 100644
--- a/app/views/routes/show.html.slim
+++ b/app/views/routes/show.html.slim
@@ -40,7 +40,7 @@
), \
TableBuilderHelper::Column.new( \
key: :name, \
- attribute: Proc.new {|s| s.try(:stop_area).try(:name)}, \
+ attribute: Proc.new { |s| content_tag :span, s.stop_area&.name, class: s.stop_area&.area_type }, \
link_to: lambda do |stop_point| \
referential_stop_area_path(@referential, stop_point.stop_area) \
end \
diff --git a/spec/controllers/autocomplete_stop_areas_controller_spec.rb b/spec/controllers/autocomplete_stop_areas_controller_spec.rb
index 50fc877dd..2af471361 100644
--- a/spec/controllers/autocomplete_stop_areas_controller_spec.rb
+++ b/spec/controllers/autocomplete_stop_areas_controller_spec.rb
@@ -5,6 +5,8 @@ RSpec.describe AutocompleteStopAreasController, type: :controller do
let(:referential) { Referential.first }
let!(:stop_area) { create :stop_area, name: 'écolà militaire' }
+ let!(:zdep_stop_area) { create :stop_area, area_type: "zdep" }
+ let!(:not_zdep_stop_area) { create :stop_area, area_type: "lda" }
describe 'GET #index' do
it 'should be successful' do
@@ -26,4 +28,26 @@ RSpec.describe AutocompleteStopAreasController, type: :controller do
end
end
end
+
+ context "when searching from the route editor" do
+ let(:scope) { :route_editor }
+ let(:request){
+ get :index, referential_id: referential.id, scope: scope
+ }
+ it "should filter stop areas based on type" do
+ request
+ expect(assigns(:stop_areas)).to include(zdep_stop_area)
+ expect(assigns(:stop_areas)).to_not include(not_zdep_stop_area)
+ end
+
+ with_feature :route_stop_areas_all_types do
+ it "should not filter stop areas based on type" do
+ request
+ expect(assigns(:stop_areas)).to include(zdep_stop_area)
+ expect(assigns(:stop_areas)).to include(not_zdep_stop_area)
+ end
+ end
+ end
+
+
end
diff --git a/spec/support/controller_spec_helper.rb b/spec/support/controller_spec_helper.rb
index 1d0288dea..dbc7d582b 100644
--- a/spec/support/controller_spec_helper.rb
+++ b/spec/support/controller_spec_helper.rb
@@ -11,6 +11,21 @@ module ControllerSpecHelper
end
end
+ def with_feature feature, &block
+ context "with feature #{feature}" do
+ login_user
+ before(:each) do
+ organisation = @user.organisation
+ unless organisation.has_feature?(feature)
+ organisation.features << feature
+ organisation.save!
+ end
+ sign_in @user
+ end
+ context('', &block) if block_given?
+ end
+ end
+
end
RSpec.configure do |config|