aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlban Peignier2016-05-15 09:22:06 +0200
committerAlban Peignier2016-05-15 09:22:06 +0200
commitaffbacfcd955230f66badb261dcc462cca9cd0b9 (patch)
tree5410864baa11d3e5b24671cfb8f9258aaa833e62
parentf5a3f0061fed4f8f51ebc0d556539a483626f76e (diff)
downloadchouette-core-affbacfcd955230f66badb261dcc462cca9cd0b9.tar.bz2
Associate LineReferential to Referential. Create ReferentialLines to manage lines in Referential. Refs #826
-rw-r--r--app/controllers/referential_lines_controller.rb89
-rw-r--r--app/models/referential.rb8
-rw-r--r--app/views/referential_lines/_form.erb54
-rw-r--r--app/views/referential_lines/_line.erb51
-rw-r--r--app/views/referential_lines/_lines.html.erb9
-rw-r--r--app/views/referential_lines/edit.html.erb3
-rw-r--r--app/views/referential_lines/index.html.erb51
-rw-r--r--app/views/referential_lines/index.js.erb1
-rw-r--r--app/views/referential_lines/new.html.erb3
-rw-r--r--app/views/referential_lines/show.html.erb137
-rw-r--r--app/views/referential_lines/show.kml.erb14
-rw-r--r--config/routes.rb2
-rw-r--r--db/migrate/20160513180957_add_line_referential_to_referential.rb5
-rw-r--r--db/schema.rb67
-rw-r--r--spec/factories/chouette_lines.rb4
-rw-r--r--spec/support/referential.rb7
-rw-r--r--spec/views/lines/new.html.erb_spec.rb4
17 files changed, 461 insertions, 48 deletions
diff --git a/app/controllers/referential_lines_controller.rb b/app/controllers/referential_lines_controller.rb
new file mode 100644
index 000000000..7112cf452
--- /dev/null
+++ b/app/controllers/referential_lines_controller.rb
@@ -0,0 +1,89 @@
+class ReferentialLinesController < ChouetteController
+
+ defaults :resource_class => Chouette::Line, :collection_name => 'lines', :instance_name => 'line'
+ respond_to :html
+ respond_to :xml
+ respond_to :json
+ respond_to :kml, :only => :show
+ respond_to :js, :only => :index
+
+ belongs_to :referential
+
+ def index
+ index! do |format|
+ format.html {
+ if collection.out_of_bounds?
+ redirect_to params.merge(:page => 1)
+ end
+ build_breadcrumb :index
+ }
+ end
+ end
+
+ def show
+ @map = LineMap.new(resource).with_helpers(self)
+ @routes = @line.routes
+ @group_of_lines = @line.group_of_lines
+ show! do
+ build_breadcrumb :show
+ end
+ end
+
+ # overwrite inherited resources to use delete instead of destroy
+ # foreign keys will propagate deletion)
+ def destroy_resource(object)
+ object.delete
+ end
+
+ def delete_all
+ objects =
+ get_collection_ivar || set_collection_ivar(end_of_association_chain.where(:id => params[:ids]))
+ objects.each { |object| object.delete }
+ respond_with(objects, :location => smart_collection_url)
+ end
+
+ def name_filter
+ respond_to do |format|
+ format.json { render :json => filtered_lines_maps}
+ end
+ end
+
+ protected
+
+ def filtered_lines_maps
+ filtered_lines.collect do |line|
+ { :id => line.id, :name => (line.published_name ? line.published_name : line.name) }
+ end
+ end
+
+ def filtered_lines
+ referential.lines.select{ |t| [t.name, t.published_name].find { |e| /#{params[:q]}/i =~ e } }
+ end
+
+ def collection
+ if params[:q] && params[:q]["network_id_eq"] == "-1"
+ params[:q]["network_id_eq"] = ""
+ params[:q]["network_id_blank"] = "1"
+ end
+
+ if params[:q] && params[:q]["company_id_eq"] == "-1"
+ params[:q]["company_id_eq"] = ""
+ params[:q]["company_id_blank"] = "1"
+ end
+
+ if params[:q] && params[:q]["group_of_lines_id_eq"] == "-1"
+ params[:q]["group_of_lines_id_eq"] = ""
+ params[:q]["group_of_lines_id_blank"] = "1"
+ end
+
+ @q = referential.lines.search(params[:q])
+ @lines ||= @q.result(:distinct => true).order(:number).paginate(:page => params[:page]).includes([:network, :company])
+ end
+
+ private
+
+ def line_params
+ params.require(:line).permit( :transport_mode, :network_id, :company_id, :objectid, :object_version, :creation_time, :creator_id, :name, :number, :published_name, :transport_mode_name, :registration_number, :comment, :mobility_restricted_suitability, :int_user_needs, :flexible_service, :group_of_lines, :group_of_line_ids, :group_of_line_tokens, :url, :color, :text_color, :stable_id, { footnotes_attributes: [ :code, :label, :_destroy, :id ] } )
+ end
+
+end
diff --git a/app/models/referential.rb b/app/models/referential.rb
index 1f0c5bcfd..55e7eff79 100644
--- a/app/models/referential.rb
+++ b/app/models/referential.rb
@@ -25,6 +25,10 @@ class Referential < ActiveRecord::Base
belongs_to :organisation
validates_presence_of :organisation
+ belongs_to :line_referential
+ # validates_presence_of :line_referential
+ has_many :lines, through: :line_referential
+
def slug_excluded_values
if ! slug.nil?
if slug.start_with? "pg_"
@@ -47,10 +51,6 @@ class Referential < ActiveRecord::Base
self.class.human_attribute_name(*args)
end
- def lines
- Chouette::Line.all
- end
-
def networks
Chouette::Network.all
end
diff --git a/app/views/referential_lines/_form.erb b/app/views/referential_lines/_form.erb
new file mode 100644
index 000000000..442434d3b
--- /dev/null
+++ b/app/views/referential_lines/_form.erb
@@ -0,0 +1,54 @@
+<%= semantic_form_for [@referential, @line] do |form| %>
+ <%= form.inputs do %>
+ <%= form.input :network, :as => :select, :collection => Chouette::Network.all, :include_blank => false %>
+ <%= form.input :company, :as => :select, :collection => Chouette::Company.all, :include_blank => false%>
+ <%= form.input :name, :input_html => { :title => t("formtastic.titles#{format_restriction_for_locales(@referential)}.line.name") } %>
+ <%= form.input :published_name %>
+ <%= form.input :registration_number, :input_html => { :title => t("formtastic.titles#{format_restriction_for_locales(@referential)}.line.registration_number")} %>
+ <%= form.input :number, :input_html => { :title => t("formtastic.titles#{format_restriction_for_locales(@referential)}.line.number") } %>
+ <%= form.input :transport_mode, :as => :select, :collection => Chouette::Line.transport_modes, :include_blank => false, :member_label => Proc.new { |mode| t("transport_modes.label.#{mode}") } %>
+ <%= form.input :color, :as => :string %>
+ <%= form.input :text_color %>
+ <%= form.input :stable_id %>
+ <%= form.input :url %>
+ <%= form.input :mobility_restricted_suitability, :as => :select, :collection => [[@line.human_attribute_name("accessible"), true], [@line.human_attribute_name("not_accessible"), false]], :include_blank => true %>
+ <%= form.input :flexible_service, :as => :select, :collection => [[@line.human_attribute_name("on_demaond_fs"), true], [@line.human_attribute_name("regular_fs"), false]], :include_blank => true %>
+ <%= form.input :comment %>
+ <%= form.input :objectid, :required => !@line.new_record?, :input_html => { :title => t("formtastic.titles#{format_restriction_for_locales(@referential)}.line.objectid")} %>
+ <%= form.input :group_of_line_tokens, :label => t('.group_of_lines'), :as => :text, :input_html => { :"data-pre" => ( @line.group_of_lines.map { |group_of_line| { :id => group_of_line.id, :name => group_of_line.name } } ).to_json } %>
+
+ <div class="footnotes_block">
+ <h3><%= t("footnotes.index.title") %></h3>
+ <div id="footnotes">
+ <%= form.semantic_fields_for :footnotes do |f| %>
+ <%= render "footnotes/footnote_fields", :f => f %>
+ <% end %>
+ </div>
+ <div class="add_footnote">
+ <%= link_to_add_association t("footnotes.actions.add_footnote"), form, :footnotes ,
+ :partial => "footnotes/footnote_fields",
+ :"data-association-insertion-method" => "append",
+ :"data-association-insertion-node" => "div#footnotes", :class => "add" %>
+ </div>
+ </div>
+ <% end %>
+
+ <%= form.actions do %>
+ <%= form.action :submit, :as => :button %>
+ <%= form.action :cancel, :as => :link %>
+ <% end %>
+<% end %>
+
+<script>
+ $(function() {
+ $( "#line_group_of_line_tokens" ).tokenInput('<%= name_filter_referential_group_of_lines_path(@referential, :format => :json) %>', {
+ crossDomain: false,
+ prePopulate: $('#group_of_line_tokens').data('pre'),
+ minChars: 3,
+ preventDuplicates: true,
+ hintText: '<%= t('search_hint') %>',
+ noResultsText: '<%= t('no_result_text') %>',
+ searchingText: '<%= t('searching_term') %>'
+ });
+ });
+</script>
diff --git a/app/views/referential_lines/_line.erb b/app/views/referential_lines/_line.erb
new file mode 100644
index 000000000..512f6ae7b
--- /dev/null
+++ b/app/views/referential_lines/_line.erb
@@ -0,0 +1,51 @@
+<div id="index_item" class="panel panel-default line ce-LineBlock">
+ <div class="panel-heading ce-LineBlock-header">
+ <ul class="ce-LineBlock-header-list">
+ <li>
+ <%= check_box_tag "ids[]", line.id, false, class: "multiple_selection", style: "display: none;" %>
+ <% if line.number && line.number.length <= 3 %>
+ <span class="label label-default line_number" style="<%= number_style(line) %>"><%= line.number %></span>
+ <% end %>
+ </li>
+ <li>
+ <%= link_to([@referential, line], class: 'preview', title: "#{Chouette::Line.model_name.human.capitalize} #{line.name}") do %>
+ <h5 class="ce-LineBlock-header-title"><%= truncate(line.name, length: 24) %></h5>
+ <% end %>
+ </li>
+ <li>
+ <%= link_to edit_referential_line_path(@referential, line), class: 'btn btn-default btn-sm' do %>
+ <span class="fa fa-pencil"></span>
+ <% end if edit %>
+ <%= link_to referential_line_path(@referential, line), method: :delete, data: { confirm: t('lines.actions.destroy_confirm') }, class: 'btn btn-danger btn-sm' do %>
+ <span class="fa fa-trash-o"></span>
+ <% end if delete %>
+ </li>
+ </ul>
+ </div>
+ <div class="panel-body">
+ <p>
+ <% if line.network.nil? %>
+ <%= line.human_attribute_name('network') %> <%= t('lines.index.unset') %>
+ <% else %>
+ <%= line.human_attribute_name('network') %> <%= link_to_if line.network, line.network.name, referential_network_path(@referential, line.network), :title => "#{line.human_attribute_name('network')} #{line.network.name}" %>
+ <% end %>
+ </p>
+ <p>
+ <% if line.company.nil? %>
+ <%= line.human_attribute_name('company') %> <%= t('lines.index.unset') %>
+ <% else %>
+ <%= line.human_attribute_name('company') %> <%= link_to_if( line.company, line.company.name, referential_company_path(@referential, line.company), :title => "#{line.human_attribute_name('company')} #{line.company.name}" ) %>
+ <% end %>
+ </p>
+ <p>
+ <% if line.group_of_lines.count == 0 %>
+ <br><%# t('lines.form.no_group_of_line') %>
+ <% elsif line.group_of_lines.count == 1 %>
+ <%= line.human_attribute_name('group_of_line') %>
+ <%= link_to_if( line.group_of_lines.first, line.group_of_lines.first.name, referential_group_of_line_path(@referential, line.group_of_lines.first), :title => "#{line.human_attribute_name('group_of_line')} #{line.group_of_lines.first.name}") %>
+ <% else %>
+ <%= t('lines.form.several_group_of_lines', :count => line.group_of_lines.count) %>
+ <% end %>
+ </p>
+ </div>
+</div>
diff --git a/app/views/referential_lines/_lines.html.erb b/app/views/referential_lines/_lines.html.erb
new file mode 100644
index 000000000..a4d9a3f0b
--- /dev/null
+++ b/app/views/referential_lines/_lines.html.erb
@@ -0,0 +1,9 @@
+<div class="page_info">
+ <span class="search"> <%= t("will_paginate.page_entries_info.search") %></span> <%= page_entries_info @lines %>
+</div>
+<div class="lines paginated_content">
+ <%= paginated_content(@lines) %>
+</div>
+<div class="pagination">
+ <%= will_paginate @lines, :container => false, renderer: RemoteBootstrapPaginationLinkRenderer %>
+</div>
diff --git a/app/views/referential_lines/edit.html.erb b/app/views/referential_lines/edit.html.erb
new file mode 100644
index 000000000..d2c9880ae
--- /dev/null
+++ b/app/views/referential_lines/edit.html.erb
@@ -0,0 +1,3 @@
+<%= title_tag t('lines.edit.title', :line => @line.name ) %>
+
+<%= render "form" %>
diff --git a/app/views/referential_lines/index.html.erb b/app/views/referential_lines/index.html.erb
new file mode 100644
index 000000000..e0c601572
--- /dev/null
+++ b/app/views/referential_lines/index.html.erb
@@ -0,0 +1,51 @@
+<%= title_tag t('lines.index.title') %>
+
+<%= search_form_for @q, :url => referential_lines_path(@referential), remote: true, :html => {:method => :get, class: "form-inline", :id => "search", role: "form"} do |f| %>
+<div class="panel panel-default">
+ <div class="panel-heading">
+ <div class="input-group col-md-9">
+ <%= f.text_field :name_or_number_cont, :placeholder => "#{t('.name_or_number')}", :class => 'form-control' %>
+ <div class="input-group-btn">
+ <button class="btn btn-default" type="submit"><i class="fa fa-search"></i></button>
+ </div>
+ </div><!-- /input-group -->
+ <a data-toggle="collapse" data-parent="#search" href="#advanced_search">
+ <i class="fa fa-plus"></i> <%= "#{t('.advanced_search')}" %>
+ </a>
+ </div>
+
+ <div id="advanced_search" class="panel-collapse collapse">
+ <div class="panel-body">
+ <%= f.select(:network_id_eq, @referential.networks.collect {|n| [ n.name, n.id ] }.unshift([t('.no_networks'), -1]), {include_blank: t('.all_networks')}, { :class => 'form-control' }) %>
+ <%= f.select(:company_id_eq, @referential.companies.collect {|c| [ c.name, c.id ] }.unshift([t('.no_companies'), -1]), { include_blank: t('.all_companies')}, { :class => 'form-control' }) %>
+ <%= f.select(:group_of_lines_id_eq, @referential.group_of_lines.collect {|c| [ c.name, c.id ] }.unshift([t('.no_group_of_lines'), -1]), {include_blank: t('.all_group_of_lines')}, { :class => 'form-control' }) %>
+ </div>
+ </div>
+</div>
+<% end %>
+
+<div id="lines"><%= render 'lines' %></div>
+
+<% content_for :sidebar do %>
+<ul class="actions">
+ <li><%= link_to t('lines.actions.new'), new_referential_line_path(@referential), :class => "add" %></li>
+</ul>
+
+<div id="multiple_selection_menu">
+ <h4><%= t(".multi_selection") %> </h4>
+ <div class="disabled">
+ <a class="enable" href="#"><%= t(".multi_selection_enable") %></a>
+ </div>
+
+ <div class="enabled" style="display: none;">
+ <a class="disable" href="#"><%= t(".multi_selection_disable") %></a>
+
+ <ul class="actions">
+ <%= link_to t(".delete_selected"), referential_lines_path(@referential), "data-multiple-method" => "delete", :class => "remove", "confirmation-text" => t("lines.actions.destroy_selection_confirm") %>
+ </ul>
+
+ <a class="select_all" href="#"><%= t(".select_all") %></a> | <a class="deselect_all" href="#"><%= t(".deselect_all") %></a>
+ </div>
+</div>
+
+<% end %>
diff --git a/app/views/referential_lines/index.js.erb b/app/views/referential_lines/index.js.erb
new file mode 100644
index 000000000..97595d5e9
--- /dev/null
+++ b/app/views/referential_lines/index.js.erb
@@ -0,0 +1 @@
+$('#lines').html('<%= escape_javascript(render("lines")) %>'); \ No newline at end of file
diff --git a/app/views/referential_lines/new.html.erb b/app/views/referential_lines/new.html.erb
new file mode 100644
index 000000000..452ec5df2
--- /dev/null
+++ b/app/views/referential_lines/new.html.erb
@@ -0,0 +1,3 @@
+<%= title_tag t('lines.new.title') %>
+
+<%= render "form" %>
diff --git a/app/views/referential_lines/show.html.erb b/app/views/referential_lines/show.html.erb
new file mode 100644
index 000000000..b1248c275
--- /dev/null
+++ b/app/views/referential_lines/show.html.erb
@@ -0,0 +1,137 @@
+<% text_color = @line.text_color.blank? ? "black" : "##{@line.text_color}" %>
+<% bg_color = @line.color.blank? ? "white" : "#"+@line.color %>
+
+<%= title_tag t('lines.show.title', :line => @line.name ) %>
+
+<div class="line_show">
+ <%= @map.to_html %>
+
+ <div class="summary">
+ <% text_color = @line.text_color.blank? ? "black" : "##{@line.text_color}" %>
+ <% bg_color = @line.color.blank? ? "white" : "#"+@line.color %>
+ <% if colors?(@line) %>
+ <p>
+ <label><%= t('lines.index.color') %>: </label>
+ <label class="color" style='<%="#{number_style(@line)}"%>'><%= line_sticker(@line) %></label>
+ </p>
+ <% end %>
+ <p>
+ <label><%= @line.human_attribute_name(:network) %>: </label>
+ <% if @line.network.nil? %>
+ <%= t('lines.index.unset') %>
+ <% else %>
+ <%= link_to @line.network.name, [@referential, @line.network] %>
+ <% end %>
+ </p>
+ <p>
+ <label><%= @line.human_attribute_name(:company) %>: </label>
+ <% if @line.company.nil? %>
+ <%= t('lines.index.unset') %>
+ <% else %>
+ <%= link_to @line.company.name, [@referential, @line.company] %>
+ <% end %>
+ </p>
+ <p>
+ <label><%= @line.human_attribute_name("number") %>: </label>
+ <%= @line.number %>
+ </p>
+ <p>
+ <label><%= @line.human_attribute_name("published_name") %>: </label>
+ <%= @line.published_name %>
+ </p>
+ <p>
+ <label><%= @line.human_attribute_name("registration_number") %>: </label>
+ <%= @line.registration_number %>
+ </p>
+ <p>
+ <label><%= @line.human_attribute_name("transport_mode") %>: </label>
+ <%= t("transport_modes.label.#{@line.transport_mode}") %>
+ </p>
+ <p>
+ <label><%= @line.human_attribute_name("stable_id") %>: </label>
+ <%= @line.stable_id %>
+ </p>
+
+ <p>
+ <label><%= @line.human_attribute_name("url") %>: </label>
+ <%= @line.url %>
+ </p>
+
+ <p>
+ <label><%= @line.human_attribute_name("mobility_restricted_suitability") %> : </label>
+ <% if @line.mobility_restricted_suitability.nil? %>
+ <%= @line.human_attribute_name("unspecified_mrs") %>
+ <% elsif @line.mobility_restricted_suitability? %>
+ <%= @line.human_attribute_name("accessible") %>
+ <% else %>
+ <%= @line.human_attribute_name("not_accessible") %>
+ <% end %>
+ <br>&nbsp;&nbsp;<%= @line.human_attribute_name("number_of_mrs_vj") %> : <%= @line.vehicle_journeys.where("mobility_restricted_suitability = ?", true).count %>
+ <br>&nbsp;&nbsp;<%= @line.human_attribute_name("number_of_non_mrs_vj") %> : <%= @line.vehicle_journeys.where("mobility_restricted_suitability = ?", false).count %>
+ <br>&nbsp;&nbsp;<%= @line.human_attribute_name("number_of_null_mrs_vj") %> : <%= @line.vehicle_journeys.count -
+ (@line.vehicle_journeys.where("mobility_restricted_suitability = ?", true).count +
+ @line.vehicle_journeys.where("mobility_restricted_suitability = ?", false).count) %>
+ </p>
+ <p>
+ <label><%= @line.human_attribute_name("flexible_service") %> : </label>
+ <% if @line.flexible_service.nil? %>
+ <%= @line.human_attribute_name("unspecified_fs") %>
+ <% elsif @line.flexible_service? %>
+ <%= @line.human_attribute_name("on_demaond_fs") %>
+ <% else %>
+ <%= @line.human_attribute_name("regular_fs") %>
+ <% end %>
+ <br>&nbsp;&nbsp;<%= @line.human_attribute_name("number_of_fs_vj") %> : <%= @line.vehicle_journeys.where("flexible_service = ?", true).count %>
+ <br>&nbsp;&nbsp;<%= @line.human_attribute_name("number_of_non_fs_vj") %> : <%= @line.vehicle_journeys.where("flexible_service = ?", false).count %>
+ <br>&nbsp;&nbsp;<%= @line.human_attribute_name("number_of_null_fs_vj") %>
+ <% if @line.flexible_service.nil? %>
+ (<%= @line.human_attribute_name("default_fs_msg") %>)
+ <% end %>
+ : <%= @line.vehicle_journeys.count -
+ (@line.vehicle_journeys.where("flexible_service = ?", true).count +
+ @line.vehicle_journeys.where("flexible_service = ?", false).count) %>
+ </p>
+ <p>
+ <label><%= @line.human_attribute_name("footnotes") %>: </label>
+ <ul>
+ <% @line.footnotes.each do |footnote| %>
+ <li><%= footnote.code %> : <%= footnote.label %></li>
+ <% end %>
+ </ul>
+ </p>
+ <p>
+ <label><%= @line.human_attribute_name("comment") %>: </label>
+ <%= @line.comment %>
+ </p>
+ </div>
+
+ <div class="row">
+ <div id="mobility_restricted_suitability" class="col-md-6"></div>
+ <div id="flexible_service" class="col-md-6"></div>
+ </div>
+</div>
+
+<p class="after_map" />
+<h3 class="routes"><%= t('.itineraries') %></h3>
+<div class="routes paginated_content">
+ <%= paginated_content @routes, "routes/route" %>
+</div>
+
+<% if @line.group_of_lines.any? %>
+ <h3 class="line_group_of_lines"><%= t('.group_of_lines') %></h3>
+ <div class="group_of_lines paginated_content">
+ <%= paginated_content @group_of_lines, "group_of_lines/group_of_line", :delete => false %>
+ </div>
+<% end %>
+
+<% content_for :sidebar do %>
+<ul class="actions">
+ <li><%= link_to t('lines.actions.new'), new_referential_line_path(@referential), :class => "add" %></li>
+ <li><%= link_to t('lines.actions.edit'), edit_referential_line_path(@referential, @line), :class => "edit" %></li>
+ <li><%= link_to t('lines.actions.destroy'), referential_line_path(@referential, @line), :method => :delete, :data => {:confirm => t('lines.actions.destroy_confirm')}, :class => "remove" %></li>
+ <% if !@line.hub_restricted? || (@line.hub_restricted? && @line.routes.size < 2) %>
+ <li><%= link_to t('routes.actions.new'), new_referential_line_route_path(@referential, @line), :class => "add" %></li>
+ <% end %>
+</ul>
+ <%= creation_tag(@line) %>
+<% end %>
diff --git a/app/views/referential_lines/show.kml.erb b/app/views/referential_lines/show.kml.erb
new file mode 100644
index 000000000..8e1c82eef
--- /dev/null
+++ b/app/views/referential_lines/show.kml.erb
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<kml xmlns="http://www.opengis.net/kml/2.2">
+ <Document>
+ <% @line.commercial_stop_areas.each do |stop_area| %>
+ <Placemark id="<%= stop_area.id %>" >
+ <name><%= stop_area.name %></name>
+ <stop_area_type><%= stop_area.area_type.underscore %></stop_area_type>
+ <stop_area_type_label><%= t("area_types.label.#{stop_area.stop_area_type}") %></stop_area_type_label>
+ <%= (stop_area.position or stop_area.default_position).kml_representation.html_safe %>
+ </Placemark>
+ <% end %>
+ </Document>
+</kml>
+
diff --git a/config/routes.rb b/config/routes.rb
index d43309096..05618863b 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -68,7 +68,7 @@ ChouetteIhm::Application.routes.draw do
resources :networks
match 'lines' => 'lines#destroy_all', :via => :delete
- resources :lines do
+ resources :lines, controller: "referential_lines" do
delete :index, on: :collection, action: :delete_all
collection do
get 'name_filter'
diff --git a/db/migrate/20160513180957_add_line_referential_to_referential.rb b/db/migrate/20160513180957_add_line_referential_to_referential.rb
new file mode 100644
index 000000000..d34a36a36
--- /dev/null
+++ b/db/migrate/20160513180957_add_line_referential_to_referential.rb
@@ -0,0 +1,5 @@
+class AddLineReferentialToReferential < ActiveRecord::Migration
+ def change
+ add_reference :referentials, :line_referential
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index ac4a8fd10..38442ae7b 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: 20160512110510) do
+ActiveRecord::Schema.define(version: 20160513180957) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -211,6 +211,18 @@ ActiveRecord::Schema.define(version: 20160512110510) do
t.integer "line_id", limit: 8
end
+ create_table "jobs", force: true do |t|
+ t.string "action"
+ t.datetime "created"
+ t.string "filename"
+ t.text "parameters"
+ t.string "referential"
+ t.datetime "started"
+ t.string "status"
+ t.string "type"
+ t.datetime "updated"
+ end
+
create_table "journey_frequencies", force: true do |t|
t.integer "vehicle_journey_id", limit: 8
t.time "scheduled_headway_interval", null: false
@@ -239,7 +251,7 @@ ActiveRecord::Schema.define(version: 20160512110510) do
create_table "journey_patterns", force: true do |t|
t.integer "route_id", limit: 8
- t.string "objectid", null: false
+ t.string "objectid", null: false
t.integer "object_version"
t.datetime "creation_time"
t.string "creator_id"
@@ -249,10 +261,12 @@ ActiveRecord::Schema.define(version: 20160512110510) do
t.string "published_name"
t.integer "departure_stop_point_id", limit: 8
t.integer "arrival_stop_point_id", limit: 8
- t.integer "section_status", default: 0, null: false
+ t.integer "route_section_ids", default: [], array: true
+ t.integer "section_status", default: 0, null: false
end
add_index "journey_patterns", ["objectid"], :name => "journey_patterns_objectid_key", :unique => true
+ add_index "journey_patterns", ["route_section_ids"], :name => "index_journey_patterns_on_route_section_ids"
create_table "journey_patterns_stop_points", id: false, force: true do |t|
t.integer "journey_pattern_id", limit: 8
@@ -300,6 +314,12 @@ ActiveRecord::Schema.define(version: 20160512110510) do
add_index "lines", ["objectid"], :name => "lines_objectid_key", :unique => true
add_index "lines", ["registration_number"], :name => "lines_registration_number_key"
+ create_table "links", id: false, force: true do |t|
+ t.integer "job_id", limit: 8, null: false
+ t.string "rel"
+ t.string "type"
+ end
+
create_table "networks", force: true do |t|
t.string "objectid", null: false
t.integer "object_version"
@@ -363,11 +383,12 @@ ActiveRecord::Schema.define(version: 20160512110510) do
t.integer "user_id", limit: 8
t.string "user_name"
t.string "data_format"
+ t.integer "line_referential_id"
end
create_table "route_sections", force: true do |t|
- t.integer "departure_id", limit: 8
- t.integer "arrival_id", limit: 8
+ t.integer "departure_id"
+ t.integer "arrival_id"
t.string "objectid", null: false
t.integer "object_version"
t.datetime "creation_time"
@@ -573,7 +594,7 @@ ActiveRecord::Schema.define(version: 20160512110510) do
t.integer "invited_by_id"
t.string "invited_by_type"
t.datetime "invitation_created_at"
- t.string "username", null: false
+ t.string "username"
end
add_index "users", ["email"], :name => "index_users_on_email", :unique => true
@@ -620,44 +641,12 @@ ActiveRecord::Schema.define(version: 20160512110510) do
add_index "vehicle_journeys", ["route_id"], :name => "index_vehicle_journeys_on_route_id"
Foreigner.load
- add_foreign_key "access_links", "access_points", name: "aclk_acpt_fkey", dependent: :delete
-
- add_foreign_key "group_of_lines_lines", "group_of_lines", name: "groupofline_group_fkey", dependent: :delete
-
add_foreign_key "journey_frequencies", "timebands", name: "journey_frequencies_timeband_id_fk", dependent: :nullify
add_foreign_key "journey_frequencies", "vehicle_journeys", name: "journey_frequencies_vehicle_journey_id_fk", dependent: :nullify
add_foreign_key "journey_pattern_sections", "journey_patterns", name: "journey_pattern_sections_journey_pattern_id_fk", dependent: :delete
add_foreign_key "journey_pattern_sections", "route_sections", name: "journey_pattern_sections_route_section_id_fk", dependent: :delete
- add_foreign_key "journey_patterns", "routes", name: "jp_route_fkey", dependent: :delete
- add_foreign_key "journey_patterns", "stop_points", name: "arrival_point_fkey", column: "arrival_stop_point_id", dependent: :nullify
- add_foreign_key "journey_patterns", "stop_points", name: "departure_point_fkey", column: "departure_stop_point_id", dependent: :nullify
-
- add_foreign_key "journey_patterns_stop_points", "journey_patterns", name: "jpsp_jp_fkey", dependent: :delete
- add_foreign_key "journey_patterns_stop_points", "stop_points", name: "jpsp_stoppoint_fkey", dependent: :delete
-
- add_foreign_key "routes", "routes", name: "route_opposite_route_fkey", column: "opposite_route_id", dependent: :nullify
-
- add_foreign_key "stop_areas", "stop_areas", name: "area_parent_fkey", column: "parent_id", dependent: :nullify
-
- add_foreign_key "stop_areas_stop_areas", "stop_areas", name: "stoparea_child_fkey", column: "child_id", dependent: :delete
- add_foreign_key "stop_areas_stop_areas", "stop_areas", name: "stoparea_parent_fkey", column: "parent_id", dependent: :delete
-
- add_foreign_key "stop_points", "routes", name: "stoppoint_route_fkey", dependent: :delete
-
- add_foreign_key "time_table_dates", "time_tables", name: "tm_date_fkey", dependent: :delete
-
- add_foreign_key "time_table_periods", "time_tables", name: "tm_period_fkey", dependent: :delete
-
- add_foreign_key "time_tables_vehicle_journeys", "time_tables", name: "vjtm_tm_fkey", dependent: :delete
- add_foreign_key "time_tables_vehicle_journeys", "vehicle_journeys", name: "vjtm_vj_fkey", dependent: :delete
-
- add_foreign_key "vehicle_journey_at_stops", "stop_points", name: "vjas_sp_fkey", dependent: :delete
- add_foreign_key "vehicle_journey_at_stops", "vehicle_journeys", name: "vjas_vj_fkey", dependent: :delete
-
- add_foreign_key "vehicle_journeys", "companies", name: "vj_company_fkey", dependent: :nullify
- add_foreign_key "vehicle_journeys", "journey_patterns", name: "vj_jp_fkey", dependent: :delete
- add_foreign_key "vehicle_journeys", "routes", name: "vj_route_fkey", dependent: :delete
+ add_foreign_key "links", "jobs", name: "fk_n5ypxycc1stckgkm6ust2l6on"
end
diff --git a/spec/factories/chouette_lines.rb b/spec/factories/chouette_lines.rb
index 35de831b1..0a720da48 100644
--- a/spec/factories/chouette_lines.rb
+++ b/spec/factories/chouette_lines.rb
@@ -8,7 +8,9 @@ FactoryGirl.define do
association :network, :factory => :network
association :company, :factory => :company
- association :line_referential
+ before(:create) do |line|
+ line.line_referential ||= LineReferential.find_by! name: "first"
+ end
sequence(:registration_number) { |n| "test-#{n}" }
diff --git a/spec/support/referential.rb b/spec/support/referential.rb
index 8c468eb53..ddad29963 100644
--- a/spec/support/referential.rb
+++ b/spec/support/referential.rb
@@ -39,7 +39,12 @@ RSpec.configure do |config|
Apartment::Tenant.drop('first') rescue nil
# Create the default tenant for our tests
organisation = Organisation.create!(:name => "first")
- Referential.create!(:prefix => "first", :name => "first", :slug => "first", :organisation => organisation)
+
+ line_referential = LineReferential.find_or_create_by(name: "first") do |referential|
+ referential.add_member organisation, owner: true
+ end
+
+ Referential.create! prefix: "first", name: "first", slug: "first", organisation: organisation, line_referential: line_referential
end
config.before(:each) do
diff --git a/spec/views/lines/new.html.erb_spec.rb b/spec/views/lines/new.html.erb_spec.rb
index 8b09f9ce9..ae38099d5 100644
--- a/spec/views/lines/new.html.erb_spec.rb
+++ b/spec/views/lines/new.html.erb_spec.rb
@@ -4,8 +4,8 @@ describe "/lines/new", :type => :view do
let!(:network) { create(:network) }
let!(:company) { create(:company) }
- let!(:line) { assign(:line, build(:line, :network => network, :company => company )) }
- let!(:line_referential) { assign :line_referential, line.line_referential }
+ let!(:line) { assign(:line, build(:line, :network => network, :company => company, line_referential: referential.line_referential )) }
+ let!(:line_referential) { assign :line_referential, referential.line_referential }
describe "form" do