Class: Crm::EmployeeGoalPresenter

Inherits:
BasePresenter show all
Defined in:
app/presenters/crm/employee_goal_presenter.rb

Overview

Presenter: employee goal presenter.

Instance Attribute Summary

Attributes inherited from BasePresenter

#current_account, #options, #url_helper

Instance Method Summary collapse

Methods inherited from BasePresenter

#initialize

Methods inherited from BasePresenter

#can?, #capture, #concat, #content_tag, #fa_icon, #h, #initialize, #link_to, #number_to_currency, #present, presents, #r, #safe_present, #simple_format, #u

Constructor Details

This class inherits a constructor from Crm::BasePresenter

Instance Method Details

Link to delete the goal.

Returns:

  • (ActiveSupport::SafeBuffer, nil)

    link HTML, or nil when not permitted



94
95
96
97
98
# File 'app/presenters/crm/employee_goal_presenter.rb', line 94

def delete_link
  return unless can?(:destroy, r)

  link_to(fa_icon('trash'), r, data: { turbo_method: :delete, turbo_confirm: "Are you sure want to delete this review?" })
end

#departmentString?

Department of the reviewed employee.

Returns:

  • (String, nil)

    department name



65
66
67
# File 'app/presenters/crm/employee_goal_presenter.rb', line 65

def department
  r.employee_review&.employee_record&.department
end

#display_nameActiveSupport::SafeBuffer

Goal name with an info icon showing the description on hover.

Returns:

  • (ActiveSupport::SafeBuffer)

    icon-with-text HTML



102
103
104
# File 'app/presenters/crm/employee_goal_presenter.rb', line 102

def display_name
  fa_icon('info-circle', text: r.name, title: r.description)
end

#due_dateString?

Formatted due date for the goal.

Returns:

  • (String, nil)

    rendered date



50
51
52
# File 'app/presenters/crm/employee_goal_presenter.rb', line 50

def due_date
  h.render_date(r.due_date)
end

Link to edit/review the goal.

Returns:

  • (ActiveSupport::SafeBuffer, nil)

    link HTML, or nil when not permitted



9
10
11
12
13
14
15
# File 'app/presenters/crm/employee_goal_presenter.rb', line 9

def edit_link
  return unless can?(:update, r)

  link_to(fa_icon('pen-square', text: 'Edit/Review'),
            h.edit_employee_goal_path(r),
            class: "btn btn-#{r.defined? ? 'info' : 'default'}")
end

#employeeParty?

The goal's employee (party record).

Returns:

  • (Party, nil)

    the employee



71
72
73
# File 'app/presenters/crm/employee_goal_presenter.rb', line 71

def employee
  r.employee_review&.employee_record&.party
end

Link to the goal, or the plain name when not permitted.

Returns:

  • (ActiveSupport::SafeBuffer, String)

    link or name



77
78
79
80
81
# File 'app/presenters/crm/employee_goal_presenter.rb', line 77

def employee_goal_link
  return r.name unless h.can?(:read, r)

  link_to r.name, h.employee_goal_path(r)
end

#employee_goal_state_label(options = {}) ⇒ String

Renders a badge showing the employee goal's state.

Parameters:

  • options (Hash) (defaults to: {})

    html options forwarded to content_tag

Options Hash (options):

  • style (String)

    inline CSS ('font-size: 1em' by
    default)

Returns:

  • (String)

    HTML span



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/presenters/crm/employee_goal_presenter.rb', line 23

def employee_goal_state_label(options = {})
  case r.state.to_sym
  when :reached
    css_class = 'bg-success'
  when :missed
    css_class = 'bg-danger'
  when :cancelled
    css_class = 'badge-default'
  end
  css_class ||= 'bg-info'

  options[:style] ||= 'font-size: 1em'
  (:span, r.human_state_name.titleize, class: "badge #{css_class}", **options)
end

Link to the goal's employee, or the plain name when not permitted.

Returns:

  • (ActiveSupport::SafeBuffer, String, nil)

    link or name



56
57
58
59
60
61
# File 'app/presenters/crm/employee_goal_presenter.rb', line 56

def employee_link
  return unless employee
  return employee.full_name unless h.can?(:read, employee)

  link_to employee.full_name, h.employee_path(employee)
end

Link to the parent employee review.

Returns:

  • (ActiveSupport::SafeBuffer, nil)

    link HTML, or nil when not readable



85
86
87
88
89
90
# File 'app/presenters/crm/employee_goal_presenter.rb', line 85

def employee_review_link
  return unless r.employee_review
  return unless h.can?(:read, r.employee_review)

  link_to r.employee_review.review_name, h.employee_review_path(r.employee_review)
end

#reward_infoActiveSupport::SafeBuffer

Earned vs. potential reward amounts.

Returns:

  • (ActiveSupport::SafeBuffer)

    'earned / potential' currency HTML



40
41
42
43
44
45
46
# File 'app/presenters/crm/employee_goal_presenter.rb', line 40

def reward_info
  capture do
    concat number_to_currency(r.earned_reward || 0.0)
    concat " / "
    concat number_to_currency(r.potential_reward || 0.0)
  end
end