Module: WorkflowStepController

Extended by:
ActiveSupport::Concern
Defined in:
lib/generators/dunlop/install/workflow/templates/controllers/concerns/workflow_step_controller.rb

Instance Method Summary collapse

Instance Method Details

#collection_editObject

GET /contractor_completion/parallel_onnet_nls1_with_cpes/collection_edit



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/generators/dunlop/install/workflow/templates/controllers/concerns/workflow_step_controller.rb', line 38

def collection_edit
  authorize! :edit, record_class
  if params[:workflow_instance_ids].present?
    params[:workflow_instance_ids] = params[:workflow_instance_ids].split(RecordCollection.ids_separator) if params[:workflow_instance_ids].is_a?(String)
    @collection = record_class.collection.includes(:workflow_instance).joins(:workflow_instance).where(workflow_instances: {id: params[:workflow_instance_ids]})
  elsif params[:workflow_instance_batch_id].present?
    @workflow_instance_batch = WorkflowInstanceBatch.find(params[:workflow_instance_batch_id])
    @collection = record_class.collection.includes(:workflow_instance).joins(:workflow_instance)
      .where(workflow_instances: {workflow_instance_batch_id: @workflow_instance_batch.id})
      .where.not(workflow_instances: {state: 'any_rejected'})
      .refine_relation{ with_last_attribute_changes }
  else
    @collection = record_class.collection.includes(:workflow_instance).find(ids_param)
  end
  render layout: params[:reveal] != 'yes'
end

#collection_updateObject

GET /contractor_completion/parallel_onnet_nls1_with_cpes/collection_edit



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/generators/dunlop/install/workflow/templates/controllers/concerns/workflow_step_controller.rb', line 56

def collection_update
  authorize! :update, record_class
  @collection = record_class.collection.find(ids_param) # automatic security of find on specific sti class

  # Batch reject security
  if params[:workflow_instance_batch_id].present? and record_commit_action == 'reject'
    return redirect_to :back, alert: "You cannot reject an entire batch"
  end

  #TODO: the following code could be much nicer!
  if @collection.trigger_action!(record_commit_action, params[:collection])
    if params[:workflow_instance_batch_id].present?
      @workflow_instance_batch = WorkflowInstanceBatch.find(params[:workflow_instance_batch_id])
      redirect_to @workflow_instance_batch
    elsif @collection.one?
      redirect_to @collection.first.workflow_instance
    else
      redirect_to polymorphic_path([:selection, workflow_instance_class],  ids: @collection.map(&:workflow_instance_id).join(RecordCollection.ids_separator))
    end
  else
    render :collection_edit
  end
end

#destroyObject



33
34
35
# File 'lib/generators/dunlop/install/workflow/templates/controllers/concerns/workflow_step_controller.rb', line 33

def destroy

end

#editObject



10
11
# File 'lib/generators/dunlop/install/workflow/templates/controllers/concerns/workflow_step_controller.rb', line 10

def edit
end

#record_classObject



13
14
15
# File 'lib/generators/dunlop/install/workflow/templates/controllers/concerns/workflow_step_controller.rb', line 13

def record_class
  @record_class ||= self.class.name.sub(/Controller$/, '').split('::').map(&:singularize).join('::').constantize
end

#updateObject

PATCH/PUT /owner_decommission/migrate_line_onnet_without_cpes/1



22
23
24
25
26
27
28
29
30
31
# File 'lib/generators/dunlop/install/workflow/templates/controllers/concerns/workflow_step_controller.rb', line 22

def update
  authorize! :update, record_class
  @record.assign_attributes(record_params)
  if @record.valid?
    @record.public_send "#{record_commit_action}!"
    redirect_to polymorphic_path([@record.workflow_instance])
  else
    render :edit
  end
end

#workflow_instance_classObject



17
18
19
# File 'lib/generators/dunlop/install/workflow/templates/controllers/concerns/workflow_step_controller.rb', line 17

def workflow_instance_class
  @workflow_instance_class ||= "WorkflowInstance::#{self.class.name.split('::').last.sub(/Controller$/, '').singularize}".constantize
end