Class: WorkflowsController

Overview

Note:

A large amount of the task processing actually occurs within the controller. These methods are included via the various Handler modules.

Controls progress through the tasks in a Workflow as part of taking a Batch through a Pipeline

#stage is the main processing step, and responds to all HTTP methods. The currently active task is supplied by params

If params is nil it will render the page associated with the current Task using Task#render_task If params is present it will perform the current Task using Task#do_task before incrementing the stage and rendering the next task. If there are no further tasks present, it will redirect to the finish_batch page.

Constant Summary

Constants included from FlashTruncation

FlashTruncation::STRING_OVERHEAD

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Tasks::StartBatchHandler

#do_start_batch_task

Methods included from Tasks::ValidateSampleSheetHandler

#do_validate_sample_sheet_task, #render_validate_sample_sheet_task

Methods included from Tasks::TagGroupHandler

#render_tag_groups_task

Methods included from Tasks::SetCharacterisationDescriptorsHandler

#do_set_characterisation_descriptors_task, #render_set_characterisation_descriptors_task

Methods included from Tasks::SetDescriptorsHandler

#do_set_descriptors_task, #render_set_descriptors_task

Methods included from Tasks::SamplePrepQcHandler

#do_sample_prep_qc_task, #render_sample_prep_qc_task

Methods included from Tasks::PrepKitBarcodeHandler

#do_prep_kit_barcode_task, #render_prep_kit_barcode_task

Methods included from Tasks::PlateTransferHandler

#do_plate_transfer_task, #find_or_create_target, #includes_for_plate_creation, #render_plate_transfer_task, #target_plate

Methods included from Tasks::PlateTemplateHandler

generate_spreadsheet, #render_plate_template_task

Methods included from Tasks::MovieLengthHandler

#do_movie_length_task, #render_movie_length_task

Methods included from Tasks::CherrypickHandler

#do_cherrypick_task, included, #render_cherrypick_task, #setup_input_params_for_pass_through

Methods included from Tasks::BindingKitBarcodeHandler

#do_binding_kit_barcode_task, #render_binding_kit_barcode_task

Methods included from Tasks::AssignTubesToWellsHandler

#do_assign_pick_volume_task, #do_assign_requests_to_multiplexed_wells_task, #find_or_create_plate

Methods included from Tasks::AssignTagsToTubesHandler

#do_assign_tags_to_destination_task

Methods included from Tasks::AssignTagsHandler

#do_assign_tags_task, #render_assign_tags_task

Methods included from Tasks::AddSpikedInControlHandler

#do_add_spiked_in_control_task

Methods inherited from ApplicationController

#block_api_access, #clean_params_from_check, #evil_parameter_hack!, #extract_header_info, #set_cache_disabled!

Methods included from FlashTruncation

#max_flash_size, #truncate_flash, #truncate_flash_array

Instance Attribute Details

#batchObject

Returns the value of attribute batch


21
22
23
# File 'app/controllers/workflows_controller.rb', line 21

def batch
  @batch
end

#plate_purpose_optionsObject

Returns the value of attribute plate_purpose_options


21
22
23
# File 'app/controllers/workflows_controller.rb', line 21

def plate_purpose_options
  @plate_purpose_options
end

#spreadsheet_layoutObject

Returns the value of attribute spreadsheet_layout


21
22
23
# File 'app/controllers/workflows_controller.rb', line 21

def spreadsheet_layout
  @spreadsheet_layout
end

Instance Method Details

#batchesObject

TODO:

Remove

Presumably used to list all batches associated with a workflow Not listed in routes


66
67
68
69
70
# File 'app/controllers/workflows_controller.rb', line 66

def batches
  @workflow = Workflow.find(params[:id])
  # TODO: association broken here - something to do with the attachables polymorph?
  @batches = Batch.where(workflow_id: @workflow.id).sort_by(&:id).reverse
end

#indexObject

TODO:

Remove (Including route)

Note:

JG: While this works, I don't think it is used.

Lists all the workflows


43
44
45
46
47
48
49
50
# File 'app/controllers/workflows_controller.rb', line 43

def index
  @workflows = Workflow.all

  respond_to do |format|
    format.html
    format.xml { render xml: @workflows.to_xml }
  end
end

#render_task(task, params) ⇒ Object

Default render task activity, eg. from Task#render_task


134
135
136
137
138
139
140
# File 'app/controllers/workflows_controller.rb', line 134

def render_task(task, params)
  @rits = @batch.pipeline.request_information_types
  @requests = @batch.requests

  @workflow = Workflow.includes(:tasks).find(params[:workflow_id])
  @task = task
end

#showObject

TODO:

Remove (Including route)

Note:

JG: This is a remnant from when workflows were user editable. I don't believe it is used and while it doesn't throw exceptions, its output is likely misleading for many pipelines.

Shows a summary of the steps within a workflow


56
57
58
59
60
61
# File 'app/controllers/workflows_controller.rb', line 56

def show
  respond_to do |format|
    format.html
    format.xml { render xml: @workflow.to_xml }
  end
end

#sortObject

TODO:

Remove (Including route, which doesn't even seem to match up properly). Also tested in workflows_controller_test.rb, but that test can be removed.

Appears to be remnant of workflow editing? Shouldn't be in use any more.


75
76
77
78
79
80
81
82
83
# File 'app/controllers/workflows_controller.rb', line 75

def sort
  @workflow = Workflow.find(params[:workflow_id])
  @task_list = @workflow.tasks
  @task_list.each do |task|
    task.sorted = params['task_list'].index(task.id.to_s) + 1
    task.save
  end
  head :ok
end

#stageObject

TODO: This needs to be made RESTful. 1: Routes need to be refactored to provide more sensible urls 2: We call them tasks in the code, and stages in the URL. They should be consistent 3: This endpoint currently does two jobs, executing the current task, and rendering the next 4: Some tasks rely on parameters passed in from the previous task. This isn't ideal, but it might

be worth maintaining the behaviour until we solve the problems.

5: We need to improve the repeatability of tasks. 6: GET should be Idempotent. doing a task should be a POST


93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'app/controllers/workflows_controller.rb', line 93

def stage
  @workflow = Workflow.includes(:tasks).find(params[:workflow_id])
  @stage = params[:id].to_i
  @task = @workflow.tasks[@stage]
  # If params[:next_stage] is nil then just render the current task
  # else actually execute the task.
  unless params[:next_stage].nil?

    eager_loading = @task.included_for_do_task
    @batch ||= Batch.includes(eager_loading).find(params[:batch_id])

    unless @batch.editable?
      flash[:error] = 'You cannot make changes to a completed batch.'
      redirect_back fallback_location: root_path
      return false
    end

    ActiveRecord::Base.transaction do
      if @task.do_task(self, params)
        # Task completed, start the batch is necessary and display the next one
        do_start_batch_task(@task, params)
        @stage += 1
        params[:id] = @stage
        @task = @workflow.tasks[@stage]
      end
    end
  end

  # Is this the last task in the workflow?
  if @stage >= @workflow.tasks.size
    # All requests have finished all tasks: finish workflow
    redirect_to finish_batch_url(@batch)
  else
    if @batch.nil? || @task.included_for_render_task != eager_loading
      @batch = Batch.includes(@task.included_for_render_task).find(params[:batch_id])
    end
    @task.render_task(self, params)
  end
end