diff options
| author | Zakaria BOUZIANE | 2014-09-30 11:22:08 +0200 |
|---|---|---|
| committer | Zakaria BOUZIANE | 2014-09-30 11:22:08 +0200 |
| commit | beb4b02b54a4fa2a737cb2be521728cd8118cad6 (patch) | |
| tree | d4e7ccdaa45e62eb3dfd08ccb91a27a00d9d5deb /app | |
| parent | 7971467d6e6661a8d03ba25f1ecd20761f633301 (diff) | |
| download | chouette-core-beb4b02b54a4fa2a737cb2be521728cd8118cad6.tar.bz2 | |
HUB Export : adding Group of Lines export
Diffstat (limited to 'app')
| -rw-r--r-- | app/controllers/referentials_controller.rb | 2 | ||||
| -rw-r--r-- | app/exporters/chouette/hub/exporter.rb | 4 | ||||
| -rw-r--r-- | app/exporters/chouette/hub/group_of_lines_exporter.rb | 35 | ||||
| -rw-r--r-- | app/exporters/chouette/hub/line_exporter.rb | 3 | ||||
| -rw-r--r-- | app/views/api/hub/groupe_de_lignes.hub.erb | 1 | ||||
| -rw-r--r-- | app/views/api/hub/lignes.hub.erb | 2 |
6 files changed, 45 insertions, 2 deletions
diff --git a/app/controllers/referentials_controller.rb b/app/controllers/referentials_controller.rb index bf8a2f1ef..9cf4a5f62 100644 --- a/app/controllers/referentials_controller.rb +++ b/app/controllers/referentials_controller.rb @@ -26,7 +26,7 @@ class ReferentialsController < BreadcrumbController @referential ||= current_organisation.referentials.find_by_id(params[:id]) end def collection - @referentials ||= current_organisation.referentials + @referentials ||= current_organisation.referentials.order(:name) end def build_resource super.tap do |referential| diff --git a/app/exporters/chouette/hub/exporter.rb b/app/exporters/chouette/hub/exporter.rb index 091fa75c2..4dcc00045 100644 --- a/app/exporters/chouette/hub/exporter.rb +++ b/app/exporters/chouette/hub/exporter.rb @@ -133,6 +133,10 @@ class Chouette::Hub::Exporter Chouette::Hub::LineExporter.save(@lines, temp_dir, hub_export) networks = Chouette::Network.where( :id => @lines.map(&:network_id)) companies = Chouette::Network.where( :id => @lines.map(&:company_id)) + groups_of_lines = [] + @lines.each { |l| groups_of_lines << l.group_of_lines } + groups_of_lines = groups_of_lines.flatten.uniq + Chouette::Hub::GroupOfLinesExporter.save(groups_of_lines, temp_dir, hub_export) Chouette::Hub::NetworkExporter.save(networks, temp_dir, hub_export) Chouette::Hub::CompanyExporter.save(companies, temp_dir, hub_export) else diff --git a/app/exporters/chouette/hub/group_of_lines_exporter.rb b/app/exporters/chouette/hub/group_of_lines_exporter.rb new file mode 100644 index 000000000..129913c8b --- /dev/null +++ b/app/exporters/chouette/hub/group_of_lines_exporter.rb @@ -0,0 +1,35 @@ +class Chouette::Hub::GroupOfLinesExporter + include ERB::Util + attr_accessor :group_of_lines, :directory, :template + + def initialize(group_of_lines, directory) + @group_of_lines = group_of_lines + @directory = directory + @template = File.open('app/views/api/hub/groupe_de_lignes.hub.erb' ){ |f| f.read } + end + + def render() + ERB.new(@template).result(binding) + end + + def hub_name + "/GROUPELIGNE.TXT" + end + + def self.save( groups_of_lines, directory, hub_export) + groups_of_lines.each do |group_of_lines| + self.new( group_of_lines, directory).tap do |specific_exporter| + specific_exporter.save + end + end + hub_export.log_messages.create( :severity => "ok", :key => "EXPORT|GROUP_OF_LINES_COUNT", :arguments => {"0" => groups_of_lines.size}) + end + + def save + File.open(directory + hub_name , "a") do |f| + f.write("GROUPELIGNE\n") if f.size == 0 + f.write(render) + end if group_of_lines.present? + end +end + diff --git a/app/exporters/chouette/hub/line_exporter.rb b/app/exporters/chouette/hub/line_exporter.rb index 0d58f3757..f8cf07b60 100644 --- a/app/exporters/chouette/hub/line_exporter.rb +++ b/app/exporters/chouette/hub/line_exporter.rb @@ -6,6 +6,9 @@ class Chouette::Hub::LineExporter @line = line @directory = directory @template = File.open('app/views/api/hub/lignes.hub.erb' ){ |f| f.read } + if (line.group_of_lines.count > 0) + @group_of_line = line.group_of_lines[0].objectid.sub(/(\w*\:\w*\:)(\w*)/, '\2') + end end def render() diff --git a/app/views/api/hub/groupe_de_lignes.hub.erb b/app/views/api/hub/groupe_de_lignes.hub.erb new file mode 100644 index 000000000..f098b7a5e --- /dev/null +++ b/app/views/api/hub/groupe_de_lignes.hub.erb @@ -0,0 +1 @@ +<%= @group_of_lines.objectid.sub(/(\w*\:\w*\:)(\w*)/, '\2') %>;<%= @group_of_lines.name %>;<%= @group_of_lines.id %> diff --git a/app/views/api/hub/lignes.hub.erb b/app/views/api/hub/lignes.hub.erb index e5d2c4c4c..f8b007044 100644 --- a/app/views/api/hub/lignes.hub.erb +++ b/app/views/api/hub/lignes.hub.erb @@ -1 +1 @@ -<%= @line.objectid.sub(/(\w*\:\w*\:)(\w*)/, '\2') %>;<%= @line.number %>;<%= @line.name %>;;;<%= Chouette::Company.find(@line.company_id).objectid.sub(/(\w*\:\w*\:)(\w*)/, '\2') %>;<%= Chouette::Network.find(@line.network_id).objectid.sub(/(\w*\:\w*\:)(\w*)/, '\2') %>;;<%= @line.id %> +<%= @line.objectid.sub(/(\w*\:\w*\:)(\w*)/, '\2') %>;<%= @line.number %>;<%= @line.name %>;;;<%= Chouette::Company.find(@line.company_id).objectid.sub(/(\w*\:\w*\:)(\w*)/, '\2') %>;<%= Chouette::Network.find(@line.network_id).objectid.sub(/(\w*\:\w*\:)(\w*)/, '\2') %>;<%= @group_of_line %>;<%= @line.id %> |
