Module: RemoteExecutionHelper

Defined in:
app/helpers/remote_execution_helper.rb

Instance Method Summary collapse

Instance Method Details

#host_counter(label, count) ⇒ Object



38
39
40
41
42
# File 'app/helpers/remote_execution_helper.rb', line 38

def host_counter(label, count)
  (:div, :class => 'host_counter') do
    (:div, label, :class => 'header') + (:div, count.to_s, :class => 'count')
  end
end

#invocation_count(invocation, options = {}) ⇒ Object



84
85
86
87
# File 'app/helpers/remote_execution_helper.rb', line 84

def invocation_count(invocation, options = {})
  options = { :unknown_string => 'N/A' }.merge(options)
  (invocation.last_task.try(:output) || {}).fetch(options[:output_key], options[:unknown_string])
end

#job_invocation_chart(invocation) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/helpers/remote_execution_helper.rb', line 10

def job_invocation_chart(invocation)
  options = { :class => 'statistics-pie small', :expandable => true, :border => 0, :show_title => true }

  if (bulk_task = invocation.last_task)
    success = bulk_task.output['success_count'] || 0
    failed = bulk_task.output['failed_count'] || 0
    pending = (bulk_task.output['pending_count'] || 0)

    flot_pie_chart('status', job_invocation_status(invocation),
                   [{:label => _('Success'), :data => success, :color => '#5CB85C'},
                    {:label => _('Failed'), :data => failed, :color => '#D9534F'},
                    {:label => _('Pending'), :data => pending, :color => '#DEDEDE'}],
                   options)
  else
    (:h4, job_invocation_status(invocation))
  end
end

#job_invocation_status(invocation) ⇒ Object



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

def job_invocation_status(invocation)
  if invocation.last_task.blank?
    _('Job not started yet 0%')
  else
    label = invocation.last_task.pending ? _('Running') : _('Finished')
    label + ' ' + (invocation.last_task.progress * 100).to_i.to_s + '%'
  end

end

#job_invocation_task_buttons(task) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'app/helpers/remote_execution_helper.rb', line 57

def job_invocation_task_buttons(task)
  buttons = []
  buttons << link_to(_('Refresh'), {}, :class => 'btn btn-default', :title => _('Refresh this page'))
  if authorized_for(:permission => :view_foreman_tasks, :auth_object => task)
    buttons << link_to(_("Last Job Task"), foreman_tasks_task_path(task),
                       :class => "btn btn-default",
                       :title => _('See the last task details'))
  end
  if authorized_for(:permission => :edit_foreman_tasks, :auth_object => task)
    buttons << link_to(_("Cancel Job"), cancel_foreman_tasks_task_path(task),
                       :class => "btn btn-danger",
                       :title => _('Try to cancel the job'),
                       :disabled => !task.cancellable?,
                       :method => :post)
  end
  return button_group(*buttons)
end


75
76
77
78
79
80
81
82
# File 'app/helpers/remote_execution_helper.rb', line 75

def link_to_invocation_task_if_authorized(invocation)
  if invocation.last_task.present?
    link_to_if_authorized job_invocation_status(invocation),
                          hash_for_foreman_tasks_task_path(invocation.last_task).merge(:auth_object => invocation.last_task, :permission => :view_foreman_tasks)
  else
    job_invocation_status(invocation)
  end
end

#providers_optionsObject



2
3
4
# File 'app/helpers/remote_execution_helper.rb', line 2

def providers_options
  RemoteExecutionProvider.providers.map { |key, provider| [ key, _(provider) ] }
end

#template_input_types_optionsObject



6
7
8
# File 'app/helpers/remote_execution_helper.rb', line 6

def template_input_types_options
  TemplateInput::TYPES.map { |key, name| [ _(name), key ] }
end

#template_invocation_status(task) ⇒ Object



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

def template_invocation_status(task)
  case task.result
    when 'warning', 'error'
      (:i, '&nbsp'.html_safe, :class => 'glyphicon glyphicon-exclamation-sign') + (:span, _('failed'), :class => 'status-error')
    when 'success'
      (:i, '&nbsp'.html_safe, :class => 'glyphicon glyphicon-ok-sign') + (:span, _('success'), :class => 'status-ok')
    when 'pending'
      (:i, '&nbsp'.html_safe, :class => 'glyphicon glyphicon-question-sign') + (:span, _('pending'))
    else
      task.result
  end
end