Class: LcpRuby::Import::ImportDialogHandler

Inherits:
Events::HandlerBase show all
Defined in:
lib/lcp_ruby/import/import_dialog_handler.rb

Instance Attribute Summary

Attributes inherited from Events::HandlerBase

#changes, #context, #current_user, #event_name, #record, #request_params

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Events::HandlerBase

async?, #initialize

Constructor Details

This class inherits a constructor from LcpRuby::Events::HandlerBase

Class Method Details

.handles_eventObject



4
5
6
# File 'lib/lcp_ruby/import/import_dialog_handler.rb', line 4

def self.handles_event
  "dialog_submit"
end

Instance Method Details

#callObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/lcp_ruby/import/import_dialog_handler.rb', line 8

def call
  # "Back" button: re-render upload step. Checked before resolve_presenter!
  # because handle_back only needs `record` (set by HandlerBase), not the
  # resolved presenter/evaluator.
  if request_params["_form_action"] == "back"
    return handle_back
  end

  resolve_presenter!
  step = record.respond_to?(:step) ? record.step : "upload"

  case step.to_s
  when "upload"
    handle_upload
  when "mapping"
    handle_mapping
  else
    failure(I18n.t("lcp_ruby.import.errors.unknown_step",
                   step: step,
                   default: "Unknown import step: %{step}"))
  end
rescue LcpRuby::Error => e
  failure(e.message)
rescue StandardError => e
  raise unless Rails.env.production?

  LcpRuby.record_error(e, subsystem: "import", presenter: @presenter&.name, model: @presenter&.model)
  failure(I18n.t("lcp_ruby.import.errors.generic_failure",
                 reason: e.message,
                 default: "Import failed: %{reason}"))
end