Class: Crm::EmployeeReviewPresenter

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

Overview

Presenter: employee review 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 review, redirecting back to the employee's reviews tab.

Returns:

  • (ActiveSupport::SafeBuffer, nil)

    link HTML, or nil when not permitted



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

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

  h.delete_link r, destroy: { success_url: h.employee_path(r.employee_record.party, tab: "reviews") }
end

#dynamic_status_drop_downActiveSupport::SafeBuffer

Status dropdown for the review.

Returns:

  • (ActiveSupport::SafeBuffer)

    dropdown HTML



35
36
37
# File 'app/presenters/crm/employee_review_presenter.rb', line 35

def dynamic_status_drop_down
  h.dynamic_status_drop_down r
end

Link to review/edit the employee review.

Returns:

  • (ActiveSupport::SafeBuffer, nil)

    link HTML, or nil when not permitted



77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'app/presenters/crm/employee_review_presenter.rb', line 77

def edit_review_link
  return unless h.can?(:update, r)

  if employee_review.in_progress?
    css_class = "btn btn-outline-success"
    label = 'Review'
  else
    css_class = "btn btn-outline-primary"
    label = 'Edit'
  end
  link_to(fa_icon('pen-square', text: label),
              h.edit_employee_review_path(employee_review),
              class: css_class)
end

#employee_review_state_labelActiveSupport::SafeBuffer

Badge showing the review's workflow state.

Returns:

  • (ActiveSupport::SafeBuffer)

    badge HTML



9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/presenters/crm/employee_review_presenter.rb', line 9

def employee_review_state_label
  css_class_state = {
    in_progress: 'info',
    process_reward: 'success',
    allocate_reward: 'success',
    complete: 'primary',
    cancelled: 'secondary'
  }[employee_review.state&.to_sym]
  css_class = "badge bg-#{css_class_state}"

  (:span, employee_review.human_state_name, class: css_class)
end

#goals_unfinished_alertActiveSupport::SafeBuffer?

Warning alert listing goals that block review completion.

Returns:

  • (ActiveSupport::SafeBuffer, nil)

    alert HTML, or nil when finalized



41
42
43
44
45
46
47
48
49
# File 'app/presenters/crm/employee_review_presenter.rb', line 41

def goals_unfinished_alert
  return unless r.in_progress? && !r.all_goals_finalized?
  return if r.employee_goals.unfinalized.blank?

  (:div, class: 'alert alert-warning') do
    concat (:h4, 'Before the review can be completed:')
    concat (:p, "Goal(s): #{r.employee_goals.unfinalized.pluck(:name).to_sentence} must be marked complete, not reached or cancelled")
  end
end

Link to define a new goal while the review is in progress.

Returns:

  • (ActiveSupport::SafeBuffer, nil)

    link HTML, or nil when not permitted



24
25
26
27
28
29
30
31
# File 'app/presenters/crm/employee_review_presenter.rb', line 24

def new_goal_link
  return unless employee_review.in_progress? && can?(:update, employee_review)

  css_class = 'btn btn-outline-primary'
  link_to(fa_icon('plus-circle', text: 'Define a new goal'),
    h.new_employee_review_employee_goal_path(employee_review),
    class: css_class)
end

#next_step_alertActiveSupport::SafeBuffer?

Info alert with the next available workflow action.

Returns:

  • (ActiveSupport::SafeBuffer, nil)

    alert HTML, or nil when no action applies



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'app/presenters/crm/employee_review_presenter.rb', line 53

def next_step_alert
  if r.can_complete_review? && r.employee_goals.present?
    alert = "This review is ready to complete."
    wf_action = :complete_review
  elsif r.can_complete_allocate_reward?
    alert = "Rewards are ready to be allocated for this review."
    wf_action = :complete_allocate_reward
  end

  return unless wf_action

   :div, class: 'alert alert-info' do
    h.centered_row do
      concat alert
      concat link_to(fa_icon('check', text: wf_action.to_s.humanize),
                     h.workflow_action_employee_review_path(r, wf_action: wf_action),
                     method: :post,
                     class: 'btn btn-success')
    end
  end
end

#render_employee_goalsString?

Renders the employee goals partial for quarterly reviews.

Returns:

  • (String, nil)

    rendered partial, or nil for non-quarterly reviews



102
103
104
105
106
# File 'app/presenters/crm/employee_review_presenter.rb', line 102

def render_employee_goals
  return unless employee_review.quarterly?

  h.render partial: 'employee_goals', locals: { erp: self }
end

#render_reward_allocationsString?

Renders the reward allocations partial once the review reaches reward stages.

Returns:

  • (String, nil)

    rendered partial, or nil before reward stages



110
111
112
113
114
# File 'app/presenters/crm/employee_review_presenter.rb', line 110

def render_reward_allocations
  return unless r.allocate_reward? || r.process_reward? || r.complete?

  h.render partial: 'reward_allocations', locals: { erp: self }
end

#setup_employee_review_for_reward_allocationsEmployeeReview

Builds reward allocations up to three rows for the form.

Returns:



118
119
120
121
122
# File 'app/presenters/crm/employee_review_presenter.rb', line 118

def setup_employee_review_for_reward_allocations
  employee_review.tap do |er|
    [3 - er.reward_allocations.size, 0].max.times { er.reward_allocations.build }
  end
end