Module: ForemanTasks::ForemanTasksHelper

Defined in:
app/helpers/foreman_tasks/foreman_tasks_helper.rb

Instance Method Summary collapse

Instance Method Details



115
116
117
118
119
120
121
# File 'app/helpers/foreman_tasks/foreman_tasks_helper.rb', line 115

def breadcrumb_items
  items = [index_breadcrumb_item]
  return items if action_name == 'index'
  items << task_breadcrumb_item(@task, action_name == 'show')
  items << { :caption => _('Sub tasks') } if action_name == 'sub_tasks'
  items
end

#date_f(f, attr, field_options = {}, date_options = {}, html_options = {}) ⇒ Object



67
68
69
70
71
72
73
# File 'app/helpers/foreman_tasks/foreman_tasks_helper.rb', line 67

def date_f(f, attr, field_options = {}, date_options = {}, html_options = {})
  f.fields_for attr do |fields|
    field(fields, attr, field_options) do
      fields.date_select attr, date_options, html_options
    end
  end
end

#datetime_f(f, attr, field_options = {}, datetime_options = {}, html_options = {}) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'app/helpers/foreman_tasks/foreman_tasks_helper.rb', line 75

def datetime_f(f, attr, field_options = {}, datetime_options = {}, html_options = {})
  f.fields_for attr do |fields|
    field(fields, attr, field_options) do
      [
        (:span, nil, :class => 'date', :style => 'white-space: nowrap;') do
          fields.date_select(attr, datetime_options, html_options)
        end,
        ' &mdash; ',
        (:span, nil, :class => 'time', :style => 'white-space: nowrap;') do
          fields.time_select(attr, datetime_options.merge(:ignore_date => true), html_options)
        end,
      ].join
    end
  end
end

#index_breadcrumb_itemObject



109
110
111
112
113
# File 'app/helpers/foreman_tasks/foreman_tasks_helper.rb', line 109

def index_breadcrumb_item
  item = { :caption => _('Tasks') }
  item[:url] = foreman_tasks_tasks_url if action_name != 'index'
  item
end

#inline_checkboxes_f(f, attr, field_options = {}, checkboxes = {}, options = {}) ⇒ Object



91
92
93
94
95
96
97
# File 'app/helpers/foreman_tasks/foreman_tasks_helper.rb', line 91

def inline_checkboxes_f(f, attr, field_options = {}, checkboxes = {}, options = {})
  field(f, attr, field_options) do
    checkboxes.map do |key, name|
      [f.check_box(key, options), " #{name} "]
    end.flatten.join('')
  end
end

#recurring_logic_action_buttons(recurring_logic) ⇒ Object



41
42
43
44
45
46
47
48
49
# File 'app/helpers/foreman_tasks/foreman_tasks_helper.rb', line 41

def recurring_logic_action_buttons(recurring_logic)
  buttons = []
  if authorized_for(:permission => :edit_recurring_logics, :auth_object => recurring_logic)
    buttons << link_to(N_('Enable'), enable_foreman_tasks_recurring_logic_path(recurring_logic), :method => :put, :class => '') if !recurring_logic.done? && recurring_logic.disabled?
    buttons << link_to(N_('Disable'), disable_foreman_tasks_recurring_logic_path(recurring_logic), :method => :put, :class => '') if !recurring_logic.done? && recurring_logic.enabled?
    buttons << link_to(N_('Cancel'), cancel_foreman_tasks_recurring_logic_path(recurring_logic), :method => :post, :class => '') unless recurring_logic.done?
  end
  action_buttons buttons
end

#recurring_logic_next_occurrence(recurring_logic) ⇒ Object



51
52
53
54
55
56
57
# File 'app/helpers/foreman_tasks/foreman_tasks_helper.rb', line 51

def recurring_logic_next_occurrence(recurring_logic)
  default = '-'
  return default if recurring_logic.done? || recurring_logic.disabled?

  upcoming_task = recurring_logic.next_task
  upcoming_task ? upcoming_task.start_at : default
end

#recurring_logic_state(recurring_logic) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'app/helpers/foreman_tasks/foreman_tasks_helper.rb', line 3

def recurring_logic_state(recurring_logic)
  icon, status = case recurring_logic.state
                 when 'active'
                   'glyphicon-info-sign'
                 when 'disabled'
                   'glyphicon glyphicon-pause'
                 when 'finished'
                   ['glyphicon-ok-sign', 'status-ok']
                 when 'cancelled'
                   ['glyphicon-warning-sign', 'status-error']
                 else
                   'glyphicon-question-sign'
                 end
  (:i, '&nbsp'.html_safe, :class => "glyphicon #{icon}") + (:span, recurring_logic.humanized_state, :class => status)
end

#task_breadcrumb_item(task, active = false) ⇒ Object



103
104
105
106
107
# File 'app/helpers/foreman_tasks/foreman_tasks_helper.rb', line 103

def task_breadcrumb_item(task, active = false)
  item = { :caption => format_task_input(task) }
  item[:url] = url_for(foreman_tasks_task_path(task.id)) unless active
  item
end

#time_f(f, attr, field_options = {}, time_options = {}, html_options = {}) ⇒ Object



59
60
61
62
63
64
65
# File 'app/helpers/foreman_tasks/foreman_tasks_helper.rb', line 59

def time_f(f, attr, field_options = {}, time_options = {}, html_options = {})
  f.fields_for attr do |fields|
    field(fields, attr, field_options) do
      fields.time_select attr, time_options, html_options
    end
  end
end

#trigger_selector(f, triggering = Triggering.new, _options = {}) ⇒ Object



99
100
101
# File 'app/helpers/foreman_tasks/foreman_tasks_helper.rb', line 99

def trigger_selector(f, triggering = Triggering.new, _options = {})
  render :partial => 'common/trigger_form', :locals => { :f => f, :triggering => triggering }
end

#troubleshooting_infoObject



19
20
21
22
23
24
25
# File 'app/helpers/foreman_tasks/foreman_tasks_helper.rb', line 19

def troubleshooting_info
  return if @task.state != 'paused' || @task.main_action.nil?
  helper = TroubleshootingHelpGenerator.new(@task.main_action)
  ret = '<p><b>Troubleshooting</b></p>'
  ret += '<p>%{help}</p>' % { help: helper.generate_html }
  ret.html_safe
end

#troubleshooting_info_textObject



27
28
29
30
31
# File 'app/helpers/foreman_tasks/foreman_tasks_helper.rb', line 27

def troubleshooting_info_text
  return if @task.state != 'paused' || @task.main_action.nil?
  helper = TroubleshootingHelpGenerator.new(@task.main_action)
  helper.generate_html
end


33
34
35
36
37
38
39
# File 'app/helpers/foreman_tasks/foreman_tasks_helper.rb', line 33

def username_link_task(owner, username)
  if owner.present? && username != User::ANONYMOUS_API_ADMIN && username != User::ANONYMOUS_ADMIN
    link_to_if_authorized(username, hash_for_edit_user_path(owner))
  else
    username
  end
end