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



77
78
79
80
81
# File 'app/controllers/wf/workitems_controller.rb', line 77

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



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

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



67
68
69
# File 'app/controllers/wf/workitems_controller.rb', line 67

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

#finishObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'app/controllers/wf/workitems_controller.rb', line 39

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



55
56
57
58
59
60
61
62
63
64
65
# File 'app/controllers/wf/workitems_controller.rb', line 55

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
# File 'app/controllers/wf/workitems_controller.rb', line 13

def index
  @workitems = Wf::Workitem.todo(wf_current_user)
  @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



33
34
35
36
37
# File 'app/controllers/wf/workitems_controller.rb', line 33

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



20
21
22
23
# File 'app/controllers/wf/workitems_controller.rb', line 20

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

#startObject



25
26
27
28
29
30
31
# File 'app/controllers/wf/workitems_controller.rb', line 25

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