Module: EmployeeTopicsHelper

Defined in:
app/helpers/employee_topics_helper.rb

Overview

View helper: employee topics.

Instance Method Summary collapse

Instance Method Details

#employee_topic_assign_selectable_headerObject



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

def employee_topic_assign_selectable_header
  (:div, class: 'checkbox') do
    (:label) do
      concat check_box_tag(:check_all, "1", false,
        data: { action: "change->check-all#toggle", selector: "input[type=checkbox]" })
      concat (:span, 'Assign Training To', style: 'margin-left:0.5em')
    end
  end
end

#employee_topic_badge(state) ⇒ Object



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

def employee_topic_badge(state)
  return unless state

  icon_map = {
               reviewed: { icon: 'thumbs-o-up', style: 'color: green' },
               certified: { icon: 'certificate', style: 'color: gold' }
             }
  return unless (badge_data = icon_map[state.to_sym])

  fa_icon(badge_data[:icon], style: badge_data[:style])
end

#employee_topic_badge_state_color(state) ⇒ Object



24
25
26
# File 'app/helpers/employee_topics_helper.rb', line 24

def employee_topic_badge_state_color(state)
  { 'requested' => 'primary', 'assigned' => 'warning', 'certified' => 'success' }[state] || 'default'
end

#employee_topic_state_label(employee_topic) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/helpers/employee_topics_helper.rb', line 40

def employee_topic_state_label(employee_topic)
  css_class = {
    assigned: :danger,
    reviewed: :info,
    certified: :success,
    cancelled: :default,
    requested: :warning
  }[employee_topic.state.to_sym]
  label_value = employee_topic.human_state_name.titleize
  label_value = fa_icon('diploma', text: label_value) if employee_topic.state.to_sym == :certified
  (:span, label_value, class: "badge bg-#{css_class}")
end

#employee_topics_state_counters(topics, employee) ⇒ Object



17
18
19
20
21
22
# File 'app/helpers/employee_topics_helper.rb', line 17

def employee_topics_state_counters(topics, employee)
  topics.group_by { |t| t.employee_topics.where(employee: employee).first.try(:state) || 'unassigned' }.map do |state, topics|
    (:span, "#{state.titleize}: #{topics.size}",
    class: "badge bg-#{employee_topic_badge_state_color(state)}")
  end.join(' ').html_safe
end

#select_options_for_employee_topic(employee_topic) ⇒ Object

Assume topic passed is prefetched with party_topic filtered on the current employee



5
6
7
8
9
10
11
12
13
14
15
# File 'app/helpers/employee_topics_helper.rb', line 5

def select_options_for_employee_topic(employee_topic)
  if employee_topic
    # State Flow check
    options = employee_topic.possible_events_for_select
    # Permission check
    options = options.select { |o| can? o[1].to_sym, employee_topic }
  else
    options = [%w[Assign assign]]
  end
  options
end

#topic_category_selectable_header(topic_category) ⇒ Object



53
54
55
56
57
58
59
60
61
# File 'app/helpers/employee_topics_helper.rb', line 53

def topic_category_selectable_header(topic_category)
  (:div, class: 'checkbox') do
    (:label) do
      concat check_box_tag(:check_all, "1", false,
        data: { action: "change->check-all#toggle", selector: "input[type=checkbox]" })
      concat (:span, topic_category.to_s, class: 'ms-2')
    end
  end
end