From ae948e21cbbe6945cc218016a4db8cc35d89189a Mon Sep 17 00:00:00 2001 From: Katy Taylor Date: Thu, 5 Mar 2026 15:24:28 +0000 Subject: [PATCH] Quite functional code made by Github Copilot. Adds a field to the choose workflow component, which allows you to search by project id. Adds project uuid to the payload sent to Sequencescape to create the submission - this part doesn't work yet. To add - only display this field when configured to do so. Take hardcoded project out of submission template. Improve styling / UX. --- .../sequencescape_submission_behaviour.rb | 2 +- app/controllers/plates_controller.rb | 13 +++++ app/models/sequencescape_submission.rb | 14 +++-- app/views/plates/_choose_workflow.html.erb | 56 +++++++++++++++++++ config/routes.rb | 3 + 5 files changed, 81 insertions(+), 7 deletions(-) diff --git a/app/controllers/concerns/sequencescape_submission_behaviour.rb b/app/controllers/concerns/sequencescape_submission_behaviour.rb index 099ac478bb..6be036139e 100644 --- a/app/controllers/concerns/sequencescape_submission_behaviour.rb +++ b/app/controllers/concerns/sequencescape_submission_behaviour.rb @@ -20,7 +20,7 @@ def create_submission def sequencescape_submission_parameters params .require(:sequencescape_submission) - .permit(:template_uuid, :labware_barcode, request_options: {}, assets: [], asset_groups: {}, extra_barcodes: []) + .permit(:template_uuid, :labware_barcode, :supplied_project_uuid, request_options: {}, assets: [], asset_groups: {}, extra_barcodes: []) .merge(user: current_user_uuid) end end diff --git a/app/controllers/plates_controller.rb b/app/controllers/plates_controller.rb index 82d24acaa7..45644b487f 100644 --- a/app/controllers/plates_controller.rb +++ b/app/controllers/plates_controller.rb @@ -5,6 +5,19 @@ # fail_wells => Updates the state of individual wells when failing # Note: Finds plates via the v2 api class PlatesController < LabwareController + # AJAX endpoint to search for a Project by id using Sequencescape API + def find_project_by_id + project_id = params[:project_id] + begin + project = Sequencescape::Api::V2::Project.find!(project_id) + # Ensure we return both id and uuid for clarity + render json: { found: true, project: { id: project.first.id, uuid: project.first.uuid, name: project.first.name } } + rescue JsonApiClient::Errors::NotFound + render json: { found: false, error: 'Project not found' }, status: :not_found + rescue StandardError => e + render json: { found: false, error: e.message }, status: :internal_server_error + end + end before_action :check_for_current_user!, only: %i[update fail_wells] # rubocop:todo Rails/LexicallyScopedActionFilter def fail_wells # rubocop:todo Metrics/AbcSize diff --git a/app/models/sequencescape_submission.rb b/app/models/sequencescape_submission.rb index 5e6fb19034..145753be53 100644 --- a/app/models/sequencescape_submission.rb +++ b/app/models/sequencescape_submission.rb @@ -31,6 +31,7 @@ class SequencescapeSubmission attr_reader :asset_groups attr_accessor :allowed_extra_barcodes, :extra_barcodes, :num_extra_barcodes, :labware_barcode, :submission_uuid + attr_accessor :supplied_project_uuid validates :user, :assets, :template_uuid, :request_options, presence: true validate :check_extra_barcodes @@ -127,12 +128,13 @@ def generate_orders def generate_submissions orders = generate_orders - @submission_uuid = - Sequencescape::Api::V2::Submission.create!( - and_submit: true, - order_uuids: orders.map(&:uuid), - user_uuid: user - ).uuid + submission_params = { + and_submit: true, + order_uuids: orders.map(&:uuid), + user_uuid: user + } + submission_params[:project_uuid] = supplied_project_uuid if supplied_project_uuid.present? + @submission_uuid = Sequencescape::Api::V2::Submission.create!(submission_params).uuid true rescue JsonApiClient::Errors::ConnectionError => e errors.add(:sequencescape_connection, e.message) diff --git a/app/views/plates/_choose_workflow.html.erb b/app/views/plates/_choose_workflow.html.erb index f902bf50c9..72d1189bef 100644 --- a/app/views/plates/_choose_workflow.html.erb +++ b/app/views/plates/_choose_workflow.html.erb @@ -6,6 +6,12 @@ allowing you to proceed.

+
+ + +
+
+
<% presenter.each_submission_option do |name, submission| %> <%= card do %> @@ -45,10 +51,60 @@ <% end %> <% end %> + + + + <%= submit_tag name, class: 'create-submission-button', disabled: presenter.disable_workflow_creation? %> <% end %> <% end %> <% end %> +
+ + <% end %> diff --git a/config/routes.rb b/config/routes.rb index 35a8fecf40..7a768cc7f9 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -32,6 +32,9 @@ resources :qcables, controller: :tag_plates, only: [:show] resources :plates, controller: :plates do + collection do + get 'find_project_by_id', action: :find_project_by_id + end resources :child_plate_creations, controller: :plate_creation resources :child_tube_creations, controller: :tube_creation resources :child_tube_rack_creations, controller: :tube_rack_creation