Module: Crm::EdiCommunicationLogsHelper

Defined in:
app/helpers/crm/edi_communication_logs_helper.rb

Constant Summary collapse

ECL_STATE_BADGE =
{
  'ready'      => 'text-bg-info',
  'processing' => 'text-bg-primary',
  'processed'  => 'text-bg-success',
  'retry'      => 'text-bg-warning',
  'exception'  => 'text-bg-danger',
  'archived'   => 'text-bg-secondary'
}.freeze
ECL_ROW_CLASS =
{
  'exception'  => 'table-danger',
  'processing' => 'table-primary',
  'retry'      => 'table-warning'
}.freeze

Instance Method Summary collapse

Instance Method Details

#all_orchestrators_all_partnersObject



57
58
59
60
61
62
63
64
# File 'app/helpers/crm/edi_communication_logs_helper.rb', line 57

def all_orchestrators_all_partners
  Edi::BaseOrchestrator.all_orchestrators_class.each do |orchestrator_class|
    oc_name = orchestrator_class.name
    orchestrator_class.orchestrators.select(&:active).map(&:partner).each do |partner|
      yield(oc_name, partner)
    end
  end
end

#ecl_row_class(ecl) ⇒ Object



24
25
26
# File 'app/helpers/crm/edi_communication_logs_helper.rb', line 24

def ecl_row_class(ecl)
  ECL_ROW_CLASS.fetch(ecl.state.to_s, '')
end

#ecl_state_badge(ecl) ⇒ Object



17
18
19
20
21
22
# File 'app/helpers/crm/edi_communication_logs_helper.rb', line 17

def ecl_state_badge(ecl)
  css = ECL_STATE_BADGE.fetch(ecl.state.to_s, 'text-bg-secondary')
  label = ecl.human_state_name
  label = "#{label}" if ecl.transmit_after&.future?
  tag.span(label, class: "badge #{css}")
end

#edi_communication_log_actions(ecl, include_show_action: true, return_path: nil) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/helpers/crm/edi_communication_logs_helper.rb', line 43

def edi_communication_log_actions(ecl, include_show_action: true, return_path: nil)
  links = []
  with_options(controller: 'crm/edi_communication_logs', return_path: return_path) do |defaults|
    links << link_to('Status', defaults.url_for(action: :do_status, id: ecl.id), data: { turbo_method: :post }) if ecl.processing?
    links << link_to('Process', defaults.url_for(action: :do_process, id: ecl.id), data: { turbo_method: :post }) if ecl.ready?
    links << link_to('Show', defaults.url_for(action: :show, id: ecl.id))
    links << link_to('Edit', defaults.url_for(action: :edit, id: ecl.id)) if can?(:update, ecl)
    links << link_to('Clone', defaults.url_for(action: :clone, id: ecl.id), data: { turbo_method: :post }) if can?(:create, EdiCommunicationLog)
    links << link_to('Download', defaults.url_for(action: :download, id: ecl.id))
    links << link_to('Delete', defaults.url_for(action: :destroy, id: ecl.id), data: { turbo_method: :delete, turbo_confirm: 'Please confirm you want to delete this record?' }) if can?(:destroy, ecl)
  end
  links
end

#edi_communication_log_actions_for_inventory_flowObject



76
77
78
79
80
81
82
83
84
# File 'app/helpers/crm/edi_communication_logs_helper.rb', line 76

def edi_communication_log_actions_for_inventory_flow
  res = []
  res << link_to('Run inventory flow (all)', inventory_flow_edi_communication_logs_path, data: { turbo_method: :post })
  all_orchestrators_all_partners do |oc_name, partner|
    res << link_to("Run inventory flow #{oc_name} - #{partner}",
                   inventory_flow_edi_communication_logs_path(orchestrator_name: oc_name, partner:), data: { turbo_method: :post })
  end
  res
end

#edi_communication_log_actions_for_order_flowObject



66
67
68
69
70
71
72
73
74
# File 'app/helpers/crm/edi_communication_logs_helper.rb', line 66

def edi_communication_log_actions_for_order_flow
  res = []
  res << link_to('Run order flow (all)', order_flow_edi_communication_logs_path, data: { turbo_method: :post })
  all_orchestrators_all_partners do |oc_name, partner|
    res << link_to("Run order flow #{oc_name} - #{partner}",
                   order_flow_edi_communication_logs_path(orchestrator_name: oc_name, partner:), data: { turbo_method: :post })
  end
  res
end

#edi_communication_log_actions_for_product_data_flowObject



86
87
88
89
90
91
92
93
94
# File 'app/helpers/crm/edi_communication_logs_helper.rb', line 86

def edi_communication_log_actions_for_product_data_flow
  res = []
  res << link_to('Run data flow (all)', product_data_flow_edi_communication_logs_path, data: { turbo_method: :post })
  all_orchestrators_all_partners do |oc_name, partner|
    res << link_to("Run product data flow #{oc_name} - #{partner}",
                   product_data_flow_edi_communication_logs_path(orchestrator_name: oc_name, partner:), data: { turbo_method: :post })
  end
  res
end

#edi_communication_log_format_data(ecl) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'app/helpers/crm/edi_communication_logs_helper.rb', line 28

def edi_communication_log_format_data(ecl)
  return if ecl.data.blank?

  if ecl.json? && ecl.data.size < 30_000
    pretty_json_tag ecl.data_as_json, expand: 8
  else
    tag.pre ecl.data_as_json
  end
end

#setup_edi_communication_log(ecl) ⇒ Object



38
39
40
41
# File 'app/helpers/crm/edi_communication_logs_helper.rb', line 38

def setup_edi_communication_log(ecl)
  ecl.uploads.build unless ecl.uploads.any?(&:new_record?)
  ecl
end