diff options
| author | Alban Peignier | 2016-05-13 16:53:13 +0200 |
|---|---|---|
| committer | Alban Peignier | 2016-05-13 16:53:30 +0200 |
| commit | 2cb49d26214f9082fa00fe58ee1c1388e45a34ed (patch) | |
| tree | f15d5d25279a24a310a25b59a112c2cded69d7b8 /app | |
| parent | 6045f57aa95fbd1d45f33180639bbf322b7ec2ab (diff) | |
| download | chouette-core-2cb49d26214f9082fa00fe58ee1c1388e45a34ed.tar.bz2 | |
Refactor controllers to manage StopAreas in StopAreaReferential. Refs #821
Diffstat (limited to 'app')
| -rw-r--r-- | app/controllers/stop_areas_controller.rb | 22 | ||||
| -rw-r--r-- | app/helpers/breadcrumb_helper.rb | 4 | ||||
| -rw-r--r-- | app/maps/stop_area_map.rb | 2 | ||||
| -rw-r--r-- | app/models/chouette/stop_area.rb | 7 | ||||
| -rw-r--r-- | app/models/concerns/projection_fields.rb | 6 | ||||
| -rw-r--r-- | app/models/concerns/stop_area_referential_support.rb | 19 | ||||
| -rw-r--r-- | app/models/stop_area_referential.rb | 2 | ||||
| -rw-r--r-- | app/views/access_points/_access_point.html.erb | 21 | ||||
| -rw-r--r-- | app/views/stop_area_referentials/show.html.erb | 9 | ||||
| -rw-r--r-- | app/views/stop_areas/_form.html.erb | 10 | ||||
| -rw-r--r-- | app/views/stop_areas/_stop_area.html.erb | 24 | ||||
| -rw-r--r-- | app/views/stop_areas/index.html.erb | 16 | ||||
| -rw-r--r-- | app/views/stop_areas/show.html.erb | 45 |
13 files changed, 112 insertions, 75 deletions
diff --git a/app/controllers/stop_areas_controller.rb b/app/controllers/stop_areas_controller.rb index dbbadb80c..275066efa 100644 --- a/app/controllers/stop_areas_controller.rb +++ b/app/controllers/stop_areas_controller.rb @@ -1,12 +1,15 @@ # -*- coding: utf-8 -*- -class StopAreasController < ChouetteController +class StopAreasController < BreadcrumbController + include ApplicationHelper + defaults :resource_class => Chouette::StopArea - belongs_to :referential do - belongs_to :line, :parent_class => Chouette::Line, :optional => true, :polymorphic => true - belongs_to :network, :parent_class => Chouette::Network, :optional => true, :polymorphic => true - belongs_to :connection_link, :parent_class => Chouette::ConnectionLink, :optional => true, :polymorphic => true - end + belongs_to :stop_area_referential + # do + # belongs_to :line, :parent_class => Chouette::Line, :optional => true, :polymorphic => true + # belongs_to :network, :parent_class => Chouette::Network, :optional => true, :polymorphic => true + # belongs_to :connection_link, :parent_class => Chouette::ConnectionLink, :optional => true, :polymorphic => true + # end respond_to :html, :kml, :xml, :json respond_to :js, :only => :index @@ -48,7 +51,7 @@ class StopAreasController < ChouetteController def index request.format.kml? ? @per_page = nil : @per_page = 12 - @zip_codes = referential.stop_areas.collect(&:zip_code).compact.uniq + @zip_codes = stop_area_referential.stop_areas.collect(&:zip_code).compact.uniq index! do |format| format.html { if collection.out_of_bounds? @@ -104,9 +107,9 @@ class StopAreasController < ChouetteController end def default_geometry - count = referential.stop_areas.without_geometry.default_geometry! + count = stop_area_referential.stop_areas.without_geometry.default_geometry! flash[:notice] = I18n.translate("stop_areas.default_geometry_success", :count => count) - redirect_to referential_stop_areas_path(@referential) + redirect_to stop_area_referential_stop_areas_path(@stop_area_referential) end def zip_codes @@ -118,6 +121,7 @@ class StopAreasController < ChouetteController protected alias_method :stop_area, :resource + alias_method :stop_area_referential, :parent def map @map = StopAreaMap.new(stop_area).with_helpers(self) diff --git a/app/helpers/breadcrumb_helper.rb b/app/helpers/breadcrumb_helper.rb index aebd242be..453c2c622 100644 --- a/app/helpers/breadcrumb_helper.rb +++ b/app/helpers/breadcrumb_helper.rb @@ -85,8 +85,8 @@ module BreadcrumbHelper def stop_area_breadcrumb(action) referential_breadcrumb - add_breadcrumb Chouette::StopArea.model_name.human(:count => 2), referential_stop_areas_path(@referential) unless action == :index - add_breadcrumb breadcrumb_label(@stop_area), referential_stop_area_path(@referential, @stop_area),:title => breadcrumb_tooltip(@stop_area) if action == :edit + add_breadcrumb Chouette::StopArea.model_name.human(:count => 2), referential_stop_areas_path(@stop_area.stop_area_referential) unless action == :index + add_breadcrumb breadcrumb_label(@stop_area), referential_stop_area_path(@stop_area.stop_area_referential, @stop_area),:title => breadcrumb_tooltip(@stop_area) if action == :edit end def stop_area_copy_breadcrumb(action) diff --git a/app/maps/stop_area_map.rb b/app/maps/stop_area_map.rb index 8518b0558..07321834b 100644 --- a/app/maps/stop_area_map.rb +++ b/app/maps/stop_area_map.rb @@ -126,7 +126,7 @@ EOF end def projection_type - stop_area.referential.projection_type + stop_area.projection end def ready? diff --git a/app/models/chouette/stop_area.rb b/app/models/chouette/stop_area.rb index 588014fff..9a2358348 100644 --- a/app/models/chouette/stop_area.rb +++ b/app/models/chouette/stop_area.rb @@ -1,13 +1,16 @@ require 'geokit' require 'geo_ruby' -class Chouette::StopArea < Chouette::TridentActiveRecord +class Chouette::StopArea < Chouette::ActiveRecord # FIXME http://jira.codehaus.org/browse/JRUBY-6358 self.primary_key = "id" include Geokit::Mappable include ProjectionFields include StopAreaRestrictions + include DefaultAttributesSupport + include StopAreaReferentialSupport + has_many :stop_points, :dependent => :destroy has_many :access_points, :dependent => :destroy has_many :access_links, :dependent => :destroy @@ -158,7 +161,7 @@ class Chouette::StopArea < Chouette::TridentActiveRecord def default_position # for first StopArea ... the bounds is nil :( - Chouette::StopArea.bounds ? Chouette::StopArea.bounds.center : self.referential.envelope.center + Chouette::StopArea.bounds ? Chouette::StopArea.bounds.center : nil # FIXME #821 stop_area_referential.envelope.center end def self.near(origin, distance = 0.3) diff --git a/app/models/concerns/projection_fields.rb b/app/models/concerns/projection_fields.rb index 2d7222f73..64a3804fc 100644 --- a/app/models/concerns/projection_fields.rb +++ b/app/models/concerns/projection_fields.rb @@ -15,10 +15,8 @@ module ProjectionFields end def projection - if self.referential.projection_type.nil? || self.referential.projection_type.empty? - nil - else - self.referential.projection_type + if referential.respond_to?(:projection_type) && referential.projection_type.present? + referential.projection_type end end @point = nil diff --git a/app/models/concerns/stop_area_referential_support.rb b/app/models/concerns/stop_area_referential_support.rb new file mode 100644 index 000000000..5a01ef57e --- /dev/null +++ b/app/models/concerns/stop_area_referential_support.rb @@ -0,0 +1,19 @@ +module StopAreaReferentialSupport + extend ActiveSupport::Concern + + included do + belongs_to :stop_area_referential + # validates_presence_of :stop_area_referential_id + + alias_method :referential, :stop_area_referential + end + + def hub_restricted? + false + end + + def prefix + # FIXME #825 + "dummy" + end +end diff --git a/app/models/stop_area_referential.rb b/app/models/stop_area_referential.rb index e8cfbaa1f..325385011 100644 --- a/app/models/stop_area_referential.rb +++ b/app/models/stop_area_referential.rb @@ -2,6 +2,8 @@ class StopAreaReferential < ActiveRecord::Base has_many :stop_area_referential_memberships has_many :organisations, through: :stop_area_referential_memberships + has_many :stop_areas, class_name: 'Chouette::StopArea' + def add_member(organisation, options = {}) attributes = options.merge organisation: organisation stop_area_referential_memberships.build attributes diff --git a/app/views/access_points/_access_point.html.erb b/app/views/access_points/_access_point.html.erb index 020d9bd58..76cf16fd7 100644 --- a/app/views/access_points/_access_point.html.erb +++ b/app/views/access_points/_access_point.html.erb @@ -1,26 +1,27 @@ <div id="index_item" class="panel panel-default access_point"> <div class="panel-heading"> <div class="panel-title clearfix"> - <span class="pull-right"> - <%= link_to edit_referential_stop_area_access_point_path(@referential, @stop_area, access_point), :class => "btn btn-default btn-sm" do %> + <span class="pull-right"> + <!-- FIXME #821 --> + <%#= link_to edit_referential_stop_area_access_point_path(@referential, @stop_area, access_point), :class => "btn btn-default btn-sm" do %> <span class="fa fa-pencil"></span> - <% end %> - <%= link_to referential_stop_area_access_point_path(@referential, @stop_area, access_point), :method => :delete, :data => {:confirm => t('access_points.actions.destroy_confirm')}, :class => "btn btn-danger btn-sm" do %> + <%# end %> + <%#= link_to referential_stop_area_access_point_path(@referential, @stop_area, access_point), :method => :delete, :data => {:confirm => t('access_points.actions.destroy_confirm')}, :class => "btn btn-danger btn-sm" do %> <span class="fa fa-trash-o"></span> - <% end %> + <%# end %> </span> <h5> - <%= link_to([@referential, @stop_area, access_point], :class => "preview", :title => "#{Chouette::StopArea.model_name.human.capitalize} #{access_point.name}") do %> + <%#= link_to([@referential, @stop_area, access_point], :class => "preview", :title => "#{Chouette::StopArea.model_name.human.capitalize} #{access_point.name}") do %> <span class="name"> - <%= image_tag "map/access_" + access_point.access_point_type + ".png" %> <%= truncate(access_point.name, :length => 20) %> + <%= image_tag "map/access_" + access_point.access_point_type + ".png" %> <%= truncate(access_point.name, :length => 20) %> </span> - <% end %> + <%# end %> </h5> - </div> + </div> </div> <div class="panel-body"> <% unless access_point.geometry %> - <p> + <p> <span class="warning"><%= t('.no_position') %></span> - </p> <% end %> diff --git a/app/views/stop_area_referentials/show.html.erb b/app/views/stop_area_referentials/show.html.erb index 92b37d451..aa198bcce 100644 --- a/app/views/stop_area_referentials/show.html.erb +++ b/app/views/stop_area_referentials/show.html.erb @@ -4,6 +4,15 @@ <div class="summary"> </div> +<div class="panel panel-default"> + <ul class="list-group" width="75%"> + <li class="list-group-item"> + <span class="badge"><%= @stop_area_referential.stop_areas.size %></span> + <%= link_to Referential.human_attribute_name("stop_areas"), stop_area_referential_stop_areas_path(@stop_area_referential) %> + </li> + </ul> +</div> + <% content_for :sidebar do %> <ul class="actions"> </ul> diff --git a/app/views/stop_areas/_form.html.erb b/app/views/stop_areas/_form.html.erb index e977a0279..b0152297d 100644 --- a/app/views/stop_areas/_form.html.erb +++ b/app/views/stop_areas/_form.html.erb @@ -1,4 +1,4 @@ -<%= semantic_form_for [@referential, @stop_area] do |form| %> +<%= semantic_form_for [@stop_area_referential, @stop_area] do |form| %> <div class="row"> <div class="container-fluid"> <% if !manage_itl && @map %> @@ -14,7 +14,7 @@ <label><%= t('.geolocalize') %></label> <input class="typeahead form-control input-lg" maxlength="255" type="text" placeholder="<%= t('.address') %>" /> </div> - <% unless @referential.projection_type_label.empty? %> + <% unless @stop_area.projection.blank? or @stop_area.projection_type_label.empty? %> <%= form.input :projection_xy, :label => t("projection_xy", :projection => @referential.projection_type_label), :input_html => { :title => t("formtastic.titles#{format_restriction_for_locales(@referential)}.stop_area.projection_xy")} %> <% end %> <%= form.input :coordinates, :input_html => { :title => t("formtastic.titles#{format_restriction_for_locales(@referential)}.stop_area.coordinates")} %> @@ -121,8 +121,9 @@ }, limit: 10, remote: { - url: 'http://nominatim.openstreetmap.org/search?q=%QUERY&format=json&addressdetails=1&bounded=1&viewbox='+ - '<%= @referential.viewbox_left_top_right_bottom %>', + url: 'http://nominatim.openstreetmap.org/search?q=%QUERY&format=json&addressdetails=1&bounded=1&viewbox='+ + // FIXME #821 + '<%#= @stop_area_referential.viewbox_left_top_right_bottom %>', filter: filtering, } }); @@ -157,4 +158,3 @@ }) }); </script> - diff --git a/app/views/stop_areas/_stop_area.html.erb b/app/views/stop_areas/_stop_area.html.erb index 3f8768feb..4a6a632a5 100644 --- a/app/views/stop_areas/_stop_area.html.erb +++ b/app/views/stop_areas/_stop_area.html.erb @@ -1,44 +1,44 @@ <div id="index_item" class="panel panel-default stop_area"> <div class="panel-heading"> <div class="panel-title clearfix"> - <span class="pull-right"> - <%= link_to edit_referential_stop_area_path(@referential, stop_area), :class => "btn btn-default btn-sm" do %> + <span class="pull-right"> + <%= link_to edit_stop_area_referential_stop_area_path(@stop_area_referential, stop_area), :class => "btn btn-default btn-sm" do %> <span class="fa fa-pencil"></span> <% end %> - <%= link_to referential_stop_area_path(@referential, stop_area), :method => :delete, :data => {:confirm => t('stop_areas.actions.destroy_confirm')}, :class => "btn btn-danger btn-sm" do %> + <%= link_to stop_area_referential_stop_area_path(@stop_area_referential, stop_area), :method => :delete, :data => {:confirm => t('stop_areas.actions.destroy_confirm')}, :class => "btn btn-danger btn-sm" do %> <span class="fa fa-trash-o"></span> <% end %> </span> <h5> - <%= link_to([@referential, stop_area], :class => "preview", :title => t("area_types.label.#{stop_area.stop_area_type}") + " #{stop_area.name}") do %> + <%= link_to([@stop_area_referential, stop_area], :class => "preview", :title => t("area_types.label.#{stop_area.stop_area_type}") + " #{stop_area.name}") do %> <span class="name"> - <%= image_tag "map/" + stop_area.stop_area_type + ".png" %> <%= truncate(stop_area.name, :length => 20) %> + <%= image_tag "map/" + stop_area.stop_area_type + ".png" %> <%= truncate(stop_area.name, :length => 20) %> </span> <% end %> </h5> - </div> + </div> </div> <div class="panel-body"> - <p> + <p> <% unless stop_area.area_type == 'ITL' || stop_area.geometry %> <span class="warning"><%= t('.no_position') %></span> <% end %> </p> - <p> + <p> <%= stop_area.human_attribute_name('registration_number') %> : <%= stop_area.registration_number.present? ? stop_area.registration_number : t(".no_object") %> </p> <p> - <%= t('.address') %> : <%= (stop_area.zip_code.present? || stop_area.city_name.present?) ? "#{stop_area.zip_code} #{stop_area.city_name}" : t(".no_object") %> + <%= t('.address') %> : <%= (stop_area.zip_code.present? || stop_area.city_name.present?) ? "#{stop_area.zip_code} #{stop_area.city_name}" : t(".no_object") %> </p> <p> <% if stop_area.area_type == 'ITL' %> <%= t('.lines') %> : <% if stop_area.routing_lines.blank? %> <%= t(".no_object") %> - <% else %> + <% else %> <% stop_area.routing_lines.each do |line| %> <span class="label label-default line"><%= line.number %></span> <% end %> - <% end %> + <% end %> <% else %> <%= t('.lines') %> : <% if stop_area.lines.blank? %> <%= t(".no_object") %> @@ -46,7 +46,7 @@ <% stop_area.lines.each do |line| %> <span class="label label-default line"><%= line.number || truncate( line.name, :length => 4 ) %></span> <% end %> - <% end %> + <% end %> <% end %> </p> </div> diff --git a/app/views/stop_areas/index.html.erb b/app/views/stop_areas/index.html.erb index 8486af7ad..9f6f04599 100644 --- a/app/views/stop_areas/index.html.erb +++ b/app/views/stop_areas/index.html.erb @@ -1,13 +1,13 @@ -<%= title_tag t('stop_areas.index.title') %> +<%= title_tag t('stop_areas.index.title') %> <div id="country_codes"> <%= @country_codes.to_json %> </div> -<%= search_form_for @q, :url => referential_stop_areas_path(@referential), remote: true, :html => {:method => :get, class: "form-inline", :id => "search", role: "form"} do |f| %> +<%= search_form_for @q, :url => stop_area_referential_stop_areas_path(@stop_area_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"> + <div class="panel-heading"> + <div class="input-group col-md-9"> <%= f.text_field :name_cont, :placeholder => "#{t('.name')}", :class => 'form-control' %> <div class="input-group-btn"> <button class="btn btn-default" type="submit"><i class="fa fa-search"></i></button> @@ -17,8 +17,8 @@ <i class="fa fa-plus"></i> <%= "#{t('.advanced_search')}" %> </a> </div> - - <div id="advanced_search" class="panel-collapse collapse"> + + <div id="advanced_search" class="panel-collapse collapse"> <div class="panel-body"> <%= f.text_field :zip_code_cont, :placeholder => "#{t('.zip_code')}", :class => 'form-control typeahead' %> <%= f.select(:area_type_cont, options_from_collection_for_select(Chouette::StopArea.stop_area_types, 'name', Proc.new { |stop_area_type| t("area_types.label.#{stop_area_type}") } ), { :include_blank => "#{t('.area_type')}" }, { :class => 'form-control' }) %> @@ -31,8 +31,8 @@ <% content_for :sidebar do %> <ul class="actions"> - <li><%= link_to t('stop_areas.actions.new'), new_referential_stop_area_path(@referential), :class => "add" %></li> - <li><%= link_to t('stop_areas.actions.default_geometry'), default_geometry_referential_stop_areas_path(@referential), :method => :put, :class => "calculator" %></li> + <li><%= link_to t('stop_areas.actions.new'), new_stop_area_referential_stop_area_path(@stop_area_referential), :class => "add" %></li> + <li><%#= link_to t('stop_areas.actions.default_geometry'), default_geometry_referential_stop_areas_path(@stop_area_referential), :method => :put, :class => "calculator" %></li> </ul> <% end %> diff --git a/app/views/stop_areas/show.html.erb b/app/views/stop_areas/show.html.erb index 6a34f808c..bcc7435f3 100644 --- a/app/views/stop_areas/show.html.erb +++ b/app/views/stop_areas/show.html.erb @@ -3,7 +3,7 @@ <div class="stop_area_show"> <% if show_map? %> <%= @map.to_html %> - <% end %> + <% end %> <div class="summary"> <p> <label><%= @stop_area.human_attribute_name("comment") %>: </label> @@ -82,7 +82,7 @@ <% if !@stop_area.projection.nil? %> <p> <span class='geo_data'><%= @stop_area.human_attribute_name("projection") %>: </span> - <%= @referential.projection_type_label %> + <%= @stop_area_referential.projection_type_label %> </p> <p> <span class='geo_data'><%= @stop_area.human_attribute_name("projection_x") %>: </span> @@ -116,59 +116,60 @@ <div class="genealogical clearfix"> <%= render "stop_areas/genealogical" %> </div> - + <% if manage_access_points %> <div> <h3><%= t('.access_points') %></h3> - + <div class="access_points paginated_content"> + <!-- FIXME #821 --> <%= paginated_content @access_points, "access_points/access_point" %> </div> </div> <% end %> - + <% content_for :sidebar do %> <table> - <tr><td> + <tr><td> <ul class="actions"> - <li><%= link_to t('stop_areas.actions.new'), new_referential_stop_area_path(@referential), :class => "add" %></li> - <li><%= link_to t('stop_areas.actions.edit'), edit_referential_stop_area_path(@referential, @stop_area), :class => "edit" %></li> - <li><%= link_to t('stop_areas.actions.destroy'), referential_stop_area_path(@referential, @stop_area), :method => :delete, :data => {:confirm => t('stop_areas.actions.destroy_confirm')}, :class => "remove" %></li> + <li><%= link_to t('stop_areas.actions.new'), new_stop_area_referential_stop_area_path(@stop_area_referential), :class => "add" %></li> + <li><%= link_to t('stop_areas.actions.edit'), edit_stop_area_referential_stop_area_path(@stop_area_referential, @stop_area), :class => "edit" %></li> + <li><%= link_to t('stop_areas.actions.destroy'), stop_area_referential_stop_area_path(@stop_area_referential, @stop_area), :method => :delete, :data => {:confirm => t('stop_areas.actions.destroy_confirm')}, :class => "remove" %></li> </ul> </td></tr> <% if manage_itl %> - <tr><td> + <tr><td> <h4><%= t(".itl_managment") %></h4> <ul class="actions"> - <li><%= link_to t('stop_areas.actions.add_routing_lines'), add_routing_lines_referential_stop_area_path(@referential, @stop_area), :class => "add_routing_lines" %></li> - <li><%= link_to t('stop_areas.actions.add_routing_stops'), add_routing_stops_referential_stop_area_path(@referential, @stop_area), :class => "add_routing_stops" %></li> + <li><%= link_to t('stop_areas.actions.add_routing_lines'), add_routing_lines_stop_area_referential_stop_area_path(@stop_area_referential, @stop_area), :class => "add_routing_lines" %></li> + <li><%= link_to t('stop_areas.actions.add_routing_stops'), add_routing_stops_stop_area_referential_stop_area_path(@stop_area_referential, @stop_area), :class => "add_routing_stops" %></li> </ul> </td></tr> <% else %> - <tr><td> + <tr><td> <h4><%= t(".stop_managment") %></h4> <ul class="actions"> - <li><%= link_to t('stop_areas.actions.select_parent'), select_parent_referential_stop_area_path(@referential, @stop_area), :class => "parent" %></li> + <li><%#= link_to t('stop_areas.actions.select_parent'), select_parent_referential_stop_area_path(@referential, @stop_area), :class => "parent" %></li> <% if @stop_area.parent == nil %> - <li><%= link_to t('stop_areas.actions.clone_as_parent'), new_referential_stop_area_stop_area_copy_path(@referential, @stop_area, :hierarchy => "parent"), :class => "clone" %></li> + <li><%#= link_to t('stop_areas.actions.clone_as_parent'), new_referential_stop_area_stop_area_copy_path(@referential, @stop_area, :hierarchy => "parent"), :class => "clone" %></li> <% end %> <% if manage_children %> - <li><%= link_to t('stop_areas.actions.add_children'), add_children_referential_stop_area_path(@referential, @stop_area), :class => "children" %></li> - <li><%= link_to t('stop_areas.actions.clone_as_child'), new_referential_stop_area_stop_area_copy_path(@referential, @stop_area, :hierarchy => "child"), :class => "clone" %></li> + <li><%#= link_to t('stop_areas.actions.add_children'), add_children_referential_stop_area_path(@referential, @stop_area), :class => "children" %></li> + <li><%#= link_to t('stop_areas.actions.clone_as_child'), new_referential_stop_area_stop_area_copy_path(@referential, @stop_area, :hierarchy => "child"), :class => "clone" %></li> <% end %> </ul> </td></tr> - + <% if manage_access_points %> - <tr><td> + <tr><td> <h4><%= t(".access_managment") %></h4> <ul class="actions"> - <li><%= link_to t('access_points.actions.new'), new_referential_stop_area_access_point_path(@referential,@stop_area), :class => "add" %></li> - <li><%= link_to t('stop_areas.actions.manage_access_links'), access_links_referential_stop_area_path(@referential,@stop_area), :class => "access_link" %></li> + <li><%#= link_to t('access_points.actions.new'), new_referential_stop_area_access_point_path(@referential,@stop_area), :class => "add" %></li> + <li><%#= link_to t('stop_areas.actions.manage_access_links'), access_links_referential_stop_area_path(@referential,@stop_area), :class => "access_link" %></li> </ul> </td></tr> <% end %> - + <% end %> </table> <br> |
