aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichel Etienne2012-10-09 16:03:11 +0200
committerMichel Etienne2012-10-09 16:03:11 +0200
commit72de1c47254ca70d7be04a96b5b11dfed8f79df6 (patch)
treec4ccd9fb97779edd589071570596779f266b990d
parent04835501dbf267b2046d24e65400e23c927d4ab3 (diff)
downloadchouette-core-72de1c47254ca70d7be04a96b5b11dfed8f79df6.tar.bz2
add group_of_line managment
-rw-r--r--app/assets/javascripts/group_of_line.js.coffee15
-rw-r--r--app/assets/stylesheets/group_of_lines.css.scss101
-rw-r--r--app/controllers/group_of_lines_controller.rb47
-rw-r--r--app/controllers/lines_controller.rb17
-rw-r--r--app/maps/group_of_line_map.rb34
-rw-r--r--app/models/referential.rb4
-rw-r--r--app/views/group_of_lines/_form.erb27
-rw-r--r--app/views/group_of_lines/_group_of_line.erb9
-rw-r--r--app/views/group_of_lines/_lines_detail.html.erb10
-rw-r--r--app/views/group_of_lines/edit.html.erb3
-rw-r--r--app/views/group_of_lines/index.html.erb26
-rw-r--r--app/views/group_of_lines/new.html.erb3
-rw-r--r--app/views/group_of_lines/show.html.erb48
-rw-r--r--app/views/group_of_lines/show.js.erb4
-rw-r--r--app/views/group_of_lines/show.kml.erb13
-rw-r--r--app/views/layouts/application.html.erb1
-rw-r--r--app/views/vehicle_journeys/_form.html.erb1
-rw-r--r--config/locales/group_of_lines.yml76
-rw-r--r--config/locales/stop_areas.yml2
-rw-r--r--config/routes.rb27
20 files changed, 466 insertions, 2 deletions
diff --git a/app/assets/javascripts/group_of_line.js.coffee b/app/assets/javascripts/group_of_line.js.coffee
new file mode 100644
index 000000000..c49b0d54a
--- /dev/null
+++ b/app/assets/javascripts/group_of_line.js.coffee
@@ -0,0 +1,15 @@
+jQuery ->
+
+ switch_lines = (event) ->
+ event.preventDefault()
+ $('.group_of_lines.show .lines_detail').toggle('slow')
+ $('a.lines .switcher').toggle()
+
+ $('.group_of_lines.show a.lines').click(switch_lines)
+
+
+ make_ajax_pagination = () ->
+ $.get(this.href, null, null, 'script')
+ false
+
+ $('.group_of_lines.show .lines_detail .pagination a').live("click", make_ajax_pagination)
diff --git a/app/assets/stylesheets/group_of_lines.css.scss b/app/assets/stylesheets/group_of_lines.css.scss
new file mode 100644
index 000000000..24fbdce12
--- /dev/null
+++ b/app/assets/stylesheets/group_of_lines.css.scss
@@ -0,0 +1,101 @@
+// Place all the styles related to the lines controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
+@import "common";
+
+#workspace.group_of_lines.index
+{
+ .group_of_line:after {
+ @include after_div_for_object;
+ }
+
+ .group_of_lines {
+ margin-top: 20px;
+ }
+
+ .group_of_lines:after {
+ @include content_to_clear;
+ }
+
+ .group_of_line {
+ @include div_for_object;
+
+ /* to create multi-column index */
+ width: 350px;
+ float: left;
+ padding-right: 10px;
+
+ }
+}
+
+#workspace.group_of_lines.show
+{
+ .summary p label {
+ font-weight: bold;
+ }
+ .lines_detail div.page_info {
+ margin-top: 0px;
+ }
+
+ .line:after {
+ @include after_div_for_object;
+ }
+
+ .lines {
+ margin-top: 10px;
+ }
+
+ .lines:after {
+ @include content_to_clear;
+ }
+ .group_of_line_lines {
+ clear: both;
+ margin: 0px;
+ padding: 0px;
+ a {
+ cursor: pointer;
+ }
+ }
+
+ .line {
+ @include div_for_object;
+ /* to create multi-column index */
+ width: 250px;
+ float: left;
+ padding-right: 10px;
+
+ .position {
+ width: 25px;
+ height: 20px;
+ float: left;
+ background-color: #61970B;
+ font-weight: bold;
+ color: white;
+ margin-right: 10px;
+ padding-left: 4px;
+ }
+ .color {
+ background-color: white;
+ width: 64px;
+ height: 64px;
+ float: left;
+ margin-right: 10px;
+ border: 1px solid #999;
+
+ a {
+ text-decoration: none;
+ }
+ }
+
+ .number {
+ font-size: 16px;
+ text-align: center;
+ font-weight: bold;
+ padding-top: 21px;
+ }
+ .name a {
+ display: inline;
+ }
+ }
+}
+
diff --git a/app/controllers/group_of_lines_controller.rb b/app/controllers/group_of_lines_controller.rb
new file mode 100644
index 000000000..c758ad16d
--- /dev/null
+++ b/app/controllers/group_of_lines_controller.rb
@@ -0,0 +1,47 @@
+class GroupOfLinesController < ChouetteController
+ defaults :resource_class => Chouette::GroupOfLine
+ respond_to :html
+ respond_to :xml
+ respond_to :json
+ respond_to :kml, :only => :show
+
+ belongs_to :referential
+
+ def show
+ @map = GroupOfLineMap.new(resource).with_helpers(self)
+ @lines = resource.lines.order(:name).paginate(:page => params[:page])
+ show!
+ end
+
+ def name_filter
+ respond_to do |format|
+ format.json { render :json => filtered_group_of_lines_maps}
+ end
+
+ end
+
+ protected
+
+ def filtered_group_of_lines_maps
+ filtered_group_of_lines.collect do |group_of_line|
+ { :id => group_of_line.id, :name => group_of_line.name }
+ end
+ end
+
+ def filtered_group_of_lines
+ referential.group_of_lines.select{ |t| t.name =~ /#{params[:q]}/i }
+ end
+
+ def collection
+ @q = referential.group_of_lines.search(params[:q])
+ @group_of_lines ||= @q.result(:distinct => true).order(:name).paginate(:page => params[:page])
+ end
+
+ def resource_url(group_of_line = nil)
+ referential_group_of_line_path(referential, group_of_line || resource)
+ end
+
+ def collection_url
+ referential_group_of_lines_path(referential)
+ end
+end
diff --git a/app/controllers/lines_controller.rb b/app/controllers/lines_controller.rb
index e85c29fc9..0699b0047 100644
--- a/app/controllers/lines_controller.rb
+++ b/app/controllers/lines_controller.rb
@@ -20,8 +20,25 @@ class LinesController < ChouetteController
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 }
+ end
+ end
+
+ def filtered_lines
+ referential.lines.select{ |t| t.published_name =~ /#{params[:q]}/i }
+ end
+
def collection
@q = referential.lines.search(params[:q])
@lines ||= @q.result(:distinct => true).order(:number).paginate(:page => params[:page]).includes([:network, :company])
diff --git a/app/maps/group_of_line_map.rb b/app/maps/group_of_line_map.rb
new file mode 100644
index 000000000..fdd8cac1d
--- /dev/null
+++ b/app/maps/group_of_line_map.rb
@@ -0,0 +1,34 @@
+class GroupOfLineMap < ApplicationMap
+
+ attr_reader :group_of_line, :group_of_line_style
+
+ def initialize(group_of_line, group_of_line_style = nil)
+ @group_of_line = group_of_line
+ @group_of_line_style = group_of_line_style
+ end
+
+ def map
+ @map ||= MapLayers::Map.new(id, :projection => projection("EPSG:900913"), :controls => controls) do |map, page|
+ page << map.add_layer(MapLayers::OSM_MAPNIK)
+ page << map.add_layer(google_physical)
+ page << map.add_layer(google_streets)
+ page << map.add_layer(google_hybrid)
+ page << map.add_layer(google_satellite)
+
+ page.assign "stop_areas_layer", kml_layer([group_of_line.referential, group_of_line], :styleMap => StyleMap::StopAreasStyleMap.new(helpers).style_map)
+
+ page << map.add_layer(:stop_areas_layer)
+ page << map.add_control( hover_control_display_name(:stop_areas_layer) )
+ page << map.zoom_to_extent(bounds.to_google.to_openlayers) if bounds
+ end
+ end
+
+ def bounds
+ @bounds ||= GeoRuby::SimpleFeatures::Point.bounds(group_of_line.stop_areas.collect(&:geometry).compact)
+ end
+
+ def ready?
+ Chouette::StopArea.bounds.present?
+ end
+
+end
diff --git a/app/models/referential.rb b/app/models/referential.rb
index ab4290cdd..b4601caee 100644
--- a/app/models/referential.rb
+++ b/app/models/referential.rb
@@ -47,6 +47,10 @@ class Referential < ActiveRecord::Base
Chouette::Network.scoped
end
+ def group_of_lines
+ Chouette::GroupOfLine.scoped
+ end
+
def companies
Chouette::Company.scoped
end
diff --git a/app/views/group_of_lines/_form.erb b/app/views/group_of_lines/_form.erb
new file mode 100644
index 000000000..0dcdc9379
--- /dev/null
+++ b/app/views/group_of_lines/_form.erb
@@ -0,0 +1,27 @@
+<%= semantic_form_for [@referential, @group_of_line] do |form| %>
+ <%= form.inputs do %>
+ <%= form.input :name %>
+ <%= form.input :comment %>
+ <%= form.input :objectid, :required => !@group_of_line.new_record?, :input_html => { :disabled => !@group_of_line.new_record? } %>
+ <% end %>
+
+ <%= form.inputs do %>
+ <%= form.input :line_tokens, :label => t('.lines'), :as => :text, :input_html => { :"data-pre" => ( @group_of_line.lines.map { |line| { :id => line.id, :name => line.published_name } } ).to_json } %>
+ <% end %>
+
+ <%= form.actions do %>
+ <%= form.action :submit, :as => :button %>
+ <%= form.action :cancel, :as => :link %>
+ <% end %>
+<% end %>
+
+<script>
+ $(function() {
+ $( "#group_of_line_line_tokens" ).tokenInput('<%= name_filter_referential_lines_path(@referential, :format => :json) %>', {
+ crossDomain: false,
+ prePopulate: $('#line_tokens').data('pre'),
+ minChars: 3,
+ preventDuplicates: true,
+ });
+ });
+</script>
diff --git a/app/views/group_of_lines/_group_of_line.erb b/app/views/group_of_lines/_group_of_line.erb
new file mode 100644
index 000000000..b3a9099d8
--- /dev/null
+++ b/app/views/group_of_lines/_group_of_line.erb
@@ -0,0 +1,9 @@
+<%= div_for(group_of_line) do %>
+ <%= link_to group_of_line.name, [@referential, group_of_line] %>
+ <div class="info">
+ <div class="actions">
+ <%= link_to t("actions.edit"), edit_referential_group_of_line_path(@referential, group_of_line), :class => "edit" %> |
+ <%= link_to t("actions.destroy"), referential_group_of_line_path(@referential, group_of_line), :method => :delete, :confirm => t('group_of_lines.actions.destroy_confirm'), :class => "remove" %>
+ </div>
+ </div>
+<% end %>
diff --git a/app/views/group_of_lines/_lines_detail.html.erb b/app/views/group_of_lines/_lines_detail.html.erb
new file mode 100644
index 000000000..4d4058540
--- /dev/null
+++ b/app/views/group_of_lines/_lines_detail.html.erb
@@ -0,0 +1,10 @@
+ <div class="page_info">
+ <span class="search"> <%= t("will_paginate.page_entries_info.list") %></span> <%= page_entries_info @lines %>
+ </div>
+ <div class="lines paginated_content">
+ <%= render :partial => "lines/line", :collection => @lines %>
+ </div>
+ <div class="pagination">
+ <%= will_paginate @lines, :container => false %>
+ </div>
+
diff --git a/app/views/group_of_lines/edit.html.erb b/app/views/group_of_lines/edit.html.erb
new file mode 100644
index 000000000..541e708ca
--- /dev/null
+++ b/app/views/group_of_lines/edit.html.erb
@@ -0,0 +1,3 @@
+<%= title_tag t('group_of_lines.edit.title', :group_of_line => @group_of_line.name) %>
+
+<%= render "form" %>
diff --git a/app/views/group_of_lines/index.html.erb b/app/views/group_of_lines/index.html.erb
new file mode 100644
index 000000000..6f01455b8
--- /dev/null
+++ b/app/views/group_of_lines/index.html.erb
@@ -0,0 +1,26 @@
+<%= title_tag t('group_of_lines.index.title') %>
+
+<%= search_form_for @q, :url => referential_group_of_lines_path(@referential), :html => {:method => :get} do |f| %>
+ <%= f.label :name_cont, "#{t('.name')} :" %>
+ <%= f.text_field :name_cont %>
+
+ <%= f.submit t('actions.search') %> <%= t("or") %>
+ <%= link_to t("cancel"), referential_group_of_lines_path(@referential) %>
+<% end %>
+
+<div class="page_info">
+ <span class="search"> <%= t("will_paginate.page_entries_info.search") %></span> <%= page_entries_info @group_of_lines %>
+</div>
+<div class="group_of_lines paginated_content">
+ <%= render :partial => "group_of_line", :collection => @group_of_lines %>
+</div>
+<div class="pagination">
+ <%= will_paginate @group_of_lines, :container => false %>
+</div>
+
+<% content_for :sidebar do %>
+<ul class="actions">
+ <li><%= link_to t('group_of_lines.actions.new'), new_referential_group_of_line_path(@referential), :class => "add" %></li>
+ <br>
+</ul>
+<% end %>
diff --git a/app/views/group_of_lines/new.html.erb b/app/views/group_of_lines/new.html.erb
new file mode 100644
index 000000000..a2da652af
--- /dev/null
+++ b/app/views/group_of_lines/new.html.erb
@@ -0,0 +1,3 @@
+<%= title_tag t('group_of_lines.new.title') %>
+
+<%= render "form" %>
diff --git a/app/views/group_of_lines/show.html.erb b/app/views/group_of_lines/show.html.erb
new file mode 100644
index 000000000..01084fb74
--- /dev/null
+++ b/app/views/group_of_lines/show.html.erb
@@ -0,0 +1,48 @@
+<%= title_tag t('group_of_lines.show.title', :group_of_line => @group_of_line.name )%>
+
+<div class="group_of_line_show">
+ <%= @map.to_html %>
+ <div class="summary">
+ <p>
+ <label><%= @group_of_line.human_attribute_name("name") %>: </label>
+ <%= @group_of_line.name %>
+ </p>
+ <p>
+ <label><%= @group_of_line.human_attribute_name("comment") %>: </label>
+ <%= @group_of_line.comment %>
+ </p>
+ <p>
+ <label><%= @group_of_line.human_attribute_name("objectid") %>: </label>
+ <%= @group_of_line.objectid %>
+ </p>
+ <p>
+ <label><%= @group_of_line.human_attribute_name("creation_time") %>: </label>
+ <%= l @group_of_line.creation_time %>
+ </p>
+ <p>
+ <label><%= @group_of_line.human_attribute_name("creator_id") %>: </label>
+ <%= @group_of_line.creator_id %>
+ </p>
+ </div>
+
+ <p class="after_map" />
+ <h3 class="group_of_line_lines">
+ <a class="lines"><%= t('.lines') %>
+ <%= image_tag("icons/plus.png" , :class => "switcher") %>
+ <%= image_tag("icons/minus.png" , :class => "switcher" , :style => "display: none;") %>
+ </a>
+ </h3>
+ <div class="lines_detail" style="display: none;">
+ <%= render :partial => "lines_detail" %>
+ </div>
+
+
+</div>
+
+<% content_for :sidebar do %>
+<ul class="actions">
+ <li><%= link_to t('group_of_lines.actions.edit'), edit_referential_group_of_line_path(@referential, @group_of_line), :class => "edit" %></li>
+ <li><%= link_to t('group_of_lines.actions.destroy'), referential_group_of_line_path(@referential, @group_of_line), :method => :delete, :confirm => t('group_of_lines.actions.destroy_confirm'), :class => "remove" %></li>
+ <br>
+</ul>
+<% end %>
diff --git a/app/views/group_of_lines/show.js.erb b/app/views/group_of_lines/show.js.erb
new file mode 100644
index 000000000..bd8ac5a7f
--- /dev/null
+++ b/app/views/group_of_lines/show.js.erb
@@ -0,0 +1,4 @@
+$(function (){
+ $(".lines_detail").html("<%= escape_javascript(render(:partial => "lines_detail")) %>");
+});
+
diff --git a/app/views/group_of_lines/show.kml.erb b/app/views/group_of_lines/show.kml.erb
new file mode 100644
index 000000000..6b1a34688
--- /dev/null
+++ b/app/views/group_of_lines/show.kml.erb
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<kml xmlns="http://www.opengis.net/kml/2.2">
+ <Document>
+ <% @group_of_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.position or stop_area.default_position).kml_representation.html_safe %>
+ </Placemark>
+ <% end %>
+ </Document>
+</kml>
+
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb
index 5df5f6b41..77873a855 100644
--- a/app/views/layouts/application.html.erb
+++ b/app/views/layouts/application.html.erb
@@ -47,6 +47,7 @@
<li><%= link_to t("layouts.tabs.dashboard").capitalize, referential_path(@referential), :class => ("current" if current_page?(referential_path(@referential))) %></li>
<li><%= tab_link_to Chouette::Network, referential_networks_path(@referential) %></li>
<li><%= tab_link_to Chouette::Company, referential_companies_path(@referential) %></li>
+ <li><%= tab_link_to Chouette::GroupOfLine, referential_group_of_lines_path(@referential) %></li>
<li><%= tab_link_to Chouette::Line, referential_lines_path(@referential) %></li>
<li><%= tab_link_to Chouette::StopArea, referential_stop_areas_path(@referential) %></li>
<li><%= tab_link_to Chouette::ConnectionLink, referential_connection_links_path(@referential) %></li>
diff --git a/app/views/vehicle_journeys/_form.html.erb b/app/views/vehicle_journeys/_form.html.erb
index 0c0ccaecc..dd1a0dbaf 100644
--- a/app/views/vehicle_journeys/_form.html.erb
+++ b/app/views/vehicle_journeys/_form.html.erb
@@ -62,6 +62,7 @@
crossDomain: false,
prePopulate: $('#time_table_tokens').data('pre'),
minChars: 3,
+ preventDuplicates: true,
});
});
</script>
diff --git a/config/locales/group_of_lines.yml b/config/locales/group_of_lines.yml
new file mode 100644
index 000000000..24baecc67
--- /dev/null
+++ b/config/locales/group_of_lines.yml
@@ -0,0 +1,76 @@
+en:
+ group_of_lines:
+ actions:
+ new: Add a new group of lines
+ edit: Edit this group of lines
+ destroy: Remove this group of lines
+ destroy_confirm: "Are you sure you want destroy this group of lines?"
+ new:
+ title: "Add a new group of lines"
+ edit:
+ title: "Update group of lines %{group_of_line}"
+ show:
+ title: "Group of lines %{group_of_line}"
+ lines: Lines list
+ index:
+ title: "Group of Lines"
+ name: Name
+ form:
+ lines: Associated lines
+ activerecord:
+ models:
+ group_of_line:
+ zero: group of line
+ one: group of line
+ other: groups of lines
+ attributes:
+ group_of_line:
+ name: "Name"
+ comment: "Comments"
+ objectid: Neptune identifier
+ object_version: Version
+ creation_time: Created on
+ creator_id: Created by
+ formtastic:
+ hints:
+ group_of_line:
+ objectid: "[prefix]:GroupOfLine:[unique_key] : prefix contains only alphanumerical or underscore characters, unique_key accepts also minus character"
+
+fr:
+ group_of_lines:
+ actions:
+ new: Ajouter un groupe de lignes
+ edit: Modifier ce groupe de lignes
+ destroy: Supprimer ce groupe de lignes
+ destroy_confirm: "Etes vous sûr de détruire ce groupe de lignes ?"
+ new:
+ title: "Ajouter un groupe de lignes"
+ edit:
+ title: Modifier le groupe de lignes %{group_of_line}
+ show:
+ title: Groupe de lignes %{group_of_line}
+ lines: Liste des lignes
+ index:
+ title: "Groupes de lignes"
+ name: Nom
+ form:
+ lines: Lignes associées
+ activerecord:
+ models:
+ group_of_line:
+ zero: groupe de lignes
+ one: groupe de lignes
+ other: groupes de lignes
+ attributes:
+ group_of_line:
+ name: "Nom"
+ comment: "Commentaire"
+ objectid: "Identifiant Neptune"
+ object_version: "Version"
+ creation_time: "Créé le"
+ creator_id: "Créé par"
+ formtastic:
+ hints:
+ group_of_line:
+ objectid: "[prefixe]:GroupOfLine:[clé_unique] caractères autorisés : alphanumériques et 'souligné' pour le préfixe, la clé unique accepte en plus le 'moins'"
+
diff --git a/config/locales/stop_areas.yml b/config/locales/stop_areas.yml
index 2d920435d..124ab05c6 100644
--- a/config/locales/stop_areas.yml
+++ b/config/locales/stop_areas.yml
@@ -101,7 +101,7 @@ fr:
genealogical: Lien entre arrêts
genealogical_routing: "Liens de l'ITL"
index:
- name_or_country_code: Nom ou Code Postal
+ name_or_country_code: Nom ou Code INSEE
title: Arrêts
selection: Filtrer sur
selection_all: Tous
diff --git a/config/routes.rb b/config/routes.rb
index 6f51978a3..27f586261 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -14,7 +14,32 @@ ChouetteIhm::Application.routes.draw do
resources :referentials do
resources :stop_point_areas
match 'lines' => 'lines#destroy_all', :via => :delete
- resources :lines, :networks do
+ resources :group_of_lines do
+ resources :stop_areas do
+ resources :stop_area_parents
+ resources :stop_area_children
+ resources :stop_area_routing_lines
+ resources :stop_area_routing_stops
+ member do
+ get 'add_children'
+ get 'select_parent'
+ get 'add_routing_lines'
+ get 'add_routing_stops'
+ end
+ end
+ resources :lines
+ collection do
+ get :name_filter
+ end
+ end
+
+ resources :lines do
+ collection do
+ get :name_filter
+ end
+ end
+
+ resources :lines, :networks, :group_of_lines do
resources :stop_areas do
resources :stop_area_parents
resources :stop_area_children