Class: WorkflowInstancesController

Inherits:
ApplicationController show all
Defined in:
lib/generators/dunlop/install/workflow/templates/controllers/workflow_instances_controller.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.record_batch_classObject



164
165
166
167
# File 'lib/generators/dunlop/install/workflow/templates/controllers/workflow_instances_controller.rb', line 164

def record_batch_class
  return @record_batch_class if @record_batch_class
  @record_batch_class = record_class.try(:batch_class)
end

.record_classObject



157
158
159
160
161
162
# File 'lib/generators/dunlop/install/workflow/templates/controllers/workflow_instances_controller.rb', line 157

def record_class
  return @record_class if @record_class
  parts = controller_path.split('/').map(&:classify)
  parts.pop until klass = parts.join('::').safe_constantize
  @record_class = klass
end

Instance Method Details

#collection_editObject



26
27
28
29
30
31
32
# File 'lib/generators/dunlop/install/workflow/templates/controllers/workflow_instances_controller.rb', line 26

def collection_edit
  authorize! :update, record_class
  redirect_to record_class and return unless @collection.any?
  if params[:reveal].present?
    render layout: false # popup
  end
end

#collection_updateObject



61
62
63
64
65
66
67
68
# File 'lib/generators/dunlop/install/workflow/templates/controllers/workflow_instances_controller.rb', line 61

def collection_update
  authorize! :update, record_class
  if @collection.update params[:collection]
    redirect_to polymorphic_path([:selection, record_class],  ids: @collection.ids)
  else
    render "collection_edit"
  end
end

#indexObject



9
10
11
12
13
14
15
16
17
18
# File 'lib/generators/dunlop/install/workflow/templates/controllers/workflow_instances_controller.rb', line 9

def index
  authorize! :read, record_class
  set_records_for_index
  respond_to do |format|
    format.html do
      @records = @records.page(params[:page]).per(params[:per_page]).decorate
    end
    format.csv { respond_with @records, record_class: record_class, include_notes: params[:include_notes] }
  end
end

#resetObject



70
71
72
73
74
# File 'lib/generators/dunlop/install/workflow/templates/controllers/workflow_instances_controller.rb', line 70

def reset
  authorize! :reset, @record
  @record.reset!
  redirect_to @record
end

#selectionObject

POST /records/selection input=EAP/123; …ETC.…



77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/generators/dunlop/install/workflow/templates/controllers/workflow_instances_controller.rb', line 77

def selection
  authorize! :read, record_class unless record_class == WorkflowInstance
  respond_to do |format|
    format.html do
      @records = find_records_by_ids_or_input decorate: true
    end
    format.csv do
      @records = find_records_by_ids_or_input
      respond_with @records, record_class: record_class, include_notes: params[:include_notes]
    end
  end
end

#showObject



20
21
22
23
24
# File 'lib/generators/dunlop/install/workflow/templates/controllers/workflow_instances_controller.rb', line 20

def show
  authorize! :read, @record
  @record = @record.decorate
  respond_with(@record)
end

#with_bas_correctionObject

This is a custom reporting action where an extra filter is applied to the full index scope. reports



37
38
39
40
41
42
43
44
45
# File 'lib/generators/dunlop/install/workflow/templates/controllers/workflow_instances_controller.rb', line 37

def with_bas_correction
  authorize! :read, record_class
  set_records_for_index
  @records = @records.where(data_corrected_by_bas_data: true).decorate
  respond_to do |format|
    format.html { render action: :selection }
    format.csv { respond_with @records, record_class: record_class, include_notes: params[:include_notes] }
  end
end

#with_incomplete_bas_recordsObject

reports



48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/generators/dunlop/install/workflow/templates/controllers/workflow_instances_controller.rb', line 48

def with_incomplete_bas_records
  authorize! :read, record_class
  set_records_for_index
  @records = @records.with_incomplete_bas_records.decorate
  respond_to do |format|
    format.html do
      redirect_to :back, notice: "There are no incompletely enriched DSLAMs" and return unless @records.any?
      render action: :selection
    end
    format.csv { respond_with @records, record_class: record_class, include_notes: params[:include_notes] }
  end
end

#workflow_instance_classObject



5
# File 'lib/generators/dunlop/install/workflow/templates/controllers/workflow_instances_controller.rb', line 5

alias_method :workflow_instance_class, :record_class