aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorAlban Peignier2017-12-27 00:17:35 +0100
committerGitHub2017-12-27 00:17:35 +0100
commitce109f3b7ad1aefe1c120796c24535cd178f2af2 (patch)
treea021ac0f19eeeb09a912ca939e0efa13e910e3e8 /app
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
Diffstat (limited to 'app')
-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
5 files changed, 45 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 \