diff options
| author | Zog | 2018-03-16 11:02:51 +0100 | 
|---|---|---|
| committer | Zog | 2018-03-16 11:02:51 +0100 | 
| commit | 25df1bea61409294e9944a66a25d81ea55f0391f (patch) | |
| tree | 3049cca0135cce028b9c7445ebd2e6fc65f9407d /app | |
| parent | e761d6fb5c70e060fc53f9119903b38a531d99c9 (diff) | |
| download | chouette-core-25df1bea61409294e9944a66a25d81ea55f0391f.tar.bz2 | |
Refs #6218; UI for exports
Diffstat (limited to 'app')
| -rw-r--r-- | app/helpers/exports_helper.rb | 2 | ||||
| -rw-r--r-- | app/models/chouette/journey_pattern.rb | 2 | ||||
| -rw-r--r-- | app/models/chouette/stop_area.rb | 4 | ||||
| -rw-r--r-- | app/models/export/base.rb | 24 | ||||
| -rw-r--r-- | app/models/export/referential_companies.rb | 92 | ||||
| -rw-r--r-- | app/views/exports/show.html.slim | 11 | ||||
| -rw-r--r-- | app/views/shared/iev_interfaces/_messages.html.slim | 2 | 
7 files changed, 39 insertions, 98 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 ff85f376a..9c3ef78fa 100644 --- a/app/models/chouette/journey_pattern.rb +++ b/app/models/chouette/journey_pattern.rb @@ -177,7 +177,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 1918c90d1..79eb314bc 100644 --- a/app/models/chouette/stop_area.rb +++ b/app/models/chouette/stop_area.rb @@ -383,11 +383,11 @@ module Chouette      end      def activated? -      deleted_at.nil? && confirmed_at +      !!(deleted_at.nil? && confirmed_at)      end      def deactivated? -      deleted_at && confirmed_at.nil? +      !!(deleted_at && confirmed_at.nil?)      end      def activate 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 | 
