Module: Crm::EdiCommunicationLogsHelper

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

Overview

View helper: edi communication logs.

Constant Summary collapse

ECL_STATE_BADGE =

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 =

Ecl row class.

{
  'exception'  => 'table-danger',
  'processing' => 'table-primary',
  'retry'      => 'table-warning'
}.freeze

Instance Method Summary collapse

Instance Method Details

#all_orchestrators_all_partnersObject



61
62
63
64
65
66
67
68
# File 'app/helpers/crm/edi_communication_logs_helper.rb', line 61

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



28
29
30
# File 'app/helpers/crm/edi_communication_logs_helper.rb', line 28

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

#ecl_state_badge(ecl) ⇒ Object



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

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

rubocop:disable Lint/UnusedMethodArgument



47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'app/helpers/crm/edi_communication_logs_helper.rb', line 47

def edi_communication_log_actions(ecl, include_show_action: true, return_path: nil) # rubocop:disable Lint/UnusedMethodArgument
  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



80
81
82
83
84
85
86
87
88
# File 'app/helpers/crm/edi_communication_logs_helper.rb', line 80

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



70
71
72
73
74
75
76
77
78
# File 'app/helpers/crm/edi_communication_logs_helper.rb', line 70

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



90
91
92
93
94
95
96
97
98
# File 'app/helpers/crm/edi_communication_logs_helper.rb', line 90

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



32
33
34
35
36
37
38
39
40
# File 'app/helpers/crm/edi_communication_logs_helper.rb', line 32

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



42
43
44
45
# File 'app/helpers/crm/edi_communication_logs_helper.rb', line 42

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