Class: Wf::WorkitemsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/wf/workitems_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#wf_current_user

Instance Method Details

#check_finishObject



81
82
83
84
85
# File 'app/controllers/wf/workitems_controller.rb', line 81

def check_finish
  unless @workitem.finished_by?(wf_current_user)
    redirect_to workitem_path(@workitem), notice: "You can not the holding use of this workitem, Please assign to youself && start it first."
  end
end

#check_startObject



75
76
77
78
79
# File 'app/controllers/wf/workitems_controller.rb', line 75

def check_start
  unless @workitem.started_by?(wf_current_user)
    redirect_to workitem_path(@workitem), notice: "You can not start this workitem, Please assign to youself first."
  end
end

#find_workitemObject



71
72
73
# File 'app/controllers/wf/workitems_controller.rb', line 71

def find_workitem
  @workitem = Wf::Workitem.find(params[:id])
end

#finishObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/controllers/wf/workitems_controller.rb', line 43

def finish
  if @workitem.transition.form && params[:workitem][:entry]
    form = @workitem.transition.form
    cmd = Wf::CaseCommand::CreateEntry.call(form, @workitem, wf_current_user, params[:workitem][:entry].permit!)
    if cmd.success?
      Wf::CaseCommand::FinishWorkitem.call(@workitem)
      finish_and_redirect
    else
      redirect_to pre_finish_workitem_path(@workitem), notice: "Your input no OK."
    end
  else
    Wf::CaseCommand::FinishWorkitem.call(@workitem)
    finish_and_redirect
  end
end

#finish_and_redirectObject



59
60
61
62
63
64
65
66
67
68
69
# File 'app/controllers/wf/workitems_controller.rb', line 59

def finish_and_redirect
  if @workitem.case.finished?
    if started_by = @workitem.case.started_by_workitem
      redirect_to workflow_case_path(started_by.workflow, started_by.case), notice: "workitem is done, and goto parent case."
    else
      redirect_to workflow_case_path(@workitem.workflow, @workitem.case), notice: "workitem is done, and the case is finished."
    end
  else
    redirect_to workitem_path(@workitem.case.workitems.enabled.first), notice: "workitem is done, and goto next fireable workitem."
  end
end

#indexObject



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

def index
  current_party_ids = [
    wf_current_user,
    Wf.org_classes.map { |org, _org_class| wf_current_user&.public_send(org) }
  ].flatten.map { |x| x&.party&.id }.compact
  @workitems = Wf::Workitem.joins(:workitem_assignments).where(Wf::WorkitemAssignment.table_name => { party_id: current_party_ids })
  @workitems = @workitems.where(state: params[:state].intern) if params[:state]
  @workitems = @workitems.where(state: params[:state].intern) if params[:state].present?
  @workitems = @workitems.distinct.order("id desc").page(params[:page])
end

#pre_finishObject



37
38
39
40
41
# File 'app/controllers/wf/workitems_controller.rb', line 37

def pre_finish
  breadcrumb @workitem.workflow.name, workflow_path(@workitem.workflow)
  breadcrumb @workitem.case.name, workflow_case_path(@workitem.workflow, @workitem.case)
  breadcrumb @workitem.name, workitem_path(@workitem)
end

#showObject



24
25
26
27
# File 'app/controllers/wf/workitems_controller.rb', line 24

def show
  breadcrumb @workitem.workflow.name, workflow_path(@workitem.workflow)
  breadcrumb @workitem.case.name, workflow_case_path(@workitem.workflow, @workitem.case)
end

#startObject



29
30
31
32
33
34
35
# File 'app/controllers/wf/workitems_controller.rb', line 29

def start
  Wf::CaseCommand::StartWorkitem.call(@workitem, wf_current_user)
  breadcrumb @workitem.workflow.name, workflow_path(@workitem.workflow)
  breadcrumb @workitem.case.name, workflow_case_path(@workitem.workflow, @workitem.case)
  breadcrumb @workitem.name, workitem_path(@workitem)
  render :pre_finish
end