aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorAlban Peignier2016-05-15 09:22:06 +0200
committerAlban Peignier2016-05-15 09:22:06 +0200
commitaffbacfcd955230f66badb261dcc462cca9cd0b9 (patch)
tree5410864baa11d3e5b24671cfb8f9258aaa833e62 /app
parentf5a3f0061fed4f8f51ebc0d556539a483626f76e (diff)
downloadchouette-core-affbacfcd955230f66badb261dcc462cca9cd0b9.tar.bz2
Associate LineReferential to Referential. Create ReferentialLines to manage lines in Referential. Refs #826
Diffstat (limited to 'app')
-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
11 files changed, 416 insertions, 4 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>
+