Class: HrLite::Admin::AppraisalsController

Inherits:
SuperadminController show all
Defined in:
app/controllers/hr_lite/admin/appraisals_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



13
14
15
16
17
18
19
20
21
22
# File 'app/controllers/hr_lite/admin/appraisals_controller.rb', line 13

def create
  @appraisal = Appraisal.new(appraisal_params.merge(
    user_id: @profile.user_id, reviewer_id: hr_current_user.id
  ))
  if @appraisal.save
    redirect_to admin_employee_path(@profile), notice: "Appraisal drafted — share when ready."
  else
    render :new, status: :unprocessable_entity
  end
end

#destroyObject



46
47
48
49
50
51
52
53
54
# File 'app/controllers/hr_lite/admin/appraisals_controller.rb', line 46

def destroy
  appraisal = scoped.find(params[:id])
  if appraisal.destroy
    redirect_to admin_employee_path(@profile), notice: "Draft appraisal removed.", status: :see_other
  else
    redirect_to admin_employee_path(@profile), status: :see_other,
                alert: appraisal.errors.full_messages.to_sentence
  end
end

#editObject



24
25
26
# File 'app/controllers/hr_lite/admin/appraisals_controller.rb', line 24

def edit
  @appraisal = scoped.find(params[:id])
end

#newObject



6
7
8
9
10
11
# File 'app/controllers/hr_lite/admin/appraisals_controller.rb', line 6

def new
  @appraisal = Appraisal.new(
    user_id: @profile.user_id,
    period_start: Date.current.beginning_of_year, period_end: Date.current
  )
end

#shareObject



37
38
39
40
41
42
43
44
# File 'app/controllers/hr_lite/admin/appraisals_controller.rb', line 37

def share
  appraisal = scoped.find(params[:id])
  appraisal.share!(actor: hr_current_user)
  redirect_to admin_employee_path(@profile), notice: "Appraisal shared with the employee."
rescue ActiveRecord::RecordInvalid => e
  message = e.record.errors.full_messages.to_sentence.presence || "This appraisal was already shared."
  redirect_to admin_employee_path(@profile), alert: message
end

#updateObject



28
29
30
31
32
33
34
35
# File 'app/controllers/hr_lite/admin/appraisals_controller.rb', line 28

def update
  @appraisal = scoped.find(params[:id])
  if @appraisal.update(appraisal_params)
    redirect_to admin_employee_path(@profile), notice: "Appraisal updated."
  else
    render :edit, status: :unprocessable_entity
  end
end