Module: Dynflow::Web::ConsoleHelpers

Defined in:
lib/dynflow/web/console_helpers.rb

Instance Method Summary collapse

Instance Method Details

#atom_css_classes(atom) ⇒ Object



99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/dynflow/web/console_helpers.rb', line 99

def atom_css_classes(atom)
  classes = ["atom"]
  step    = @plan.steps[atom.step_id]
  case step.state
  when :success
    classes << "success"
  when :error
    classes << "error"
  when :skipped, :skipping
    classes << "skipped"
  end
  return classes.join(" ")
end

#duration_to_s(duration) ⇒ Object



60
61
62
# File 'lib/dynflow/web/console_helpers.rb', line 60

def duration_to_s(duration)
  h("%0.2fs" % duration)
end

#filter_checkbox(field, values) ⇒ Object



175
176
177
178
179
180
181
182
183
184
# File 'lib/dynflow/web/console_helpers.rb', line 175

def filter_checkbox(field, values)
  out        = "<p>#{field}: %s</p>"
  checkboxes = values.map do |value|
    field_filter = filtering_options[:filters][field]
    checked      = field_filter && field_filter.include?(value)
    %{<input type="checkbox" name="filters[#{field}][]" value="#{value}" #{ "checked" if checked }/>#{value}}
  end.join(' ')
  out        %= checkboxes
  return out
end

#flow_css_classes(flow, sub_flow = nil) ⇒ Object



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/dynflow/web/console_helpers.rb', line 113

def flow_css_classes(flow, sub_flow = nil)
  classes = []
  case flow
  when Flows::Sequence
    classes << "sequence"
  when Flows::Concurrence
    classes << "concurrence"
  when Flows::Atom
    classes << atom_css_classes(flow)
  else
    raise "Unknown run plan #{run_plan.inspect}"
  end
  classes << atom_css_classes(sub_flow) if sub_flow.is_a? Flows::Atom
  return classes.join(" ")
end

#load_action(step) ⇒ Object



64
65
66
# File 'lib/dynflow/web/console_helpers.rb', line 64

def load_action(step)
  world.persistence.load_action_for_presentation(@plan, step.action_id, step)
end


162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/dynflow/web/console_helpers.rb', line 162

def order_link(attr, label)
  return h(label) unless supported_ordering?(attr)
  new_ordering_options = { order_by: attr.to_s,
                           desc:     false }
  arrow                = ""
  if ordering_options[:order_by].to_s == attr.to_s
    arrow                       = ordering_options[:desc] ? "&#9660;" : "&#9650;"
    new_ordering_options[:desc] = !ordering_options[:desc]
  end
  url = updated_url(new_ordering_options)
  return %{<a href="#{url}"> #{arrow} #{h(label)}</a>}
end

#paginated_url(delta) ⇒ Object



158
159
160
# File 'lib/dynflow/web/console_helpers.rb', line 158

def paginated_url(delta)
  h(updated_url(page: [0, page + delta].max.to_s))
end

#prettify_value(value) ⇒ Object



29
30
31
# File 'lib/dynflow/web/console_helpers.rb', line 29

def prettify_value(value)
  YAML.dump(value)
end

#prettyprint(value) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/dynflow/web/console_helpers.rb', line 33

def prettyprint(value)
  value = prettyprint_references(value)
  if value
    pretty_value = prettify_value(value)
    <<-HTML
        <pre class="prettyprint lang-yaml">#{h(pretty_value)}</pre>
      HTML
  else
    ""
  end
end

#prettyprint_references(value) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/dynflow/web/console_helpers.rb', line 45

def prettyprint_references(value)
  case value
  when Hash
    value.reduce({}) do |h, (key, val)|
      h.update(key => prettyprint_references(val))
    end
  when Array
    value.map { |val| prettyprint_references(val) }
  when ExecutionPlan::OutputReference
    value.inspect
  else
    value
  end
end

#progress_width(step) ⇒ Object



142
143
144
145
146
147
148
# File 'lib/dynflow/web/console_helpers.rb', line 142

def progress_width(step)
  if step.state == :error
    100 # we want to show the red bar in full width
  else
    step.progress_done * 100
  end
end

#show_action_data(label, value) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/dynflow/web/console_helpers.rb', line 85

def show_action_data(label, value)
  value_html = prettyprint(value)
  if !value_html.empty?
    <<-HTML
        <p>
          <b>#{h(label)}</b>
      #{value_html}
        </p>
      HTML
  else
    ""
  end
end

#show_world(world_id) ⇒ Object



77
78
79
80
81
82
83
# File 'lib/dynflow/web/console_helpers.rb', line 77

def show_world(world_id)
  if registered_world = world.coordinator.find_worlds(false, id: world_id).first
    "%{world_id} %{world_meta}" % { world_id: world_id, world_meta: registered_world.meta.inspect }
  else
    world_id
  end
end

#step(step_id) ⇒ Object



150
151
152
# File 'lib/dynflow/web/console_helpers.rb', line 150

def step(step_id)
  @plan.steps[step_id]
end

#step_css_class(step) ⇒ Object



129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/dynflow/web/console_helpers.rb', line 129

def step_css_class(step)
  case step.state
  when :success
    "success"
  when :error
    "danger"
  when :cancelled
    "warning"
  else
    "default"
  end
end

#step_error(step) ⇒ Object



68
69
70
71
72
73
74
75
# File 'lib/dynflow/web/console_helpers.rb', line 68

def step_error(step)
  if step.error
    ['<pre>',
     "#{h(step.error.message)} (#{h(step.error.exception_class)})\n",
     h(step.error.backtrace.join("\n")),
     '</pre>'].join
  end
end

#strip_heredoc(str) ⇒ Object



22
23
24
25
26
27
# File 'lib/dynflow/web/console_helpers.rb', line 22

def strip_heredoc(str)
  strip_size = str.lines.reject { |l| l =~ /^\s*$/ }.map { |l| l[/^\s*/].length }.min
  str.lines.map do |line|
    line[strip_size..-1] || ''
  end.join
end

#updated_url(new_params) ⇒ Object



154
155
156
# File 'lib/dynflow/web/console_helpers.rb', line 154

def updated_url(new_params)
  url(request.path_info + "?" + Rack::Utils.build_nested_query(params.merge(Utils.stringify_keys(new_params))))
end

#validation_result_css_class(result) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/dynflow/web/console_helpers.rb', line 5

def validation_result_css_class(result)
  if result == :valid
    "success"
  else
    "danger"
  end
end

#value_field(key, value) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/dynflow/web/console_helpers.rb', line 13

def value_field(key, value)
  strip_heredoc(<<-HTML)
    <p>
      <b>#{key}:</b>
      #{h(value)}
    </p>
  HTML
end