Class: WorkflowsController

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!

Instance Attribute Details

#batchObject

Returns the value of attribute batch


7
8
9
# File 'app/controllers/workflows_controller.rb', line 7

def batch
  @batch
end

#plate_purpose_optionsObject

Returns the value of attribute plate_purpose_options


7
8
9
# File 'app/controllers/workflows_controller.rb', line 7

def plate_purpose_options
  @plate_purpose_options
end

#spreadsheet_layoutObject

Returns the value of attribute spreadsheet_layout


7
8
9
# File 'app/controllers/workflows_controller.rb', line 7

def spreadsheet_layout
  @spreadsheet_layout
end

Instance Method Details

#batchesObject


42
43
44
45
46
# File 'app/controllers/workflows_controller.rb', line 42

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 { |batch| batch.id }.reverse
end

#indexObject


26
27
28
29
30
31
32
33
# File 'app/controllers/workflows_controller.rb', line 26

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


106
107
108
109
110
111
112
# File 'app/controllers/workflows_controller.rb', line 106

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


35
36
37
38
39
40
# File 'app/controllers/workflows_controller.rb', line 35

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

#sortObject


48
49
50
51
52
53
54
55
56
# File 'app/controllers/workflows_controller.rb', line 48

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


66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'app/controllers/workflows_controller.rb', line 66

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