Skip to content
This repository has been archived by the owner on Dec 8, 2022. It is now read-only.

Commit

Permalink
[AV17] Add RouteSections Controller
Browse files Browse the repository at this point in the history
  • Loading branch information
Alban Peignier committed Jun 25, 2015
1 parent eaa17ed commit ef55489
Show file tree
Hide file tree
Showing 16 changed files with 230 additions and 20 deletions.
4 changes: 3 additions & 1 deletion Gemfile
Expand Up @@ -136,7 +136,9 @@ group :development do
gem 'guard'
gem 'guard-rspec'
gem 'rails-erd'
gem 'meta_request'
# gem 'meta_request'
gem 'better_errors'
gem 'binding_of_caller'
end

group :test, :development do
Expand Down
33 changes: 19 additions & 14 deletions Gemfile.lock
@@ -1,6 +1,6 @@
GIT
remote: https://github.com/afimb/ninoxe.git
revision: 51c0fb684f12cd1a104f91968f8c137358cb6a9c
revision: ba5b2fb1aa32d9995035fd264b0e829fec16a86a
branch: traces
specs:
ninoxe (1.1.5)
Expand All @@ -11,6 +11,7 @@ GIT
deep_cloneable (~> 2.0.0)
enumerize (~> 0.10.0)
foreigner (= 1.6.0)
georuby (= 2.3.0)
georuby-ext (= 0.0.5)

GEM
Expand Down Expand Up @@ -70,11 +71,16 @@ GEM
parser (>= 2.2.0.pre.3, < 3.0)
bcrypt (3.1.10)
bcrypt (3.1.10-java)
better_errors (2.1.1)
coderay (>= 1.0.0)
erubis (>= 2.6.6)
rack (>= 0.9.0)
binding_of_caller (0.7.2)
debug_inspector (>= 0.0.1)
breadcrumbs_on_rails (2.3.0)
builder (3.2.2)
calendar_helper (0.2.5)
open4
callsite (0.0.11)
capistrano (2.13.5)
highline
net-scp (>= 1.0.0)
Expand Down Expand Up @@ -104,8 +110,9 @@ GEM
coffee-script-source (1.9.1)
daemons (1.1.9)
database_cleaner (1.4.1)
dbf (2.0.9)
dbf (2.0.10)
fastercsv (~> 1.5)
debug_inspector (0.0.2)
deep_cloneable (2.0.2)
activerecord (>= 3.1.0, < 5.0.0)
delayed_job (4.0.6)
Expand Down Expand Up @@ -215,8 +222,8 @@ GEM
jruby-rack (1.1.18)
jruby-rack-worker (0.10.0)
jruby-rack (>= 1.1.10)
json (1.8.2)
json (1.8.2-java)
json (1.8.3)
json (1.8.3-java)
language_engine (0.0.6)
rails (~> 4.1.1)
launchy (2.4.3)
Expand All @@ -233,16 +240,12 @@ GEM
mail (2.6.3)
mime-types (>= 1.16, < 3)
map_layers (0.0.4)
meta_request (0.3.4)
callsite (~> 0.0, >= 0.0.11)
rack-contrib (~> 1.1)
railties (>= 3.0.0, < 5.0.0)
method_source (0.8.2)
mime-types (2.4.3)
mini_portile (0.6.2)
minitest (5.6.1)
minitest (5.7.0)
modernizr-rails (2.0.6)
multi_json (1.11.0)
multi_json (1.11.1)
multipart-post (2.0.0)
nenv (0.2.0)
net-scp (1.2.1)
Expand Down Expand Up @@ -283,8 +286,6 @@ GEM
rabl (0.11.6)
activesupport (>= 2.3.14)
rack (1.5.3)
rack-contrib (1.2.0)
rack (>= 0.9.1)
rack-test (0.6.3)
rack (>= 1.0)
rails (4.1.10)
Expand Down Expand Up @@ -473,6 +474,8 @@ DEPENDENCIES
acts_as_list (~> 0.6.0)
acts_as_tree (~> 2.1.0)
apartment (~> 1.0.0)
better_errors
binding_of_caller
breadcrumbs_on_rails
calendar_helper (= 0.2.5)
capistrano (= 2.13.5)
Expand Down Expand Up @@ -509,7 +512,6 @@ DEPENDENCIES
language_engine (= 0.0.6)
launchy
map_layers (= 0.0.4)
meta_request
modernizr-rails (~> 2.0.6)
newrelic_rpm
ninoxe!
Expand Down Expand Up @@ -549,3 +551,6 @@ DEPENDENCIES
warbler
will_paginate (~> 3.0.7)
will_paginate-bootstrap (~> 1.0.1)

BUNDLED WITH
1.10.3
14 changes: 14 additions & 0 deletions app/assets/javascripts/route_section.js.coffee
@@ -0,0 +1,14 @@
jQuery ->
if $("#map.route_section").length > 0 and user_geometry?
projWGS84 = new OpenLayers.Projection("EPSG:4326")
proj900913 = new OpenLayers.Projection("EPSG:900913")
wtk_format = new OpenLayers.Format.WKT()

user_geometry.events.on({
afterfeaturemodified: (event) ->
wgs84_geometry = event.feature.geometry.transform(proj900913, projWGS84)
wgs84_feature = new OpenLayers.Feature.Vector(wgs84_geometry)
ewtk = "SRID=4326;#{wtk_format.write(wgs84_feature)}"

$('#route_section_editable_geometry').val(ewtk)
})
27 changes: 27 additions & 0 deletions app/controllers/route_sections_controller.rb
@@ -0,0 +1,27 @@
class RouteSectionsController < ChouetteController

defaults :resource_class => Chouette::RouteSection

respond_to :html
respond_to :kml, :only => :show

belongs_to :referential

def show
@stop_areas = referential.stop_areas.with_geometry
@map = RouteSectionMap.new(resource).with_helpers(self)
show!
end

def edit
@map = RouteSectionMap.new(resource, true).with_helpers(self)
edit!
end

private

def route_section_params
params.require(:route_section).permit(:departure_id, :arrival_id, :editable_geometry)
end

end
53 changes: 53 additions & 0 deletions app/maps/route_section_map.rb
@@ -0,0 +1,53 @@
class RouteSectionMap < ApplicationMap

attr_reader :route_section

attr_accessor :editable
alias_method :editable?, :editable

def initialize(route_section, editable = false)
@route_section = route_section
@editable = editable
end

def customize_map(map, page)
# layers order seems to matter for ModifyFeature control
route_section.stop_areas.each do |stop_area|
layer = "stop_area_#{stop_area.id}".to_sym
page.assign layer.to_s, kml_layer(stop_area, :styleMap => Design::StopAreasStyleMap.new(helpers).style_map)
page << map.add_layer(layer)
page << map.add_control( hover_control_display_name(layer) )
end

geometry_options = {}.tap do |options|
options[:mode] = :editable if editable?
end
geometry_kml_layer = kml_layer(route_section, geometry_options, {}) # , :styleMap => Design::LineStyleMap.new(style: nil).style_map)

if editable
page.assign :user_geometry, geometry_kml_layer
page << map.add_layer(:user_geometry)

page.assign :modify_feature, OpenLayers::Control::ModifyFeature.new(:user_geometry, autoActivate: true)
page << map.add_control( :modify_feature )
else
page << map.add_layer(geometry_kml_layer)
end

page << map.zoom_to_extent(bounds.to_google.to_openlayers) if bounds
end

def bounds
@bounds ||=
if route_section.geometry.present?
route_section.geometry.bounds
elsif route_section.stop_areas.present?
GeoRuby::SimpleFeatures::Point.bounds route_section.stop_areas.collect(&:geometry)
end
end

def ready?
bounds.present?
end

end
4 changes: 4 additions & 0 deletions app/models/referential.rb
Expand Up @@ -87,6 +87,10 @@ def vehicle_journeys
Chouette::VehicleJourney.all
end

def route_sections
Chouette::RouteSection.all
end

after_initialize :define_default_attributes

def define_default_attributes
Expand Down
22 changes: 22 additions & 0 deletions app/views/route_sections/_form.html.erb
@@ -0,0 +1,22 @@
<%= semantic_form_for [@referential, @route_section] do |form| %>
<%= form.inputs do %>
<% if @route_section.new_record? %>
<%= form.input :departure, as: :select, collection: @stop_areas, include_blank: false %>
<%= form.input :arrival, as: :select, collection: @stop_areas, include_blank: false %>
<% else %>
<p>
<label><%= @route_section.human_attribute_name("departure") %>: </label>
<%= @route_section.departure.name %>
</p>
<p>
<label><%= @route_section.human_attribute_name("arrival") %>: </label>
<%= @route_section.arrival.name %>
</p>
<%= form.input :editable_geometry, as: :hidden %>
<% end %>
<% end %>
<%= form.actions do %>
<%= form.action :submit, :as => :button %>
<%= form.action :cancel, :as => :link %>
<% end %>
<% end %>
4 changes: 4 additions & 0 deletions app/views/route_sections/edit.html.erb
@@ -0,0 +1,4 @@
<%= title_tag t('route_sections.edit.title') %>
<%= @map.to_html %>
<%= render "form" %>
11 changes: 11 additions & 0 deletions app/views/route_sections/index.html
@@ -0,0 +1,11 @@
<%= title_tag t('route_sections.index.title') %>

<div id="route_sections">

</div>

<% content_for :sidebar do %>
<ul class="actions">
<li><%= link_to t('route_sections.actions.new'), new_referential_route_section_path(@referential), :class => "add" %></li>
</ul>
<% end %>
3 changes: 3 additions & 0 deletions app/views/route_sections/new.html
@@ -0,0 +1,3 @@
<%= title_tag t('route_sections.new.title') %>

<%= render "form" %>
3 changes: 3 additions & 0 deletions app/views/route_sections/new.html.erb
@@ -0,0 +1,3 @@
<%= title_tag t('route_sections.new.title') %>
<%= render "form" %>
25 changes: 25 additions & 0 deletions app/views/route_sections/show.html.erb
@@ -0,0 +1,25 @@
<%= title_tag t('route_sections.show.title') %>

<div class="route_section">
<%= @map.to_html %>

<div class="summary">
<p>
<label><%= @route_section.human_attribute_name("departure") %>: </label>
<%= @route_section.departure.name %>
</p>
<p>
<label><%= @route_section.human_attribute_name("arrival") %>: </label>
<%= @route_section.arrival.name %>
</p>
</div>
</div>

<% content_for :sidebar do %>
<ul class="actions">
<li><%= link_to t('route_sections.actions.new'), new_referential_route_section_path(@referential), :class => "add" %></li>
<li><%= link_to t('route_sections.actions.edit'), edit_referential_route_section_path(@referential, @route_section), :class => "edit" %></li>
<li><%= link_to t('route_sections.actions.destroy'), referential_route_section_path(@referential, @route_section), :method => :delete, :data => {:confirm => t('route_sections.actions.destroy_confirm')}, :class => "remove" %></li>
</ul>
<%= creation_tag(@route_section) %>
<% end %>
8 changes: 8 additions & 0 deletions app/views/route_sections/show.kml.erb
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<Placemark id="route-section-<%= @route_section.id %>">
<%= @route_section.geometry(params[:mode]).kml_representation.html_safe %>
</Placemark>
</Document>
</kml>
1 change: 1 addition & 0 deletions config/routes.rb
Expand Up @@ -159,6 +159,7 @@
end
resources :clean_ups

resources :route_sections
end
root :to => "referentials#index"

Expand Down
@@ -1,11 +1,16 @@
# This migration comes from ninoxe_engine (originally 20150529132301)
class CreateRouteSections < ActiveRecord::Migration
def change
create_table :route_sections do |t|
t.belongs_to :departure
t.belongs_to :arrival

t.line_string :geometry
t.line_string :input_geometry, srid: 4326
t.line_string :processed_geometry, srid: 4326

t.string :objectid, null: false
t.integer :object_version
t.datetime :creation_time
t.string :creator_id
end
end
end
29 changes: 26 additions & 3 deletions db/schema.rb
Expand Up @@ -209,6 +209,18 @@
t.integer "line_id", limit: 8
end

create_table "jobs", force: true do |t|
t.string "action"
t.datetime "created"
t.string "filename"
t.text "parameters"
t.string "referential"
t.datetime "started"
t.string "status"
t.string "type"
t.datetime "updated"
end

create_table "journey_patterns", force: true do |t|
t.integer "route_id", limit: 8
t.string "objectid", null: false
Expand Down Expand Up @@ -256,6 +268,12 @@
add_index "lines", ["objectid"], :name => "lines_objectid_key", :unique => true
add_index "lines", ["registration_number"], :name => "lines_registration_number_key", :unique => true

create_table "links", id: false, force: true do |t|
t.integer "job_id", limit: 8, null: false
t.string "rel"
t.string "type"
end

create_table "networks", force: true do |t|
t.string "objectid", null: false
t.integer "object_version"
Expand Down Expand Up @@ -313,9 +331,14 @@
end

create_table "route_sections", force: true do |t|
t.integer "departure_id"
t.integer "arrival_id"
t.spatial "geometry", limit: {:srid=>0, :type=>"line_string"}
t.integer "departure_id"
t.integer "arrival_id"
t.string "objectid", null: false
t.integer "object_version"
t.datetime "creation_time"
t.string "creator_id"
t.spatial "input_geometry", limit: {:srid=>4326, :type=>"line_string"}
t.spatial "processed_geometry", limit: {:srid=>4326, :type=>"line_string"}
end

create_table "routes", force: true do |t|
Expand Down

0 comments on commit ef55489

Please sign in to comment.