aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuc Donnet2017-09-19 15:47:38 +0200
committerLuc Donnet2017-09-19 15:47:38 +0200
commit307e5a191509e08981d16084b57d5dcc71be6bcd (patch)
tree71c10b52c1aee715e20d44a8115819f98da84bf9
parentcf25969daf8a039e29f1a653c3a2ee7d23cd4103 (diff)
parent5ffc337dfc86017840a5402058d490fd20d29bf4 (diff)
downloadchouette-core-307e5a191509e08981d16084b57d5dcc71be6bcd.tar.bz2
Merge branch 'master' of github.com:AF83/stif-boiv
-rw-r--r--app/controllers/compliance_controls_controller.rb16
-rw-r--r--app/decorators/compliance_control_decorator.rb25
-rw-r--r--app/models/journey_pattern_control/duplicates.rb13
-rw-r--r--app/models/route_control/duplicates.rb1
-rw-r--r--app/models/route_control/speed.rb15
-rw-r--r--app/models/route_control/time_table.rb13
-rw-r--r--app/models/route_control/vehicle_journey_at_stops.rb13
-rw-r--r--app/models/routing_constaint_zone_control/unactivated_stop_point.rb13
-rw-r--r--app/models/vechicle_journey_control/delta.rb15
-rw-r--r--app/models/vechicle_journey_control/waiting_time.rb13
-rw-r--r--app/policies/compliance_control_policy.rb19
-rw-r--r--app/views/compliance_control_sets/index.html.slim1
-rw-r--r--app/views/compliance_controls/_form.html.slim12
-rw-r--r--app/views/compliance_controls/index.html.slim44
-rw-r--r--app/views/compliance_controls/new.html.slim9
-rw-r--r--config/locales/compliance_controls.en.yml81
-rw-r--r--config/locales/compliance_controls.fr.yml61
-rw-r--r--spec/policies/compliance_control_policy_spec.rb28
18 files changed, 373 insertions, 19 deletions
diff --git a/app/controllers/compliance_controls_controller.rb b/app/controllers/compliance_controls_controller.rb
index d198f2cdb..dad9b935a 100644
--- a/app/controllers/compliance_controls_controller.rb
+++ b/app/controllers/compliance_controls_controller.rb
@@ -1,7 +1,16 @@
class ComplianceControlsController < BreadcrumbController
+ include PolicyChecker
defaults resource_class: ComplianceControl
belongs_to :compliance_control_set
+ def index
+ index! do |format|
+ format.html {
+ @compliance_controls = decorate_compliance_controls(@compliance_controls)
+ }
+ end
+ end
+
def create
create!(notice: t('notice.compliance_control.created'))
end
@@ -16,6 +25,13 @@ class ComplianceControlsController < BreadcrumbController
end
private
+ def decorate_compliance_controls(compliance_controls)
+ ModelDecorator.decorate(
+ compliance_controls,
+ with: ComplianceControlDecorator,
+ )
+ end
+
def compliance_control_params
params.require(:compliance_control).permit(:name, :code, :criticity, :comment, :control_attributes)
end
diff --git a/app/decorators/compliance_control_decorator.rb b/app/decorators/compliance_control_decorator.rb
new file mode 100644
index 000000000..38b968ad1
--- /dev/null
+++ b/app/decorators/compliance_control_decorator.rb
@@ -0,0 +1,25 @@
+class ComplianceControlDecorator < Draper::Decorator
+ delegate_all
+
+ def action_links
+ links = []
+
+ if h.policy(object).destroy?
+ links << Link.new(
+ content: h.destroy_link_content,
+ href: h.compliance_control_set_compliance_control_path(object.compliance_control_set.id, object.id),
+ method: :delete,
+ data: { confirm: h.t('compliance_controls.actions.destroy_confirm') }
+ )
+ end
+
+ if h.policy(object).edit?
+ links << Link.new(
+ content: h.t('compliance_controls.actions.edit'),
+ href: h.edit_compliance_control_set_path(object.compliance_control_set.id, object.id)
+ )
+ end
+ links
+ end
+
+end
diff --git a/app/models/journey_pattern_control/duplicates.rb b/app/models/journey_pattern_control/duplicates.rb
new file mode 100644
index 000000000..78ca07e90
--- /dev/null
+++ b/app/models/journey_pattern_control/duplicates.rb
@@ -0,0 +1,13 @@
+module JourneyPatternControl
+ class Duplicates < ComplianceControl
+
+ @@default_criticity = :warning
+ @@default_code = "3-JourneyPattern-1"
+
+ after_initialize do
+ self.name = self.class.name
+ self.code = @@default_code
+ self.criticity = @@default_criticity
+ end
+ end
+end
diff --git a/app/models/route_control/duplicates.rb b/app/models/route_control/duplicates.rb
index 803ac063e..379d7cf98 100644
--- a/app/models/route_control/duplicates.rb
+++ b/app/models/route_control/duplicates.rb
@@ -9,6 +9,5 @@ module RouteControl
self.code = @@default_code
self.criticity = @@default_criticity
end
-
end
end
diff --git a/app/models/route_control/speed.rb b/app/models/route_control/speed.rb
new file mode 100644
index 000000000..fb07b5c87
--- /dev/null
+++ b/app/models/route_control/speed.rb
@@ -0,0 +1,15 @@
+module VehicleJourneyControl
+ class Speed < ComplianceControl
+
+ hstore_accessor :control_attributes, minimum: :integer, maximum: :integer
+
+ @@default_criticity = :warning
+ @@default_code = "3-VehicleJourney-2"
+
+ after_initialize do
+ self.name = self.class.name
+ self.code = @@default_code
+ self.criticity = @@default_criticity
+ end
+ end
+end
diff --git a/app/models/route_control/time_table.rb b/app/models/route_control/time_table.rb
new file mode 100644
index 000000000..911807ba9
--- /dev/null
+++ b/app/models/route_control/time_table.rb
@@ -0,0 +1,13 @@
+module VehicleJourneyControl
+ class TimeTable < ComplianceControl
+
+ @@default_criticity = :error
+ @@default_code = "3-VehicleJourney-4"
+
+ after_initialize do
+ self.name = self.class.name
+ self.code = @@default_code
+ self.criticity = @@default_criticity
+ end
+ end
+end
diff --git a/app/models/route_control/vehicle_journey_at_stops.rb b/app/models/route_control/vehicle_journey_at_stops.rb
new file mode 100644
index 000000000..02a43fb10
--- /dev/null
+++ b/app/models/route_control/vehicle_journey_at_stops.rb
@@ -0,0 +1,13 @@
+module VehicleJourneyControl
+ class VehicleJourneyAtStops < ComplianceControl
+
+ @@default_criticity = :error
+ @@default_code = "3-VehicleJourney-5"
+
+ after_initialize do
+ self.name = self.class.name
+ self.code = @@default_code
+ self.criticity = @@default_criticity
+ end
+ end
+end
diff --git a/app/models/routing_constaint_zone_control/unactivated_stop_point.rb b/app/models/routing_constaint_zone_control/unactivated_stop_point.rb
new file mode 100644
index 000000000..92a1d1a58
--- /dev/null
+++ b/app/models/routing_constaint_zone_control/unactivated_stop_point.rb
@@ -0,0 +1,13 @@
+module RoutingConstaintZoneControl
+ class UnactivatedStopPoint < ComplianceControl
+
+ @@default_criticity = :warning
+ @@default_code = "3-ITL-1"
+
+ after_initialize do
+ self.name = self.class.name
+ self.code = @@default_code
+ self.criticity = @@default_criticity
+ end
+ end
+end
diff --git a/app/models/vechicle_journey_control/delta.rb b/app/models/vechicle_journey_control/delta.rb
new file mode 100644
index 000000000..d4e1e6eca
--- /dev/null
+++ b/app/models/vechicle_journey_control/delta.rb
@@ -0,0 +1,15 @@
+module VehicleJourneyControl
+ class Delta < ComplianceControl
+
+ hstore_accessor :control_attributes, delta: :integer
+
+ @@default_criticity = :warning
+ @@default_code = "3-VehicleJourney-3"
+
+ after_initialize do
+ self.name = self.class.name
+ self.code = @@default_code
+ self.criticity = @@default_criticity
+ end
+ end
+end
diff --git a/app/models/vechicle_journey_control/waiting_time.rb b/app/models/vechicle_journey_control/waiting_time.rb
new file mode 100644
index 000000000..a7e90b6ac
--- /dev/null
+++ b/app/models/vechicle_journey_control/waiting_time.rb
@@ -0,0 +1,13 @@
+module VehicleJourneyControl
+ class WatingTime < ComplianceControl
+
+ @@default_criticity = :warning
+ @@default_code = "3-VehicleJourney-1"
+
+ after_initialize do
+ self.name = self.class.name
+ self.code = @@default_code
+ self.criticity = @@default_criticity
+ end
+ end
+end
diff --git a/app/policies/compliance_control_policy.rb b/app/policies/compliance_control_policy.rb
new file mode 100644
index 000000000..aeb0ab0a9
--- /dev/null
+++ b/app/policies/compliance_control_policy.rb
@@ -0,0 +1,19 @@
+class ComplianceControlPolicy < ApplicationPolicy
+ class Scope < Scope
+ def resolve
+ scope
+ end
+ end
+
+ def destroy?
+ organisation_match? && user.has_permission?('compliance_controls.destroy')
+ end
+
+ def create?
+ user.has_permission?('compliance_controls.create')
+ end
+
+ def update?
+ organisation_match? && user.has_permission?('compliance_controls.update')
+ end
+end
diff --git a/app/views/compliance_control_sets/index.html.slim b/app/views/compliance_control_sets/index.html.slim
index 16879af5a..fa85c38f7 100644
--- a/app/views/compliance_control_sets/index.html.slim
+++ b/app/views/compliance_control_sets/index.html.slim
@@ -45,7 +45,6 @@
) \
],
sortable: true,
- links: [:show],
cls: 'table has-filter has-search'
diff --git a/app/views/compliance_controls/_form.html.slim b/app/views/compliance_controls/_form.html.slim
new file mode 100644
index 000000000..1377ed12b
--- /dev/null
+++ b/app/views/compliance_controls/_form.html.slim
@@ -0,0 +1,12 @@
+= simple_form_for [@compliance_control_set, @compliance_control], html: { class: 'form-horizontal', id: 'compliance_control_form' }, wrapper: :horizontal_form do |f|
+ .row
+ .col-lg-12
+ = f.input :name
+ = f.input :type
+ = f.input :code
+ = f.input :criticity
+ = f.input :comment
+
+ .separator
+
+ = f.button :submit, t('actions.submit'), class: 'btn btn-default formSubmitr', form: 'compliance_control_form'
diff --git a/app/views/compliance_controls/index.html.slim b/app/views/compliance_controls/index.html.slim
index e69de29bb..fd1293837 100644
--- a/app/views/compliance_controls/index.html.slim
+++ b/app/views/compliance_controls/index.html.slim
@@ -0,0 +1,44 @@
+/ PageHeader
+- header_params = ['jeux-de-donnees',
+ t('compliance_controls.index.title'),
+ '']
+- header_params << link_to(t('compliance_controls.actions.new'), new_compliance_control_set_compliance_control_path(@compliance_control_set), class: 'btn btn-default') if policy(ComplianceControl).create?
+= pageheader(*header_params) do
+
+ .row.mb-sm
+ .col-lg-12.text-right
+
+.page_content
+ .container-fluid
+ .row
+ .col-lg-12
+ /= render 'filters'
+ .row
+ .col-lg-12
+ .select_table
+ = table_builder_2 @compliance_controls,
+ [ \
+ TableBuilderHelper::Column.new( \
+ key: :code, \
+ attribute: 'code' \
+ ), \
+ TableBuilderHelper::Column.new( \
+ key: :name, \
+ attribute: 'name', \
+ link_to: lambda do |compliance_control| \
+ compliance_control_set_compliance_control_path(@compliance_control_set, compliance_control) \
+ end \
+ ), \
+ TableBuilderHelper::Column.new( \
+ key: :criticity, \
+ attribute: 'criticity' \
+ ), \
+ TableBuilderHelper::Column.new( \
+ key: :comment, \
+ attribute: 'comment' \
+ ), \
+ ],
+ sortable: true,
+ cls: 'table has-filter has-search'
+
+
diff --git a/app/views/compliance_controls/new.html.slim b/app/views/compliance_controls/new.html.slim
index e69de29bb..0651461cb 100644
--- a/app/views/compliance_controls/new.html.slim
+++ b/app/views/compliance_controls/new.html.slim
@@ -0,0 +1,9 @@
+= pageheader 'compliance-control',
+ t('compliance_control.index.new')
+
+
+.page_content
+ .container-fluid
+ .row
+ .col-lg-8.col-lg-offset-2.col-md-8.col-md-offset-2.col-sm-10.col-sm-offset-1
+ = render 'form'
diff --git a/config/locales/compliance_controls.en.yml b/config/locales/compliance_controls.en.yml
index 78073f047..bad190b56 100644
--- a/config/locales/compliance_controls.en.yml
+++ b/config/locales/compliance_controls.en.yml
@@ -1,30 +1,83 @@
-fr:
+en:
compliance_controls:
- route_control:
+ actions:
+ new: Add a new compliance control
+ edit: Edit this compliance control
+ destroy: Remove this compliance control
+ destroy_confirm: Are you sure you want destroy this compliance control?
+ show:
+ title: Compliance control
+ index:
+ title: Compliance control
+ new:
+ title: Add a new compliance control
+ edit:
+ title: Update compliance control
+ activerecord:
+ models:
+ compliance_control: compliance control
+ attributes:
+ compliance_control:
+ name: Name
+ code: Code
+ route:
zdl_stop_area:
messages:
- 3_route_1: L'itinéraire % dessert successivement les arrêts % % et % % de la même zone de lieu
- description: Deux arrêts d’une même ZDL ne peuvent pas se succéder dans un itinéraire
+ 3_route_1: The route with % objectid connect the stop points % % et % % which belong to the same ZDL
+ description: Two stop points which belong to the same ZDL cannot follow one another in a route
opposite_route:
messages:
- 3_route_2: L'itinéraire {objectId} référence un itinéraire retour % incohérent
+ 3_route_2: The route with % objectid references an incoherent oppposite route : %
description: |
- 'Si l'itinéraire référence un itinéraire inverse, celui-ci doit :
- - référencer l'itinéraire inverse
- - avoir un sens opposé à l'itinéraire testé'
+ 'If the route has an opposite route, it must :
+ - reference the opposite route
+ - have an opposite route in relation with the tested route'
duplicates:
messages:
- 3_route_4: L'itinéraire % est identique à l'itinéraire %
- description: 2 itinéraires ne doivent pas desservir strictement les mêmes arrêts dans le même ordre avec les mêmes critères de monté/descente
+ 3_route_4: The route with % objectid is identical with another route : %
+ description: 2 routes cannot connect the same stop points with the same order and the same boarding and alighting characteristics
minimum_length:
messages:
- 3_route_6: L'itinéraire % ne dessert pas assez d'arrêts (minimum 2 requis)
- description: Un itinéraire doit référencer au moins 2 arrêts
+ 3_route_6: The route with % objectid does not connect enough stop points (required 2 stop points)
+ description: A route must have at least 2 stop points
omnibus_journey_pattern:
messages:
- 3_route_9: L'itinéraire % n'a aucune mission desservant l'ensemble de ses arrêts
- description: Une mission de l'itinéraire devrait desservir l'ensemble des arrêts de celui-ci
+ 3_route_9: The route with % objectid does not have a journey pattern that connect all of its stop points
+ description: A journey pattern of a route should connect all of a route's stop points
unactivated_stop_point:
messages:
3_route_10: L'itinéraire % référence un arrêt (ZDEp) désactivé % (%)
description: Les arrêts d'un itinéraire ne doivent pas être désactivés
+ journey_pattern:
+ duplicates:
+ messages:
+ 3_journeypattern_1: The journey pattern with objectid % is identical with another one : %
+ description: Two journey patterns belonging to the same line must not connect the same stop points in the same order
+ vehicle_journey:
+ waiting_time:
+ messages:
+ 3_vehiclejourney_1: On the following vehicle journey : %, the waiting time % a this stop point : % (%) is greater than the threshold (%)
+ description: The waiting time at a specific stop point cannot be too big
+ speed:
+ messages:
+ 3_vehiclejourney_2_1: On the following vehicle journey : %, the computed speed % between the stop points % (%) and % (%) is greater than the threshold (%)
+ 3_vehiclejourney_2_2: On the following vehicle journey : %, the computed speed % between the stop points % (%) and % (%) is smaller than the threshold (%)
+ description: The speed between 2 stop points should be confined between two thresholds
+ delta:
+ messages:
+ 3_vehiclejourney_3: The travel time on the vehicle journey with % objectid between the stop points % (%) and % (% is too far off % the average waiting on the journey pattern
+ description: The travel time between two following stop points must be close to all the vehicle journey of a journey pattern
+ time_table:
+ messages:
+ 3_vehiclejourney_4: The vehicle journey with % objectid does not have a timetable
+ description: A vehicle journey must have at least one timetable
+ vehicle_journey_at_stops:
+ messages:
+ 3_vehiclejourney_5_1: The vehicle journey with % objectid has an arrival time % greater than the departure time % at the stop point % (%)
+ 3_vehiclejourney_5_2: The vehicle journey with % objectid has an departure time % at stop point % (%) greater than the arrival % at the next stop point
+ description: The arrival time of a stop point must be smaller than the departure time of this stop point AND the departure time of the stop points must be in chronological order
+ routing_constraint_zone:
+ vehicle_journey_at_stops:
+ messages:
+ 3_itl_1: The Routing Constraint Zone % references an unactivated stop point (ZDEp) : % (%)
+ description: The stop points of a Routing Constraint Zone must be activated
diff --git a/config/locales/compliance_controls.fr.yml b/config/locales/compliance_controls.fr.yml
index d4f2c608e..0c96265ac 100644
--- a/config/locales/compliance_controls.fr.yml
+++ b/config/locales/compliance_controls.fr.yml
@@ -1,13 +1,35 @@
fr:
compliance_controls:
- route_control:
+ actions:
+ new: Ajouter un jeu de controle
+ edit: Editer un jeu de controle
+ destroy: Supprimer un jeu de controle
+ destroy_confirm: Etes vous sûr de vouloir détruire le jeu de controle ?
+ show:
+ title: Jeu de controle
+ index:
+ title: Jeux de controles
+ new:
+ title: Ajouter un jeu de controle
+ edit:
+ title: Editer le jeu de controle
+ activerecord:
+ models:
+ compliance_control: Jeu de controle
+ attributes:
+ compliance_control:
+ name: Nom
+ criticity: Criticité
+ comment: Commentaire
+ code: Code
+ route:
zdl_stop_area:
messages:
3_route_1: L'itinéraire % dessert successivement les arrêts % % et % % de la même zone de lieu
description: Deux arrêts d’une même ZDL ne peuvent pas se succéder dans un itinéraire
opposite_route:
messages:
- 3_route_2: L'itinéraire {objectId} référence un itinéraire retour % incohérent
+ 3_route_2: L'itinéraire % référence un itinéraire retour % incohérent
description: |
'Si l'itinéraire référence un itinéraire inverse, celui-ci doit :
- référencer l'itinéraire inverse
@@ -26,5 +48,38 @@ fr:
description: Une mission de l'itinéraire devrait desservir l'ensemble des arrêts de celui-ci
unactivated_stop_point:
messages:
- 3_route_10: L'itinéraire % référence un arrêt (ZDEp) désactivé % (%)
+ 3_route_10: L'itinéraire % référence un arrêt (ZDEp) désactivé % (%)
description: Les arrêts d'un itinéraire ne doivent pas être désactivés
+ journey_pattern:
+ duplicates:
+ messages:
+ 3_journeypattern_1: La mission % est identique à la mission %
+ description: Deux missions de la même ligne ne doivent pas desservir les mêmes arrêts dans le même ordre
+ vehicle_journey:
+ waiting_time:
+ messages:
+ 3_vehiclejourney_1: Sur la course %, le temps d'attente % à l'arrêt % (%) est supérieur au seuil toléré (%)
+ description: La durée d’attente à un arrêt ne doit pas être trop grande
+ speed:
+ messages:
+ 3_vehiclejourney_2_1: Sur la course %, la vitesse calculée % entre les arrêts % (%) et % (%) est supérieur au seuil toléré (%)
+ 3_vehiclejourney_2_2: Sur la course %, la vitesse calculée % entre les arrêts % (%) et % (%) est inférieur au seuil toléré (%)
+ description: La vitesse entre deux arrêts doit être dans une fourchette paramétrable
+ delta:
+ messages:
+ 3_vehiclejourney_3: Le temps de parcours sur la course % entre les arrêts % (%) et % (% s'écarte de % du temps moyen constaté sur la mission
+ description: Les temps de parcours entre 2 arrêts successifs doivent être similaires pour toutes les courses d’une même mission
+ time_table:
+ messages:
+ 3_vehiclejourney_4: La course % n'a pas de calendrier d'application
+ description: Une course doit avoir au moins un calendrier d’application
+ vehicle_journey_at_stops:
+ messages:
+ 3_vehiclejourney_5_1: La course % a un horaire d'arrivé % supérieur à l'horaire de départ % à l'arrêt {nomArrêt} (%)
+ 3_vehiclejourney_5_2: La course % a un horaire de départ % à l'arrêt {nomArrêt} (%) supérieur à l'horaire d'arrivé % à l'arrêt suivant
+ description: L'horaire d'arrivée à un arrêt doit être antérieur à l'horaire de départ de cet arrêt ET les horaires de départ aux arrêts doivent être dans l'ordre chronologique croissant.
+ routing_constraint_zone:
+ vehicle_journey_at_stops:
+ messages:
+ 3_itl_1: L'ITL % référence un arrêt (ZDEp) désactivé % (%)
+ description: Les arrêts d'une ITL ne doivent pas être désactivés
diff --git a/spec/policies/compliance_control_policy_spec.rb b/spec/policies/compliance_control_policy_spec.rb
new file mode 100644
index 000000000..d7c80143d
--- /dev/null
+++ b/spec/policies/compliance_control_policy_spec.rb
@@ -0,0 +1,28 @@
+require 'rails_helper'
+
+RSpec.describe ComplianceControlPolicy do
+
+ let(:user) { User.new }
+
+ subject { described_class }
+
+ permissions ".scope" do
+ pending "add some examples to (or delete) #{__FILE__}"
+ end
+
+ permissions :show? do
+ pending "add some examples to (or delete) #{__FILE__}"
+ end
+
+ permissions :create? do
+ pending "add some examples to (or delete) #{__FILE__}"
+ end
+
+ permissions :update? do
+ pending "add some examples to (or delete) #{__FILE__}"
+ end
+
+ permissions :destroy? do
+ pending "add some examples to (or delete) #{__FILE__}"
+ end
+end