Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 13 additions & 0 deletions app/controllers/plates_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 8 additions & 6 deletions app/models/sequencescape_submission.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
56 changes: 56 additions & 0 deletions app/views/plates/_choose_workflow.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
allowing you to proceed.
</p>

<div class="form-group row">
<label for="project_cost_code_global" class="plate-label col-md-2">Project / Cost Code</label>
<input type="text" id="project_cost_code_global" class="form-control col-md-8" placeholder="Enter project id and hit enter" />
</div>
<div id="project_search_result" class="col-md-8 offset-md-2" style="margin-bottom: 1em;"></div>

<div id="submission_forms">
<% presenter.each_submission_option do |name, submission| %>
<%= card do %>
Expand Down Expand Up @@ -45,10 +51,60 @@
<% end %>
<% end %>


<input type="hidden" name="submission[project_cost_code]" class="project-cost-code-hidden" />
<input type="hidden" name="sequencescape_submission[supplied_project_uuid]" class="supplied-project-uuid-hidden" />

<%= submit_tag name, class: 'create-submission-button', disabled: presenter.disable_workflow_creation? %>
<% end %>
<% end %>
<% end %>

</div>

<script type="text/javascript">
document.addEventListener('DOMContentLoaded', function() {
const globalInput = document.getElementById('project_cost_code_global');
const resultDiv = document.getElementById('project_search_result');
let foundProjectId = null;

globalInput.addEventListener('keydown', function(e) {
if (e.key === 'Enter') {
e.preventDefault();
const projectId = globalInput.value.trim();
if (!projectId) return;
resultDiv.textContent = 'Searching...';
fetch(`/plates/find_project_by_id?project_id=${encodeURIComponent(projectId)}`)
.then(response => response.json())
.then(data => {
if (data.found) {
foundProjectId = data.project.uuid;
resultDiv.textContent = `Project found: ${data.project.name || data.project.uuid}`;
} else {
foundProjectId = null;
resultDiv.textContent = data.error || 'Project not found.';
}
})
.catch(() => {
foundProjectId = null;
resultDiv.textContent = 'Error searching for project.';
});
}
});

document.querySelectorAll('#submission_forms form').forEach(function(form) {
form.addEventListener('submit', function() {
const hidden = form.querySelector('.project-cost-code-hidden');
const projectIdHidden = form.querySelector('.supplied-project-uuid-hidden');
if (hidden && globalInput) {
hidden.value = globalInput.value;
}
if (projectIdHidden) {
projectIdHidden.value = foundProjectId || '';
}
});
});
});
</script>

<% end %>
3 changes: 3 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading