diff options
| author | Edouard Maffert | 2016-09-09 16:07:34 +0200 | 
|---|---|---|
| committer | Edouard Maffert | 2016-09-09 16:07:34 +0200 | 
| commit | 2d52366ebac8af84cfec37dab9df5b43261fffe4 (patch) | |
| tree | b820e064516f58b4f5fed6cddde99f7f5b9e042b | |
| parent | 4747990c6d3ceb5020d06099d086500b066db6e4 (diff) | |
| download | chouette-core-2d52366ebac8af84cfec37dab9df5b43261fffe4.tar.bz2 | |
associate networks to line referential
33 files changed, 299 insertions, 87 deletions
| diff --git a/app/controllers/networks_controller.rb b/app/controllers/networks_controller.rb index 239f022b3..beced7e55 100644 --- a/app/controllers/networks_controller.rb +++ b/app/controllers/networks_controller.rb @@ -1,4 +1,6 @@ -class NetworksController < ChouetteController +class NetworksController < BreadcrumbController +  include ApplicationHelper +    defaults :resource_class => Chouette::Network    respond_to :html    respond_to :xml @@ -6,7 +8,7 @@ class NetworksController < ChouetteController    respond_to :kml, :only => :show    respond_to :js, :only => :index -  belongs_to :referential +  belongs_to :line_referential    def show      @map = NetworkMap.new(resource).with_helpers(self) @@ -15,7 +17,7 @@ class NetworksController < ChouetteController      end    end -  def index     +  def index      index! do |format|        format.html {          if collection.out_of_bounds? @@ -23,26 +25,28 @@ class NetworksController < ChouetteController          end        }        build_breadcrumb :index -    end        +    end    end    protected -  def collection     -    @q = referential.networks.search(params[:q]) +  def collection +    @q = line_referential.networks.search(params[:q])      @networks ||= @q.result(:distinct => true).order(:name).paginate(:page => params[:page])    end    def resource_url(network = nil) -    referential_network_path(referential, network || resource) +    line_referential_network_path(line_referential, network || resource)    end    def collection_url -    referential_networks_path(referential) +    line_referential_networks_path(line_referential)    end +  alias_method :line_referential, :parent +    def network_params      params.require(:network).permit(:objectid, :object_version, :creation_time, :creator_id, :version_date, :description, :name, :registration_number, :source_name, :source_type_name, :source_identifier, :comment )    end -   +  end diff --git a/app/controllers/referential_networks_controller.rb b/app/controllers/referential_networks_controller.rb new file mode 100644 index 000000000..2d3f4ad6b --- /dev/null +++ b/app/controllers/referential_networks_controller.rb @@ -0,0 +1,54 @@ +class ReferentialNetworksController < ChouetteController +  defaults :resource_class => Chouette::Network, :collection_name => 'networks', :instance_name => 'network' +  respond_to :html +  respond_to :xml +  respond_to :json +  respond_to :kml, :only => :show +  respond_to :js, :only => :index + +  belongs_to :referential, :parent_class => Referential + +  def show +    @map = NetworkMap.new(resource).with_helpers(self) +    show! do +      build_breadcrumb :show +    end +  end + +  def index +    index! do |format| +      format.html { +        if collection.out_of_bounds? +          redirect_to params.merge(:page => 1) +        end +      } +      build_breadcrumb :index +    end +  end + +  protected + +  def build_resource +    super.tap do |network| +      network.line_referential = referential.line_referential +    end +  end + +  def collection +    @q = referential.networks.search(params[:q]) +    @networks ||= @q.result(:distinct => true).order(:name).paginate(:page => params[:page]) +  end + +  def resource_url(network = nil) +    referential_network_path(referential, network || resource) +  end + +  def collection_url +    referential_networks_path(referential) +  end + +  def network_params +    params.require(:network).permit(:objectid, :object_version, :creation_time, :creator_id, :version_date, :description, :name, :registration_number, :source_name, :source_type_name, :source_identifier, :comment ) +  end + +end diff --git a/app/helpers/breadcrumb_helper.rb b/app/helpers/breadcrumb_helper.rb index 6cbeee4c9..91f3a56c0 100644 --- a/app/helpers/breadcrumb_helper.rb +++ b/app/helpers/breadcrumb_helper.rb @@ -74,15 +74,27 @@ module BreadcrumbHelper    end    def network_breadcrumb(action) -    referential_breadcrumb -    add_breadcrumb Chouette::Network.model_name.human(:count => 2), referential_networks_path(@referential) unless action == :index -    add_breadcrumb breadcrumb_label(@network), referential_line_path(@referential, @network),:title => breadcrumb_tooltip(@network) if action == :edit +    if @line_referential +      line_referential_breadcrumb +      add_breadcrumb Chouette::Network.model_name.human(:count => 2), line_referential_networks_path(@line_referential) unless action == :index +      add_breadcrumb breadcrumb_label(@network), line_referential_network_path(@line_referential, @network),:title => breadcrumb_tooltip(@network) if action == :edit +    else +      referential_breadcrumb +      add_breadcrumb Chouette::Network.model_name.human(:count => 2), referential_networks_path(@referential) unless action == :index +      add_breadcrumb breadcrumb_label(@network), referential_network_path(@referential, @network),:title => breadcrumb_tooltip(@network) if action == :edit +    end    end    def group_of_line_breadcrumb(action) -    referential_breadcrumb -    add_breadcrumb Chouette::GroupOfLine.model_name.human(:count => 2), line_referential_group_of_lines_path(@line_referential) unless action == :index -    add_breadcrumb breadcrumb_label(@group_of_line), line_referential_group_of_line_path(@line_referential, @group_of_line),:title => breadcrumb_tooltip(@group_of_line) if action == :edit +    if @line_referential +      line_referential_breadcrumb +      add_breadcrumb Chouette::GroupOfLine.model_name.human(:count => 2), line_referential_group_of_lines_path(@line_referential) unless action == :index +      add_breadcrumb breadcrumb_label(@group_of_line), line_referential_group_of_line_path(@line_referential, @group_of_line),:title => breadcrumb_tooltip(@group_of_line) if action == :edit +    else +      referential_breadcrumb +      add_breadcrumb Chouette::GroupOfLine.model_name.human(:count => 2), referential_group_of_lines_path(@referential) unless action == :index +      add_breadcrumb breadcrumb_label(@group_of_line), referential_group_of_line_path(@referential, @group_of_line),:title => breadcrumb_tooltip(@group_of_line) if action == :edit +    end    end    def stop_area_breadcrumb(action) @@ -131,9 +143,15 @@ module BreadcrumbHelper    end    def line_breadcrumb(action) -    referential_breadcrumb -    add_breadcrumb Chouette::Line.model_name.human(:count => 2), line_referential_lines_path(@line.line_referential) unless action == :index -    add_breadcrumb breadcrumb_label(@line), line_referential_line_path(@line.line_referential, @line),:title => breadcrumb_tooltip(@line) if action == :edit +    if @line_referential +      line_referential_breadcrumb +      add_breadcrumb Chouette::Line.model_name.human(:count => 2), line_referential_lines_path(@line_referential) unless action == :index +      add_breadcrumb breadcrumb_label(@line), line_referential_line_path(@line_referential, @line),:title => breadcrumb_tooltip(@line) if action == :edit +    else +      referential_breadcrumb +      add_breadcrumb Chouette::Line.model_name.human(:count => 2), referential_lines_path(@referential) unless action == :index +      add_breadcrumb breadcrumb_label(@line), referential_line_path(@referential, @line),:title => breadcrumb_tooltip(@line) if action == :edit +    end    end    def route_breadcrumb(action) @@ -173,7 +191,7 @@ module BreadcrumbHelper      if @line_referential        line_referential_breadcrumb        add_breadcrumb Chouette::Company.model_name.human(:count => 2), line_referential_companies_path(@line_referential) unless action == :index -      add_breadcrumb breadcrumb_label(@company), referential_company_path(@line_referential, @company),:title => breadcrumb_tooltip(@company) if action == :edit +      add_breadcrumb breadcrumb_label(@company), line_referential_company_path(@line_referential, @company),:title => breadcrumb_tooltip(@company) if action == :edit      else        referential_breadcrumb        add_breadcrumb Chouette::Company.model_name.human(:count => 2), referential_companies_path(@referential) unless action == :index diff --git a/app/models/line_referential.rb b/app/models/line_referential.rb index 7592bb5f1..ccab5bf8a 100644 --- a/app/models/line_referential.rb +++ b/app/models/line_referential.rb @@ -5,6 +5,7 @@ class LineReferential < ActiveRecord::Base    has_many :lines, class_name: 'Chouette::Line'    has_many :group_of_lines, class_name: 'Chouette::GroupOfLine'    has_many :companies, class_name: 'Chouette::Company' +  has_many :networks, class_name: 'Chouette::Network'    has_one :line_referential_sync diff --git a/app/models/referential.rb b/app/models/referential.rb index 0063244e8..d8731a8d3 100644 --- a/app/models/referential.rb +++ b/app/models/referential.rb @@ -30,6 +30,7 @@ class Referential < ActiveRecord::Base    has_many :lines, through: :line_referential    has_many :companies, through: :line_referential    has_many :group_of_lines, through: :line_referential +  has_many :networks, through: :line_referential    belongs_to :stop_area_referential    # validates_presence_of :stop_area_referential @@ -59,10 +60,6 @@ class Referential < ActiveRecord::Base      self.class.human_attribute_name(*args)    end -  def networks -    Chouette::Network.all -  end -    def stop_areas      Chouette::StopArea.all    end diff --git a/app/views/line_referentials/show.html.slim b/app/views/line_referentials/show.html.slim index 019a0650a..68b31c6e1 100644 --- a/app/views/line_referentials/show.html.slim +++ b/app/views/line_referentials/show.html.slim @@ -6,6 +6,14 @@  .panel.panel-default    ul.list-group width="75%"      li.list-group-item +      span.badge = @line_referential.companies.size +      = link_to Referential.human_attribute_name("companies"), line_referential_companies_path(@line_referential) + +    li.list-group-item +      span.badge = @line_referential.networks.size +      = link_to Referential.human_attribute_name("networks"), line_referential_networks_path(@line_referential) + +    li.list-group-item        span.badge = @line_referential.group_of_lines.size        = link_to Referential.human_attribute_name("group_of_lines"), line_referential_group_of_lines_path(@line_referential) @@ -13,10 +21,6 @@        span.badge = @line_referential.operating_lines.size        = link_to Referential.human_attribute_name("lines"), line_referential_lines_path(@line_referential) -    li.list-group-item -      span.badge = @line_referential.companies.size -      = link_to Referential.human_attribute_name("companies"), line_referential_companies_path(@line_referential) -  - unless @line_referential.line_referential_sync.line_sync_operations.empty?    h3 Historique des synchronisations diff --git a/app/views/networks/_form.html.slim b/app/views/networks/_form.html.slim index e7020ef68..f7b97c27d 100644 --- a/app/views/networks/_form.html.slim +++ b/app/views/networks/_form.html.slim @@ -1,7 +1,7 @@ -= semantic_form_for [@referential, @network] do |form| += semantic_form_for [@line_referential, @network] do |form|    = form.inputs do -    = form.input :name, :input_html => { :title => t("formtastic.titles#{format_restriction_for_locales(@referential)}.network.name")} -    = form.input :registration_number, :input_html => { :title => t("formtastic.titles#{format_restriction_for_locales(@referential)}.network.registration_number")} +    = form.input :name, :input_html => { :title => t("formtastic.titles#{format_restriction_for_locales(@line_referential)}.network.name")} +    = form.input :registration_number, :input_html => { :title => t("formtastic.titles#{format_restriction_for_locales(@line_referential)}.network.registration_number")}      = form.input :comment      = form.input :version_date, as: :date_picker      = form.input :description diff --git a/app/views/networks/_network.html.slim b/app/views/networks/_network.html.slim index dc1aa6b5c..ed216c4c7 100644 --- a/app/views/networks/_network.html.slim +++ b/app/views/networks/_network.html.slim @@ -2,13 +2,13 @@    .panel-heading      .panel-title.clearfix        span.pull-right -        = link_to edit_referential_network_path(@referential, network), class: 'btn btn-default btn-sm' do +        = link_to edit_line_referential_network_path(@line_referential, network), class: 'btn btn-default btn-sm' do            span.fa.fa-pencil -        = link_to referential_network_path(@referential, network), method: :delete, :data => { :confirm => t('networks.actions.destroy_confirm') }, class: 'btn btn-danger btn-sm' do +        = link_to line_referential_network_path(@line_referential, network), method: :delete, :data => { :confirm => t('networks.actions.destroy_confirm') }, class: 'btn btn-danger btn-sm' do            span.fa.fa-trash-o        h5 -        = link_to [@referential, network], class: 'preview', title: "#{Chouette::Network.model_name.human.capitalize} #{network.name}" do +        = link_to [@line_referential, network], class: 'preview', title: "#{Chouette::Network.model_name.human.capitalize} #{network.name}" do            span.name              = truncate(network.name, :length => 20)
\ No newline at end of file diff --git a/app/views/networks/index.html.slim b/app/views/networks/index.html.slim index f3ead931e..bc32d273c 100644 --- a/app/views/networks/index.html.slim +++ b/app/views/networks/index.html.slim @@ -1,6 +1,6 @@  = title_tag t('networks.index.title') -= search_form_for @q, :url => referential_networks_path(@referential), remote: true, :html => {:method => :get, class: "form-inline", :id => "search", role: "form"} do |f| += search_form_for @q, :url => line_referential_networks_path(@line_referential), remote: true, :html => {:method => :get, class: "form-inline", :id => "search", role: "form"} do |f|    .panel.panel-default      .panel-heading        .input-group.col-md-12 @@ -19,5 +19,5 @@  - content_for :sidebar do    ul.actions      li -      = link_to t('networks.actions.new'), new_referential_network_path(@referential), class: 'add' +      = link_to t('networks.actions.new'), new_line_referential_network_path(@line_referential), class: 'add'      br
\ No newline at end of file diff --git a/app/views/networks/show.html.slim b/app/views/networks/show.html.slim index 936f6a4a8..e6bf4e399 100644 --- a/app/views/networks/show.html.slim +++ b/app/views/networks/show.html.slim @@ -37,11 +37,11 @@  - content_for :sidebar do    ul.actions      li -      = link_to t('networks.actions.new'), new_referential_network_path(@referential), class: 'add' +      = link_to t('networks.actions.new'), new_line_referential_network_path(@line_referential), class: 'add'      li -      = link_to t('networks.actions.edit'), edit_referential_network_path(@referential, @network), class: 'edit' +      = link_to t('networks.actions.edit'), edit_line_referential_network_path(@line_referential, @network), class: 'edit'      li -      = link_to t('networks.actions.destroy'), referential_network_path(@referential, @network), method: :delete, data: { :confirm => t('networks.actions.destroy_confirm')}, class: 'remove' +      = link_to t('networks.actions.destroy'), line_referential_network_path(@line_referential, @network), method: :delete, data: { :confirm => t('networks.actions.destroy_confirm')}, class: 'remove'      br -   +    = creation_tag(@network)
\ No newline at end of file diff --git a/app/views/networks/show.kml.slim b/app/views/networks/show.kml.slim index 5fd79cd47..8a5db0587 100644 --- a/app/views/networks/show.kml.slim +++ b/app/views/networks/show.kml.slim @@ -1,9 +1,9 @@  doctype XML -kml xmlns="http://www.opengis.net/kml/2.2"  +kml xmlns="http://www.opengis.net/kml/2.2"    document      - @network.commercial_stop_areas.each do |stop_area| -      placemark id="#{stop_area.id}"  +      placemark id="#{stop_area.id}"          name = stop_area.name          stop_area_type = stop_area.area_type.underscore          stop_area_type_label = t("area_types.label.#{stop_area.stop_area_type}") diff --git a/app/views/referential_networks/_form.html.slim b/app/views/referential_networks/_form.html.slim new file mode 100644 index 000000000..e7020ef68 --- /dev/null +++ b/app/views/referential_networks/_form.html.slim @@ -0,0 +1,15 @@ += semantic_form_for [@referential, @network] do |form| +  = form.inputs do +    = form.input :name, :input_html => { :title => t("formtastic.titles#{format_restriction_for_locales(@referential)}.network.name")} +    = form.input :registration_number, :input_html => { :title => t("formtastic.titles#{format_restriction_for_locales(@referential)}.network.registration_number")} +    = form.input :comment +    = form.input :version_date, as: :date_picker +    = form.input :description +    = form.input :source_name +    = form.input :source_type_name, as: :select, :collection => Chouette::Network.source_type_names, :include_blank => true, :member_label => Proc.new { |mode| t("source_types.label.#{mode}") } +    = form.input :source_identifier +    = form.input :objectid, :required => !@network.new_record?, :input_html => { :title => t("formtastic.titles#{format_restriction_for_locales(@referential)}.network.objectid")} + +  = form.actions do +    = form.action :submit, as: :button +    = form.action :cancel, as: :link
\ No newline at end of file diff --git a/app/views/referential_networks/_network.html.slim b/app/views/referential_networks/_network.html.slim new file mode 100644 index 000000000..dc1aa6b5c --- /dev/null +++ b/app/views/referential_networks/_network.html.slim @@ -0,0 +1,14 @@ +#index_item.panel.panel-default.network +  .panel-heading +    .panel-title.clearfix +      span.pull-right +        = link_to edit_referential_network_path(@referential, network), class: 'btn btn-default btn-sm' do +          span.fa.fa-pencil + +        = link_to referential_network_path(@referential, network), method: :delete, :data => { :confirm => t('networks.actions.destroy_confirm') }, class: 'btn btn-danger btn-sm' do +          span.fa.fa-trash-o + +      h5 +        = link_to [@referential, network], class: 'preview', title: "#{Chouette::Network.model_name.human.capitalize} #{network.name}" do +          span.name +            = truncate(network.name, :length => 20)
\ No newline at end of file diff --git a/app/views/referential_networks/_networks.html.slim b/app/views/referential_networks/_networks.html.slim new file mode 100644 index 000000000..9143e5c16 --- /dev/null +++ b/app/views/referential_networks/_networks.html.slim @@ -0,0 +1,9 @@ +.page_info +  span.search = t('will_paginate.page_entries_info.search') +  = page_entries_info @networks + +.networks.paginated_content +  = paginated_content(@networks) + +.pagination +  = will_paginate @networks, :container => false, renderer: RemoteBootstrapPaginationLinkRenderer
\ No newline at end of file diff --git a/app/views/referential_networks/edit.html.slim b/app/views/referential_networks/edit.html.slim new file mode 100644 index 000000000..d4e088937 --- /dev/null +++ b/app/views/referential_networks/edit.html.slim @@ -0,0 +1,3 @@ += title_tag t('networks.edit.title', network: @network.name) + += render 'form'
\ No newline at end of file diff --git a/app/views/referential_networks/index.html.slim b/app/views/referential_networks/index.html.slim new file mode 100644 index 000000000..f3ead931e --- /dev/null +++ b/app/views/referential_networks/index.html.slim @@ -0,0 +1,23 @@ += title_tag t('networks.index.title') + += search_form_for @q, :url => referential_networks_path(@referential), remote: true, :html => {:method => :get, class: "form-inline", :id => "search", role: "form"} do |f| +  .panel.panel-default +    .panel-heading +      .input-group.col-md-12 +        = f.text_field :name_cont, placeholder: "#{t('.name')}", class: 'form-control' +        .input-group-btn +          button.btn.btn-default type="submit" +            i.fa.fa-search + +      / <!-- <a data-toggle="collapse" data-parent="#search" href="#advanced_search"> --> +      / <!--   <i class="fa fa-plus"></i> <%= "#{t('.advanced_search')}" %> --> +      / <!-- </a> --> + +#networks +  = render 'networks' + +- content_for :sidebar do +  ul.actions +    li +      = link_to t('networks.actions.new'), new_referential_network_path(@referential), class: 'add' +    br
\ No newline at end of file diff --git a/app/views/referential_networks/index.js.slim b/app/views/referential_networks/index.js.slim new file mode 100644 index 000000000..930880dfa --- /dev/null +++ b/app/views/referential_networks/index.js.slim @@ -0,0 +1 @@ +| $('#networks').html("#{escape_javascript(render('networks'))}");
\ No newline at end of file diff --git a/app/views/referential_networks/new.html.slim b/app/views/referential_networks/new.html.slim new file mode 100644 index 000000000..7071ded33 --- /dev/null +++ b/app/views/referential_networks/new.html.slim @@ -0,0 +1,3 @@ += title_tag t('networks.new.title') + += render 'form'
\ No newline at end of file diff --git a/app/views/referential_networks/show.html.slim b/app/views/referential_networks/show.html.slim new file mode 100644 index 000000000..936f6a4a8 --- /dev/null +++ b/app/views/referential_networks/show.html.slim @@ -0,0 +1,47 @@ += title_tag t('networks.show.title', network: @network.name) + +.network_show +  = @map.to_html + +  .summary +    p +      label = "#{Chouette::Network.human_attribute_name('registration_number')} : " +      = @network.registration_number + +    p +      label = "#{Chouette::Network.human_attribute_name('comment')} : " +      = @network.comment + +    p +      label = "#{Chouette::Network.human_attribute_name('version_date')} : " +      - if @network.version_date.present? +        = l @network.version_date + +    p +      label = "#{Chouette::Network.human_attribute_name('description')} : " +      = @network.description + +    p +      label = "#{Chouette::Network.human_attribute_name('source_name')} : " +      = @network.source_name + +    p +      label = "#{Chouette::Network.human_attribute_name('source_type_name')} : " +      - if @network.source_type_name.present? +        = t("source_types.label.#{@network.source_type_name}") + +    p +      label = "#{Chouette::Network.human_attribute_name('source_identifier')} : " +      = @network.source_identifier + +- content_for :sidebar do +  ul.actions +    li +      = link_to t('networks.actions.new'), new_referential_network_path(@referential), class: 'add' +    li +      = link_to t('networks.actions.edit'), edit_referential_network_path(@referential, @network), class: 'edit' +    li +      = link_to t('networks.actions.destroy'), referential_network_path(@referential, @network), method: :delete, data: { :confirm => t('networks.actions.destroy_confirm')}, class: 'remove' +    br +   +  = creation_tag(@network)
\ No newline at end of file diff --git a/app/views/referential_networks/show.kml.slim b/app/views/referential_networks/show.kml.slim new file mode 100644 index 000000000..5fd79cd47 --- /dev/null +++ b/app/views/referential_networks/show.kml.slim @@ -0,0 +1,10 @@ +doctype XML + +kml xmlns="http://www.opengis.net/kml/2.2"  +  document +    - @network.commercial_stop_areas.each do |stop_area| +      placemark id="#{stop_area.id}"  +        name = stop_area.name +        stop_area_type = stop_area.area_type.underscore +        stop_area_type_label = t("area_types.label.#{stop_area.stop_area_type}") +        = (stop_area.position or stop_area.default_position).kml_representation.html_safe
\ No newline at end of file diff --git a/config/initializers/apartment.rb b/config/initializers/apartment.rb index 59bbea437..93ce2d8c6 100644 --- a/config/initializers/apartment.rb +++ b/config/initializers/apartment.rb @@ -29,7 +29,8 @@ Apartment.configure do |config|      "LineReferential",      "Chouette::Line",      "Chouette::GroupOfLine", -    "Chouette::Company" +    "Chouette::Company", +    "Chouette::Network"    ]    # use postgres schemas? diff --git a/config/locales/networks.en.yml b/config/locales/networks.en.yml index 0a5555b43..69b45050e 100644 --- a/config/locales/networks.en.yml +++ b/config/locales/networks.en.yml @@ -1,5 +1,5 @@  en: -  networks: +  networks: &en_networks      actions:        new: "Add a new network"        edit: "Edit this network" @@ -17,7 +17,7 @@ en:        advanced_search: "Advanced search"    activerecord:      models: -      network:  +      network:          zero:  "network"          one:   "network"          other: "networks" @@ -59,5 +59,7 @@ en:        hub:          network:            name: "maximum 75 characters" -          registration_number: "Positif integer, unique key, of no more than 8 digits."  +          registration_number: "Positif integer, unique key, of no more than 8 digits."            objectid: "[prefix]:PTNetwork:[unique_key] : prefix contains only alphanumerical or underscore characters, unique_key accepts also minus character. Maximum length of the unique key = 3." +  referential_networks: +    <<: *en_networks
\ No newline at end of file diff --git a/config/locales/networks.fr.yml b/config/locales/networks.fr.yml index 1abd6e1c0..c31982b43 100644 --- a/config/locales/networks.fr.yml +++ b/config/locales/networks.fr.yml @@ -1,5 +1,5 @@  fr: -  networks: +  networks: &fr_networks      actions:        new: "Ajouter un réseau"        edit: "Modifier ce réseau" @@ -61,3 +61,5 @@ fr:            name: "maximum 75 caractères"            registration_number: "Entier positif, clé unique, d'un maximum de 8 chiffres."            objectid: "[prefixe]:PTNetwork:[clé_unique]  caractères autorisés : alphanumériques et 'souligné' pour le préfixe, la clé unique accepte en plus le 'moins'. Longueur maximale de la clé unique = 3." +  referential_networks: +    <<: *fr_networks
\ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 1cd809c59..414bbde79 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -59,6 +59,7 @@ ChouetteIhm::Application.routes.draw do      resources :lines      resources :group_of_lines      resources :companies +    resources :networks    end    resources :referentials do @@ -79,7 +80,7 @@ ChouetteIhm::Application.routes.draw do        put :unarchive      end -    resources :networks +    resources :networks, controller: "referential_networks"      match 'lines' => 'lines#destroy_all', :via => :delete      resources :lines, controller: "referential_lines" do diff --git a/spec/factories/chouette_networks.rb b/spec/factories/chouette_networks.rb index f9cc4b5d6..3ad719cd9 100644 --- a/spec/factories/chouette_networks.rb +++ b/spec/factories/chouette_networks.rb @@ -4,6 +4,7 @@ FactoryGirl.define do      sequence(:name) { |n| "Network #{n}" }      sequence(:objectid) { |n| "chouette:test:GroupOfLine:#{n}" }      sequence(:registration_number) { |n| "test-#{n}" } -  end +    association :line_referential +  end  end diff --git a/spec/features/networks_spec.rb b/spec/features/networks_spec.rb index b68dda558..fc73ea6a2 100644 --- a/spec/features/networks_spec.rb +++ b/spec/features/networks_spec.rb @@ -4,39 +4,40 @@ require 'spec_helper'  describe "Networks", :type => :feature do    login_user -  let!(:networks) { Array.new(2) { create(:network) } } +  let(:line_referential) { create :line_referential } +  let!(:networks) { Array.new(2) { create(:network, line_referential: line_referential) } }    subject { networks.first }    describe "list" do      it "display networks" do -      visit referential_networks_path(referential) +      visit line_referential_networks_path(line_referential)        expect(page).to have_content(networks.first.name)        expect(page).to have_content(networks.last.name)      end -     -  end  + +  end    describe "show" do      it "display network" do        # allow(subject).to receive(:stop_areas).and_return(Array.new(2) { create(:stop_area) }) -      visit referential_networks_path(referential) +      visit line_referential_networks_path(line_referential)        click_link "#{networks.first.name}"        expect(page).to have_content(networks.first.name)      end      # it "display map" do      #   # allow(subject).to receive(:stop_areas).and_return(Array.new(2) { create(:stop_area) }) -    #   visit referential_networks_path(referential) +    #   visit line_referential_networks_path(line_referential)      #   click_link "#{networks.first.name}"      #   expect(page).to have_selector("#map.network")      # end -     +    end    describe "new" do      it "creates network and return to show" do        # allow(subject).to receive(:stop_areas).and_return(Array.new(2) { create(:stop_area) }) -      visit referential_networks_path(referential) +      visit line_referential_networks_path(line_referential)        click_link "Ajouter un réseau"        fill_in "network_name", :with => "Network 1"        fill_in "Numéro d'enregistrement", :with => "test-1" @@ -49,7 +50,7 @@ describe "Networks", :type => :feature do    describe "edit and return to show" do      it "edit network" do        # allow(subject).to receive(:stop_areas).and_return(Array.new(2) { create(:stop_area) }) -      visit referential_network_path(referential, subject) +      visit line_referential_network_path(line_referential, subject)        click_link "Modifier ce réseau"        fill_in "network_name", :with => "Network Modified"        fill_in "Numéro d'enregistrement", :with => "test-1" @@ -60,8 +61,8 @@ describe "Networks", :type => :feature do    # describe "delete", :js => true do    #   it "delete network and return to the list" do -  #     subject.stub(:stop_areas).and_return(Array.new(2) { create(:stop_area) })      -  #     visit referential_network_path(referential, subject) +  #     subject.stub(:stop_areas).and_return(Array.new(2) { create(:stop_area) }) +  #     visit line_referential_network_path(line_referential, subject)    #     click_link "Supprimer ce réseau"    #     page.evaluate_script('window.confirm = function() { return true; }')    #     click_button "Valider" diff --git a/spec/models/chouette/active_record_spec.rb b/spec/models/chouette/active_record_spec.rb index 110807e51..355d26dad 100644 --- a/spec/models/chouette/active_record_spec.rb +++ b/spec/models/chouette/active_record_spec.rb @@ -11,7 +11,7 @@ describe Chouette::ActiveRecord, :type => :model do      end      it "should return ptnetwork for Chouette::Network" do -      expect(Chouette::Network.table_name).to eq("networks") +      expect(Chouette::Network.table_name).to eq("public.networks")      end      it "should return timetable_date for Chouette::TimeTableDate" do diff --git a/spec/routing/group_of_lines_spec.rb b/spec/routing/group_of_lines_spec.rb index ee5596cf7..8bc437249 100644 --- a/spec/routing/group_of_lines_spec.rb +++ b/spec/routing/group_of_lines_spec.rb @@ -3,21 +3,21 @@ require 'spec_helper'  describe GroupOfLinesController do    describe "routing" do      it "not recognize #routes" do -      get( "/referentials/1/group_of_lines/2/routes").should_not route_to( +      get( "/line_referentials/1/group_of_lines/2/routes").should_not route_to(          :controller => "group_of_lines", :action => "routes", -        :referential_id => "1", :id => "2" +        :line_referential_id => "1", :id => "2"        )      end      it "not recognize #lines" do -      get( "/referentials/1/group_of_lines/2/lines").should_not route_to( +      get( "/line_referentials/1/group_of_lines/2/lines").should_not route_to(          :controller => "group_of_lines", :action => "lines", -        :referential_id => "1", :id => "2" +        :line_referential_id => "1", :id => "2"        )      end      it "recognize and generate #show" do -      get( "/referentials/1/group_of_lines/2").should route_to( +      get( "/line_referentials/1/group_of_lines/2").should route_to(          :controller => "group_of_lines", :action => "show", -        :referential_id => "1", :id => "2" +        :line_referential_id => "1", :id => "2"        )      end    end diff --git a/spec/routing/networks_spec.rb b/spec/routing/networks_spec.rb index c0544980d..8d5366f88 100644 --- a/spec/routing/networks_spec.rb +++ b/spec/routing/networks_spec.rb @@ -3,21 +3,21 @@ require 'spec_helper'  describe NetworksController do    describe "routing" do      it "not recognize #routes" do -      get( "/referentials/1/networks/2/routes").should_not route_to( +      get( "/line_referentials/1/networks/2/routes").should_not route_to(          :controller => "networks", :action => "routes", -        :referential_id => "1", :id => "2" +        :line_referential_id => "1", :id => "2"        )      end      it "not recognize #lines" do -      get( "/referentials/1/networks/2/lines").should_not route_to( +      get( "/line_referentials/1/networks/2/lines").should_not route_to(          :controller => "networks", :action => "lines", -        :referential_id => "1", :id => "2" +        :line_referential_id => "1", :id => "2"        )      end      it "recognize and generate #show" do -      get( "/referentials/1/networks/2").should route_to( +      get( "/line_referentials/1/networks/2").should route_to(          :controller => "networks", :action => "show", -        :referential_id => "1", :id => "2" +        :line_referential_id => "1", :id => "2"        )      end    end diff --git a/spec/views/networks/edit.html.erb_spec.rb b/spec/views/networks/edit.html.erb_spec.rb index 2a18e09b6..f77459837 100644 --- a/spec/views/networks/edit.html.erb_spec.rb +++ b/spec/views/networks/edit.html.erb_spec.rb @@ -1,12 +1,13 @@  require 'spec_helper'  describe "/networks/edit", :type => :view do -  assign_referential +    let!(:network) { assign(:network, create(:network) ) } +  let!(:line_referential) { assign :line_referential, network.line_referential }    describe "test" do      it "should render h2 with the group name" do -      render     +      render        expect(rendered).to have_selector("h2", :text => Regexp.new(network.name))      end    end diff --git a/spec/views/networks/index.html.erb_spec.rb b/spec/views/networks/index.html.erb_spec.rb index d78ef7c95..2aef66920 100644 --- a/spec/views/networks/index.html.erb_spec.rb +++ b/spec/views/networks/index.html.erb_spec.rb @@ -2,20 +2,20 @@ require 'spec_helper'  describe "/networks/index", :type => :view do -  assign_referential -  let!(:networks) { assign :networks, Array.new(2){ create(:network) }.paginate }   +  let!(:line_referential) { assign :line_referential, create(:line_referential) } +  let!(:networks) { assign :networks, Array.new(2){ create(:network, line_referential: line_referential) }.paginate }    let!(:search) { assign :q, Ransack::Search.new(Chouette::Network) } -  it "should render a show link for each group" do         -    render   -    networks.each do |network|       -      expect(rendered).to have_selector(".network a[href='#{view.referential_network_path(referential, network)}']", :text => network.name) +  it "should render a show link for each group" do +    render +    networks.each do |network| +      expect(rendered).to have_selector(".network a[href='#{view.line_referential_network_path(line_referential, network)}']", :text => network.name)      end    end    it "should render a link to create a new group" do      render -    expect(view.content_for(:sidebar)).to have_selector(".actions a[href='#{new_referential_network_path(referential)}']") +    expect(view.content_for(:sidebar)).to have_selector(".actions a[href='#{new_line_referential_network_path(line_referential)}']")    end  end diff --git a/spec/views/networks/new.html.erb_spec.rb b/spec/views/networks/new.html.erb_spec.rb index 0e9c08372..41fba412b 100644 --- a/spec/views/networks/new.html.erb_spec.rb +++ b/spec/views/networks/new.html.erb_spec.rb @@ -1,11 +1,11 @@  require 'spec_helper'  describe "/networks/new", :type => :view do -  assign_referential +    let!(:network) {  assign(:network, build(:network)) } +  let!(:line_referential) { assign :line_referential, network.line_referential }    describe "form" do -          it "should render input for name" do        render        expect(rendered).to have_selector("form") do diff --git a/spec/views/networks/show.html.erb_spec.rb b/spec/views/networks/show.html.erb_spec.rb index 29efacb17..e73ab55c3 100644 --- a/spec/views/networks/show.html.erb_spec.rb +++ b/spec/views/networks/show.html.erb_spec.rb @@ -1,10 +1,10 @@  require 'spec_helper'  describe "/networks/show", :type => :view do -   -  assign_referential +    let!(:network) { assign(:network, create(:network)) }    let!(:map) { assign(:map, double(:to_html => '<div id="map"/>'.html_safe)) } +  let!(:line_referential) { assign :line_referential, network.line_referential }    it "should render h2 with the network name" do      render @@ -18,12 +18,12 @@ describe "/networks/show", :type => :view do    it "should render a link to edit the network" do      render -    expect(view.content_for(:sidebar)).to have_selector(".actions a[href='#{view.edit_referential_network_path(referential, network)}']") +    expect(view.content_for(:sidebar)).to have_selector(".actions a[href='#{view.edit_line_referential_network_path(line_referential, network)}']")    end    it "should render a link to remove the network" do      render -    expect(view.content_for(:sidebar)).to have_selector(".actions a[href='#{view.referential_network_path(referential, network)}'][class='remove']") +    expect(view.content_for(:sidebar)).to have_selector(".actions a[href='#{view.line_referential_network_path(line_referential, network)}'][class='remove']")    end  end | 
