aboutsummaryrefslogtreecommitdiffstats
path: root/app/controllers
diff options
context:
space:
mode:
authorLuc Donnet2017-07-13 17:13:12 +0200
committerLuc Donnet2017-07-13 17:13:12 +0200
commitea3ad8d1f9db76e3d2dfc5f96c930af8db074690 (patch)
treebde3f033418d512a80ef28703abb4c021c5a0f06 /app/controllers
parent3ef09ffa403dd253c19537bd3d477357d85bfa3d (diff)
parent0a2f9ff965389133fb9656dfb5b222ccfc2b0531 (diff)
downloadchouette-core-ea3ad8d1f9db76e3d2dfc5f96c930af8db074690.tar.bz2
Merge branch 'master' into staging
Diffstat (limited to 'app/controllers')
-rw-r--r--app/controllers/companies_controller.rb8
-rw-r--r--app/controllers/concerns/policy_checker.rb2
-rw-r--r--app/controllers/line_footnotes_controller.rb38
-rw-r--r--app/controllers/networks_controller.rb13
-rw-r--r--app/controllers/referential_companies_controller.rb8
-rw-r--r--app/controllers/referential_lines_controller.rb20
-rw-r--r--app/controllers/referential_networks_controller.rb16
-rw-r--r--app/controllers/referential_stop_areas_controller.rb5
-rw-r--r--app/controllers/referentials_controller.rb8
-rw-r--r--app/controllers/routes_controller.rb5
-rw-r--r--app/controllers/routing_constraint_zones_controller.rb21
-rw-r--r--app/controllers/stop_areas_controller.rb10
-rw-r--r--app/controllers/time_tables_controller.rb4
13 files changed, 121 insertions, 37 deletions
diff --git a/app/controllers/companies_controller.rb b/app/controllers/companies_controller.rb
index 9d33c6cb8..07a732fc9 100644
--- a/app/controllers/companies_controller.rb
+++ b/app/controllers/companies_controller.rb
@@ -15,6 +15,14 @@ class CompaniesController < BreadcrumbController
if collection.out_of_bounds?
redirect_to params.merge(:page => 1)
end
+
+ @companies = ModelDecorator.decorate(
+ @companies,
+ with: CompanyDecorator,
+ context: {
+ referential: line_referential
+ }
+ )
}
build_breadcrumb :index
end
diff --git a/app/controllers/concerns/policy_checker.rb b/app/controllers/concerns/policy_checker.rb
index c8a821cf7..65a4428e2 100644
--- a/app/controllers/concerns/policy_checker.rb
+++ b/app/controllers/concerns/policy_checker.rb
@@ -2,7 +2,7 @@ module PolicyChecker
extend ActiveSupport::Concern
included do
- before_action :authorize_resource, except: [:create, :index, :new]
+ before_action :authorize_resource, only: [:destroy, :edit, :show, :update]
before_action :authorize_resource_class, only: [:create, :index, :new]
end
diff --git a/app/controllers/line_footnotes_controller.rb b/app/controllers/line_footnotes_controller.rb
index 6a9048392..581c921e8 100644
--- a/app/controllers/line_footnotes_controller.rb
+++ b/app/controllers/line_footnotes_controller.rb
@@ -1,15 +1,9 @@
-class LineFootnotesController < BreadcrumbController
- defaults :resource_class => Chouette::Line
- include PolicyChecker
- respond_to :json, :only => :show
+class LineFootnotesController < ChouetteController
+ defaults resource_class: Chouette::Line, collection_name: 'lines', instance_name: 'line'
belongs_to :referential
- def show
- show! do
- build_breadcrumb :show
- end
- @footnotes = @line.footnotes
- end
+ before_action :authorize_resource, only: [:destroy_footnote, :edit_footnote, :show_footnote, :update_footnote]
+ before_action :authorize_resource_class, only: [:create_footnote, :index_footnote, :new_footnote]
def edit
edit! do
@@ -18,25 +12,31 @@ class LineFootnotesController < BreadcrumbController
end
def update
- if @line.update(line_params)
- redirect_to referential_line_footnotes_path(@referential, @line) , notice: t('notice.footnotes.updated')
- else
- render :edit
+ update! do |success, failure|
+ success.html { redirect_to referential_line_footnotes_path(@referential, @line) , notice: t('notice.footnotes.updated') }
+ failure.html { render :edit }
end
end
protected
- # overrides default
- def check_policy
+
+ protected
+ def authorize_resource
authorize resource, "#{action_name}_footnote?".to_sym
end
- private
+ def authorize_resource_class
+ authorize resource_class, "#{action_name}_footnote?".to_sym
+ end
+
+ alias_method :line, :resource
+
def resource
- @referential = Referential.find params[:referential_id]
- @line = @referential.lines.find params[:line_id]
+ @line ||= current_referential.lines.find params[:line_id]
end
+ private
+
def line_params
params.require(:line).permit(
{ footnotes_attributes: [ :code, :label, :_destroy, :id ] } )
diff --git a/app/controllers/networks_controller.rb b/app/controllers/networks_controller.rb
index ea8410c5b..d1f83340e 100644
--- a/app/controllers/networks_controller.rb
+++ b/app/controllers/networks_controller.rb
@@ -12,7 +12,12 @@ class NetworksController < BreadcrumbController
def show
@map = NetworkMap.new(resource).with_helpers(self)
+
show! do
+ @network = @network.decorate(context: {
+ line_referential: line_referential
+ })
+
build_breadcrumb :show
end
end
@@ -31,6 +36,14 @@ class NetworksController < BreadcrumbController
if collection.out_of_bounds?
redirect_to params.merge(:page => 1)
end
+
+ @networks = ModelDecorator.decorate(
+ @networks,
+ with: NetworkDecorator,
+ context: {
+ line_referential: line_referential
+ }
+ )
}
build_breadcrumb :index
end
diff --git a/app/controllers/referential_companies_controller.rb b/app/controllers/referential_companies_controller.rb
index e8b104d14..53dde93bb 100644
--- a/app/controllers/referential_companies_controller.rb
+++ b/app/controllers/referential_companies_controller.rb
@@ -13,6 +13,14 @@ class ReferentialCompaniesController < ChouetteController
if collection.out_of_bounds?
redirect_to params.merge(:page => 1)
end
+
+ @companies = ModelDecorator.decorate(
+ @companies,
+ with: CompanyDecorator,
+ context: {
+ referential: referential
+ }
+ )
}
build_breadcrumb :index
end
diff --git a/app/controllers/referential_lines_controller.rb b/app/controllers/referential_lines_controller.rb
index 4b4a822b4..1da64991d 100644
--- a/app/controllers/referential_lines_controller.rb
+++ b/app/controllers/referential_lines_controller.rb
@@ -10,18 +10,6 @@ class ReferentialLinesController < ChouetteController
belongs_to :referential
- def index
- @hide_group_of_line = referential.group_of_lines.empty?
- index! do |format|
- format.html {
- if collection.out_of_bounds?
- redirect_to params.merge(:page => 1)
- end
- build_breadcrumb :index
- }
- end
- end
-
def show
@routes = resource.routes
@@ -49,6 +37,14 @@ class ReferentialLinesController < ChouetteController
)
show! do
+ @line = ReferentialLineDecorator.decorate(
+ @line,
+ context: {
+ referential: referential,
+ current_organisation: current_organisation
+ }
+ )
+
build_breadcrumb :show
end
end
diff --git a/app/controllers/referential_networks_controller.rb b/app/controllers/referential_networks_controller.rb
index 30c7dd244..e0ce71ce4 100644
--- a/app/controllers/referential_networks_controller.rb
+++ b/app/controllers/referential_networks_controller.rb
@@ -10,7 +10,15 @@ class ReferentialNetworksController < ChouetteController
def show
@map = NetworkMap.new(resource).with_helpers(self)
+
show! do
+ @network = ReferentialNetworkDecorator.decorate(
+ @network,
+ context: {
+ referential: referential
+ }
+ )
+
build_breadcrumb :show
end
end
@@ -21,6 +29,14 @@ class ReferentialNetworksController < ChouetteController
if collection.out_of_bounds?
redirect_to params.merge(:page => 1)
end
+
+ @networks = ModelDecorator.decorate(
+ @networks,
+ with: ReferentialNetworkDecorator,
+ context: {
+ referential: referential
+ }
+ )
}
build_breadcrumb :index
end
diff --git a/app/controllers/referential_stop_areas_controller.rb b/app/controllers/referential_stop_areas_controller.rb
index 4d33ebb2e..7519418e7 100644
--- a/app/controllers/referential_stop_areas_controller.rb
+++ b/app/controllers/referential_stop_areas_controller.rb
@@ -72,13 +72,16 @@ class ReferentialStopAreasController < ChouetteController
def show
map.editable = false
@access_points = @stop_area.access_points
+
show! do |format|
unless stop_area.position or params[:default] or params[:routing]
format.kml {
render :nothing => true, :status => :not_found
}
-
end
+
+ @stop_area = @stop_area.decorate
+
build_breadcrumb :show
end
end
diff --git a/app/controllers/referentials_controller.rb b/app/controllers/referentials_controller.rb
index 9505a47f3..838c46168 100644
--- a/app/controllers/referentials_controller.rb
+++ b/app/controllers/referentials_controller.rb
@@ -27,6 +27,14 @@ class ReferentialsController < BreadcrumbController
show! do |format|
@referential = @referential.decorate
@reflines = lines_collection.paginate(page: params[:page], per_page: 10)
+ @reflines = ModelDecorator.decorate(
+ @reflines,
+ with: ReferentialLineDecorator,
+ context: {
+ referential: referential,
+ current_organisation: current_organisation
+ }
+ )
format.json {
render :json => { :lines_count => resource.lines.count,
diff --git a/app/controllers/routes_controller.rb b/app/controllers/routes_controller.rb
index 4781d0d16..7ba2c1a58 100644
--- a/app/controllers/routes_controller.rb
+++ b/app/controllers/routes_controller.rb
@@ -47,6 +47,11 @@ class RoutesController < ChouetteController
line: @line
})
+ @route_sp = ModelDecorator.decorate(
+ @route_sp,
+ with: StopPointDecorator
+ )
+
build_breadcrumb :show
end
end
diff --git a/app/controllers/routing_constraint_zones_controller.rb b/app/controllers/routing_constraint_zones_controller.rb
index c526e6348..6c3cb8a29 100644
--- a/app/controllers/routing_constraint_zones_controller.rb
+++ b/app/controllers/routing_constraint_zones_controller.rb
@@ -10,12 +10,29 @@ class RoutingConstraintZonesController < ChouetteController
belongs_to :line, parent_class: Chouette::Line
end
+ def index
+ index! do |format|
+ @routing_constraint_zones = ModelDecorator.decorate(
+ @routing_constraint_zones,
+ with: RoutingConstraintZoneDecorator,
+ context: {
+ referential: referential,
+ line: parent
+ }
+ )
+
+ build_breadcrumb :index
+ end
+ end
+
def show
show! do |format|
@routing_constraint_zone = @routing_constraint_zone.decorate(context: {
- referential: current_referential,
- line: parent.id
+ referential: referential,
+ line: parent
})
+
+ build_breadcrumb :show
end
end
diff --git a/app/controllers/stop_areas_controller.rb b/app/controllers/stop_areas_controller.rb
index ae3edbd3e..cdb7c59ab 100644
--- a/app/controllers/stop_areas_controller.rb
+++ b/app/controllers/stop_areas_controller.rb
@@ -53,11 +53,18 @@ class StopAreasController < BreadcrumbController
def index
request.format.kml? ? @per_page = nil : @per_page = 12
@zip_codes = stop_area_referential.stop_areas.where("zip_code is NOT null").distinct.pluck(:zip_code)
+
index! do |format|
format.html {
if collection.out_of_bounds?
redirect_to params.merge(:page => 1)
end
+
+ @stop_areas = ModelDecorator.decorate(
+ @stop_areas,
+ with: StopAreaDecorator
+ )
+
build_breadcrumb :index
}
end
@@ -90,6 +97,9 @@ class StopAreasController < BreadcrumbController
}
end
+
+ @stop_area = @stop_area.decorate
+
build_breadcrumb :show
end
end
diff --git a/app/controllers/time_tables_controller.rb b/app/controllers/time_tables_controller.rb
index f23e4c201..20d500ea9 100644
--- a/app/controllers/time_tables_controller.rb
+++ b/app/controllers/time_tables_controller.rb
@@ -117,7 +117,7 @@ class TimeTablesController < ChouetteController
end
def tags
- @tags = ActsAsTaggableOn::Tag.where("tags.name LIKE ?", "%#{params[:tag]}%")
+ @tags = ActsAsTaggableOn::Tag.where("tags.name = ?", "%#{params[:tag]}%")
respond_to do |format|
format.json { render :json => @tags.map{|t| {:id => t.id, :name => t.name }} }
end
@@ -130,7 +130,7 @@ class TimeTablesController < ChouetteController
if params[:q] && params[:q]["tag_search"]
tags = params[:q]["tag_search"].reject {|c| c.empty?}
params[:q].delete("tag_search")
- scope = select_time_tables.tagged_with(tags, :wild => true, :any => true) if tags.any?
+ scope = select_time_tables.tagged_with(tags, :any => true) if tags.any?
end
scope = ransack_periode(scope)
@q = scope.search(params[:q])