aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/controllers/routing_constraint_zones_controller.rb15
-rw-r--r--app/helpers/breadcrumb_helper.rb8
-rw-r--r--app/helpers/newfront_helper.rb1
-rw-r--r--app/models/chouette/line.rb2
-rw-r--r--app/models/chouette/routing_constraint_zone.rb9
-rw-r--r--app/policies/routing_constraint_zone_policy.rb13
-rw-r--r--app/views/referential_lines/show.html.slim2
-rw-r--r--app/views/referentials/_form.html.slim2
-rw-r--r--app/views/routing_constraint_zones/_form.html.slim13
-rw-r--r--app/views/routing_constraint_zones/edit.html.slim5
-rw-r--r--app/views/routing_constraint_zones/index.html.slim10
-rw-r--r--app/views/routing_constraint_zones/new.html.slim5
-rw-r--r--app/views/routing_constraint_zones/show.html.slim18
-rw-r--r--config/initializers/inflections.rb5
-rw-r--r--config/locales/referentials.en.yml1
-rw-r--r--config/locales/routing_constraint_zones.en.yml23
-rw-r--r--config/locales/routing_constraint_zones.fr.yml20
-rw-r--r--config/routes.rb1
-rw-r--r--db/migrate/20161208112130_create_routing_constraint_zones.rb11
-rw-r--r--db/migrate/20161208114057_add_trident_fields_to_routing_constraint_zone.rb6
-rw-r--r--db/migrate/20161208120132_add_other_trident_fields_to_routing_constraint_zone.rb6
-rw-r--r--db/schema.rb16
-rw-r--r--spec/factories/chouette_routing_constraint_zones.rb7
-rw-r--r--spec/features/routing_constraint_zone_spec.rb26
-rw-r--r--spec/models/chouette/routing_constraint_zone_spec.rb13
25 files changed, 234 insertions, 4 deletions
diff --git a/app/controllers/routing_constraint_zones_controller.rb b/app/controllers/routing_constraint_zones_controller.rb
new file mode 100644
index 000000000..1c2c40cbb
--- /dev/null
+++ b/app/controllers/routing_constraint_zones_controller.rb
@@ -0,0 +1,15 @@
+class RoutingConstraintZonesController < ChouetteController
+ defaults resource_class: Chouette::RoutingConstraintZone
+
+ respond_to :html, :xml, :json
+
+ belongs_to :referential do
+ belongs_to :line, parent_class: Chouette::Line
+ end
+
+ private
+ def routing_constraint_zone_params
+ params.require(:routing_constraint_zone).permit(:name, { stop_area_ids: [] }, :line_id, :objectid, :object_version, :creation_time, :creator_id)
+ end
+
+end
diff --git a/app/helpers/breadcrumb_helper.rb b/app/helpers/breadcrumb_helper.rb
index 9d503fe2e..dc68bd897 100644
--- a/app/helpers/breadcrumb_helper.rb
+++ b/app/helpers/breadcrumb_helper.rb
@@ -36,6 +36,8 @@ module BreadcrumbHelper
route_section_breadcrumb action
when "Chouette::Timeband"
timeband_breadcrumb action
+ when 'Chouette::RoutingConstraintZone'
+ routing_constraint_zone_breadcrumb action
when "StopAreaCopy"
stop_area_copy_breadcrumb action
when "Import"
@@ -159,6 +161,12 @@ module BreadcrumbHelper
add_breadcrumb breadcrumb_label(@route), referential_line_route_path(@referential, @line,@route),:title => breadcrumb_tooltip(@route) if action == :edit
end
+ def routing_constraint_zone_breadcrumb(action)
+ line_breadcrumb :edit
+ add_breadcrumb Chouette::RoutingConstraintZone.model_name.human.pluralize(:fr), referential_line_routing_constraint_zones_path(@referential, @line) unless action == :index
+ add_breadcrumb breadcrumb_label(@routing_constraint_zone), referential_line_routing_constraint_zone_path(@referential, @line, @routing_constraint_zone), title: breadcrumb_tooltip(@routing_constraint_zone) if %i(show edit).include? action
+ end
+
def journey_pattern_breadcrumb(action)
route_breadcrumb :edit
add_breadcrumb breadcrumb_label(@journey_pattern), referential_line_route_journey_pattern_path(@referential, @line,@route,@journey_pattern),:title => breadcrumb_tooltip(@journey_pattern) if action == :edit
diff --git a/app/helpers/newfront_helper.rb b/app/helpers/newfront_helper.rb
index 806502391..2abfd589d 100644
--- a/app/helpers/newfront_helper.rb
+++ b/app/helpers/newfront_helper.rb
@@ -57,6 +57,7 @@ module NewfrontHelper
if current_referential
polymorph_url << current_referential
+ polymorph_url << item.line if item.respond_to? :line
elsif item.respond_to? :referential
polymorph_url << item.referential
elsif item.respond_to? :line_referential
diff --git a/app/models/chouette/line.rb b/app/models/chouette/line.rb
index 3f7a72021..6c5d8501f 100644
--- a/app/models/chouette/line.rb
+++ b/app/models/chouette/line.rb
@@ -23,6 +23,8 @@ class Chouette::Line < Chouette::ActiveRecord
has_many :footnotes, :inverse_of => :line, :validate => :true, :dependent => :destroy
accepts_nested_attributes_for :footnotes, :reject_if => :all_blank, :allow_destroy => true
+ has_many :routing_constraint_zones
+
attr_reader :group_of_line_tokens
# validates_presence_of :network
diff --git a/app/models/chouette/routing_constraint_zone.rb b/app/models/chouette/routing_constraint_zone.rb
new file mode 100644
index 000000000..681069416
--- /dev/null
+++ b/app/models/chouette/routing_constraint_zone.rb
@@ -0,0 +1,9 @@
+class Chouette::RoutingConstraintZone < Chouette::TridentActiveRecord
+ belongs_to :line
+ has_array_of :stop_areas, class_name: 'Chouette::StopArea'
+
+ validates_presence_of :name, :stop_area_ids, :line_id
+ validates :stop_areas, length: { minimum: 2 }
+
+ self.primary_key = 'id'
+end
diff --git a/app/policies/routing_constraint_zone_policy.rb b/app/policies/routing_constraint_zone_policy.rb
new file mode 100644
index 000000000..c6caf4ec5
--- /dev/null
+++ b/app/policies/routing_constraint_zone_policy.rb
@@ -0,0 +1,13 @@
+class RoutingConstraintZonePolicy < ApplicationPolicy
+ class Scope < Scope
+ def resolve
+ scope
+ end
+ end
+
+ def create? ; true end
+ def update? ; true end
+ def new? ; true end
+ def edit? ; true end
+ def destroy? ; true end
+end
diff --git a/app/views/referential_lines/show.html.slim b/app/views/referential_lines/show.html.slim
index 9b754a5aa..ad455862d 100644
--- a/app/views/referential_lines/show.html.slim
+++ b/app/views/referential_lines/show.html.slim
@@ -112,6 +112,8 @@ h2
/ p
/ label = "#{@line.human_attribute_name('comment')} : "
/ = @line.comment
+ p
+ label = link_to Chouette::RoutingConstraintZone.model_name.human.pluralize(:fr), referential_line_routing_constraint_zones_path(@referential, @line)
.row
#mobility_restricted_suitability.col-md-6
diff --git a/app/views/referentials/_form.html.slim b/app/views/referentials/_form.html.slim
index f1c7a0192..9fb6c6ced 100644
--- a/app/views/referentials/_form.html.slim
+++ b/app/views/referentials/_form.html.slim
@@ -71,7 +71,7 @@
.alert.alert-danger
- @referential.errors[:metadatas].each do |msg|
p.small = "- #{msg}"
-
+
= form.simple_fields_for :metadatas do |subform|
= subform.simple_fields_for :periods do |period_form|
.row
diff --git a/app/views/routing_constraint_zones/_form.html.slim b/app/views/routing_constraint_zones/_form.html.slim
new file mode 100644
index 000000000..d9e243746
--- /dev/null
+++ b/app/views/routing_constraint_zones/_form.html.slim
@@ -0,0 +1,13 @@
+= simple_form_for [@referential, @line, @routing_constraint_zone] do |f|
+ .row
+ .col-lg-6.col-sm-12
+ = f.input :name, label: t('activerecord.models.attributes.routing_constraint_zone.name')
+ .row
+ .col-lg-6.col-sm-12
+ = f.input :stop_area_ids, as: :select, collection: Chouette::StopArea.all, selected: @routing_constraint_zone.stop_area_ids, label: Chouette::StopArea.model_name.human.pluralize.capitalize, label_method: :name, input_html: { 'data-select2ed': 'true', 'data-select2ed-placeholder': 'Sélection de arrêts', 'multiple': 'multiple', style: 'width: 100%' }
+
+ .row
+ .col-lg-12.text-right
+ = link_to 'Annuler', :back, class: 'btn btn-link'
+ = f.button :submit, class: 'btn btn-danger'
+
diff --git a/app/views/routing_constraint_zones/edit.html.slim b/app/views/routing_constraint_zones/edit.html.slim
new file mode 100644
index 000000000..fcb0d08a8
--- /dev/null
+++ b/app/views/routing_constraint_zones/edit.html.slim
@@ -0,0 +1,5 @@
+= title_tag t('.title', routing_constraint_zone: @routing_constraint_zone.name)
+
+.row
+ .col-lg-8.col-lg-offset-2.col-md-8.col-md-offset-2.col-sm-8.col-sm-offset-2
+ == render 'form'
diff --git a/app/views/routing_constraint_zones/index.html.slim b/app/views/routing_constraint_zones/index.html.slim
new file mode 100644
index 000000000..b12fbd3dd
--- /dev/null
+++ b/app/views/routing_constraint_zones/index.html.slim
@@ -0,0 +1,10 @@
+= title_tag Chouette::RoutingConstraintZone.model_name.human.pluralize(:fr)
+
+= link_to t('routing_constraint_zones.actions.new'), new_referential_line_routing_constraint_zone_path
+
+- if @routing_constraint_zones.any?
+ = table_builder @routing_constraint_zones,
+ { @routing_constraint_zones.human_attribute_name(:name) => 'name' },
+ [:show, :edit, :delete],
+ 'table table-bordered'
+
diff --git a/app/views/routing_constraint_zones/new.html.slim b/app/views/routing_constraint_zones/new.html.slim
new file mode 100644
index 000000000..fcb0d08a8
--- /dev/null
+++ b/app/views/routing_constraint_zones/new.html.slim
@@ -0,0 +1,5 @@
+= title_tag t('.title', routing_constraint_zone: @routing_constraint_zone.name)
+
+.row
+ .col-lg-8.col-lg-offset-2.col-md-8.col-md-offset-2.col-sm-8.col-sm-offset-2
+ == render 'form'
diff --git a/app/views/routing_constraint_zones/show.html.slim b/app/views/routing_constraint_zones/show.html.slim
new file mode 100644
index 000000000..0f88f5b3f
--- /dev/null
+++ b/app/views/routing_constraint_zones/show.html.slim
@@ -0,0 +1,18 @@
+= title_tag @routing_constraint_zone.name
+
+p
+ label => "#{@routing_constraint_zone.human_attribute_name(:name)} : "
+ = @routing_constraint_zone.name
+
+p
+ label => "#{Chouette::Line.model_name.human.capitalize} : "
+ = link_to @routing_constraint_zone.line.name, referential_line_path(@referential, @line)
+
+p
+ label => "#{Chouette::StopArea.model_name.human.pluralize.capitalize} : "
+ br
+ - @routing_constraint_zone.stop_areas.each do |stop_area|
+ = link_to stop_area.name, referential_stop_area_path(@referential, stop_area)
+ br
+
+
diff --git a/config/initializers/inflections.rb b/config/initializers/inflections.rb
index 5f618b7d5..2dfacf970 100644
--- a/config/initializers/inflections.rb
+++ b/config/initializers/inflections.rb
@@ -4,12 +4,13 @@
# Add new inflection rules using the following format. Inflections
# are locale specific, and you may define rules for as many different
# locales as you wish. All of these examples are active by default:
-ActiveSupport::Inflector.inflections(:en) do |inflect|
+ActiveSupport::Inflector.inflections(:fr) do |inflect|
# inflect.plural /^(ox)$/i, '\1en'
# inflect.singular /^(ox)en/i, '\1'
# inflect.irregular 'person', 'people'
# inflect.uncountable %w( fish sheep )
- inflect.irregular 'réseau', 'réseaux'
+ inflect.plural 'réseau', 'réseaux'
+ inflect.plural 'Zone de contrainte', 'Zones de contrainte'
end
# These inflection rules are supported but not enabled by default:
diff --git a/config/locales/referentials.en.yml b/config/locales/referentials.en.yml
index 07af15bc0..17d77e975 100644
--- a/config/locales/referentials.en.yml
+++ b/config/locales/referentials.en.yml
@@ -71,6 +71,7 @@ en:
data_format_restrictions: "Data format constraint"
data_format: "Favorite format for export"
timebands: "Time bands"
+ routing_constraint_zone: Zone de contrainte
formtastic:
titles:
referential:
diff --git a/config/locales/routing_constraint_zones.en.yml b/config/locales/routing_constraint_zones.en.yml
new file mode 100644
index 000000000..10bcd2f62
--- /dev/null
+++ b/config/locales/routing_constraint_zones.en.yml
@@ -0,0 +1,23 @@
+en:
+ activerecord:
+ models:
+ routing_constraint_zone: Routing constraint zone
+ attributes:
+ routing_constraint_zone:
+ name: Name
+ stop_areas: Stop areas
+ line: Line
+ routing_constraint_zones:
+ actions:
+ new: New routing constraint zone
+ edit: Edit this routing constraint zone
+ destroy: Delete this routing constraint zone
+ destroy_confirm: Are you sure you want to delete this routing constraint zone?
+ new:
+ title: Add a new routings constraint zone
+ edit:
+ title: "Update routing constraint zone %{routing_constraint_zone}"
+ show:
+ title: "Routing constraint zone %{routing_constraint_zone}"
+ index:
+
diff --git a/config/locales/routing_constraint_zones.fr.yml b/config/locales/routing_constraint_zones.fr.yml
new file mode 100644
index 000000000..a4e6ed256
--- /dev/null
+++ b/config/locales/routing_constraint_zones.fr.yml
@@ -0,0 +1,20 @@
+fr:
+ activerecord:
+ models:
+ routing_constraint_zone: Zone de contrainte
+ attributes:
+ routing_constraint_zone:
+ name: Nom
+ routing_constraint_zones:
+ actions:
+ new: Ajouter une zone de contrainte
+ edit: Modifier cette zone de contrainte
+ destroy: Supprimer cette zone de contrainte
+ destroy_confirm: Etes vous sûr de supprimer cette zone de contrainte ?
+ new:
+ title: Ajouter une zone de contrainte
+ edit:
+ title: "Modifier la zone de contrainte %{routing_constraint_zone}"
+ show:
+ title: "Zone de contrainte %{routing_constraint_zone}"
+ index:
diff --git a/config/routes.rb b/config/routes.rb
index 04d1875c9..c49b28a07 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -115,6 +115,7 @@ ChouetteIhm::Application.routes.draw do
resources :vehicle_journey_imports
resources :vehicle_journey_exports
end
+ resources :routing_constraint_zones
end
resources :import_tasks, :only => [:new, :create]
diff --git a/db/migrate/20161208112130_create_routing_constraint_zones.rb b/db/migrate/20161208112130_create_routing_constraint_zones.rb
new file mode 100644
index 000000000..0fa1ef1ae
--- /dev/null
+++ b/db/migrate/20161208112130_create_routing_constraint_zones.rb
@@ -0,0 +1,11 @@
+class CreateRoutingConstraintZones < ActiveRecord::Migration
+ def change
+ create_table :routing_constraint_zones do |t|
+ t.string :name
+ t.integer :stop_area_ids, array: true
+ t.belongs_to :line, index: true
+
+ t.timestamps
+ end
+ end
+end
diff --git a/db/migrate/20161208114057_add_trident_fields_to_routing_constraint_zone.rb b/db/migrate/20161208114057_add_trident_fields_to_routing_constraint_zone.rb
new file mode 100644
index 000000000..afe9379c0
--- /dev/null
+++ b/db/migrate/20161208114057_add_trident_fields_to_routing_constraint_zone.rb
@@ -0,0 +1,6 @@
+class AddTridentFieldsToRoutingConstraintZone < ActiveRecord::Migration
+ def change
+ add_column :routing_constraint_zones, :objectid, :string, null: false
+ add_column :routing_constraint_zones, :object_version, :integer
+ end
+end
diff --git a/db/migrate/20161208120132_add_other_trident_fields_to_routing_constraint_zone.rb b/db/migrate/20161208120132_add_other_trident_fields_to_routing_constraint_zone.rb
new file mode 100644
index 000000000..89ed46a97
--- /dev/null
+++ b/db/migrate/20161208120132_add_other_trident_fields_to_routing_constraint_zone.rb
@@ -0,0 +1,6 @@
+class AddOtherTridentFieldsToRoutingConstraintZone < ActiveRecord::Migration
+ def change
+ add_column :routing_constraint_zones, :creation_time, :datetime
+ add_column :routing_constraint_zones, :creator_id, :string
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index e97ba8e52..0277cae91 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema.define(version: 20161118101544) do
+ActiveRecord::Schema.define(version: 20161208120132) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -466,6 +466,20 @@ ActiveRecord::Schema.define(version: 20161118101544) do
add_index "routes", ["objectid"], :name => "routes_objectid_key", :unique => true
+ create_table "routing_constraint_zones", force: true do |t|
+ t.string "name"
+ t.integer "stop_area_ids", array: true
+ t.integer "line_id"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ t.string "objectid", null: false
+ t.integer "object_version"
+ t.datetime "creation_time"
+ t.string "creator_id"
+ end
+
+ add_index "routing_constraint_zones", ["line_id"], :name => "index_routing_constraint_zones_on_line_id"
+
create_table "routing_constraints_lines", id: false, force: true do |t|
t.integer "stop_area_id", limit: 8
t.integer "line_id", limit: 8
diff --git a/spec/factories/chouette_routing_constraint_zones.rb b/spec/factories/chouette_routing_constraint_zones.rb
new file mode 100644
index 000000000..9a2529483
--- /dev/null
+++ b/spec/factories/chouette_routing_constraint_zones.rb
@@ -0,0 +1,7 @@
+FactoryGirl.define do
+ factory :routing_constraint_zone, class: Chouette::RoutingConstraintZone do
+ sequence(:name) { |n| "Routing constraint zone #{n}" }
+ stop_area_ids { [create(:stop_area).id, create(:stop_area).id] }
+ association :line, factory: :line
+ end
+end
diff --git a/spec/features/routing_constraint_zone_spec.rb b/spec/features/routing_constraint_zone_spec.rb
new file mode 100644
index 000000000..6d82323e1
--- /dev/null
+++ b/spec/features/routing_constraint_zone_spec.rb
@@ -0,0 +1,26 @@
+# -*- coding: utf-8 -*-
+require 'spec_helper'
+
+describe 'RoutingConstraintZones', type: :feature do
+ login_user
+
+ let(:referential) { Referential.first }
+ let!(:line) { create :line }
+ let!(:routing_constraint_zones) { Array.new(2) { create :routing_constraint_zone, line: line } }
+
+ describe 'index' do
+ before(:each) { visit referential_line_routing_constraint_zones_path(referential, line) }
+
+ it 'displays referential routing constraint zones' do
+ expect(page).to have_content(routing_constraint_zones.first.name)
+ expect(page).to have_content(routing_constraint_zones.last.name)
+ end
+ end
+
+ describe 'show' do
+ it 'displays referential routing constraint zone' do
+ visit referential_line_routing_constraint_zone_path(referential, line, routing_constraint_zones.first)
+ expect(page).to have_content(routing_constraint_zones.first.name)
+ end
+ end
+end
diff --git a/spec/models/chouette/routing_constraint_zone_spec.rb b/spec/models/chouette/routing_constraint_zone_spec.rb
new file mode 100644
index 000000000..d991538ba
--- /dev/null
+++ b/spec/models/chouette/routing_constraint_zone_spec.rb
@@ -0,0 +1,13 @@
+require 'spec_helper'
+
+describe Chouette::RoutingConstraintZone, type: :model do
+
+ subject { create(:routing_constraint_zone) }
+
+ it { is_expected.to validate_presence_of :name }
+ it { is_expected.to validate_presence_of :stop_area_ids }
+ it { is_expected.to validate_presence_of :line_id }
+ # shoulda matcher to validate length of array ?
+ xit { is_expected.to validate_length_of(:stop_area_ids).is_at_least(2) }
+
+end