diff options
29 files changed, 231 insertions, 123 deletions
diff --git a/app/controllers/referentials_controller.rb b/app/controllers/referentials_controller.rb index 9cf4a5f62..c1c5df386 100644 --- a/app/controllers/referentials_controller.rb +++ b/app/controllers/referentials_controller.rb @@ -1,7 +1,7 @@ class ReferentialsController < BreadcrumbController defaults :resource_class => Referential - + respond_to :html respond_to :json, :only => :show respond_to :js, :only => :show @@ -17,7 +17,7 @@ class ReferentialsController < BreadcrumbController :referential_id => resource.id} } format.html { build_breadcrumb :show} - + end end diff --git a/app/controllers/rule_parameter_sets_controller.rb b/app/controllers/rule_parameter_sets_controller.rb index a422bed15..f06de5cd0 100644 --- a/app/controllers/rule_parameter_sets_controller.rb +++ b/app/controllers/rule_parameter_sets_controller.rb @@ -1,29 +1,50 @@ -class RuleParameterSetsController < ChouetteController +class RuleParameterSetsController < BreadcrumbController defaults :resource_class => RuleParameterSet respond_to :html respond_to :js, :only => [ :mode ] - belongs_to :referential - def new - @rule_parameter_set = RuleParameterSet.default( @referential) + @rule_parameter_set = RuleParameterSet.default( current_organisation) new! do - build_breadcrumb :new + build_breadcrumb :new end end def destroy - if @referential.rule_parameter_sets.count == 1 + if current_organisation.rule_parameter_sets.count == 1 flash[:alert] = "Suppression impossible, le referentiel doit compter au minimum un jeu de parametre." - redirect_to referential_rule_parameter_sets_path( @referential ) + redirect_to organisation_rule_parameter_sets_path else - destroy! + destroy! do |success, failure| + success.html { redirect_to organisation_rule_parameter_sets_path } + end + end + end + + def update + update! do |success, failure| + success.html { redirect_to organisation_rule_parameter_sets_path } + end + end + + def create + create! do |success, failure| + success.html { redirect_to organisation_rule_parameter_sets_path } end end protected alias_method :rule_parameter_set, :resource + + def collection + @rule_parameter_sets = current_organisation.rule_parameter_sets + end + + def create_resource(rule_parameter_sets) + rule_parameter_sets.organisation = current_organisation + super + end end diff --git a/app/helpers/breadcrumb_helper.rb b/app/helpers/breadcrumb_helper.rb index 34e03383c..b85dc3527 100644 --- a/app/helpers/breadcrumb_helper.rb +++ b/app/helpers/breadcrumb_helper.rb @@ -53,7 +53,7 @@ module BreadcrumbHelper organisation_breadcrumb :index end end - + def network_breadcrumb(action) referential_breadcrumb @@ -121,52 +121,53 @@ module BreadcrumbHelper add_breadcrumb I18n.t("breadcrumbs.vehicle_journeys"), referential_line_route_vehicle_journeys_path(@referential, @line,@route) unless action == :index add_breadcrumb breadcrumb_label(@vehicle_journey), referential_line_route_vehicle_journey_path(@referential, @line,@route,@vehicle_journey),:title => breadcrumb_tooltip(@vehicle_journey) if action == :edit end - + def vehicle_journey_import_breadcrumb (action) route_breadcrumb :edit end def company_breadcrumb (action) - referential_breadcrumb + referential_breadcrumb add_breadcrumb Chouette::Company.model_name.human(:count => 2), referential_companies_path(@referential) unless action == :index add_breadcrumb breadcrumb_label(@company), referential_company_path(@referential, @company),:title => breadcrumb_tooltip(@company) if action == :edit end - + def import_breadcrumb (action) - referential_breadcrumb + referential_breadcrumb add_breadcrumb Referential.human_attribute_name("import_tasks"), referential_import_tasks_path(@referential) unless action == :index end - + def export_breadcrumb (action) - referential_breadcrumb + referential_breadcrumb add_breadcrumb Referential.human_attribute_name("exports"), referential_exports_path(@referential) unless action == :index end def compliance_breadcrumb (action) - referential_breadcrumb + referential_breadcrumb add_breadcrumb Referential.human_attribute_name("compliance_check_tasks"), referential_compliance_check_tasks_path(@referential) unless action == :index add_breadcrumb breadcrumb_label(@compliance_check_task), referential_compliance_check_task_path(@referential, @compliance_check_task),:title => breadcrumb_tooltip(@compliance_check_task) if action == :edit end def rule_parameter_breadcrumb (action) - referential_breadcrumb - add_breadcrumb Referential.human_attribute_name("import_tasks"), referential_import_tasks_path(@referential) - add_breadcrumb Referential.human_attribute_name("compliance_check_tasks"), referential_compliance_check_tasks_path(@referential) - add_breadcrumb Referential.human_attribute_name("rule_parameter_sets"), referential_rule_parameter_sets_path(@referential) unless action == :index + organisation_breadcrumb + add_breadcrumb Referential.human_attribute_name("rule_parameter_sets"), organisation_path unless action == :index + add_breadcrumb breadcrumb_label(@rule_parameter_set), organisation_rule_parameter_set_path(@rule_parameter_set),:title => breadcrumb_tooltip(@rule_parameter_set) if action == :edit end def referential_breadcrumb (action = :edit) organisation_breadcrumb - add_breadcrumb breadcrumb_label(@referential), referential_path(@referential),:title => breadcrumb_tooltip(@referential) if action == :edit || action == :show || action == :update + if @referential + add_breadcrumb breadcrumb_label(@referential), referential_path(@referential),:title => breadcrumb_tooltip(@referential) if action == :edit || action == :show || action == :update + end end - + def organisation_breadcrumb (action = :index) - add_breadcrumb I18n.t("breadcrumbs.referentials"), referentials_path + add_breadcrumb I18n.t("breadcrumbs.referentials"), referentials_path add_breadcrumb breadcrumb_label(@organisation), organisation_path,:title => breadcrumb_tooltip(@organisation) unless action == :index end def user_breadcrumb (action) - organisation_breadcrumb + organisation_breadcrumb add_breadcrumb I18n.t("breadcrumbs.users"), organisation_path unless action == :index add_breadcrumb breadcrumb_label(@user), organisation_user_path(@user),:title => breadcrumb_tooltip(@user) if action == :edit end @@ -176,14 +177,14 @@ module BreadcrumbHelper if label.blank? label = obj.class.model_name.human+" "+obj.id.to_s end - + if label.length > 20 label[0..16]+"..." else - label + label end end - + def breadcrumb_tooltip(obj) label = breadcrumb_name(obj) if label.blank? @@ -196,12 +197,12 @@ module BreadcrumbHelper def breadcrumb_name(obj) label = "" - if obj.respond_to?('name') + if obj.respond_to?('name') label = obj.name - elsif obj.respond_to?('comment') + elsif obj.respond_to?('comment') label = obj.comment end - label + label end end diff --git a/app/models/organisation.rb b/app/models/organisation.rb index f4b2e35f8..cd2691ace 100644 --- a/app/models/organisation.rb +++ b/app/models/organisation.rb @@ -2,6 +2,12 @@ class Organisation < ActiveRecord::Base has_many :users, :dependent => :destroy has_many :referentials, :dependent => :destroy + has_many :rule_parameter_sets, :dependent => :destroy validates :name, :presence => true, :uniqueness => true + + after_create :add_rule_parameter_set + def add_rule_parameter_set + RuleParameterSet.default_for_all_modes( self).save + end end diff --git a/app/models/referential.rb b/app/models/referential.rb index 01dba95ab..c207b6441 100644 --- a/app/models/referential.rb +++ b/app/models/referential.rb @@ -18,7 +18,6 @@ class Referential < ActiveRecord::Base attr_accessor :lower_corner has_one :user - has_many :rule_parameter_sets, :dependent => :destroy has_many :import_tasks, :dependent => :destroy has_many :compliance_check_tasks, :dependent => :destroy has_many :exports, :dependent => :destroy @@ -147,11 +146,6 @@ class Referential < ActiveRecord::Base Apartment::Database.drop slug end - after_create :add_rule_parameter_set - def add_rule_parameter_set - RuleParameterSet.default_for_all_modes( self).save - end - def upper_corner envelope.upper_corner end @@ -208,7 +202,7 @@ Rails.application.config.after_initialize do end def hub_restricted? - referential.organisation.hub_restrictions == true + referential.hub_restrictions == true end # override prefix for good prefix in objectid generation diff --git a/app/models/rule_parameter_set.rb b/app/models/rule_parameter_set.rb index 3eb74fdcf..cce5cf9b7 100644 --- a/app/models/rule_parameter_set.rb +++ b/app/models/rule_parameter_set.rb @@ -1,5 +1,4 @@ class RuleParameterSet < ActiveRecord::Base - belongs_to :referential belongs_to :organisation #validates_presence_of :referential @@ -7,7 +6,11 @@ class RuleParameterSet < ActiveRecord::Base serialize :parameters, JSON - attr_accessible :name, :referential_id, :organisation_id + attr_accessible :name, :organisation_id + + # TODO: remove when migration deployed + # convert referential id to organisation id + attr_accessible :referential_id, def self.mode_attribute_prefixes %w( allowed_transport inter_stop_area_distance_min inter_stop_area_distance_max speed_max speed_min inter_stop_duration_variation_max) @@ -308,16 +311,15 @@ class RuleParameterSet < ActiveRecord::Base } # :waterborne, :bus, :ferry, :walk, :metro, :shuttle, :rapidtransit, :taxi, :localtrain, :train, :longdistancetrain, :tramway, :trolleybus, :privatevehicle, :bicycle, :other end - def self.default( referential) - self.default_for_all_modes( referential).tap do |rps| + def self.default( organisation) + self.default_for_all_modes( organisation).tap do |rps| rps.name = "" end end - def self.default_for_all_modes( referential) + def self.default_for_all_modes( organisation) mode_attributes = mode_default_params.values.inject(self.default_params){|memo, obj| memo.merge! obj} self.new( - { :referential_id => referential.id, - :stop_areas_area => referential.envelope.to_polygon.points.map(&:to_coordinates).to_json, + { :organisation_id => organisation.id, :name => "valeurs par defaut" }.merge( mode_attributes)) end diff --git a/app/views/compliance_check_tasks/index.html.erb b/app/views/compliance_check_tasks/index.html.erb index fe05b3cdc..6cddaeff7 100644 --- a/app/views/compliance_check_tasks/index.html.erb +++ b/app/views/compliance_check_tasks/index.html.erb @@ -6,6 +6,6 @@ <% content_for :sidebar do %> <ul class="actions"> <li><%= link_to t('compliance_check_tasks.actions.new'), new_referential_compliance_check_task_path(), :class => "add" %></li> - <li><%= link_to t('rule_parameter_sets.actions.index'), referential_rule_parameter_sets_path(@referential), :class => "link" %></li> + <li><%= link_to t('rule_parameter_sets.actions.index'), organisation_rule_parameter_sets_path, :class => "link" %></li> </ul> <% end %> diff --git a/app/views/organisations/edit.html.erb b/app/views/organisations/edit.html.erb index f37c2e7df..7c2d75f11 100644 --- a/app/views/organisations/edit.html.erb +++ b/app/views/organisations/edit.html.erb @@ -3,7 +3,7 @@ <%= semantic_form_for @organisation, :url => organisation_path do |form| %> <%= form.inputs do %> <%= form.input :name %> - <%= form.input :hub_restrictions %> + <%= form.input :hub_restrictions_by_default %> <% end %> <%= form.actions do %> diff --git a/app/views/organisations/show.html.erb b/app/views/organisations/show.html.erb index 27b1eccb2..0eae19b91 100644 --- a/app/views/organisations/show.html.erb +++ b/app/views/organisations/show.html.erb @@ -2,19 +2,55 @@ <div class="summary"> <p> -<label><%= Organisation.human_attribute_name("hub_restrictions") %>: </label> -<%= @organisation.hub_restrictions %> +<label><%= Organisation.human_attribute_name("hub_restrictions_by_default") %>: </label> +<%= @organisation.hub_restrictions_by_default %> </p> </div> -<div class="users paginated_content"> - <%= paginated_content(@organisation.users, "users/user") %> +<div class="panel-group" id="accordion"> + <div class="panel panel-default"> + <div class="panel-heading"> + <h4 class="panel-title"> + <a data-toggle="collapse" data-parent="#accordion" href="#users"> + <%= t('.users') %> + </a> + </h4> + </div> + <div id="users" class="panel-collapse collapse"> + <div class="panel-body"> + <div class="users paginated_content"> + <%= paginated_content(@organisation.users, "users/user") %> + </div> + </div> + </div> + </div> +</div> + + +<div class="panel-group" id="accordion"> + <div class="panel panel-default"> + <div class="panel-heading"> + <h4 class="panel-title"> + <a data-toggle="collapse" data-parent="#accordion" href="#rule_parameter_sets"> + <%= t('.rule_parameter_sets') %> + </a> + </h4> + </div> + <div id="rule_parameter_sets" class="panel-collapse collapse"> + <div class="panel-body"> + <div class="rule_parameter_sets paginated_content"> + <%= paginated_content(@organisation.rule_parameter_sets, "rule_parameter_sets/rule_parameter_set") %> + </div> + </div> + </div> + </div> </div> <% content_for :sidebar do %> <ul class="actions"> <li><%= link_to t('organisations.actions.edit'), edit_organisation_path, :class => "edit" %></li> <li><%= link_to t('users.actions.new'), new_organisation_user_path, :class => "add" %></li> + <li><%= link_to t('rule_parameter_sets.actions.new'), new_organisation_rule_parameter_set_path, :class => "add" %></li> </ul> <% end %> diff --git a/app/views/referentials/_form.erb b/app/views/referentials/_form.erb index 814195dde..cd57a0549 100644 --- a/app/views/referentials/_form.erb +++ b/app/views/referentials/_form.erb @@ -14,6 +14,7 @@ <%= form.input :time_zone %> <%= form.input :upper_corner, :input_html => { :title => t("formtastic.titles.referential.upper_corner")} %> <%= form.input :lower_corner, :input_html => { :title => t("formtastic.titles.referential.lower_corner")} %> + <%= form.input :hub_restrictions %> <% end %> <%= form.actions do %> diff --git a/app/views/referentials/show.html.erb b/app/views/referentials/show.html.erb index d8e209c7f..1ce3fa072 100644 --- a/app/views/referentials/show.html.erb +++ b/app/views/referentials/show.html.erb @@ -20,6 +20,10 @@ <%= @referential.time_zone %> </p> <p> + <label><%= Referential.human_attribute_name("hub_restrictions") %>: </label> + <%= @referential.hub_restrictions %> + </p> + <p> <label><%= Referential.human_attribute_name("validity_period") %>: </label> <% if Chouette::TimeTable.start_validity_period.nil? %> <%= Referential.human_attribute_name("no_validity_period") %> @@ -30,10 +34,10 @@ <%= l Chouette::TimeTable.end_validity_period %> <% end %> </p> - + <table width="100%"> <tr> - <td valign="top" width="50%"> + <td valign="top" width="50%"> <%= render "counts" %> </td> <td valign="top" > @@ -43,12 +47,12 @@ </table> <% if @referential.api_keys.present? %> - <h3 class="api_keys"><%= t('.api_keys') %></h3> + <h3 class="api_keys"><%= t('.api_keys') %></h3> <div class="api_keys paginated_content"> <%= paginated_content(@referential.api_keys, "api_keys/api_key") %> </div> <% end %> -</div> +</div> <% content_for :sidebar do %> <ul class="actions"> diff --git a/app/views/rule_parameter_sets/_form.html.erb b/app/views/rule_parameter_sets/_form.html.erb index abe4b0c96..a2d1c2bc1 100644 --- a/app/views/rule_parameter_sets/_form.html.erb +++ b/app/views/rule_parameter_sets/_form.html.erb @@ -1,4 +1,4 @@ -<%= semantic_form_for [@referential, @rule_parameter_set] do |form| %> +<%= semantic_form_for [ :organisation, @rule_parameter_set] do |form| %> <%= form.inputs do %> <%= form.input :name %> <%= form.input :inter_stop_area_distance_min, :as => :number %> @@ -14,13 +14,13 @@ <%= form.input :inter_access_link_distance_max, :as => :number %> <%= form.input :inter_stop_duration_max, :as => :number %> <%= form.input :facility_stop_area_distance_max, :as => :number %> - + <%= form.input :check_lines_in_groups, :as => :boolean %> <%= form.input :check_line_routes, :as => :boolean %> <%= form.input :check_stop_parent, :as => :boolean %> <%= form.input :check_connection_link_on_physical, :as => :boolean %> <%= form.input :check_allowed_transport_modes, :as => :boolean %> - + <table class="table table-striped table-condensed"> <thead> <tr> @@ -43,7 +43,7 @@ <% end %> </tbody> </table> - + <%= t("rule_parameter_sets.labels.columns_restrictions") %> <table class="table table-bordered table-condensed"> <% RuleParameterSet.validable_objects.each do |obj| %> diff --git a/app/views/rule_parameter_sets/_rule_parameter_set.html.erb b/app/views/rule_parameter_sets/_rule_parameter_set.html.erb index 3b9af4751..257b8e145 100644 --- a/app/views/rule_parameter_sets/_rule_parameter_set.html.erb +++ b/app/views/rule_parameter_sets/_rule_parameter_set.html.erb @@ -1,23 +1,23 @@ <div id="index_item" class="panel panel-default rule_parameter_set"> <div class="panel-heading"> <div class="panel-title clearfix"> - <span class="pull-right"> - <%= link_to edit_referential_rule_parameter_set_path(@referential, rule_parameter_set), :class => "btn btn-default btn-sm" do %> + <span class="pull-right"> + <%= link_to edit_organisation_rule_parameter_set_path( rule_parameter_set), :class => "btn btn-default btn-sm" do %> <span class="fa fa-pencil"></span> <% end %> - <% if @referential.rule_parameter_sets.size > 1 %> - <%= link_to referential_rule_parameter_set_path(@referential, rule_parameter_set), :method => :delete, :data => {:confirm => t('rule_parameter_sets.actions.destroy_confirm')}, :class => "btn btn-danger btn-sm" do %> + <% if rule_parameter_set.organisation.rule_parameter_sets.size > 1 %> + <%= link_to organisation_rule_parameter_set_path( rule_parameter_set), :method => :delete, :data => {:confirm => t('rule_parameter_sets.actions.destroy_confirm')}, :class => "btn btn-danger btn-sm" do %> <span class="fa fa-trash-o"></span> <% end %> <% end %> </span> <h5> - <%= link_to([@referential, rule_parameter_set], :class => "preview", :title => "#{RuleParameterSet.model_name.human.capitalize} #{rule_parameter_set.name}") do %> + <%= link_to( organisation_rule_parameter_set_path( rule_parameter_set), :class => "preview", :title => "#{RuleParameterSet.model_name.human.capitalize} #{rule_parameter_set.name}") do %> <span class="name"> - <%= truncate(rule_parameter_set.name, :length => 20) %> + <%= truncate(rule_parameter_set.name, :length => 20) %> </span> <% end %> </h5> - </div> + </div> </div> </div> diff --git a/app/views/rule_parameter_sets/index.html.erb b/app/views/rule_parameter_sets/index.html.erb index a92840529..0d091829a 100644 --- a/app/views/rule_parameter_sets/index.html.erb +++ b/app/views/rule_parameter_sets/index.html.erb @@ -4,6 +4,6 @@ <% content_for :sidebar do %> <ul class="actions"> - <li><%= link_to t('rule_parameter_sets.actions.new'), new_referential_rule_parameter_set_path(@referential), :class => "add" %></li> + <li><%= link_to t('rule_parameter_sets.actions.new'), new_organisation_rule_parameter_set_path, :class => "add" %></li> </ul> <% end %> diff --git a/app/views/rule_parameter_sets/show.html.erb b/app/views/rule_parameter_sets/show.html.erb index e86aa47ac..c00f92a40 100644 --- a/app/views/rule_parameter_sets/show.html.erb +++ b/app/views/rule_parameter_sets/show.html.erb @@ -68,7 +68,7 @@ <label><%= t(".inter_stop_duration_max") %>: </label> <%= @rule_parameter_set.inter_stop_duration_max %> </p> - + <p> <label><%= RuleParameterSet.human_attribute_name("check_lines_in_groups") %>: </label> <%= boolean_value(@rule_parameter_set.check_lines_in_groups)%> @@ -113,7 +113,7 @@ <tr> <td><%= t("transport_modes.label.#{mode}") %></td> <% RuleParameterSet.mode_attribute_prefixes.each do |prefix| %> - + <% unless prefix == "allowed_transport" %> <td><%= @rule_parameter_set.send "#{prefix}_mode_#{mode}" %></td> <% end %> @@ -162,11 +162,11 @@ <% content_for :sidebar do %> <ul class="actions"> - <li><%= link_to t('rule_parameter_sets.actions.new'), new_referential_rule_parameter_set_path(@referential), :class => "add" %></li> + <li><%= link_to t('rule_parameter_sets.actions.new'), new_organisation_rule_parameter_set_path, :class => "add" %></li> <% if @rule_parameter_set.persisted? %> - <li><%= link_to t('rule_parameter_sets.actions.edit'), edit_referential_rule_parameter_set_path(@referential, @rule_parameter_set), :class => "edit" %></li> - <% if @referential.rule_parameter_sets.size > 1 %> - <li><%= link_to t('rule_parameter_sets.actions.destroy'), referential_rule_parameter_set_path(@referential, @rule_parameter_set), :method => :delete, :data => {:confirm => t('rule_parameter_sets.actions.destroy_confirm')}, :class => "remove" %></li> + <li><%= link_to t('rule_parameter_sets.actions.edit'), edit_organisation_rule_parameter_set_path( @rule_parameter_set), :class => "edit" %></li> + <% if current_organisation.rule_parameter_sets.size > 1 %> + <li><%= link_to t('rule_parameter_sets.actions.destroy'), organisation_rule_parameter_set_path( @rule_parameter_set), :method => :delete, :data => {:confirm => t('rule_parameter_sets.actions.destroy_confirm')}, :class => "remove" %></li> <% end %> <% end %> </ul> diff --git a/config/locales/organisations.yml b/config/locales/organisations.yml index e6b86d29d..38928f500 100644 --- a/config/locales/organisations.yml +++ b/config/locales/organisations.yml @@ -6,11 +6,15 @@ en: title: "Update your organisation" key_registered: "Key registered" key_not_registered: "No key registered" - activerecord: + show: + users: "Users" + rule_parameter_sets: "Rule parameter sets" + activerecord: attributes: organisation: name: "Name" - geoportail_key: "IGN Geoportail Key" + hub_restrictions_by_default: "Hub constraint by default" + geoportail_key: "IGN Geoportail Key" fr: organisations: @@ -20,8 +24,12 @@ fr: title: "Modifier votre organisation" key_registered: "Clé enregistrée" key_not_registered: "Pas de clé" - activerecord: + show: + users: "Utilisateurs" + rule_parameter_sets: "Jeux de paramètres" + activerecord: attributes: organisation: name: "Nom" - geoportail_key: "Clé de l'API du Geoportail IGN" + hub_restrictions_by_default: "Appliquer les contraintes Hub par defaut" + geoportail_key: "Clé de l'API du Geoportail IGN" diff --git a/config/locales/referentials.yml b/config/locales/referentials.yml index 0d3a63498..ddc88223d 100644 --- a/config/locales/referentials.yml +++ b/config/locales/referentials.yml @@ -10,7 +10,7 @@ en: title: "Data space" clean_up: "Clean up" api_keys: "Authentification keys for an API REST access" - counts: + counts: objects: "Data space elements" count: "count" validity_out: @@ -30,7 +30,7 @@ en: user_excluded: "%{user} is a reserved value" activerecord: models: - referential: + referential: zero: "Data space" one: "Data space" other: "Data spaces" @@ -66,6 +66,7 @@ en: export_tasks: "Exports" compliance_check_tasks: "Validations" rule_parameter_sets: "Rule parameters sets" + hub_restrictions: "Apply constraints specific to Hub" formtastic: titles: referential: @@ -86,8 +87,8 @@ fr: title: "Espace de données" clean_up: "Purge des données obsolètes" api_keys: "Clés d'authentification pour un accès à l'API REST" - counts: - objects: "Eléments" + counts: + objects: "Eléments" count: "Qté" validity_out: validity_out_time_tables: "Calendriers échus" @@ -106,7 +107,7 @@ fr: user_excluded: "%{user} est une valeur réservée" activerecord: models: - referential: + referential: zero: "Espace de Données" one: "Espace de Données" other: "Espaces de Données" @@ -117,7 +118,7 @@ fr: prefix: "Préfixe des identifiants Neptune" projection_type: "Système de référence spatiale (SRID) optionnel" time_zone: "Fuseau horaire" - upper_corner: "Point haut/droite de l'emprise par défaut" + upper_corner: "Point haut/droite de l'emprise par défaut" lower_corner: "Point bas/gauche de l'emprise par défaut" resources: "Import Neptune" validity_period: "Période de validité" @@ -142,10 +143,11 @@ fr: export_tasks: "Exports" compliance_check_tasks: "Validations" rule_parameter_sets: "Jeux de paramètres" + hub_restrictions: "Appliquer les contraintes propres au format Hub" formtastic: titles: referential: - slug: "caractères autorisés : alphanumériques minuscules et 'souligné' et doit commencer par une lettre" + slug: "caractères autorisés : alphanumériques minuscules et 'souligné' et doit commencer par une lettre" prefix: "caractères autorisés : alphanumériques et 'souligné'" upper_corner: "latitude,longitude dans le référentiel WGS84, le séparateur de décimales est 'point'" lower_corner: "latitude,longitude dans le référentiel WGS84, le séparateur de décimales est 'point'" diff --git a/config/routes.rb b/config/routes.rb index c629877b7..8285c800a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -56,6 +56,7 @@ ChouetteIhm::Application.routes.draw do resource :organisation do resources :users + resources :rule_parameter_sets end resources :referentials do @@ -72,6 +73,9 @@ ChouetteIhm::Application.routes.draw do match 'lines' => 'lines#destroy_all', :via => :delete resources :lines do + collection do + get 'name_filter' + end resources :routes do member do get 'edit_boarding_alighting' diff --git a/db/migrate/20150121144108_add_hub_restrictions_to_organisation.rb b/db/migrate/20150121144108_add_hub_restrictions_to_organisation.rb index 7417105e9..27955b43f 100644 --- a/db/migrate/20150121144108_add_hub_restrictions_to_organisation.rb +++ b/db/migrate/20150121144108_add_hub_restrictions_to_organisation.rb @@ -1,7 +1,10 @@ class AddHubRestrictionsToOrganisation < ActiveRecord::Migration - def change - change_table :organisations do |t| - t.boolean :hub_restrictions - end + def self.up + add_column :organisations, :hub_restrictions_by_default, :boolean + add_column :referentials, :hub_restrictions, :boolean + end + def self.down + remove_column :organisations, :hub_restrictions_by_default + remove_column :referentials, :hub_restrictions end end diff --git a/db/migrate/20150218175300_set_organisation_id_to_rps.rb b/db/migrate/20150218175300_set_organisation_id_to_rps.rb new file mode 100644 index 000000000..efd43124b --- /dev/null +++ b/db/migrate/20150218175300_set_organisation_id_to_rps.rb @@ -0,0 +1,14 @@ +class SetOrganisationIdToRps < ActiveRecord::Migration + def up + RuleParameterSet.all.each_with_index do |rps, index| + rps.update_attributes :organisation_id => Referential.find( rps.referential_id).organisation_id, + :name => "#{rps.name} #{index}" + end + end + + def down + RuleParameterSet.all.each_with_index do |rps, index| + rps.update_attributes :organisation_id => nil + end + end +end diff --git a/db/schema.rb b/db/schema.rb index b49ca789f..a2a5a8ba5 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20150129170104) do +ActiveRecord::Schema.define(:version => 20150218175300) do create_table "access_links", :force => true do |t| t.integer "access_point_id", :limit => 8 @@ -326,9 +326,9 @@ ActiveRecord::Schema.define(:version => 20150129170104) do create_table "organisations", :force => true do |t| t.string "name" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false - t.boolean "hub_restrictions" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + t.boolean "hub_restrictions_by_default" end create_table "pt_links", :force => true do |t| @@ -359,6 +359,7 @@ ActiveRecord::Schema.define(:version => 20150129170104) do t.text "geographical_bounds" t.integer "user_id", :limit => 8 t.string "user_name" + t.boolean "hub_restrictions" end create_table "routes", :force => true do |t| diff --git a/spec/factories.rb b/spec/factories.rb index 2599645d3..f0858e643 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -15,9 +15,9 @@ FactoryGirl.define do factory :rule_parameter_set do |f| f.sequence(:name) { |n| "Test #{n}" } - f.association :referential + f.association :organisation f.after_create do |rsp| - rsp.parameters = RuleParameterSet.default_for_all_modes( rsp.referential).parameters + rsp.parameters = RuleParameterSet.default_for_all_modes( rsp.organisation).parameters end end @@ -70,6 +70,6 @@ FactoryGirl.define do f.referential { Referential.find_by_slug("first") } end - factory :time_table_combination + factory :time_table_combination end diff --git a/spec/models/line_spec.rb b/spec/models/line_spec.rb index 0b7fcac1c..143d26075 100644 --- a/spec/models/line_spec.rb +++ b/spec/models/line_spec.rb @@ -9,13 +9,13 @@ describe "sdflkjskdjf" do end describe "validation objectid unique constraint" do - let(:organisation){subject.referential.organisation} + let(:referential){subject.referential} let(:objectid_a){ "A:Line:1234" } let(:objectid_b){ "B:Line:1234" } let!(:second_line){ Factory( :line, :objectid => objectid_a, :registration_number => "123456") } - context "when organisation works with HUB" do + context "when referential works with HUB" do before( :each) do - organisation.update_attributes :hub_restrictions => true + referential.update_attributes :hub_restrictions => true subject.update_attributes :objectid => objectid_a end it "should have objectid with a third part shorter than 14 char" do @@ -23,9 +23,9 @@ describe "sdflkjskdjf" do subject.should_not be_valid end end - context "when organisation doesn't works with HUB" do + context "when referential doesn't works with HUB" do before( :each) do - organisation.update_attributes :hub_restrictions => false + referential.update_attributes :hub_restrictions => false end it "should have objectid with a third part shorter than 14 char" do subject.update_attributes :objectid => objectid_b @@ -34,19 +34,19 @@ describe "sdflkjskdjf" do end end describe "validation objectid size" do - let(:organisation){subject.referential.organisation} - context "when organisation works with HUB" do + let(:referential){subject.referential} + context "when referential works with HUB" do before( :each) do - organisation.update_attributes :hub_restrictions => true + referential.update_attributes :hub_restrictions => true end it "should have objectid with a third part shorter than 14 char" do set_large_object_id( subject) subject.should_not be_valid end end - context "when organisation doesn't works with HUB" do + context "when referential doesn't works with HUB" do before( :each) do - organisation.update_attributes :hub_restrictions => false + referential.update_attributes :hub_restrictions => false end it "should have objectid with a third part shorter than 14 char" do set_large_object_id( subject) diff --git a/spec/models/organisation_spec.rb b/spec/models/organisation_spec.rb index 6baf13c46..ffac3374b 100644 --- a/spec/models/organisation_spec.rb +++ b/spec/models/organisation_spec.rb @@ -4,4 +4,9 @@ describe Organisation do it { should validate_presence_of(:name) } it { should validate_uniqueness_of(:name) } + + it "create a rule_parameter_set" do + organisation = Factory.create(:organisation) + organisation.rule_parameter_sets.size.should == 1 + end end diff --git a/spec/models/referential_spec.rb b/spec/models/referential_spec.rb index 5ea88ad20..84bf0a131 100644 --- a/spec/models/referential_spec.rb +++ b/spec/models/referential_spec.rb @@ -6,10 +6,5 @@ describe Referential do it { should validate_presence_of(:slug) } it { should validate_presence_of(:prefix) } it { should validate_presence_of(:time_zone) } - - it "create a rule_parameter_set" do - referential = Factory.create(:referential) - referential.rule_parameter_sets.size.should == 1 - end end diff --git a/spec/models/rule_parameter_set_spec.rb b/spec/models/rule_parameter_set_spec.rb index 3e872598f..bf33c0c13 100644 --- a/spec/models/rule_parameter_set_spec.rb +++ b/spec/models/rule_parameter_set_spec.rb @@ -37,9 +37,9 @@ describe RuleParameterSet do it { should allow_mass_assignment_of attribute.to_sym} end - describe "#referential" do + describe "#organisation" do #it { should validate_presence_of(:referential) } - it { should allow_mass_assignment_of :referential_id } + it { should allow_mass_assignment_of :organisation_id } end describe "#name" do diff --git a/spec/support/referential.rb b/spec/support/referential.rb index 28f3799ec..e581e9a3a 100644 --- a/spec/support/referential.rb +++ b/spec/support/referential.rb @@ -1,13 +1,17 @@ module ReferentialHelper def first_referential - Organisation.find_by_name("first").referentials.find_by_slug("first") + first_organisation.referentials.find_by_slug("first") + end + def first_organisation + Organisation.find_by_name("first") end def self.included(base) base.class_eval do extend ClassMethods alias_method :referential, :first_referential + alias_method :organisation, :first_organisation end end @@ -18,6 +22,12 @@ module ReferentialHelper assign :referential, referential end end + def assign_organisation + before(:each) do + assign :organisation, referential.organisation + end + end + end @@ -29,7 +39,7 @@ RSpec.configure do |config| config.before(:suite) do organisation = Organisation.find_or_create_by_name :name => "first" organisation.referentials.find_by_slug("first" ) || - Referential.create(:prefix => "first", :name => "first", :slug => "first", :organisation => organisation) + Referential.create(:prefix => "first", :name => "first", :slug => "first", :organisation => organisation) # FIXME in Rails 3.2 : # Referential.where(:slug => 'first').first_or_create(FactoryGirl.attributes_for(:referential)) end diff --git a/spec/views/rule_parameter_sets/index.html.erb_spec.rb b/spec/views/rule_parameter_sets/index.html.erb_spec.rb index 0f50ea387..72f20a65e 100644 --- a/spec/views/rule_parameter_sets/index.html.erb_spec.rb +++ b/spec/views/rule_parameter_sets/index.html.erb_spec.rb @@ -1,21 +1,22 @@ require 'spec_helper' -describe "/rule_parameter_sets/index" do +describe "/organisations/show" do - assign_referential - let!(:rule_parameter_sets) { assign :rule_parameter_sets, [ Factory(:rule_parameter_set), - Factory(:rule_parameter_set)] } + assign_organisation + + let!(:rule_parameter_sets) { assign :rule_parameter_sets, [ Factory(:rule_parameter_set, :organisation => organisation), + Factory(:rule_parameter_set, :organisation => organisation)] } it "should render a show link for each rule_parameter_set" do render rule_parameter_sets.each do |rule_parameter_set| - rendered.should have_selector(".rule_parameter_set a[href='#{view.referential_rule_parameter_set_path(referential, rule_parameter_set)}']", :text => rule_parameter_set.name) + rendered.should have_selector(".rule_parameter_sets a[href='#{view.organisation_rule_parameter_set_path( rule_parameter_set)}']", :text => rule_parameter_set.name) end end it "should render a link to create a new rule_parameter_set" do render - view.content_for(:sidebar).should have_selector(".actions a[href='#{new_referential_rule_parameter_set_path(referential)}']") + view.content_for(:sidebar).should have_selector(".actions a[href='#{new_organisation_rule_parameter_set_path}']") end end diff --git a/spec/views/rule_parameter_sets/new.html.erb_spec.rb b/spec/views/rule_parameter_sets/new.html.erb_spec.rb index 4670ecceb..c78d04c7c 100644 --- a/spec/views/rule_parameter_sets/new.html.erb_spec.rb +++ b/spec/views/rule_parameter_sets/new.html.erb_spec.rb @@ -2,8 +2,8 @@ require 'spec_helper' describe "/rule_parameter_sets/new" do - assign_referential - let!(:rule_parameter_set) { assign :rule_parameter_set, build( :rule_parameter_set, :referential => referential) } + assign_organisation + let!(:rule_parameter_set) { assign :rule_parameter_set, build( :rule_parameter_set, :organisation => organisation) } describe "form" do |
