aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuc Donnet2018-03-23 17:38:32 +0100
committerGitHub2018-03-23 17:38:32 +0100
commit11389b61f4b4996e0518f8fa2a5e0e74278f1269 (patch)
treeba1d6ca9bbd80e9b25305e70f5f8e5fdf148d379
parentbe77a9d4c4ba561a9b062debfa1b0ef3b4437f9a (diff)
parentaa2dfab80ddc13147bb900ab67e88c43f8a02313 (diff)
downloadchouette-core-11389b61f4b4996e0518f8fa2a5e0e74278f1269.tar.bz2
Merge pull request #386 from af83/6218-sqills-exports
6218 UI for exports
-rw-r--r--app/helpers/exports_helper.rb2
-rw-r--r--app/models/chouette/journey_pattern.rb2
-rw-r--r--app/models/chouette/stop_area.rb2
-rw-r--r--app/models/export/base.rb24
-rw-r--r--app/models/export/referential_companies.rb92
-rw-r--r--app/views/exports/show.html.slim11
-rw-r--r--app/views/shared/iev_interfaces/_messages.html.slim2
-rw-r--r--config/locales/actions.en.yml1
-rw-r--r--config/locales/actions.fr.yml1
-rw-r--r--config/locales/export_messages.en.yml1
-rw-r--r--config/locales/export_messages.fr.yml1
-rw-r--r--config/locales/exports.en.yml3
-rw-r--r--config/locales/exports.fr.yml1
13 files changed, 46 insertions, 97 deletions
diff --git a/app/helpers/exports_helper.rb b/app/helpers/exports_helper.rb
index 4e92c7e38..dc0720c40 100644
--- a/app/helpers/exports_helper.rb
+++ b/app/helpers/exports_helper.rb
@@ -16,7 +16,7 @@ module ExportsHelper
if message.message_key == "full_text"
message.message_attributes["text"]
else
- t([message.class.name.underscore.gsub('/', '_').pluralize, message.message_key].join('.'), message.message_attributes.symbolize_keys)
+ t([message.class.name.underscore.gsub('/', '_').pluralize, message.message_key].join('.'), message.message_attributes&.symbolize_keys || {})
end
end
diff --git a/app/models/chouette/journey_pattern.rb b/app/models/chouette/journey_pattern.rb
index 3a3d5d56a..5a5132200 100644
--- a/app/models/chouette/journey_pattern.rb
+++ b/app/models/chouette/journey_pattern.rb
@@ -176,7 +176,7 @@ module Chouette
i += 1
_start = _end
_end = stop_points[i]
- val += costs_between(_start, _end)[:distance]
+ val += costs_between(_start, _end)[:distance] || 0
end
val
end
diff --git a/app/models/chouette/stop_area.rb b/app/models/chouette/stop_area.rb
index b49741223..ccdff609f 100644
--- a/app/models/chouette/stop_area.rb
+++ b/app/models/chouette/stop_area.rb
@@ -383,7 +383,7 @@ module Chouette
end
def activated?
- deleted_at.nil? && confirmed_at
+ !!(deleted_at.nil? && confirmed_at)
end
def deactivated?
diff --git a/app/models/export/base.rb b/app/models/export/base.rb
index 6085e0ffb..6a1eb791d 100644
--- a/app/models/export/base.rb
+++ b/app/models/export/base.rb
@@ -38,8 +38,28 @@ class Export::Base < ActiveRecord::Base
end
end
+ def self.user_visible?
+ false
+ end
+
+ def self.inherited child
+ super child
+ child.instance_eval do
+ def self.user_visible?
+ true
+ end
+ end
+ end
+
def self.option name, opts={}
store_accessor :options, name
+
+ if opts[:serialize]
+ define_method name do
+ JSON.parse(options[name.to_s]) rescue opts[:serialize].new
+ end
+ end
+
if !!opts[:required]
validates name, presence: true
end
@@ -51,6 +71,10 @@ class Export::Base < ActiveRecord::Base
@options ||= {}
end
+ def self.options= options
+ @options = options
+ end
+
include IevInterfaces::Task
def self.model_name
diff --git a/app/models/export/referential_companies.rb b/app/models/export/referential_companies.rb
deleted file mode 100644
index 0b6187060..000000000
--- a/app/models/export/referential_companies.rb
+++ /dev/null
@@ -1,92 +0,0 @@
-class Export::ReferentialCompanies < Export::Base
- option :referential_id,
- type: :select,
- collection: ->(){workbench.referentials.all},
- required: true,
- display: ->(val){r = Referential.find(val); link_to(r.name, [r])}
-
- after_create :call_exporter_async
-
- def referential
- Referential.find referential_id
- end
-
- def call_exporter_async
- SimpleExportWorker.perform_async(id)
- end
-
- def exporter
- SimpleExporter.define :referential_companies do |config|
- config.separator = ";"
- config.encoding = 'ISO-8859-1'
- config.add_column :name
- config.add_column :registration_number
- end
-
- @exporter ||= begin
- if options[:_exporter_id]
- exporter = SimpleExporter.find options[:exporter_id]
- else
- exporter = SimpleExporter.create configuration_name: :referential_companies
- options[:_exporter_id] = exporter.id
- end
- exporter
- end
- end
-
- def call_exporter
- tmp = Tempfile.new ["referential_companies", ".csv"]
- referential.switch
- exporter.configure do |config|
- config.collection = referential.companies.order(:name)
- end
- exporter.filepath = tmp.path
- exporter.export
- set_status_from_exporter
- convert_exporter_journal_to_messages
- self.file = tmp
- self.save!
- end
-
- def set_status_from_exporter
- if exporter.status == :error
- self.status = :failed
- else
- if exporter.status == :success
- self.status = :successful
- else
- self.status = :warning
- end
- end
- end
-
- def convert_exporter_journal_to_messages
- self.messages.destroy_all
- exporter.journal.each do |journal_item|
- journal_item.symbolize_keys!
- vals = {}
-
- if journal_item[:kind].to_s == "warning"
- vals[:criticity] = :warning
- elsif journal_item[:kind].to_s == "error"
- vals[:criticity] = :error
- else
- vals[:criticity] = :info
- if journal_item[:event].to_s == "success"
- vals[:message_key] = :success
- end
- end
- vals[:resource_attributes] = journal_item[:row]
-
- if journal_item[:message].present?
- vals[:message_key] = :full_text
- vals[:message_attributes] = {
- text: journal_item[:message]
- }
- end
- vals[:message_attributes] ||= {}
- vals[:message_attributes][:line] = journal_item[:line]
- self.messages.build vals
- end
- end
-end
diff --git a/app/views/exports/show.html.slim b/app/views/exports/show.html.slim
index 2a7d7583c..3a4047ae9 100644
--- a/app/views/exports/show.html.slim
+++ b/app/views/exports/show.html.slim
@@ -10,7 +10,16 @@
- metadatas = metadatas.update({I18n.t("activerecord.attributes.export.status") => export_status(@export.status)})
- metadatas = metadatas.update({I18n.t("activerecord.attributes.export.parent") => link_to(@export.parent.name, [@export.parent.workbench, @export.parent])}) if @export.parent.present?
- metadatas = metadatas.update Hash[*@export.visible_options.map{|k, v| [t("activerecord.attributes.export.#{@export.object.class.name.demodulize.underscore}.#{k}"), @export.display_option_value(k, self)]}.flatten]
- - metadatas = metadatas.update({I18n.t("activerecord.attributes.export.file") => (@export.file.present? ? link_to(t("actions.download"), @export.file.url) : "-")})
+ - if @export.children.any?
+ - files = @export.children.map(&:file).select(&:present?)
+ - if files.any?
+ - metadatas = metadatas.update({I18n.t("activerecord.attributes.export.files") => ""})
+ - @export.children.each do |e|
+ - metadatas = metadatas.update({"- #{e.class.human_name}" => e.file.present? ? link_to(e.file.file.filename, e.file.url) : "-"})
+ - else
+ - metadatas = metadatas.update({I18n.t("activerecord.attributes.export.files") => "-"})
+ - else
+ - metadatas = metadatas.update({I18n.t("activerecord.attributes.export.file") => (@export.file.present? ? link_to(t("actions.download"), @export.file.url) : "-")})
= definition_list t('metadatas'), metadatas
.row
diff --git a/app/views/shared/iev_interfaces/_messages.html.slim b/app/views/shared/iev_interfaces/_messages.html.slim
index 82f1add57..022f4ee01 100644
--- a/app/views/shared/iev_interfaces/_messages.html.slim
+++ b/app/views/shared/iev_interfaces/_messages.html.slim
@@ -3,7 +3,7 @@
- messages.order(:created_at).each do | message |
li
.row class=bootstrap_class_for_message_criticity(message.criticity)
- - if message.message_attributes["line"]
+ - if message.message_attributes && message.message_attributes["line"]
.col-md-1= "L. #{message.message_attributes["line"]}"
.col-md-5= export_message_content message
- else
diff --git a/config/locales/actions.en.yml b/config/locales/actions.en.yml
index 278915526..04f4aca6b 100644
--- a/config/locales/actions.en.yml
+++ b/config/locales/actions.en.yml
@@ -5,6 +5,7 @@ en:
deactivate: 'Deactivate'
destroy: "Destroy"
delete: "Delete"
+ download: 'Download'
search: "Search"
submit: "Submit"
processing: "Processing…"
diff --git a/config/locales/actions.fr.yml b/config/locales/actions.fr.yml
index 92e16f21e..88e08aaef 100644
--- a/config/locales/actions.fr.yml
+++ b/config/locales/actions.fr.yml
@@ -5,6 +5,7 @@ fr:
deactivate: 'Désactiver'
destroy: 'Supprimer'
delete: 'Supprimer'
+ download: 'Télécharger'
search: "Chercher"
submit: "Valider"
processing: "En cours…"
diff --git a/config/locales/export_messages.en.yml b/config/locales/export_messages.en.yml
index f7951a103..9823d7f78 100644
--- a/config/locales/export_messages.en.yml
+++ b/config/locales/export_messages.en.yml
@@ -1,3 +1,4 @@
en:
export_messages:
success: Success
+ no_matching_journey: No matching journey found
diff --git a/config/locales/export_messages.fr.yml b/config/locales/export_messages.fr.yml
index 5c2191f35..4f45fd8e1 100644
--- a/config/locales/export_messages.fr.yml
+++ b/config/locales/export_messages.fr.yml
@@ -1,3 +1,4 @@
fr:
export_messages:
success: Succès
+ no_matching_journey: Aucun trajet correspondant
diff --git a/config/locales/exports.en.yml b/config/locales/exports.en.yml
index 88c1b99f8..628065ab0 100644
--- a/config/locales/exports.en.yml
+++ b/config/locales/exports.en.yml
@@ -84,6 +84,9 @@ en:
max_distance_for_connection_link: "Max distance for connection link"
ignore_last_word: "ignore last word"
ignore_end_chars: "ignore last chars"
+ type: "Export type"
+ file: "Output"
+ files: "Outputs"
parent: Parent
export:
<<: *attrs
diff --git a/config/locales/exports.fr.yml b/config/locales/exports.fr.yml
index fa3ac8fc7..a223b85f8 100644
--- a/config/locales/exports.fr.yml
+++ b/config/locales/exports.fr.yml
@@ -86,6 +86,7 @@ fr:
ignore_end_chars: "ignorer les n derniers caractères"
type: "Type d'export"
file: "Résultat"
+ files: "Résultats"
parent: Parent
export:
<<: *attrs