diff options
| author | Alban Peignier | 2012-05-16 19:58:07 +0200 |
|---|---|---|
| committer | Alban Peignier | 2012-05-16 19:58:07 +0200 |
| commit | 085cb4a10750833679bbfa2a61930b3a9f8307c2 (patch) | |
| tree | 329ea7204fbc8d6cfb3d861512c7d7492108e9c1 | |
| parent | 8c3eb6906fbd0d62a2fe63121b1851f523671f00 (diff) | |
| parent | 7bcb93aff46042a8fd229f6c78b3e8bbb4431f5c (diff) | |
| download | chouette-core-085cb4a10750833679bbfa2a61930b3a9f8307c2.tar.bz2 | |
Merge branch 'master' of chouette.dryade.priv:/srv/git/chouette2
29 files changed, 533 insertions, 119 deletions
diff --git a/Gemfile.lock b/Gemfile.lock index 9c79ce4e0..e61074d42 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,6 +1,6 @@ GIT remote: git://chouette.dryade.priv/ninoxe - revision: 0f2f0ab0d030c395464f43e4d5da79f5b74a89c6 + revision: 9deb81a3121fdf295512f875a91ba7b5d0d106a4 specs: ninoxe (0.0.8) GeoRuby @@ -245,8 +245,8 @@ GEM rspec-core (2.10.0) rspec-expectations (2.10.0) diff-lcs (~> 1.1.3) - rspec-mocks (2.10.0) - rspec-rails (2.10.0) + rspec-mocks (2.10.1) + rspec-rails (2.10.1) actionpack (>= 3.0) activesupport (>= 3.0) railties (>= 3.0) diff --git a/app/assets/images/icons/link-small.png b/app/assets/images/icons/link-small.png Binary files differnew file mode 100644 index 000000000..27cc0d9ee --- /dev/null +++ b/app/assets/images/icons/link-small.png diff --git a/app/assets/images/icons/move.png b/app/assets/images/icons/move.png Binary files differnew file mode 100644 index 000000000..2e9bc42be --- /dev/null +++ b/app/assets/images/icons/move.png diff --git a/app/assets/stylesheets/routes.css.scss b/app/assets/stylesheets/routes.css.scss index 3e2e5b5ed..a5c63bf01 100644 --- a/app/assets/stylesheets/routes.css.scss +++ b/app/assets/stylesheets/routes.css.scss @@ -58,39 +58,40 @@ font-weight: bold; } - .stop_area:after { + .stop_point:after { @include after_div_for_object; } - .stop_areas { + .stop_points { margin-top: 20px; } - .stop_areas:after { + .stop_points:after { @include content_to_clear; } - .route_stop_areas { + .route_stop_points { clear: both; + margin: 0px; + padding: 0px; } - .stop_area { + .stop_point { @include div_for_object; /* to create multi-column index */ width: 350px; float: left; padding-right: 10px; - .area_type { + .position { width: 25px; - height: 64px; + height: 20px; float: left; + background-color: #61970B; + font-weight: bold; + color: white; margin-right: 10px; - - - a { - text-decoration: none; - } + padding-left: 4px; } } diff --git a/app/assets/stylesheets/stop_areas.css.scss b/app/assets/stylesheets/stop_areas.css.scss index b751723b4..e66f4dd28 100644 --- a/app/assets/stylesheets/stop_areas.css.scss +++ b/app/assets/stylesheets/stop_areas.css.scss @@ -65,6 +65,12 @@ span { margin-left: 7px; } img { margin: 0px 5px 0px 5px;} } + .no_parent{ + float: left; + padding: 3px 15px 3px 3px; + height: 25px; + width: 150px; + } .target{ border: 2px solid #86b41d; diff --git a/app/assets/stylesheets/stop_points.css.scss b/app/assets/stylesheets/stop_points.css.scss new file mode 100644 index 000000000..73fc22aef --- /dev/null +++ b/app/assets/stylesheets/stop_points.css.scss @@ -0,0 +1,51 @@ +// 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.stop_points.index +{ + .stop_point:after { + @include after_div_for_object; + } + + .stop_points { + } + + .stop_points:after { + @include content_to_clear; + } + + .formtastic .buttons { + a { + margin-top: 0px; + } + } + + .stop_point { + @include div_for_object; + /* to create multi-column index */ + width: 350px; + padding-right: 10px; + + .handle { + cursor: move; + margin-right: 7px; + margin-bottom: 20px; + } + + a.link { + background: url(image-path('icons/link-small.png')) no-repeat 0% 50%; + } + + .position { + background-color: #61970B; + font-weight: bold; + color: white; + margin-right: 10px; + padding-left: 4px; + } + + } +} + diff --git a/app/controllers/routes_controller.rb b/app/controllers/routes_controller.rb index 2ed39b0ac..fed76f23b 100644 --- a/app/controllers/routes_controller.rb +++ b/app/controllers/routes_controller.rb @@ -15,8 +15,8 @@ class RoutesController < ChouetteController end def show - @map = RouteMap.new referential, resource - @stop_areas = resource.stop_areas.paginate(:page => params[:page], :per_page => 10) + @map = RouteMap.new referential, route + @stop_points = route.stop_points.paginate(:page => params[:page], :per_page => 10) show! end diff --git a/app/controllers/stop_point_areas_controller.rb b/app/controllers/stop_point_areas_controller.rb new file mode 100644 index 000000000..b307936f0 --- /dev/null +++ b/app/controllers/stop_point_areas_controller.rb @@ -0,0 +1,22 @@ +class StopPointAreasController < ChouetteController + + respond_to :json, :only => :index + + def index + respond_to do |format| + format.json { render :json => areas_maps } + end + end + + def areas_maps + areas.collect do |area| + { :id => area.id.to_s, :name => "#{area.name} #{area.country_code}" } + end + end + + def areas + Chouette::StopPoint.area_candidates.select{ |p| p.name =~ /#{params[:q]}/i } + end + +end + diff --git a/app/controllers/stop_points_controller.rb b/app/controllers/stop_points_controller.rb new file mode 100644 index 000000000..a6833eb06 --- /dev/null +++ b/app/controllers/stop_points_controller.rb @@ -0,0 +1,32 @@ +class StopPointsController < ChouetteController + defaults :resource_class => Chouette::StopPoint + + respond_to :html + + belongs_to :referential do + belongs_to :line, :parent_class => Chouette::Line do + belongs_to :route, :parent_class => Chouette::Route + end + end + + alias_method :route, :parent + + def create + create! do |success, failure| + success.html { redirect_to :action => :index } + end + end + + def sort + if route.reorder!( params[:stop_point]) + flash[:notice] = t("stop_points.reorder_success") + else + flash[:alert] = t("stop_points.reorder_failure") + end + respond_to do |format| + format.html { redirect_to :action => :index } + end + end + +end + diff --git a/app/views/companies/show.html.erb b/app/views/companies/show.html.erb index 8703bbc49..b5c64b691 100644 --- a/app/views/companies/show.html.erb +++ b/app/views/companies/show.html.erb @@ -57,7 +57,7 @@ <% content_for :sidebar do %> <ul class="actions"> <li><%= link_to t('companies.actions.edit'), edit_referential_company_path(@referential, @company), :class => "edit" %></li> - <li><%= link_to t('companys.actions.destroy'), referential_company_path(@referential, @company), :method => :delete, :confirm => t('companies.actions.destroy_confirm'), :class => "remove" %></li> + <li><%= link_to t('companies.actions.destroy'), referential_company_path(@referential, @company), :method => :delete, :confirm => t('companies.actions.destroy_confirm'), :class => "remove" %></li> <br> </ul> <% end %> diff --git a/app/views/lines/index.html.erb b/app/views/lines/index.html.erb index af9ab9ad9..c39e94cbd 100644 --- a/app/views/lines/index.html.erb +++ b/app/views/lines/index.html.erb @@ -66,21 +66,21 @@ </ul> <div id="multiple_selection_menu"> - <h3>Sélection multiple</h3> + <h3><%= t(".multi_selection") %> </h3> <div class="disabled"> - <a class="enable" href="#">Activer la sélection multiple</a> + <a class="enable" href="#"><%= t(".multi_selection_enable") %></a> </div> <div class="enabled" style="display: none;"> - <a class="disable" href="#">Désactiver la sélection multiple</a> + <a class="disable" href="#"><%= t(".multi_selection_disable") %></a> <ul class="actions"> - <li><a href="#" class="remove">Supprimer les lignes</a></li> - <li><a href="#" class="export">Exporter les lignes</a></li> + <li><a href="#" class="remove"><%= t(".delete_selected") %></a></li> + <li><a href="#" class="export"><%= t(".export_selected") %></a></li> </ul> - <a class="select_all" href="#">Tout sélectionner</a> | <a class="deselect_all" href="#">désélectionner</a> - </div> + <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/routes/show.html.erb b/app/views/routes/show.html.erb index c933d3c11..b98bab92a 100644 --- a/app/views/routes/show.html.erb +++ b/app/views/routes/show.html.erb @@ -64,18 +64,26 @@ </div> -<h3 class="route_stop_areas"><%= t('.stop_areas') %></h3> -<%= will_paginate @stop_areas %> -<div class="stop_areas paginated_content"> - <%= render :partial => "stop_areas/stop_area", :collection => @stop_areas %> +<h3 class="route_stop_points"><%= t('.stop_points') %></h3> +<div class="pagination"> + <div class="page_info"> + <%= page_entries_info @stop_points %> + </div> + <%= will_paginate @stop_points, :container => false %> +</div> +<div class="stop_points paginated_content"> + <%= render :partial => "stop_points/stop_point", :collection => @stop_points %> +</div> +<div class="pagination"> + <%= will_paginate @stop_points, :container => false %> </div> -<%= will_paginate @stop_areas %> <% content_for :sidebar do %> <ul class="actions"> <li><%= link_to t('routes.actions.edit'), edit_referential_line_route_path(@referential, @line, @route), :class => "edit" %></li> <li><%= link_to t('routes.actions.destroy'), referential_line_route_path(@referential, @line, @route), :method => :delete, :confirm => t('routes.actions.destroy_confirm'), :class => "remove" %></li> <li> + <%= link_to t('stop_points.actions.index'), referential_line_route_stop_points_path(@referential, @line, @route), :class => "edit" %> </li> </ul> <% end %> diff --git a/app/views/stop_areas/_form.html.erb b/app/views/stop_areas/_form.html.erb index ffdd9faa1..208345523 100644 --- a/app/views/stop_areas/_form.html.erb +++ b/app/views/stop_areas/_form.html.erb @@ -12,11 +12,11 @@ <%= form.input :objectid %> <% else %> <li> - <label><%= @stop_area.human_attribute_name("stop_area_type") %>: </label> - <%= @stop_area.stop_area_type %> + <label><%= @stop_area.human_attribute_name("stop_area_type") %></label> + <%= t("area_types.label.#{@stop_area.stop_area_type}") %> </li> <li> - <label><%= @stop_area.human_attribute_name("objectid") %>: </label> + <label><%= @stop_area.human_attribute_name("objectid") %></label> <%= @stop_area.objectid %> </li> <% end %> diff --git a/app/views/stop_areas/show.html.erb b/app/views/stop_areas/show.html.erb index f4f7a9064..afaa5830a 100644 --- a/app/views/stop_areas/show.html.erb +++ b/app/views/stop_areas/show.html.erb @@ -96,6 +96,8 @@ <%= link_to image_tag("user_interface/ui/remove.png"), referential_stop_area_path(@referential, @stop_area.parent), :method => :delete, :confirm => t('stop_areas.actions.destroy_confirm'), :class => "remove" %> </div> <div class="link"><%= image_tag "icons/link.png"%></div> + <% else %> + <div class="no_parent"> </div> <% end %> <% if @stop_area.parent.present? || @stop_area.children.present? %> diff --git a/app/views/stop_points/_stop_point.html.erb b/app/views/stop_points/_stop_point.html.erb new file mode 100644 index 000000000..641ddf683 --- /dev/null +++ b/app/views/stop_points/_stop_point.html.erb @@ -0,0 +1,20 @@ +<%= div_for(stop_point) do %> + <span class="position"> + <%= stop_point.position + 1 %> + </span> + <%= link_to stop_point.stop_area.name, [@referential, stop_point.stop_area] %> + <div class="info"> + <p> + <% unless stop_point.stop_area.geometry %> + <span class="warning"><%= t('.no_position') %></span> - + <% end %> + </p> + <p> + <%= t('.lines') %> <% stop_point.stop_area.lines.reject { |l| l.id==@line.id}.each do |line| %> + <span class="line"><%= line.number %></span> + <% end %> - + <%= stop_point.stop_area.human_attribute_name('country_code') %> <%= stop_point.stop_area.country_code %> + </p> + </div> +<% end %> + diff --git a/app/views/stop_points/_stop_point_draggable.html.erb b/app/views/stop_points/_stop_point_draggable.html.erb new file mode 100644 index 000000000..7841b6116 --- /dev/null +++ b/app/views/stop_points/_stop_point_draggable.html.erb @@ -0,0 +1,18 @@ +<%= div_for(stop_point) do %> + <div class="handle" alt="<%= t('stop_points.index.move') %>" title="<%= t('stop_points.index.move') %>" ><%= image_tag "icons/move.png" %></div> + <span class="position"> + <%= stop_point.position + 1 %> + </span> + <%= stop_point.stop_area.name %> + <div class="info"> + <%= t('.lines') %> <% stop_point.stop_area.lines.reject { |l| l.id==@line.id}.each do |line| %> + <span class="line"><%= line.number %></span> + <% end %> - + <%= stop_point.stop_area.human_attribute_name('country_code') %> <%= stop_point.stop_area.country_code %> + <div class="actions"> + <%= link_to t("stop_points.actions.show"), referential_stop_area_path(@referential, stop_point.stop_area), :class => "link" %> | + <%= link_to t("actions.destroy"), referential_line_route_stop_point_path(@referential, @line, @route, stop_point), :method => :delete, :confirm => t('stop_points.actions.destroy_confirm'), :class => "remove" %> + </div> + </div> +<% end %> + diff --git a/app/views/stop_points/index.html.erb b/app/views/stop_points/index.html.erb new file mode 100644 index 000000000..6f3b69ae0 --- /dev/null +++ b/app/views/stop_points/index.html.erb @@ -0,0 +1,73 @@ +<%= title_tag t('stop_points.index.title', :route => @route.name ) %> + +<div class="stop_points_index"> + <div class="summary"> + <p> + <label><%= @route.class.model_name.human %>: </label> + <%= link_to @route.name, [@referential, @line, @route] %> + </p> + <p> + <label><%= @route.human_attribute_name(:line) %>: </label> + <%= link_to line_formatted_name( @line), [@referential, @line] %> + </p> + </div> + + <h3><%= t('stop_points.index.subtitle')%></h3> + <% if @route.stop_points.empty? %> + <p><%= t('.no_stop_point') %></p> + <% end %> + + <div id="sortable_stop_points"> + <%= render :partial => "stop_point_draggable", :collection => @route.stop_points, :as => :stop_point %> + </div> + <%= semantic_form_for( Chouette::StopPoint.new, + :url => sort_referential_line_route_stop_points_path( @referential, @line, @route), + :html => {:class => "formtastic stop_points_form"}) do |form| %> + <% @stop_points.each do |sp| %> + <input type="hidden" id="<%= "pos_#{sp.position}" %>" name="stop_point[]" value="<%= sp.id %>" /> + <% end %> + <%= form.buttons do %> + <%= form.commit_button t('.reorder_button') %> + <li><%= t('or') %></li> + <li><%= link_to t('cancel'), referential_line_route_stop_points_path(@referential, @line, @route) %></li> + <% end %> + <% end %> +</div> +<% content_for :sidebar do %> +<ul class="actions"> + <li><%= link_to t('stop_points.actions.new'), new_referential_line_route_stop_point_path(@referential, @line, @route), :class => "add" %> + </li> +</ul> +<% end %> +<script> +// Sorting the list + + $(document).ready(function(){ + $('#sortable_stop_points').sortable({ + axis: 'y', + dropOnEmpty: false, + handle: '.handle', + cursor: 'crosshair', + items: '.stop_point', + opacity: 0.4, + scroll: true, + update: function(){ + $('.stop_points_form input[name="stop_point[]"]').map(function(index,element){ + var stop_point_id =$('#sortable_stop_points .stop_point')[index].id.replace("stop_point_",""); + var before = $( element).attr("value"); + $( element).attr("value",stop_point_id); + var after = $( element).attr("value"); + console.log( "pos: "+index+", before: "+before+", after:"+after); + }); + // $.ajax({ + // type: 'post', + // data: $('#sortable_stop_points').sortable('serialize'), + // dataType: 'script', + // complete: function(request){ + // $('#sortable_stop_points').effect('highlight'); + // }, + // url: "<%= sort_referential_line_route_stop_points_path( @referential, @line, @route)%>"}) + } + }); + }); +</script> diff --git a/app/views/stop_points/new.html.erb b/app/views/stop_points/new.html.erb new file mode 100644 index 000000000..a69840bf6 --- /dev/null +++ b/app/views/stop_points/new.html.erb @@ -0,0 +1,31 @@ +<%= title_tag t('.title', :route => @route.name) %> + +<%= semantic_form_for [@referential, @line, @route, @stop_point] do |form| %> +<div> + <%= form.inputs do %> + <%= form.input :stop_area_id, :label => t('.select_area'),:input_html => { :"data-pre" => [].to_json } %> + <% end %> + + <%= form.buttons do %> + <%= form.commit_button %> + ou <%= link_to "revenir", referential_line_route_stop_points_path(@referential, @line, @route) %> + <% end %> +</div> +<% end %> + +<script> + $(function() { + $( "#stop_point_stop_area_id" ).tokenInput('<%= referential_stop_point_areas_path(@referential, :format => :json) %>', { + crossDomain: false, + prePopulate: $('#stop_area_id').data('pre'), + tokenLimit: 1, + minChars: 3, + }); + }); +</script> + +<% content_for :sidebar do %> +<ul class="actions"> +</ul> +<% end %> + diff --git a/config/locales/companies.yml b/config/locales/companies.yml index b6b3db0d7..86af20ab2 100644 --- a/config/locales/companies.yml +++ b/config/locales/companies.yml @@ -17,7 +17,7 @@ en: activerecord: models: - company: "Companies" + company: Company attributes: company: registrationnumber: "Registration number" @@ -58,7 +58,7 @@ fr: activerecord: models: - company: "Transporteurs" + company: Transporteur attributes: company: registrationnumber: "Numéro d'enregistrement" diff --git a/config/locales/lines.yml b/config/locales/lines.yml index 3d7cf583b..9b58eeeac 100644 --- a/config/locales/lines.yml +++ b/config/locales/lines.yml @@ -16,8 +16,15 @@ en: index: title: Lines name_or_number: Name or number - selection: Selection + selection: Filter on selection_all: All + multi_selection: Multiple selection + multi_selection_enable: Enable multiple selection + multi_selection_disable: Disable multiple selection + delete_selected: Delete lines + export_selected: Export linges + select_all: Select all + deselect_all: Deselect all activerecord: models: line: Line @@ -55,12 +62,19 @@ fr: title: Modifier la ligne %{line} show: title: Ligne %{line} - itineraries: "Liste des itinéraires de la ligne" + itineraries: "Liste des séquences d'arrêts de la ligne" index: name_or_number: Nom ou indice title: Lignes - selection: Sélection + selection: Filtrer sur selection_all: Tous + multi_selection: Sélection multiple + multi_selection_enable: Activer la sélection multiple + multi_selection_disable: Désactiver la sélection multiple + delete_selected: Supprimer les lignes + export_selected: Exporter les lignes + select_all: Tout sélectionner + deselect_all: Tout désélectionner activerecord: models: line: Ligne diff --git a/config/locales/networks.yml b/config/locales/networks.yml index 6b0070933..06c7396cf 100644 --- a/config/locales/networks.yml +++ b/config/locales/networks.yml @@ -17,7 +17,7 @@ en: activerecord: models: - network: Networks + network: Network attributes: network: registrationnumber: "Registration number" diff --git a/config/locales/routes.yml b/config/locales/routes.yml index a4cd3a366..e9422d2db 100644 --- a/config/locales/routes.yml +++ b/config/locales/routes.yml @@ -11,7 +11,7 @@ en: title: Update route %{route} show: title: Route %{route} - stop_areas: "Routes's stop areas list" + stop_points: "Stop point on route list" no_opposite_route: No reversed route associated undefined: Undefined index: @@ -39,26 +39,26 @@ en: fr: routes: actions: - new: Ajouter un itinéraire - edit: Modifier cet itinéraire - destroy: Supprimer cet itinéraire - destroy_confirm: Etes vous sûr de détruire cet itinéraire ? + new: "Ajouter une séquence d'arrêts" + edit: "Modifier cette séquence d'arrêts" + destroy: "Supprimer cette séquence d'arrêts" + destroy_confirm: "Etes vous sûr de détruire cette séquence d'arrêts ?" new: - title: Ajouter un itinéraire + title: "Ajouter une séquence d'arrêts" edit: - title: "Modifier l'itinéraire %{route}" + title: "Modifier la séquence d'arrêts %{route}" show: - title: Itinéraire %{route} de la ligne %{line} - stop_areas: "Liste des arrêts de l'itinéraire" - no_opposite_route: Aucun itinéraire associé en sens opposé + title: "Séquence d'arrêts %{route} de la ligne %{line}" + stop_areas: "Liste des arrêts de la séquence d'arrêts" + no_opposite_route: "Aucune séquence d'arrêts associée en sens opposé" undefined: Non défini index: - title: Itinéraires + title: "Séquences d'arrêts" selection: Sélection selection_all: Tous activerecord: models: - route: Itinéraire + route: "Séquence d'arrêts" attributes: route: line: Ligne @@ -68,7 +68,7 @@ fr: comment: Commentaire direction_code: Direction wayback_code: Sens - opposite_route: Itinéraire associé en sens opposé + opposite_route: "Séquence d'arrêts associée en sens opposé" objectid: Identifiant Neptune object_version: Version creation_time: Créé le diff --git a/config/locales/stop_areas.yml b/config/locales/stop_areas.yml index bb5d02869..c6d5f9274 100644 --- a/config/locales/stop_areas.yml +++ b/config/locales/stop_areas.yml @@ -22,7 +22,7 @@ en: index: title: Stop areas name_or_country_code: Name or Country code - selection: Selection + selection: Filter on selection_all: All area_type: Area Type select_parent: @@ -84,7 +84,7 @@ fr: index: name_or_country_code: Nom ou Code Postal title: Arrêts - selection: Sélection + selection: Filtrer sur selection_all: Tous area_type: Type d'arrêt select_parent: diff --git a/config/locales/stop_points.yml b/config/locales/stop_points.yml index d26b88428..70f477d8e 100644 --- a/config/locales/stop_points.yml +++ b/config/locales/stop_points.yml @@ -1,80 +1,51 @@ en: stop_points: + reorder_success: "Reordering saved" + reorder_failure: "Fail in reordering" actions: - new: Add a new stop - edit: Edit this stop - destroy: Remove this stop - destroy_confirm: Are you sure you want destroy this stop? + show: Show + index: Stops on route list + new: Add a new stop on route + edit: Edit this stop on route + destroy: Remove this stop on route + destroy_confirm: Are you sure you want destroy this stop on route ? new: - title: Add a new stop - edit: - title: Update stop %{stop_point} - show: - title: Stop %{stop_point} + title: Add a new stop route + select_area: Select a stop area index: - title: Stop areas - name: Name - selection: Selection - selection_all: All + reorder_button: Save reordering + title: Stops on route %{route} + subtitle: Stops on route ordered + move: Move + no_stop_point: No stop point on route activerecord: models: - stop_point: Stop area + stop_point: Stop point on route attributes: stop_point: - name: Name - registration_number: Registration number - comment: Comments - areatype: Area type - nearest_topic_name: Nearest point of interest - street_name: Street name - country_code: INSEE code - fare_code: Fare code - x: x-position - y: y-position - longitude: Longitude - latitude: Latitude - objectid: Neptune identifier - object_version: Version - creation_time: Created on - creator_id: Created by fr: stop_points: + reorder_success: "L'ordre a été mis à jour" + reorder_failure: "Echec de la mise à jour" actions: - new: Ajouter un arrêt - edit: Modifier cet arrêt - destroy: Supprimer cet arrêt - destroy_confirm: Etes vous sûr de détruire cet arrêt ? + show: Consulter + index: Liste des arrêts sur itinéraire + new: Ajouter un arrêt sur itinéraire + edit: Modifier cet arrêt sur itinéraire + destroy: Supprimer cet arrêt sur itinéraire + destroy_confirm: Etes vous sûr de détruire cet arrêt sur itinéraire ? new: - title: Ajouter un arrêt - edit: - title: "Modifier l'arrêt %{stop_point}" - show: - title: Arrêt %{stop_point} + title: "Ajouter un arrêt à l'itinéraire %{route}" + select_area: "Sélectionner un arrêt" index: - name: Nom - title: Arrêts - selection: Sélection - selection_all: Tous + reorder_button: "Mettre à jour l'ordre de parcours" + title: "Liste des arrêts de l'itinéraire %{route}" + subtitle: "Arrêts dans l'ordre " + move: Déplacer + no_stop_point: Aucun arrêt sur itinéraire activerecord: models: - stop_point: Arrêt + stop_point: Arrêt sur itinéraire attributes: stop_point: - name: Nom - registration_number: "Numéro d'enregistrement" - published_name: Nom public - comment: Commentaire - area_type: "Type d'arrêt" - nearest_topic_name: "Point d'intérêt le plus proche" - street_name: Nom de la rue - country_code: Code INSEE - fare_code: Zone tarifaire - x: Position X - y: Position Y - longitude: Longitude - latitude: Latitude - object_id: Identifiant Neptune - object_version: Version - creation_time: Créé le - creator_id: Créé par diff --git a/config/routes.rb b/config/routes.rb index 399bae472..305a219ce 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -19,6 +19,7 @@ ChouetteIhm::Application.routes.draw do # Sample resource route (maps HTTP verbs to controller actions automatically): # resources :products resources :referentials do + resources :stop_point_areas resources :lines, :networks do resources :stop_areas do resources :stop_area_parents @@ -28,7 +29,13 @@ ChouetteIhm::Application.routes.draw do get 'select_parent' end end - resources :routes + resources :routes do + resources :stop_points do + collection do + post :sort + end + end + end end resources :imports diff --git a/spec/controllers/routes_controller_spec.rb b/spec/controllers/routes_controller_spec.rb new file mode 100644 index 000000000..92bcbf4a8 --- /dev/null +++ b/spec/controllers/routes_controller_spec.rb @@ -0,0 +1,83 @@ +require 'spec_helper' + +describe RoutesController do + login_user + + let!(:referential) { create(:referential).switch } + let!(:route) { referential; Factory(:route) } + + it { should be_kind_of(ChouetteController) } + + shared_examples_for "redirected to referential_line_path(referential,line)" do + it "should redirect_to referential_line_path(referential,line)" do + response.should redirect_to( referential_line_path(referential,route.line) ) + end + end + shared_examples_for "line and referential linked" do + it "assigns route.line as @line" do + assigns[:line].should == route.line + end + + it "assigns referential as @referential" do + assigns[:referential].should == referential + end + end + shared_examples_for "route, line and referential linked" do + it "assigns route as @route" do + assigns[:route].should == route + end + it_behaves_like "line and referential linked" + end + + + describe "GET /index" do + before(:each) do + get :index, :line_id => route.line_id, + :referential_id => referential.id + end + + it_behaves_like "line and referential linked" + it_behaves_like "redirected to referential_line_path(referential,line)" + + end + describe "POST /create" do + before(:each) do + post :create, :line_id => route.line_id, + :referential_id => referential.id, + :route => { :name => "changed"} + + end + it_behaves_like "line and referential linked" + it_behaves_like "redirected to referential_line_path(referential,line)" + end + describe "PUT /update" do + before(:each) do + put :update, :id => route.id, :line_id => route.line_id, + :referential_id => referential.id + end + + it_behaves_like "route, line and referential linked" + it_behaves_like "redirected to referential_line_path(referential,line)" + end + describe "GET /show" do + before(:each) do + get :show, :id => route.id, + :line_id => route.line_id, + :referential_id => referential.id + end + + it_behaves_like "route, line and referential linked" + + it "assigns RouteMap.new( referential, route) as @map" do + assigns[:map].should be_an_instance_of(RouteMap) + assigns[:map].referential.should == referential + assigns[:map].route.should == route + end + + it "assigns route.stop_points.paginate(:page => nil, :per_page => 10) as @stop_points" do + assigns[:stop_points].should == route.stop_points.paginate(:page => nil, :per_page => 10) + end + + end +end + diff --git a/spec/controllers/stop_points_controller_spec.rb b/spec/controllers/stop_points_controller_spec.rb new file mode 100644 index 000000000..20ed1170e --- /dev/null +++ b/spec/controllers/stop_points_controller_spec.rb @@ -0,0 +1,75 @@ +require 'spec_helper' + +describe StopPointsController do + login_user + + let!(:referential) { create(:referential).switch } + let!(:route) { referential; Factory(:route) } + let(:permutated_stop_point_ids) { + old_stop_point_ids = route.stop_points.map(&:id) + old_stop_point_ids.permutation.to_a.select { |permutated| permutated != old_stop_point_ids}.first + } + + it { should be_kind_of(ChouetteController) } + + shared_examples_for "route, line and referential linked (stop_points)" do + it "assigns route as @route" do + assigns[:route].should == route + end + it "assigns route.line as @line" do + assigns[:line].should == route.line + end + + it "assigns referential as @referential" do + assigns[:referential].should == referential + end + end + + describe "sort routing" do + let(:path) { sort_referential_line_route_stop_points_path( referential, route.line, route)} + it "routes /referential/:referentialid/line/:lineid/route/:routeid/stop_points/sort to stop_points#sort" do + { :post => path }.should route_to(:controller => "stop_points", + :action => "sort", + :referential_id => referential.id.to_s, + :line_id => route.line_id.to_s, + :route_id => route.id.to_s ) + end + end + + describe "POST /sort" do + before(:each) do + post :sort, :line_id => route.line_id, + :route_id => route.id, + :referential_id => referential.id, + :stop_point => permutated_stop_point_ids + end + it_behaves_like "route, line and referential linked (stop_points)" + end + + describe "#sort" do + it "should delegate to route.sort! with permutated_stop_point_ids" do + controller.stub!(:route => route, :params => { :stop_point => permutated_stop_point_ids}) + controller.stub!(:respond_to => nil) + route.should_receive(:reorder!).with(permutated_stop_point_ids) + controller.sort + end + end + describe "GET /index" do + before(:each) do + get :index, :line_id => route.line_id, + :route_id => route.id, + :referential_id => referential.id + end + it_behaves_like "route, line and referential linked (stop_points)" + end + describe "POST /create" do + before(:each) do + post :create, :line_id => route.line_id, + :referential_id => referential.id, + :route_id => route.id, + :stop_point => Factory.attributes_for(:stop_point) + + end + it_behaves_like "route, line and referential linked (stop_points)" + end +end diff --git a/spec/support/devise.rb b/spec/support/devise.rb index 671c61122..444eb0fee 100644 --- a/spec/support/devise.rb +++ b/spec/support/devise.rb @@ -28,7 +28,7 @@ module DeviseRequestHelper end -module DeviseControllerhelper +module DeviseControllerHelper def login_user before(:each) do @request.env["devise.mapping"] = Devise.mappings[:user] @@ -39,7 +39,7 @@ end RSpec.configure do |config| config.include Devise::TestHelpers, :type => :controller - config.extend DeviseControllerhelper, :type => :controller + config.extend DeviseControllerHelper, :type => :controller config.include DeviseRequestHelper, :type => :request end diff --git a/spec/views/routes/show.html.erb_spec.rb b/spec/views/routes/show.html.erb_spec.rb index 05d783eb0..5fa7485b7 100644 --- a/spec/views/routes/show.html.erb_spec.rb +++ b/spec/views/routes/show.html.erb_spec.rb @@ -5,7 +5,7 @@ describe "/routes/show" do let!(:referential) { assign :referential, create(:referential) } let!(:line) { assign :line, create(:line) } let!(:route) { assign :route, create(:route, :line => line) } - let!(:stop_areas) { assign :stop_areas, Array.new(2) { create(:stop_area) }.paginate } + let!(:stop_points) { assign :stop_points, Array.new(2) { create(:stop_point) }.paginate } let!(:map) { assign(:map, mock(:to_html => '<div id="map"/>')) } it "should render h2 with the route name" do |
