diff options
| author | Luc Donnet | 2017-09-19 15:47:38 +0200 |
|---|---|---|
| committer | Luc Donnet | 2017-09-19 15:47:38 +0200 |
| commit | 307e5a191509e08981d16084b57d5dcc71be6bcd (patch) | |
| tree | 71c10b52c1aee715e20d44a8115819f98da84bf9 /app | |
| parent | cf25969daf8a039e29f1a653c3a2ee7d23cd4103 (diff) | |
| parent | 5ffc337dfc86017840a5402058d490fd20d29bf4 (diff) | |
| download | chouette-core-307e5a191509e08981d16084b57d5dcc71be6bcd.tar.bz2 | |
Merge branch 'master' of github.com:AF83/stif-boiv
Diffstat (limited to 'app')
| -rw-r--r-- | app/controllers/compliance_controls_controller.rb | 16 | ||||
| -rw-r--r-- | app/decorators/compliance_control_decorator.rb | 25 | ||||
| -rw-r--r-- | app/models/journey_pattern_control/duplicates.rb | 13 | ||||
| -rw-r--r-- | app/models/route_control/duplicates.rb | 1 | ||||
| -rw-r--r-- | app/models/route_control/speed.rb | 15 | ||||
| -rw-r--r-- | app/models/route_control/time_table.rb | 13 | ||||
| -rw-r--r-- | app/models/route_control/vehicle_journey_at_stops.rb | 13 | ||||
| -rw-r--r-- | app/models/routing_constaint_zone_control/unactivated_stop_point.rb | 13 | ||||
| -rw-r--r-- | app/models/vechicle_journey_control/delta.rb | 15 | ||||
| -rw-r--r-- | app/models/vechicle_journey_control/waiting_time.rb | 13 | ||||
| -rw-r--r-- | app/policies/compliance_control_policy.rb | 19 | ||||
| -rw-r--r-- | app/views/compliance_control_sets/index.html.slim | 1 | ||||
| -rw-r--r-- | app/views/compliance_controls/_form.html.slim | 12 | ||||
| -rw-r--r-- | app/views/compliance_controls/index.html.slim | 44 | ||||
| -rw-r--r-- | app/views/compliance_controls/new.html.slim | 9 |
15 files changed, 220 insertions, 2 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' |
