diff options
| author | Zakaria BOUZIANE | 2014-11-24 09:53:51 +0100 | 
|---|---|---|
| committer | Zakaria BOUZIANE | 2014-11-24 09:53:51 +0100 | 
| commit | f7a5c5be620cd2006ec4d17208a9e0ee9bb34dcb (patch) | |
| tree | 537510b2e8db9c8e9a74a282ee17d49ac486b923 | |
| parent | 8b67f87c71e6bdbaa46d11f077583b5c47219c95 (diff) | |
| download | chouette-core-f7a5c5be620cd2006ec4d17208a9e0ee9bb34dcb.tar.bz2 | |
HUB Export only if less than 50000 VehicleJourneyAtStops and start_date and end_date are provided.
| -rw-r--r-- | app/controllers/exports_controller.rb | 13 | ||||
| -rw-r--r-- | app/exporters/chouette/hub/exporter.rb | 15 | ||||
| -rw-r--r-- | app/views/exports/_fields_hub_export.erb | 1 | ||||
| -rw-r--r-- | config/locales/exports.yml | 8 | 
4 files changed, 30 insertions, 7 deletions
| diff --git a/app/controllers/exports_controller.rb b/app/controllers/exports_controller.rb index cb555a3dd..e8c140dd7 100644 --- a/app/controllers/exports_controller.rb +++ b/app/controllers/exports_controller.rb @@ -14,9 +14,16 @@ class ExportsController < ChouetteController    end    def create -    create! do |success, failure| -      available_exports -      success.html { flash[:notice] = I18n.t('exports.new.flash')+"<br/>"+I18n.t('exports.new.flash2'); redirect_to referential_exports_path(@referential) } +    if (params[:export][:type] == "HubExport") && Chouette::VehicleJourneyAtStop.all.count > 50000 +      flash[:notice] = I18n.t("formtastic.titles.export.vjas.size", size: Chouette::VehicleJourneyAtStop.all.count) +      redirect_to new_referential_export_path(@referential) +    elsif (params[:export][:type] == "HubExport") && (params[:export][:start_date].empty? || params[:export][:end_date].empty?) +      flash[:notice] = I18n.t("formtastic.titles.export.dates.not_nul") +      redirect_to new_referential_export_path(@referential) +    else +      create! do |success, failure| +        success.html { flash[:notice] = I18n.t('exports.new.flash')+"<br/>"+I18n.t('exports.new.flash2'); redirect_to referential_exports_path(@referential) } +      end      end    end diff --git a/app/exporters/chouette/hub/exporter.rb b/app/exporters/chouette/hub/exporter.rb index 58454a0cb..3651e9f4f 100644 --- a/app/exporters/chouette/hub/exporter.rb +++ b/app/exporters/chouette/hub/exporter.rb @@ -42,6 +42,10 @@ class Chouette::Hub::Exporter      end    end +  def referential_exportable? +    Chouette::VehicleJourneyAtStop.all.count < 50000 +  end +      def time_tables_exportable?      time_tables    end @@ -72,10 +76,12 @@ class Chouette::Hub::Exporter      begin        referential.switch -      FileUtils.rm(zip_file_path) if File.exists? zip_file_path -       -      hub_export.log_messages.create( :severity => "ok", :key => "EXPORT", :arguments => {"0" => "HUB"}) -       +      if referential_exportable? && options[:start_date] && options[:end_date] +         +        FileUtils.rm(zip_file_path) if File.exists? zip_file_path +         +        hub_export.log_messages.create( :severity => "ok", :key => "EXPORT", :arguments => {"0" => "HUB"}) +                Dir.mktmpdir(nil, "/tmp"){ |temp_dir|          @time_tables = select_time_tables(options[:start_date], options[:end_date]) @@ -239,6 +245,7 @@ class Chouette::Hub::Exporter            end          end        } +      end      ensure        # Always cleanup files        #FileUtils.remove_entry(temp_directory) diff --git a/app/views/exports/_fields_hub_export.erb b/app/views/exports/_fields_hub_export.erb index fc7cf7112..8f51c104b 100644 --- a/app/views/exports/_fields_hub_export.erb +++ b/app/views/exports/_fields_hub_export.erb @@ -1,2 +1,3 @@ +<%= I18n.t("formtastic.titles.export.vjas.size", size: Chouette::VehicleJourneyAtStop.all.count) if Chouette::VehicleJourneyAtStop.all.count > 50000 %>  <%= form.input :start_date, :as => :date_picker, :input_html => { :title => t("formtastic.titles.export.start_date")} %>  <%= form.input :end_date, :as => :date_picker, :input_html => { :title => t("formtastic.titles.export.end_date")} %> diff --git a/config/locales/exports.yml b/config/locales/exports.yml index 6ade85762..1e01507ce 100644 --- a/config/locales/exports.yml +++ b/config/locales/exports.yml @@ -118,6 +118,10 @@ en:          object_id_prefix: "when prefix has this value, it will be removed to build GTFS id"          start_date: "reduce import to vehicle journeys running from this date"          end_date: "reduce import to vehicle journeys running until this date" +        vjas: +          size: "HUB export not allowed. The number of vehicle journeys at stops (%{size}) is greater than 50000." +        dates: +          not_nul: "HUB Export interrupted. Start date and end date must be provided."    area_types:      quay: "Quays and Boarding Positions"      commercial_stop_point: "Commercial Stop Points" @@ -243,6 +247,10 @@ fr:          object_id_prefix: "lorsque le préfixe d'identifiant Netpune prend cette valeur, il n'est pas utilisé pour composer l'identifiant GTFS"          start_date: "limite l'export aux courses circulant à partir de cette date"          end_date: "limite l'export aux courses circulant jusqu'à cette date" +        vjas: +          size: "L'Export HUB est impossible. Le nombre d'horaires (%{size}) est supérieure à 50000." +        dates: +          not_nul: "Export HUB interrompu. Les dates de début et de fin doivent êtres renseignées."    area_types:      quay: "Arrêts"      commercial_stop_point: "Arrêts commerciaux" | 
