Class: WorkflowsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- WorkflowsController
- Includes:
- Tasks::CherrypickHandler, Tasks::PlateTemplateHandler, Tasks::PlateTransferHandler, Tasks::SetDescriptorsHandler
- Defined in:
- app/controllers/workflows_controller.rb
Overview
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
-
#batch ⇒ Object
Returns the value of attribute batch.
-
#plate_purpose_options ⇒ Object
Returns the value of attribute plate_purpose_options.
-
#spreadsheet_layout ⇒ Object
Returns the value of attribute spreadsheet_layout.
Instance Method Summary collapse
-
#render_task(task, params) ⇒ Object
Default render task activity, eg.
-
#stage ⇒ Object
TODO: This needs to be made RESTful.
Methods included from Tasks::SetDescriptorsHandler
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::CherrypickHandler
#do_cherrypick_task, included, #render_cherrypick_task, #setup_input_params_for_pass_through
Methods inherited from ApplicationController
#block_api_access, #evil_parameter_hack!, #extract_header_info, #set_cache_disabled!
Methods included from FlashTruncation
#max_flash_size, #truncate_flash, #truncate_flash_array
Instance Attribute Details
#batch ⇒ Object
Returns the value of attribute batch.
21 22 23 |
# File 'app/controllers/workflows_controller.rb', line 21 def batch @batch end |
#plate_purpose_options ⇒ Object
Returns the value of attribute plate_purpose_options.
21 22 23 |
# File 'app/controllers/workflows_controller.rb', line 21 def @plate_purpose_options end |
#spreadsheet_layout ⇒ Object
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
#render_task(task, params) ⇒ Object
Default render task activity, eg. from Task#render_task
86 87 88 89 90 91 92 |
# File 'app/controllers/workflows_controller.rb', line 86 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 |
#stage ⇒ Object
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 rubocop:todo Metrics/PerceivedComplexity, Metrics/MethodLength, Metrics/AbcSize
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'app/controllers/workflows_controller.rb', line 39 def stage # rubocop:todo Metrics/CyclomaticComplexity @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]) editable, = @task.can_process?(@batch) unless editable redirect_back fallback_location: batch_path(@batch), alert: return false end ActiveRecord::Base.transaction do task_success, = @task.do_task(self, params, current_user) if task_success # Task completed, start the batch is necessary and display the next one start_batch @stage += 1 params[:id] = @stage @task = @workflow.tasks[@stage] end flash[task_success ? :notice : :alert] ||= if end end if params[:commit] == 'Update' redirect_to batch_path(@batch) elsif @stage >= @workflow.tasks.size # All requests have finished all tasks: finish workflow redirect_to finish_batch_path(@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, current_user) end end |