From c18a0d49af8d4decdd10b35961357eb014d4f8f4 Mon Sep 17 00:00:00 2001 From: Kevin De Pelseneer Date: Fri, 10 Jan 2025 14:29:16 +0100 Subject: [PATCH 1/2] Better message for querying samples - Doesn't fail if attribute is not selected - Provides a message when a query fails - Provides an error message when an error occurs - Spinner is added to indicate a running query --- app/controllers/samples_controller.rb | 4 ++-- app/views/samples/query.js.erb | 2 +- app/views/samples/query_form.html.erb | 16 +++++++++++++++- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/app/controllers/samples_controller.rb b/app/controllers/samples_controller.rb index e71fa98022..faf841b349 100644 --- a/app/controllers/samples_controller.rb +++ b/app/controllers/samples_controller.rb @@ -247,7 +247,7 @@ def query end end - if params[:input_template_id].present? # linked + if params[:input_template_id].present? && params[:input_attribute_id].present? # linked input_template_attribute = TemplateAttribute.find(params[:input_attribute_id]) @result = filter_linked_samples(@result, :linked_samples, @@ -256,7 +256,7 @@ def query template_id: params[:input_template_id] }, input_template_attribute) end - if params[:output_template_id].present? # linking + if params[:output_template_id].present? && params[:output_attribute_id].present? # linking output_template_attribute = TemplateAttribute.find(params[:output_attribute_id]) @result = filter_linked_samples(@result, :linking_samples, diff --git a/app/views/samples/query.js.erb b/app/views/samples/query.js.erb index 116b356e01..5c8473cb31 100644 --- a/app/views/samples/query.js.erb +++ b/app/views/samples/query.js.erb @@ -1,3 +1,3 @@ $j('#samples-table').html('<%= escape_javascript(render(partial: "table_view", locals: { samples: @result, link: true, show_extra_info: true })) -%>'); -$j('#sample-count').html('<%= "#{@visible_samples} sample(s) visible to you" %>') +$j('#sample-count').html('<%= "#{@visible_samples}"%> sample(s) visible to you' + ' - Successful query @ <%= "#{Time.now.strftime("%d/%m/%Y %H:%M:%S")}" %>') Samples.initTable($j('#samples-table'), false, { hideEmptyColumns: true }); diff --git a/app/views/samples/query_form.html.erb b/app/views/samples/query_form.html.erb index 72e351a2f2..7d4c403569 100644 --- a/app/views/samples/query_form.html.erb +++ b/app/views/samples/query_form.html.erb @@ -121,6 +121,9 @@
+
+ <%= image("spinner") %> +

@@ -137,6 +140,7 @@ $j(document).ready(function () { initSelect2($j('.select2'), $j('#query_samples')) Samples.initTable($j('#samples-table')); + $j('#sample-query-spinner').hide(); }); $j("#template").on("change", function(){ @@ -187,7 +191,17 @@ $j.ajax({ url: "<%=query_samples_path%>", method: "POST", - data + data, + beforeSend: function(){ + $j("#sample-query-spinner").show(); + $j('#samples-table').html(""); + }, + error: function(err){ + $j('#sample-count').html(`

Error [code ${err.status}]: Failed to fetch query results!

`) + }, + complete: function(){ + $j("#sample-query-spinner").hide() + } }) } From 0579950b87effe4a6cf7f173557226ba56288869 Mon Sep 17 00:00:00 2001 From: Kevin De Pelseneer Date: Fri, 10 Jan 2025 14:40:23 +0100 Subject: [PATCH 2/2] Empty sample count juts before sending request --- app/views/samples/query_form.html.erb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/views/samples/query_form.html.erb b/app/views/samples/query_form.html.erb index 7d4c403569..fa6b0dd2b4 100644 --- a/app/views/samples/query_form.html.erb +++ b/app/views/samples/query_form.html.erb @@ -193,6 +193,7 @@ method: "POST", data, beforeSend: function(){ + $j('#sample-count').html(""); $j("#sample-query-spinner").show(); $j('#samples-table').html(""); },