Module: RigidWorkflow::WorkflowsHelper

Defined in:
app/helpers/rigid_workflow/workflows_helper.rb

Overview

Formats workflow attributes for display in views. Handles identifiers, datetimes, durations, JSON, and status badges.

Constant Summary collapse

IDENTIFIER_KEYS =
%w[id workflow_run_id run_id].freeze
DATETIME_KEYS =
%w[created_at updated_at finished_at started_at].freeze
CLASSNAME_KEYS =
%w[
  job_class
  class_name
  activity_class
  workflow_class
].freeze
DURATION_KEYS =
%w[duration].freeze
JSON_KEYS =
%w[memory params].freeze
STATUS_KEYS =
%w[status].freeze

Instance Method Summary collapse

Instance Method Details

#format_attribute(key, value) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'app/helpers/rigid_workflow/workflows_helper.rb', line 19

def format_attribute(key, value)
  return format_identifier(value) if IDENTIFIER_KEYS.include?(key)
  return format_datetime(value) if DATETIME_KEYS.include?(key)
  return format_classname(value) if CLASSNAME_KEYS.include?(key)
  return format_duration(value) if DURATION_KEYS.include?(key)
  return format_json(value) if JSON_KEYS.include?(key)
  return format_status(value) if STATUS_KEYS.include?(key)
  format_default(value)
end

#format_classname(value) ⇒ Object



47
48
49
50
51
52
53
54
# File 'app/helpers/rigid_workflow/workflows_helper.rb', line 47

def format_classname(value)
  return (:span, "", class: "text-gray-400") if value.blank?
  (
    :code,
    value,
    class: "text-sm font-mono font-medium text-gray-900 select-all"
  )
end

#format_datetime(value) ⇒ Object



38
39
40
41
42
43
44
45
# File 'app/helpers/rigid_workflow/workflows_helper.rb', line 38

def format_datetime(value)
  return (:span, "", class: "text-gray-400") if value.blank?
  (
    :span,
    local_time(value, format: "%Y-%m-%d %H:%M:%S"),
    class: "text-sm"
  )
end

#format_default(value) ⇒ Object



93
94
95
# File 'app/helpers/rigid_workflow/workflows_helper.rb', line 93

def format_default(value)
  value.to_s.presence || (:span, "", class: "text-gray-400")
end

#format_duration(value) ⇒ Object



56
57
58
59
60
61
# File 'app/helpers/rigid_workflow/workflows_helper.rb', line 56

def format_duration(value)
  return (:span, "", class: "text-gray-400") if value.blank?
  mins = value > 60 ? "#{(value / 60.0).floor}m" : ""
  secs = (value < 60 ? "%.2gs" : "%.0fs") % (value % 60)
  (:span, "#{mins}#{secs}", class: "text-sm")
end

#format_identifier(value) ⇒ Object



29
30
31
32
33
34
35
36
# File 'app/helpers/rigid_workflow/workflows_helper.rb', line 29

def format_identifier(value)
  return (:span, "", class: "text-gray-400") if value.blank?
  (
    :code,
    value,
    class: "text-xs font-mono text-gray-500 select-all"
  )
end

#format_json(value) ⇒ Object



63
64
65
66
67
68
69
70
# File 'app/helpers/rigid_workflow/workflows_helper.rb', line 63

def format_json(value)
  return (:span, "", class: "text-gray-400") if value.blank?
  (
    :pre,
    JSON.pretty_generate(value),
    class: "text-xs max-h-30 overflow-y-auto"
  )
end

#format_status(value) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'app/helpers/rigid_workflow/workflows_helper.rb', line 72

def format_status(value)
  badge_class =
    case value.to_s.downcase
    when "completed"
      "bg-green-100 text-green-800"
    when "failed", "error", "cancelled"
      "bg-red-100 text-red-800"
    when "pending"
      "bg-yellow-100 text-yellow-800"
    else
      "bg-gray-100 text-gray-800"
    end

  (
    :span,
    value.to_s.humanize,
    class:
      "inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium #{badge_class}"
  )
end

#run_actions_for(status) ⇒ Object



97
98
99
100
101
102
103
104
105
106
107
108
# File 'app/helpers/rigid_workflow/workflows_helper.rb', line 97

def run_actions_for(status)
  case status.to_s
  when "pending", "compensating"
    "cancel"
  when "running"
    "retry, cancel"
  when "failed"
    "retry"
  else
    ""
  end
end