aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Gemfile.lock2
-rw-r--r--app/assets/javascripts/exports.js.coffee5
-rw-r--r--app/exporters/chouette/kml/exporter.rb11
-rw-r--r--app/views/api/kml/stop_areas/index.kml.erb2
-rw-r--r--app/views/exports/new.html.erb2
-rw-r--r--spec/exporters/chouette/kml/exporter_spec.rb29
6 files changed, 31 insertions, 20 deletions
diff --git a/Gemfile.lock b/Gemfile.lock
index f8bc2b0f0..9211580e1 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -15,7 +15,7 @@ GIT
GIT
remote: git://github.com/dryade/ninoxe.git
- revision: 3b2dea4584e6ce4206ac71afac596efd6ba19680
+ revision: 8e555ff5bd94250c98940878c052f449f4d14d7f
specs:
ninoxe (0.1.2)
activerecord (~> 3.1)
diff --git a/app/assets/javascripts/exports.js.coffee b/app/assets/javascripts/exports.js.coffee
index 6430c38ba..71b565e91 100644
--- a/app/assets/javascripts/exports.js.coffee
+++ b/app/assets/javascripts/exports.js.coffee
@@ -3,7 +3,6 @@ jQuery ->
references_type = $(event.target).val()
toggle_input = (li) ->
- console.log(li)
enabled = (li.data("type") == references_type)
# Hide li block
li.toggle(enabled)
@@ -17,7 +16,7 @@ jQuery ->
$('#export_type_submit').hide()
export_type_change = (event) ->
- export_type = $("select option:selected").attr("value")
+ export_type = $("input:radio:checked").attr("value")
$(form).toggle($(form).is("#" + export_type + "_new")) for form in $('form.export[method = "post"]')
- $('#export_type').change(export_type_change)
+ $("#export_type_input :radio[name='export[type]']").change(export_type_change)
diff --git a/app/exporters/chouette/kml/exporter.rb b/app/exporters/chouette/kml/exporter.rb
index 9a3cf5eef..33f99a054 100644
--- a/app/exporters/chouette/kml/exporter.rb
+++ b/app/exporters/chouette/kml/exporter.rb
@@ -1,16 +1,18 @@
class Chouette::Kml::Exporter
+ attr_reader :referential
+
def initialize(referential)
@referential = referential
end
def lines(object, ids)
if object == "network"
- Chouette::Network.find( ids ).collect(&:lines)
+ ids.present? ? referential.networks.find( ids.split(",") ).collect(&:lines).flatten : referential.networks.collect(&:lines).flatten
elsif object == "company"
- Chouette::Company.find( ids ).collect(&:lines)
+ ids.present? ? referential.companies.find( ids.split(",") ).collect(&:lines).flatten : referential.companies.collect(&:lines).flatten
elsif object == "line"
- Chouette::Line.find( ids ).to_a
+ ids.present? ? referential.lines.find( ids.split(",") ): referential.lines
else
[]
end
@@ -18,7 +20,7 @@ class Chouette::Kml::Exporter
def export(zip_file_path, options = {})
begin
- @referential.switch
+ referential.switch
FileUtils.rm(zip_file_path) if File.exists? zip_file_path
@@ -39,7 +41,6 @@ class Chouette::Kml::Exporter
end
stop_areas = lines_collected.collect(&:stop_areas).flatten.uniq
- puts stop_areas.inspect
Chouette::Kml::StopAreaExporter.new( stop_areas ).tap do |stop_area_exporter|
stop_area_exporter.save(temp_dir, "stop_areas")
end
diff --git a/app/views/api/kml/stop_areas/index.kml.erb b/app/views/api/kml/stop_areas/index.kml.erb
index 09708f193..1a9ed171c 100644
--- a/app/views/api/kml/stop_areas/index.kml.erb
+++ b/app/views/api/kml/stop_areas/index.kml.erb
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
- <% @stop_areas.each do |stop_area| %>
+ <% @stop_areas.select { |sa| sa.latitude && sa.longitude}.each do |stop_area| %>
<Placemark id="<%= stop_area.objectid %>" >
<name><%= stop_area.name %></name>
<ExtendedData>
diff --git a/app/views/exports/new.html.erb b/app/views/exports/new.html.erb
index e0e37fb34..60c1cff48 100644
--- a/app/views/exports/new.html.erb
+++ b/app/views/exports/new.html.erb
@@ -2,7 +2,7 @@
<%= semantic_form_for([@referential, @export], :as => :export, :url => new_referential_export_path(@referential), :method => :get) do |form| %>
<%= form.inputs do %>
- <%= form.input :type, :as => :select, :collection => Export.types.map { |format| [ Export.format_name(format), format]}, :required => true, :include_blank => false %>
+ <%= form.input :type, :as => :radio, :collection => Export.types.map { |format| [ Export.format_name(format), format]}, :required => true, :include_blank => false %>
<% end %>
<% end %>
diff --git a/spec/exporters/chouette/kml/exporter_spec.rb b/spec/exporters/chouette/kml/exporter_spec.rb
index 5f2b30b82..f44e8f201 100644
--- a/spec/exporters/chouette/kml/exporter_spec.rb
+++ b/spec/exporters/chouette/kml/exporter_spec.rb
@@ -2,29 +2,40 @@ require 'spec_helper'
describe Chouette::Kml::Exporter do
- let(:referential) { Factory(:referential) }
- subject { Chouette::Kml::Exporter.new(referential) }
+ # let(:referential) { Factory(:referential) }
+ # subject { Chouette::Kml::Exporter.new(referential) }
+
+ # let(:zip_file_path) { "#{Rails.root}/tmp/exports/test.zip" }
+ # let(:line) {
+ # referential.switch
+ # Factory(:line_with_stop_areas_having_parent) }
+
+ subject { Chouette::Kml::Exporter.new(first_referential) }
let(:zip_file_path) { "#{Rails.root}/tmp/exports/test.zip" }
- let(:line) {
- referential.switch
- Factory(:line_with_stop_areas_having_parent) }
+ let!(:line) { Factory(:line_with_stop_areas_having_parent) }
+ let!(:line2) { Factory(:line_with_stop_areas_having_parent) }
describe "#export" do
it "should return a zip file with nothing inside with no objects in arguments" do
- subject.export(zip_file_path, {} )
+ subject.export(zip_file_path, {:export_id => 1, :o => "line"} )
File.exists?(zip_file_path).should be_true
- puts ::Zip::ZipFile.open(zip_file_path).entries.inspect
- ::Zip::ZipFile.open(zip_file_path).size.should == 0
+ ::Zip::ZipFile.open(zip_file_path).size.should == 6
end
- it "should return a zip file with the kml of the line inside with a line in arguments" do
+ it "should return a zip file with 4 kml files" do
subject.export(zip_file_path, {:export_id => 1, :o => "line", :id => "#{line.id}" } )
File.exists?(zip_file_path).should be_true
::Zip::ZipFile.open(zip_file_path).size.should == 4
end
+ it "should return a zip file with 6 kml files" do
+ subject.export(zip_file_path, {:export_id => 1, :o => "line", :id => "#{line.id},#{line2.id}" } )
+ File.exists?(zip_file_path).should be_true
+ ::Zip::ZipFile.open(zip_file_path).size.should == 6
+ end
+
end