From e33ae168608431c41b07b7dfafe4f28274798b41 Mon Sep 17 00:00:00 2001 From: Josh Adam Date: Fri, 22 Dec 2023 10:04:52 -0600 Subject: [PATCH 01/64] chore: Setup fake metadata for samples --- Gemfile | 4 ++++ Gemfile.lock | 3 +++ db/seeds.rb | 13 +++++++++++++ 3 files changed, 20 insertions(+) diff --git a/Gemfile b/Gemfile index 542f5f0428..7843498cc8 100644 --- a/Gemfile +++ b/Gemfile @@ -118,6 +118,10 @@ group :development do # Use console on exceptions pages [https://github.com/rails/web-console] gem 'web-console' + gem 'graphiql-rails' + + gem 'faker' + # Add speed badges [https://github.com/MiniProfiler/rack-mini-profiler] # gem "rack-mini-profiler" diff --git a/Gemfile.lock b/Gemfile.lock index 55330bde1e..41e394ed5f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -171,6 +171,8 @@ GEM erubi (1.12.0) et-orbi (1.2.7) tzinfo + faker (3.2.2) + i18n (>= 1.8.11, < 2) faraday (2.0.0) ruby2_keywords (>= 0.0.4) faraday-follow_redirects (0.3.0) @@ -557,6 +559,7 @@ DEPENDENCIES debug devise (~> 4.9.2) erb-formatter (~> 0.4.3) + faker faraday faraday-net_http_persistent (~> 2.0) fx diff --git a/db/seeds.rb b/db/seeds.rb index 7d4bb0f2fd..1d5b89b214 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +require 'faker' + @namespace_group_link_expiry_date = (Time.zone.today + 14).strftime('%Y-%m-%d') # This file should contain all the record creation needed to seed the database with its default values. @@ -64,6 +66,17 @@ def seed_samples(project, sample_count) { name: "#{project.namespace.parent.name}/#{project.name} Sample #{i}", description: "This is a description for sample #{project.namespace.parent.name}/#{project.name} Sample #{i}." } ).execute + + # Add metadata + params = { 'metadata' => { + 'province' => Faker::Address.state, + 'food' => Faker::Food.dish, + 'gender' => Faker::Gender.binary_type, + 'age' => Faker::Number.between(from: 1, to: 100), + 'onset' => Faker::Date.between(from: 2.years.ago, to: Date.today) + } } + Samples::Metadata::UpdateService.new(project, sample, project.creator, params).execute + # exit if max total samples has been reached next unless @maximum_total_sample_attachments == -1 || @total_sample_attachment_count < @maximum_total_sample_attachments From 3037c4b8e50abe25c6c1f01bd4417435777d004d Mon Sep 17 00:00:00 2001 From: Josh Adam Date: Fri, 22 Dec 2023 11:38:30 -0600 Subject: [PATCH 02/64] chore: Working template selector --- app/controllers/application_controller.rb | 1 + app/controllers/projects/samples_controller.rb | 18 ++++++++++++++++++ app/helpers/url_helper.rb | 12 ++++++++++++ app/views/projects/samples/_table.html.erb | 12 +++++++++++- app/views/projects/samples/index.html.erb | 2 ++ .../projects/samples/index.turbo_stream.erb | 14 ++++++++++++++ 6 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 app/helpers/url_helper.rb diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 320102fbfc..4226b87724 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -5,6 +5,7 @@ class ApplicationController < ActionController::Base include Irida::Auth include Pagy::Backend include RouteHelper + include UrlHelper add_flash_types :success, :info, :warning, :danger before_action :authenticate_user! diff --git a/app/controllers/projects/samples_controller.rb b/app/controllers/projects/samples_controller.rb index ac91f65a36..d52ccfac89 100644 --- a/app/controllers/projects/samples_controller.rb +++ b/app/controllers/projects/samples_controller.rb @@ -8,6 +8,9 @@ class SamplesController < Projects::ApplicationController def index authorize! @project, to: :sample_listing? + @templates = [{ id: 0, label: 'Default' }, { id: 1, label: 'Template 1' }, + { id: 2, label: 'Template 2' }] + @template = template(params[:template] || 'Default') @q = load_samples.ransack(params[:q]) set_default_sort @@ -115,5 +118,20 @@ def current_page def set_default_sort @q.sorts = 'updated_at desc' if @q.sorts.empty? end + + def load_samples + Sample.where(project_id: @project.id) + end + + def template(id) + case id + when '1' + %w[province onset] + when '2' + %w[province food gender age onset] + else + %w[] + end + end end end diff --git a/app/helpers/url_helper.rb b/app/helpers/url_helper.rb new file mode 100644 index 0000000000..5233c7e3ed --- /dev/null +++ b/app/helpers/url_helper.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +module UrlHelper + def pagy_template_url_for(pagy, template) + pagy_url = pagy_url_for(pagy, pagy.page) + uri = URI.parse(pagy_url) + params = Rack::Utils.parse_query(uri.query) + params['template'] = template + uri.query = Rack::Utils.build_query(params) + uri.to_s + end +end diff --git a/app/views/projects/samples/_table.html.erb b/app/views/projects/samples/_table.html.erb index 15a4d0f5f2..bc8746c9f0 100644 --- a/app/views/projects/samples/_table.html.erb +++ b/app/views/projects/samples/_table.html.erb @@ -18,7 +18,12 @@ <%= render Ransack::SortComponent.new(ransack_obj: @q, label: t(".updated_at"), url: sorting_url(@q, :updated_at), field: :updated_at) %> - <%= t(".action") %> + <% @template.each do |column| %> + <%= column %> + <% end %> + <% if allowed_to?(:update_sample?, project) %> + <%= t(".action") %> + <% end %> <%= viral_time_ago(original_time: sample.updated_at) %> + <% @template.each do |column| %> + + <%= sample[column].present? ? sample[column] : sample.metadata[column] %> + + <% end %> <% if allowed_to?(:update_sample?, project) %>
diff --git a/app/views/projects/samples/index.html.erb b/app/views/projects/samples/index.html.erb index 5967185ec0..64689430aa 100644 --- a/app/views/projects/samples/index.html.erb +++ b/app/views/projects/samples/index.html.erb @@ -53,6 +53,8 @@ placeholder: t(".search.placeholder") %>
<% end %> + <%= turbo_frame_tag "project_samples_sort_dropdown" %> + <%= turbo_frame_tag "project_metadata_template" %>
diff --git a/app/views/projects/samples/index.turbo_stream.erb b/app/views/projects/samples/index.turbo_stream.erb index 5bf532bd9d..d7674bc829 100644 --- a/app/views/projects/samples/index.turbo_stream.erb +++ b/app/views/projects/samples/index.turbo_stream.erb @@ -12,6 +12,20 @@ pagy: @pagy } %> +<%= turbo_stream.update "project_metadata_template" do %> + <%= viral_dropdown(label: "Template", caret: true) do |dropdown| %> + <%= @templates.each do |template| %> + <%= dropdown.with_item( + label: template[:label], + url: pagy_template_url_for(@pagy, template[:id]).gsub("samples.turbo_stream", "samples"), + data: { + turbo_stream: true + } + ) %> + <% end %> + <% end %> +<% end %> + <%= turbo_stream.update "project_samples_hidden_search_value" do %> <%= render Ransack::HiddenSortFieldComponent.new(@q) %> <% end %> From f541c304bfcbf26ee2bdc588711da38e06d383ec Mon Sep 17 00:00:00 2001 From: Josh Adam Date: Fri, 22 Dec 2023 11:45:17 -0600 Subject: [PATCH 03/64] chore: persist template in search --- app/controllers/projects/samples_controller.rb | 2 +- app/views/dashboard/projects/index.html.erb | 2 +- app/views/dashboard/projects/index.turbo_stream.erb | 2 +- app/views/projects/samples/index.html.erb | 2 +- app/views/projects/samples/index.turbo_stream.erb | 3 ++- 5 files changed, 6 insertions(+), 5 deletions(-) diff --git a/app/controllers/projects/samples_controller.rb b/app/controllers/projects/samples_controller.rb index d52ccfac89..2edf3cf23e 100644 --- a/app/controllers/projects/samples_controller.rb +++ b/app/controllers/projects/samples_controller.rb @@ -10,7 +10,7 @@ def index authorize! @project, to: :sample_listing? @templates = [{ id: 0, label: 'Default' }, { id: 1, label: 'Template 1' }, { id: 2, label: 'Template 2' }] - @template = template(params[:template] || 'Default') + @template = template(params[:template] || 0) @q = load_samples.ransack(params[:q]) set_default_sort diff --git a/app/views/dashboard/projects/index.html.erb b/app/views/dashboard/projects/index.html.erb index 80e70ed636..69b2b96e32 100644 --- a/app/views/dashboard/projects/index.html.erb +++ b/app/views/dashboard/projects/index.html.erb @@ -60,7 +60,7 @@
<%= viral_icon(name: "magnifying_glass", classes: "h-5 w-5") %>
- <%= turbo_frame_tag "project_hidden_search_value" %> + <%= turbo_frame_tag "project_hidden_values" %> <%= f.search_field :namespace_name_cont, "data-action": "filters#submit", class: diff --git a/app/views/dashboard/projects/index.turbo_stream.erb b/app/views/dashboard/projects/index.turbo_stream.erb index be9c3cf04e..8ddd29a201 100644 --- a/app/views/dashboard/projects/index.turbo_stream.erb +++ b/app/views/dashboard/projects/index.turbo_stream.erb @@ -57,6 +57,6 @@ ) %> <% end %> -<%= turbo_stream.update "project_hidden_search_value" do %> +<%= turbo_stream.update "project_hidden_values" do %> <%= render Ransack::HiddenSortFieldComponent.new(@q) %> <% end %> diff --git a/app/views/projects/samples/index.html.erb b/app/views/projects/samples/index.html.erb index 64689430aa..546463bf1e 100644 --- a/app/views/projects/samples/index.html.erb +++ b/app/views/projects/samples/index.html.erb @@ -45,7 +45,7 @@
<%= viral_icon(name: "magnifying_glass", classes: "h-5 w-5") %>
- <%= turbo_frame_tag "project_samples_hidden_search_value" %> + <%= turbo_frame_tag "project_samples_hidden_values" %> <%= f.search_field :name_cont, "data-action": "filters#submit", class: diff --git a/app/views/projects/samples/index.turbo_stream.erb b/app/views/projects/samples/index.turbo_stream.erb index d7674bc829..ea3d6a8e15 100644 --- a/app/views/projects/samples/index.turbo_stream.erb +++ b/app/views/projects/samples/index.turbo_stream.erb @@ -26,6 +26,7 @@ <% end %> <% end %> -<%= turbo_stream.update "project_samples_hidden_search_value" do %> +<%= turbo_stream.update "project_samples_hidden_values" do %> <%= render Ransack::HiddenSortFieldComponent.new(@q) %> + <%= hidden_field_tag "template", params[:template] %> <% end %> From de62f9be65c10e9f507e9934eb38c28829a7dc84 Mon Sep 17 00:00:00 2001 From: Josh Adam Date: Fri, 22 Dec 2023 11:47:31 -0600 Subject: [PATCH 04/64] chore: Update dropdown label --- app/views/projects/samples/index.turbo_stream.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/projects/samples/index.turbo_stream.erb b/app/views/projects/samples/index.turbo_stream.erb index ea3d6a8e15..51e54bdf12 100644 --- a/app/views/projects/samples/index.turbo_stream.erb +++ b/app/views/projects/samples/index.turbo_stream.erb @@ -13,7 +13,7 @@ } %> <%= turbo_stream.update "project_metadata_template" do %> - <%= viral_dropdown(label: "Template", caret: true) do |dropdown| %> + <%= viral_dropdown(label: "Metadata", caret: true) do |dropdown| %> <%= @templates.each do |template| %> <%= dropdown.with_item( label: template[:label], From 47611a2551166b800fd606535c61f72ea0665225 Mon Sep 17 00:00:00 2001 From: Josh Adam Date: Fri, 22 Dec 2023 11:48:02 -0600 Subject: [PATCH 05/64] chore: Renamed default to none --- app/controllers/projects/samples_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/projects/samples_controller.rb b/app/controllers/projects/samples_controller.rb index 2edf3cf23e..4ab6239111 100644 --- a/app/controllers/projects/samples_controller.rb +++ b/app/controllers/projects/samples_controller.rb @@ -8,7 +8,7 @@ class SamplesController < Projects::ApplicationController def index authorize! @project, to: :sample_listing? - @templates = [{ id: 0, label: 'Default' }, { id: 1, label: 'Template 1' }, + @templates = [{ id: 0, label: 'None' }, { id: 1, label: 'Template 1' }, { id: 2, label: 'Template 2' }] @template = template(params[:template] || 0) From 70fc4b7f79317d46b3ed933d87718ff11a65257d Mon Sep 17 00:00:00 2001 From: Josh Adam Date: Tue, 2 Jan 2024 05:30:41 -0600 Subject: [PATCH 06/64] chore: Updated time_ago component to inherit parent component's text style --- app/components/viral/time_ago_component.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/components/viral/time_ago_component.html.erb b/app/components/viral/time_ago_component.html.erb index 10db535908..e38a2cd32c 100644 --- a/app/components/viral/time_ago_component.html.erb +++ b/app/components/viral/time_ago_component.html.erb @@ -1,3 +1,3 @@ <%= viral_tooltip(title: l(original_time, format: :long)) do %> - <%= time_ago %> + <%= time_ago %> <% end %> From 2932a0a49f293a1cf6436d246d8bae89de02ccc4 Mon Sep 17 00:00:00 2001 From: Josh Adam Date: Tue, 2 Jan 2024 05:33:46 -0600 Subject: [PATCH 07/64] chore: Updated missing module comment --- app/helpers/url_helper.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/helpers/url_helper.rb b/app/helpers/url_helper.rb index 5233c7e3ed..e181d1d201 100644 --- a/app/helpers/url_helper.rb +++ b/app/helpers/url_helper.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true +# Helper functions for anything to do with URLs module UrlHelper def pagy_template_url_for(pagy, template) pagy_url = pagy_url_for(pagy, pagy.page) From cebf3ded2b33372a02a35728cc7c1a2640a4d1d4 Mon Sep 17 00:00:00 2001 From: Josh Adam Date: Tue, 2 Jan 2024 09:08:36 -0600 Subject: [PATCH 08/64] chore: Changed Faker to use en-CA --- config/application.rb | 2 +- db/seeds.rb | 21 +++++++++++++-------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/config/application.rb b/config/application.rb index 9f79fa3f61..cb9c5fe7a8 100644 --- a/config/application.rb +++ b/config/application.rb @@ -53,7 +53,7 @@ class Application < Rails::Application end # Only enables en and fr locales, avoiding unnecessarily loading other locales - config.i18n.available_locales = %i[en fr] + config.i18n.available_locales = %i[en fr en-CA] # Set default locale config.i18n.default_locale = :en diff --git a/db/seeds.rb b/db/seeds.rb index 1d5b89b214..466f75b2b5 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -2,6 +2,8 @@ require 'faker' +Faker::Config.locale = 'en-CA' + @namespace_group_link_expiry_date = (Time.zone.today + 14).strftime('%Y-%m-%d') # This file should contain all the record creation needed to seed the database with its default values. @@ -59,6 +61,16 @@ def seed_namespace_group_links(user, namespace, group, group_access_level) expires_at: @namespace_group_link_expiry_date }).execute end +def fake_metadata + { + 'province' => Faker::Address.state, + 'food' => Faker::Food.dish, + 'gender' => Faker::Gender.binary_type, + 'age' => Faker::Number.between(from: 1, to: 100), + 'onset' => Faker::Date.between(from: 2.years.ago, to: Time.zone.today) + } +end + def seed_samples(project, sample_count) 1.upto(sample_count) do |i| sample = Samples::CreateService.new( @@ -68,14 +80,7 @@ def seed_samples(project, sample_count) ).execute # Add metadata - params = { 'metadata' => { - 'province' => Faker::Address.state, - 'food' => Faker::Food.dish, - 'gender' => Faker::Gender.binary_type, - 'age' => Faker::Number.between(from: 1, to: 100), - 'onset' => Faker::Date.between(from: 2.years.ago, to: Date.today) - } } - Samples::Metadata::UpdateService.new(project, sample, project.creator, params).execute + Samples::Metadata::UpdateService.new(project, sample, project.creator, { 'metadata' => fake_metadata }).execute # exit if max total samples has been reached next unless @maximum_total_sample_attachments == -1 || From be0bcede46f54f227fab93f7df4339d07debd321 Mon Sep 17 00:00:00 2001 From: Josh Adam Date: Tue, 2 Jan 2024 14:22:31 -0600 Subject: [PATCH 09/64] chore: Horizontal scrolling when metadata is displayed --- .../projects/samples_controller.rb | 2 +- app/views/projects/samples/_table.html.erb | 32 ++++--- app/views/projects/samples/index.html.erb | 96 +++++++++---------- 3 files changed, 62 insertions(+), 68 deletions(-) diff --git a/app/controllers/projects/samples_controller.rb b/app/controllers/projects/samples_controller.rb index 4ab6239111..2ba8ef5961 100644 --- a/app/controllers/projects/samples_controller.rb +++ b/app/controllers/projects/samples_controller.rb @@ -10,7 +10,7 @@ def index authorize! @project, to: :sample_listing? @templates = [{ id: 0, label: 'None' }, { id: 1, label: 'Template 1' }, { id: 2, label: 'Template 2' }] - @template = template(params[:template] || 0) + @template = template(params[:template] || '0') @q = load_samples.ransack(params[:q]) set_default_sort diff --git a/app/views/projects/samples/_table.html.erb b/app/views/projects/samples/_table.html.erb index bc8746c9f0..ddb8c8667e 100644 --- a/app/views/projects/samples/_table.html.erb +++ b/app/views/projects/samples/_table.html.erb @@ -1,28 +1,29 @@ - +
- + <% if allowed_to?(:transfer_sample?, project) %> <% end %> - - - <% @template.each do |column| %> - + <% end %> <% if allowed_to?(:update_sample?, project) %> - + <% end %> @@ -37,8 +38,8 @@ > <% samples.each do |sample| %> <% if allowed_to?(:transfer_sample?, project) %> <% end %> - - - <% @template.each do |column| %> - <% end %> <% if allowed_to?(:update_sample?, project) %> -
+ <%= render Ransack::SortComponent.new(ransack_obj: @q, label: t(".sample"), url: sorting_url(@q, :name), field: :name) %> + <%= render Ransack::SortComponent.new(ransack_obj: @q, label: t(".created_at"), url: sorting_url(@q, :created_at), field: :created_at) %> + <%= render Ransack::SortComponent.new(ransack_obj: @q, label: t(".updated_at"), url: sorting_url(@q, :updated_at), field: :updated_at) %> <%= column %><%= column %><%= t(".action") %><%= t(".action") %>
@@ -55,7 +56,7 @@ "w-4 h-4 text-primary-600 bg-slate-100 border-slate-300 rounded focus:ring-primary-500 dark:focus:ring-primary-600 dark:ring-offset-slate-800 focus:ring-2 dark:bg-slate-700 dark:border-slate-600" %> + <%= link_to sample.name, namespace_project_sample_path(id: sample.id), data: { @@ -63,19 +64,19 @@ }, class: "text-grey-900 dark:text-grey-100 font-semibold hover:underline" %> + <%= l(sample.created_at.localtime, format: :full_date) %> + <%= viral_time_ago(original_time: sample.updated_at) %> + <%= sample[column].present? ? sample[column] : sample.metadata[column] %> +
<%= viral_dropdown(icon: "ellipsis_vertical", aria: { label: t(:'projects.samples.index.actions.dropdown_aria_label', sample_name: sample.name) }) do |dropdown| %> <%= dropdown.with_item( @@ -103,3 +104,4 @@ <% end %>
+
\ No newline at end of file diff --git a/app/views/projects/samples/index.html.erb b/app/views/projects/samples/index.html.erb index 546463bf1e..ea7d8e92c9 100644 --- a/app/views/projects/samples/index.html.erb +++ b/app/views/projects/samples/index.html.erb @@ -6,29 +6,29 @@ <%= component.with_buttons do %>
<%= link_to pipeline_selection_workflow_executions_submissions_path, data: { turbo_frame: "samples_dialog", turbo_stream: true, controller: "action-link", action_link_required_value: 1 }, - class: "button button--size-default button--state-default action-link" do %> + class: "button button--size-default button--state-default action-link" do %> <%= viral_icon( - name: :rocket_launch, - classes: "w-5 h-5 inline-block" - ) %> + name: :rocket_launch, + classes: "w-5 h-5 inline-block" + ) %> <%= t(:".workflows.button_sr") %> <% end %> <% if allowed_to?(:transfer_sample?, @project) %> <%= link_to t("projects.samples.index.transfer_button"), - new_namespace_project_samples_transfer_path, - data: { - turbo_frame: "samples_dialog", - turbo_stream: true, - controller: "action-link", - action_link_required_value: 1 - }, - class: "button button--size-default button--state-default action-link" %> + new_namespace_project_samples_transfer_path, + data: { + turbo_frame: "samples_dialog", + turbo_stream: true, + controller: "action-link", + action_link_required_value: 1 + }, + class: "button button--size-default button--state-default action-link" %> <% end %> <% if allowed_to?(:create_sample?, @project) %> <%= link_to t("projects.samples.index.new_button"), - new_namespace_project_sample_path, - class: "button button--size-default button--state-primary", - "aria-label": t(".actions.button_add_aria_label") %> + new_namespace_project_sample_path, + class: "button button--size-default button--state-primary", + "aria-label": t(".actions.button_add_aria_label") %> <% end %>
<% end %> @@ -38,8 +38,8 @@ class="flex text-sm font-medium text-center border-b text-slate-500 border-slate-200 dark:text-slate-400 dark:border-slate-700" >
- <%= search_form_for @q, url: namespace_project_samples_url(**request.query_parameters), html: {"data-controller": "filters"} do |f| %> - + <%= search_form_for @q, url: namespace_project_samples_url(**request.query_parameters), html: { "data-controller": "filters" } do |f| %> + <%= f.label :name_cont, placeholder: t(".search.placeholder"), class: "sr-only" %>
@@ -47,45 +47,37 @@
<%= turbo_frame_tag "project_samples_hidden_values" %> <%= f.search_field :name_cont, - "data-action": "filters#submit", - class: - "block w-full p-2.5 pl-10 text-sm text-slate-900 border border-slate-300 rounded-lg bg-slate-50 focus:ring-primary-500 focus:border-primary-500 dark:bg-slate-700 dark:border-slate-600 dark:placeholder-slate-400 dark:text-white dark:focus:ring-primary-500 dark:focus:border-primary-500", - placeholder: t(".search.placeholder") %> + "data-action": "filters#submit", + class: + "block w-full p-2.5 pl-10 text-sm text-slate-900 border border-slate-300 rounded-lg bg-slate-50 focus:ring-primary-500 focus:border-primary-500 dark:bg-slate-700 dark:border-slate-600 dark:placeholder-slate-400 dark:text-white dark:focus:ring-primary-500 dark:focus:border-primary-500", + placeholder: t(".search.placeholder") %>
<% end %> <%= turbo_frame_tag "project_samples_sort_dropdown" %> <%= turbo_frame_tag "project_metadata_template" %>
-
-
-
-
- <%= turbo_frame_tag "project_samples_list", - src: project_samples_path(@project, format: :turbo_stream, **request.query_parameters), - loading: :lazy do %> - - - <% 15.times do %> - - - - <% end %> - -
-
-
-
-
-
-
-
- <% end %> -
-
- <%= turbo_frame_tag "project_samples_pagination" %> -
-
+ <%= turbo_frame_tag "project_samples_list", + src: project_samples_path(@project, format: :turbo_stream, **request.query_parameters), + loading: :lazy do %> + + + <% 15.times do %> + + + + <% end %> + +
+
+
+
+
+
+
+
+ <% end %> + <%= turbo_frame_tag "project_samples_pagination" %> <% end %> From 60b9c79290e3e4f53205185458f65e53e426342e Mon Sep 17 00:00:00 2001 From: Josh Adam Date: Tue, 2 Jan 2024 14:38:13 -0600 Subject: [PATCH 10/64] chore: Ignore rubocop metrics methodlength --- db/seeds.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/db/seeds.rb b/db/seeds.rb index 466f75b2b5..6978b7c419 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -72,6 +72,7 @@ def fake_metadata end def seed_samples(project, sample_count) + # rubocop:disable Metrics/MethodLength 1.upto(sample_count) do |i| sample = Samples::CreateService.new( project.creator, project, From d1f3bf2ae45bf3b1ee042bc879114fca9562fd64 Mon Sep 17 00:00:00 2001 From: Josh Adam Date: Tue, 2 Jan 2024 14:52:37 -0600 Subject: [PATCH 11/64] chore: Disable abcsize --- db/seeds.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/db/seeds.rb b/db/seeds.rb index 6978b7c419..e70fc76cb2 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -67,12 +67,12 @@ def fake_metadata 'food' => Faker::Food.dish, 'gender' => Faker::Gender.binary_type, 'age' => Faker::Number.between(from: 1, to: 100), - 'onset' => Faker::Date.between(from: 2.years.ago, to: Time.zone.today) + 'onset' => Faker::Date.between(from: 2.years.ago.to_s, to: Time.zone.today) } end def seed_samples(project, sample_count) - # rubocop:disable Metrics/MethodLength + # rubocop:disable Metrics/MethodLength Metrics/AbcSize 1.upto(sample_count) do |i| sample = Samples::CreateService.new( project.creator, project, From 40514b3a792c49b1a5c48150432624449482ca5f Mon Sep 17 00:00:00 2001 From: Josh Adam Date: Tue, 2 Jan 2024 14:59:14 -0600 Subject: [PATCH 12/64] chore: Fixed incorrect rubocop syntax --- db/seeds.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/seeds.rb b/db/seeds.rb index e70fc76cb2..d99be9c505 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -72,7 +72,7 @@ def fake_metadata end def seed_samples(project, sample_count) - # rubocop:disable Metrics/MethodLength Metrics/AbcSize + # rubocop:disable Metrics/MethodLength, Metrics/AbcSize 1.upto(sample_count) do |i| sample = Samples::CreateService.new( project.creator, project, From babe8c468f282c96a07fe5ec06288bc8305d3a40 Mon Sep 17 00:00:00 2001 From: Josh Adam Date: Tue, 2 Jan 2024 15:05:14 -0600 Subject: [PATCH 13/64] chore: Moved rubocop message --- db/seeds.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/seeds.rb b/db/seeds.rb index d99be9c505..b767d07807 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -71,8 +71,8 @@ def fake_metadata } end +# rubocop:disable Metrics/MethodLength, Metrics/AbcSize def seed_samples(project, sample_count) - # rubocop:disable Metrics/MethodLength, Metrics/AbcSize 1.upto(sample_count) do |i| sample = Samples::CreateService.new( project.creator, project, From b8f6ac6d9786656514f240787a0ad82c8550765d Mon Sep 17 00:00:00 2001 From: Josh Adam Date: Wed, 3 Jan 2024 05:08:28 -0600 Subject: [PATCH 14/64] chore: Re-enable rubocop after method --- db/seeds.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/db/seeds.rb b/db/seeds.rb index b767d07807..ee147fe0fe 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -71,7 +71,7 @@ def fake_metadata } end -# rubocop:disable Metrics/MethodLength, Metrics/AbcSize +# rubocop:disable Metrics/AbcSize def seed_samples(project, sample_count) 1.upto(sample_count) do |i| sample = Samples::CreateService.new( @@ -96,6 +96,8 @@ def seed_samples(project, sample_count) end end +# rubocop:enable Metrics/AbcSize + def seed_attachments(sample) (0..(@attachments_per_sample - 1)).each do |i| # file list is index'd at 0 Rails.logger.info "seeding... Sample: #{sample.name}, Attachments... #{i + 1}/#{@attachments_per_sample}" From 01e48a30d14e1ac41efd308808da63f26c857638 Mon Sep 17 00:00:00 2001 From: Josh Adam Date: Wed, 3 Jan 2024 09:32:05 -0600 Subject: [PATCH 15/64] chore: Moved rubocop to inline with method declaration --- db/seeds.rb | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/db/seeds.rb b/db/seeds.rb index ee147fe0fe..2b65a30203 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -71,8 +71,7 @@ def fake_metadata } end -# rubocop:disable Metrics/AbcSize -def seed_samples(project, sample_count) +def seed_samples(project, sample_count) # rubocop:disable Metrics/AbcSize 1.upto(sample_count) do |i| sample = Samples::CreateService.new( project.creator, project, @@ -96,8 +95,6 @@ def seed_samples(project, sample_count) end end -# rubocop:enable Metrics/AbcSize - def seed_attachments(sample) (0..(@attachments_per_sample - 1)).each do |i| # file list is index'd at 0 Rails.logger.info "seeding... Sample: #{sample.name}, Attachments... #{i + 1}/#{@attachments_per_sample}" From 579f68466e40b6f20b398c78986d252a2b56ff5e Mon Sep 17 00:00:00 2001 From: Josh Adam Date: Wed, 3 Jan 2024 10:29:52 -0600 Subject: [PATCH 16/64] chore: Updated transfer to use templates --- .../projects/samples/transfers_controller.rb | 4 ++- .../projects/samples_controller.rb | 28 +++++++++++-------- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/app/controllers/projects/samples/transfers_controller.rb b/app/controllers/projects/samples/transfers_controller.rb index 13e3d0a91c..0a5355f118 100644 --- a/app/controllers/projects/samples/transfers_controller.rb +++ b/app/controllers/projects/samples/transfers_controller.rb @@ -3,9 +3,11 @@ module Projects module Samples # Controller actions for Project Samples Transfer - class TransfersController < Projects::ApplicationController + class TransfersController < Projects::SamplesController respond_to :turbo_stream before_action :projects + before_action :templates, only: %i[new create] + before_action :template, only: %i[new create] def new authorize! @project, to: :transfer_sample? diff --git a/app/controllers/projects/samples_controller.rb b/app/controllers/projects/samples_controller.rb index 2ba8ef5961..d2110519b3 100644 --- a/app/controllers/projects/samples_controller.rb +++ b/app/controllers/projects/samples_controller.rb @@ -5,12 +5,11 @@ module Projects class SamplesController < Projects::ApplicationController before_action :sample, only: %i[show edit update destroy] before_action :current_page + before_action :templates, only: %i[index] + before_action :template, only: %i[index] def index authorize! @project, to: :sample_listing? - @templates = [{ id: 0, label: 'None' }, { id: 1, label: 'Template 1' }, - { id: 2, label: 'Template 2' }] - @template = template(params[:template] || '0') @q = load_samples.ransack(params[:q]) set_default_sort @@ -123,15 +122,20 @@ def load_samples Sample.where(project_id: @project.id) end - def template(id) - case id - when '1' - %w[province onset] - when '2' - %w[province food gender age onset] - else - %w[] - end + def templates + @templates = [{ id: 0, label: 'None' }, { id: 1, label: 'Template 1' }, + { id: 2, label: 'Template 2' }] + end + + def template + @template = case params[:template] + when '1' + %w[province onset] + when '2' + %w[province food gender age onset] + else + %w[] + end end end end From 3d9bf5c364c03c8f4d9f665d47a3e2ab4c9a018e Mon Sep 17 00:00:00 2001 From: Josh Adam Date: Wed, 3 Jan 2024 12:27:00 -0600 Subject: [PATCH 17/64] chore: Fixed selector for timeago --- test/components/viral/system/time_ago_component_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/components/viral/system/time_ago_component_test.rb b/test/components/viral/system/time_ago_component_test.rb index 6a00f61848..0d5e0362ba 100644 --- a/test/components/viral/system/time_ago_component_test.rb +++ b/test/components/viral/system/time_ago_component_test.rb @@ -10,7 +10,7 @@ class TimeAgoComponentTest < ApplicationSystemTestCase assert_text '15 days ago' within('.Viral-Preview > [data-controller-connected="true"]') do assert_selector '[data-viral--tooltip-target="target"]', visible: false - find('span.text-sm', text: '15 days ago').hover + find('span', text: '15 days ago').hover assert_text (DateTime.now - 15.days).strftime('%B %d, %Y %H:%M') assert_selector '[data-viral--tooltip-target="target"]', visible: true end @@ -22,7 +22,7 @@ class TimeAgoComponentTest < ApplicationSystemTestCase assert_text '5 days ago' within('.Viral-Preview > [data-controller-connected="true"]') do assert_selector '[data-viral--tooltip-target="target"]', visible: false - find('span.text-sm', text: '5 days ago').hover + find('span', text: '5 days ago').hover assert_text (DateTime.now - 15.days).strftime('%B %d, %Y %H:%M') assert_selector '[data-viral--tooltip-target="target"]', visible: true end From a8f58a29eb862e63ad499c0d938d9a10257e8726 Mon Sep 17 00:00:00 2001 From: Josh Adam Date: Wed, 3 Jan 2024 12:52:11 -0600 Subject: [PATCH 18/64] revert: dom_id sample already set elsewhere --- app/views/projects/samples/_table.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/projects/samples/_table.html.erb b/app/views/projects/samples/_table.html.erb index ddb8c8667e..fca511b247 100644 --- a/app/views/projects/samples/_table.html.erb +++ b/app/views/projects/samples/_table.html.erb @@ -38,7 +38,7 @@ > <% samples.each do |sample| %> <% if allowed_to?(:transfer_sample?, project) %> From f1be09b772f1aef50037e701750d5412be75b3a4 Mon Sep 17 00:00:00 2001 From: Josh Adam Date: Tue, 9 Jan 2024 08:45:19 -0600 Subject: [PATCH 19/64] chore: Matched table styling to existing tables --- app/views/projects/samples/_table.html.erb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/projects/samples/_table.html.erb b/app/views/projects/samples/_table.html.erb index fca511b247..9ee3666203 100644 --- a/app/views/projects/samples/_table.html.erb +++ b/app/views/projects/samples/_table.html.erb @@ -1,4 +1,4 @@ -
+
<% if allowed_to?(:transfer_sample?, project) %> <% end %> <% if allowed_to?(:update_sample?, project) %> - + <% end %> @@ -41,28 +41,26 @@ id="<%= sample.id %>" class="bg-white border-b dark:bg-slate-800 dark:border-slate-700" > - <% if allowed_to?(:transfer_sample?, project) %> - - <% end %> - +
From d652a3aec3cddb0b04e55ea3a814785f08b34946 Mon Sep 17 00:00:00 2001 From: Josh Adam Date: Tue, 9 Jan 2024 09:30:07 -0600 Subject: [PATCH 20/64] chore: This should be lower case --- app/views/workflow_executions/index.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/workflow_executions/index.html.erb b/app/views/workflow_executions/index.html.erb index 6901fc4bd1..588cd5369c 100644 --- a/app/views/workflow_executions/index.html.erb +++ b/app/views/workflow_executions/index.html.erb @@ -38,7 +38,7 @@ <%= workflow.metadata["workflow_version"] %> - <%= workflow["state"] || "NEW" %> + <%= workflow["state"] || "new" %> <%= viral_time_ago(original_time: workflow["created_at"]) %> From 6071275b16178b7fb9f7ecf56b770e2caa3df801 Mon Sep 17 00:00:00 2001 From: Josh Adam Date: Tue, 9 Jan 2024 10:54:59 -0600 Subject: [PATCH 21/64] chore: Fix the sample name column when horizontal scrolling --- app/views/projects/samples/_table.html.erb | 32 ++++++++++------------ 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/app/views/projects/samples/_table.html.erb b/app/views/projects/samples/_table.html.erb index 9ee3666203..f4652a8f11 100644 --- a/app/views/projects/samples/_table.html.erb +++ b/app/views/projects/samples/_table.html.erb @@ -23,7 +23,7 @@ <%= column %><%= t(".action") %><%= t(".action") %>
+ + <% if allowed_to?(:transfer_sample?, project) %> <%= check_box_tag "sample_ids[]", - sample.id, - nil, - id: dom_id(sample), - "aria-label": sample.name, - data: { - action: "input->selection#toggle", - selection_target: "rowSelection" - }, - class: - "w-4 h-4 text-primary-600 bg-slate-100 border-slate-300 rounded focus:ring-primary-500 dark:focus:ring-primary-600 dark:ring-offset-slate-800 focus:ring-2 dark:bg-slate-700 dark:border-slate-600" %> - + sample.id, + nil, + id: dom_id(sample), + "aria-label": sample.name, + data: { + action: "input->selection#toggle", + selection_target: "rowSelection" + }, + class: + "w-4 h-4 mr-2.5 text-primary-600 bg-slate-100 border-slate-300 rounded focus:ring-primary-500 dark:focus:ring-primary-600 dark:ring-offset-slate-800 focus:ring-2 dark:bg-slate-700 dark:border-slate-600" %> + <% end %> <%= link_to sample.name, namespace_project_sample_path(id: sample.id), data: { turbo: false }, - class: "text-grey-900 dark:text-grey-100 font-semibold hover:underline" %> + class: "text-slate-900 dark:text-slate-100 font-semibold hover:underline" %> <%= l(sample.created_at.localtime, format: :full_date) %> From 4245949d636cacdc7745969866107b067948e104 Mon Sep 17 00:00:00 2001 From: Josh Adam Date: Fri, 12 Jan 2024 08:53:26 -0600 Subject: [PATCH 22/64] chore: Fixed bad merge --- Gemfile | 2 -- 1 file changed, 2 deletions(-) diff --git a/Gemfile b/Gemfile index 7843498cc8..b29551edd5 100644 --- a/Gemfile +++ b/Gemfile @@ -118,8 +118,6 @@ group :development do # Use console on exceptions pages [https://github.com/rails/web-console] gem 'web-console' - gem 'graphiql-rails' - gem 'faker' # Add speed badges [https://github.com/MiniProfiler/rack-mini-profiler] From 805ff5ddf0e75628d6e209c7902dedc1923fbf0d Mon Sep 17 00:00:00 2001 From: Josh Adam Date: Fri, 12 Jan 2024 09:23:25 -0600 Subject: [PATCH 23/64] chore: Fixed broken tests after moving checkbox --- test/system/projects/samples_test.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/system/projects/samples_test.rb b/test/system/projects/samples_test.rb index 1265b36fee..939d137714 100644 --- a/test/system/projects/samples_test.rb +++ b/test/system/projects/samples_test.rb @@ -194,7 +194,7 @@ class SamplesTest < ApplicationSystemTestCase assert_no_selector 'table#samples-table tbody tr', text: @sample1.name assert_selector 'h1', text: I18n.t(:'projects.samples.index.title'), count: 1 assert_selector 'table#samples-table tbody tr', count: 2 - within first('tbody tr td:nth-child(2)') do + within first('tbody tr td:first-child') do assert_text @sample2.name end end @@ -424,7 +424,7 @@ class SamplesTest < ApplicationSystemTestCase visit namespace_project_samples_url(@namespace, @project) assert_selector 'table#samples-table tbody tr', count: 3 - within first('tbody tr td:nth-child(2)') do + within first('tbody tr td:first-child') do assert_text @sample1.name end @@ -489,7 +489,7 @@ class SamplesTest < ApplicationSystemTestCase visit namespace_project_samples_url(@namespace, @project) assert_selector 'table#samples-table tbody tr', count: 3 - within first('tbody tr td:nth-child(2)') do + within first('tbody tr td:first-child') do assert_text @sample1.name end @@ -503,7 +503,7 @@ class SamplesTest < ApplicationSystemTestCase click_on I18n.t('projects.samples.table.sample') assert_selector 'table#samples-table tbody tr', count: 1 - within first('tbody tr td:nth-child(2)') do + within first('tbody tr td:first-child') do assert_text @sample1.name end end @@ -512,7 +512,7 @@ class SamplesTest < ApplicationSystemTestCase visit namespace_project_samples_url(@namespace, @project) assert_selector 'table#samples-table tbody tr', count: 3 - within first('tbody tr td:nth-child(2)') do + within first('tbody tr td:first-child') do assert_text @sample1.name end @@ -520,7 +520,7 @@ class SamplesTest < ApplicationSystemTestCase click_on I18n.t('projects.samples.table.sample') assert_selector 'table#samples-table tbody tr', count: 3 - within first('tbody tr td:nth-child(2)') do + within first('tbody tr td:first-child') do assert_text @sample3.name end From d322861831b419225599a33b1858fbce67b8d52f Mon Sep 17 00:00:00 2001 From: Josh Adam Date: Mon, 15 Jan 2024 13:56:00 -0600 Subject: [PATCH 24/64] chore: Work on updating seeds --- app/controllers/projects/samples_controller.rb | 4 ++-- db/seeds.rb | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/app/controllers/projects/samples_controller.rb b/app/controllers/projects/samples_controller.rb index d2110519b3..42f6941a01 100644 --- a/app/controllers/projects/samples_controller.rb +++ b/app/controllers/projects/samples_controller.rb @@ -130,9 +130,9 @@ def templates def template @template = case params[:template] when '1' - %w[province onset] + %w[WGS_id country onset] when '2' - %w[province food gender age onset] + %w[WGS_id NCBI_ACCESSION country food gender age onset] else %w[] end diff --git a/db/seeds.rb b/db/seeds.rb index 2b65a30203..7a15a2a192 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -63,11 +63,14 @@ def seed_namespace_group_links(user, namespace, group, group_access_level) def fake_metadata { - 'province' => Faker::Address.state, + 'WGS_id' => Faker::Number.number(digits: 10), + 'NCBI_ACCESSION' => "NM_#{Faker::Number.decimal(l_digits: 7, r_digits: 1)}", + 'country' => Faker::Address.country, 'food' => Faker::Food.dish, 'gender' => Faker::Gender.binary_type, 'age' => Faker::Number.between(from: 1, to: 100), 'onset' => Faker::Date.between(from: 2.years.ago.to_s, to: Time.zone.today) + # SourceState earliest_date species subspecies serovar patient_sex patient_age source_type source_site TypeDetails Event ID Outbreak FNC travel comments Category } end From 88414db59237032465c9a964f1a7af5d42993132 Mon Sep 17 00:00:00 2001 From: Josh Adam Date: Mon, 15 Jan 2024 18:50:18 -0600 Subject: [PATCH 25/64] chore: Updated to use more accurate fake data --- app/controllers/projects/samples_controller.rb | 4 ++-- db/seeds.rb | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/controllers/projects/samples_controller.rb b/app/controllers/projects/samples_controller.rb index 42f6941a01..be195888d8 100644 --- a/app/controllers/projects/samples_controller.rb +++ b/app/controllers/projects/samples_controller.rb @@ -130,9 +130,9 @@ def templates def template @template = case params[:template] when '1' - %w[WGS_id country onset] + %w[WGS_id country earliest_date] when '2' - %w[WGS_id NCBI_ACCESSION country food gender age onset] + %w[WGS_id NCBI_ACCESSION country patient_sex earliest_date] else %w[] end diff --git a/db/seeds.rb b/db/seeds.rb index 7a15a2a192..dc6928e0e5 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -69,8 +69,10 @@ def fake_metadata 'food' => Faker::Food.dish, 'gender' => Faker::Gender.binary_type, 'age' => Faker::Number.between(from: 1, to: 100), - 'onset' => Faker::Date.between(from: 2.years.ago.to_s, to: Time.zone.today) - # SourceState earliest_date species subspecies serovar patient_sex patient_age source_type source_site TypeDetails Event ID Outbreak FNC travel comments Category + 'onset' => Faker::Date.between(from: 2.years.ago.to_s, to: Time.zone.today), + 'earliest_date' => Faker::Date.between(from: 2.years.ago.to_s, to: Time.zone.today), + 'patient_sex' => Faker::Gender.binary_type + # SourceState species subspecies serovar patient_sex patient_age source_type source_site TypeDetails Event ID Outbreak FNC travel comments Category } end From 538bf671bc5f066d16c5377a4a0e59b0157767af Mon Sep 17 00:00:00 2001 From: Josh Adam Date: Mon, 15 Jan 2024 18:56:34 -0600 Subject: [PATCH 26/64] chore: Made first column darker since it is fixed when scrolling --- app/views/projects/samples/_table.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/projects/samples/_table.html.erb b/app/views/projects/samples/_table.html.erb index f4652a8f11..cb5527fa1a 100644 --- a/app/views/projects/samples/_table.html.erb +++ b/app/views/projects/samples/_table.html.erb @@ -41,7 +41,7 @@ id="<%= sample.id %>" class="bg-white border-b dark:bg-slate-800 dark:border-slate-700" > - + <% if allowed_to?(:transfer_sample?, project) %> <%= check_box_tag "sample_ids[]", sample.id, From 9b371b4803a8a131bd15ccb9636b84796627a6ae Mon Sep 17 00:00:00 2001 From: Josh Adam Date: Mon, 15 Jan 2024 19:12:35 -0600 Subject: [PATCH 27/64] chore: Fixed line length of commmented out extra fields --- db/seeds.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/db/seeds.rb b/db/seeds.rb index dc6928e0e5..2896810119 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -72,7 +72,8 @@ def fake_metadata 'onset' => Faker::Date.between(from: 2.years.ago.to_s, to: Time.zone.today), 'earliest_date' => Faker::Date.between(from: 2.years.ago.to_s, to: Time.zone.today), 'patient_sex' => Faker::Gender.binary_type - # SourceState species subspecies serovar patient_sex patient_age source_type source_site TypeDetails Event ID Outbreak FNC travel comments Category + # SourceState species subspecies serovar patient_sex patient_age + # source_type source_site TypeDetails Event ID Outbreak FNC travel comments Category } end From 1072c4be3262856f5088cd051e0518bc28188a3b Mon Sep 17 00:00:00 2001 From: Josh Adam Date: Tue, 16 Jan 2024 07:09:50 -0600 Subject: [PATCH 28/64] chore: Cleaned up dark mode first column colours --- app/views/projects/samples/_table.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/projects/samples/_table.html.erb b/app/views/projects/samples/_table.html.erb index cb5527fa1a..96281d1acc 100644 --- a/app/views/projects/samples/_table.html.erb +++ b/app/views/projects/samples/_table.html.erb @@ -41,7 +41,7 @@ id="<%= sample.id %>" class="bg-white border-b dark:bg-slate-800 dark:border-slate-700" > - + <% if allowed_to?(:transfer_sample?, project) %> <%= check_box_tag "sample_ids[]", sample.id, From f664e58d8ae33394a9a4649c8fe88de49cdc1214 Mon Sep 17 00:00:00 2001 From: Josh Adam Date: Tue, 16 Jan 2024 10:48:23 -0600 Subject: [PATCH 29/64] chore: Removed commented out lines of possible fields --- app/controllers/projects/samples_controller.rb | 2 +- db/seeds.rb | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/app/controllers/projects/samples_controller.rb b/app/controllers/projects/samples_controller.rb index be195888d8..6c4453bc36 100644 --- a/app/controllers/projects/samples_controller.rb +++ b/app/controllers/projects/samples_controller.rb @@ -132,7 +132,7 @@ def template when '1' %w[WGS_id country earliest_date] when '2' - %w[WGS_id NCBI_ACCESSION country patient_sex earliest_date] + %w[WGS_id NCBI_ACCESSION country patient_age patient_sex earliest_date] else %w[] end diff --git a/db/seeds.rb b/db/seeds.rb index 2896810119..e1666c0fa2 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -71,9 +71,8 @@ def fake_metadata 'age' => Faker::Number.between(from: 1, to: 100), 'onset' => Faker::Date.between(from: 2.years.ago.to_s, to: Time.zone.today), 'earliest_date' => Faker::Date.between(from: 2.years.ago.to_s, to: Time.zone.today), - 'patient_sex' => Faker::Gender.binary_type - # SourceState species subspecies serovar patient_sex patient_age - # source_type source_site TypeDetails Event ID Outbreak FNC travel comments Category + 'patient_sex' => Faker::Gender.binary_type, + 'patient_age' => Faker::Number.between(from: 1, to: 100) } end From d77ed0791b7c6b63b95161541c08e9644e7c9a38 Mon Sep 17 00:00:00 2001 From: Josh Adam Date: Wed, 17 Jan 2024 11:26:04 -0600 Subject: [PATCH 30/64] chore: Display only all or none for metadata field templates --- app/controllers/projects/samples_controller.rb | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/app/controllers/projects/samples_controller.rb b/app/controllers/projects/samples_controller.rb index 6c4453bc36..06bfe58fcd 100644 --- a/app/controllers/projects/samples_controller.rb +++ b/app/controllers/projects/samples_controller.rb @@ -122,17 +122,18 @@ def load_samples Sample.where(project_id: @project.id) end + def all_metadata_fields + @all_metadata_fields = @project.namespace.metadata_summary + end + def templates - @templates = [{ id: 0, label: 'None' }, { id: 1, label: 'Template 1' }, - { id: 2, label: 'Template 2' }] + @templates = [{ id: 0, label: 'None' }, { id: 1, label: 'All' }] end def template @template = case params[:template] when '1' - %w[WGS_id country earliest_date] - when '2' - %w[WGS_id NCBI_ACCESSION country patient_age patient_sex earliest_date] + @project.namespace.metadata_summary.keys else %w[] end From 5d00731f864a94416b260ea9323a418ed5d44527 Mon Sep 17 00:00:00 2001 From: Josh Adam Date: Fri, 19 Jan 2024 07:34:38 -0600 Subject: [PATCH 31/64] chore: Fixed group samples table spacing issues --- app/views/groups/samples/_table.html.erb | 31 ++++++++++++++++++------ 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/app/views/groups/samples/_table.html.erb b/app/views/groups/samples/_table.html.erb index d1684af67d..b4bf1812d7 100644 --- a/app/views/groups/samples/_table.html.erb +++ b/app/views/groups/samples/_table.html.erb @@ -1,5 +1,22 @@ - - +
+ - - - - From e7db78bac9adb3820bc309c640df8941beafaa3e Mon Sep 17 00:00:00 2001 From: Josh Adam Date: Mon, 22 Jan 2024 09:18:35 -0600 Subject: [PATCH 32/64] chore: Fixed rebase errors --- app/views/projects/samples/_table.html.erb | 3 --- 1 file changed, 3 deletions(-) diff --git a/app/views/projects/samples/_table.html.erb b/app/views/projects/samples/_table.html.erb index 96281d1acc..e805c59ccc 100644 --- a/app/views/projects/samples/_table.html.erb +++ b/app/views/projects/samples/_table.html.erb @@ -7,9 +7,6 @@ > - <% if allowed_to?(:transfer_sample?, project) %> - - <% end %> From a90e613702dd74a77ed09ef077fc51d4dd2c09f2 Mon Sep 17 00:00:00 2001 From: Josh Adam Date: Mon, 22 Jan 2024 13:42:30 -0600 Subject: [PATCH 33/64] chore: Moved common methods to Projects::ApplicationController --- .../projects/application_controller.rb | 17 +++++++++++++++ .../projects/samples/transfers_controller.rb | 2 +- .../projects/samples_controller.rb | 21 ------------------- 3 files changed, 18 insertions(+), 22 deletions(-) diff --git a/app/controllers/projects/application_controller.rb b/app/controllers/projects/application_controller.rb index f4272c25c4..943ae4e540 100644 --- a/app/controllers/projects/application_controller.rb +++ b/app/controllers/projects/application_controller.rb @@ -23,5 +23,22 @@ def context_crumbs def load_samples Sample.where(project_id: @project.id) end + + def all_metadata_fields + @all_metadata_fields = @project.namespace.metadata_summary + end + + def templates + @templates = [{ id: 0, label: 'None' }, { id: 1, label: 'All' }] + end + + def template + @template = case params[:template] + when '1' + @project.namespace.metadata_summary.keys + else + %w[] + end + end end end diff --git a/app/controllers/projects/samples/transfers_controller.rb b/app/controllers/projects/samples/transfers_controller.rb index 0a5355f118..01d4291648 100644 --- a/app/controllers/projects/samples/transfers_controller.rb +++ b/app/controllers/projects/samples/transfers_controller.rb @@ -3,7 +3,7 @@ module Projects module Samples # Controller actions for Project Samples Transfer - class TransfersController < Projects::SamplesController + class TransfersController < Projects::ApplicationController respond_to :turbo_stream before_action :projects before_action :templates, only: %i[new create] diff --git a/app/controllers/projects/samples_controller.rb b/app/controllers/projects/samples_controller.rb index 06bfe58fcd..9863277d31 100644 --- a/app/controllers/projects/samples_controller.rb +++ b/app/controllers/projects/samples_controller.rb @@ -117,26 +117,5 @@ def current_page def set_default_sort @q.sorts = 'updated_at desc' if @q.sorts.empty? end - - def load_samples - Sample.where(project_id: @project.id) - end - - def all_metadata_fields - @all_metadata_fields = @project.namespace.metadata_summary - end - - def templates - @templates = [{ id: 0, label: 'None' }, { id: 1, label: 'All' }] - end - - def template - @template = case params[:template] - when '1' - @project.namespace.metadata_summary.keys - else - %w[] - end - end end end From 2e2d917ed09aecb6a694c3bd45ba2a0e3b096187 Mon Sep 17 00:00:00 2001 From: Josh Adam Date: Tue, 23 Jan 2024 06:19:37 -0600 Subject: [PATCH 34/64] chore: Fixed table header when horizontally scrolling --- app/views/projects/samples/_table.html.erb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/views/projects/samples/_table.html.erb b/app/views/projects/samples/_table.html.erb index e805c59ccc..ea9c691a65 100644 --- a/app/views/projects/samples/_table.html.erb +++ b/app/views/projects/samples/_table.html.erb @@ -7,20 +7,20 @@ > - - - <% @template.each do |column| %> - + <% end %> <% if allowed_to?(:update_sample?, project) %> - + <% end %> From e0ea0111ec6e9dffdf1efcc92ca09d91627203db Mon Sep 17 00:00:00 2001 From: Josh Adam Date: Tue, 23 Jan 2024 08:48:51 -0600 Subject: [PATCH 35/64] chore: Moved template logic into a concern --- app/controllers/concerns/metadata_templates.rb | 14 ++++++++++++++ .../projects/application_controller.rb | 17 ----------------- app/controllers/projects/samples_controller.rb | 6 +++++- app/views/projects/samples/index.html.erb | 2 +- 4 files changed, 20 insertions(+), 19 deletions(-) create mode 100644 app/controllers/concerns/metadata_templates.rb diff --git a/app/controllers/concerns/metadata_templates.rb b/app/controllers/concerns/metadata_templates.rb new file mode 100644 index 0000000000..493abb7186 --- /dev/null +++ b/app/controllers/concerns/metadata_templates.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +# Executes basic metadata template logic for controllers +module MetadataTemplates + extend ActiveSupport::Concern + + def templates + @templates = [{ id: 0, label: 'None' }, { id: 1, label: 'All' }] + end + + def template(namespace = nil, template_id = 0) + @template = template_id.zero? || namespace.nil? ? [] : namespace.metadata_summary.keys + end +end diff --git a/app/controllers/projects/application_controller.rb b/app/controllers/projects/application_controller.rb index 943ae4e540..f4272c25c4 100644 --- a/app/controllers/projects/application_controller.rb +++ b/app/controllers/projects/application_controller.rb @@ -23,22 +23,5 @@ def context_crumbs def load_samples Sample.where(project_id: @project.id) end - - def all_metadata_fields - @all_metadata_fields = @project.namespace.metadata_summary - end - - def templates - @templates = [{ id: 0, label: 'None' }, { id: 1, label: 'All' }] - end - - def template - @template = case params[:template] - when '1' - @project.namespace.metadata_summary.keys - else - %w[] - end - end end end diff --git a/app/controllers/projects/samples_controller.rb b/app/controllers/projects/samples_controller.rb index 9863277d31..aaa9626ee9 100644 --- a/app/controllers/projects/samples_controller.rb +++ b/app/controllers/projects/samples_controller.rb @@ -3,10 +3,14 @@ module Projects # Controller actions for Samples class SamplesController < Projects::ApplicationController + include MetadataTemplates + before_action :sample, only: %i[show edit update destroy] before_action :current_page before_action :templates, only: %i[index] - before_action :template, only: %i[index] + before_action only: %i[index] do + template(@project.namespace, params[:template].to_i) + end def index authorize! @project, to: :sample_listing? diff --git a/app/views/projects/samples/index.html.erb b/app/views/projects/samples/index.html.erb index ea7d8e92c9..e1b585346c 100644 --- a/app/views/projects/samples/index.html.erb +++ b/app/views/projects/samples/index.html.erb @@ -35,7 +35,7 @@ <% end %> <% if @has_samples %>
<%= search_form_for @q, url: namespace_project_samples_url(**request.query_parameters), html: { "data-controller": "filters" } do |f| %> From d666b668695f472e6f8b5e94fb62002d279637b6 Mon Sep 17 00:00:00 2001 From: Josh Adam Date: Tue, 23 Jan 2024 10:56:02 -0600 Subject: [PATCH 36/64] chore: Removed templates dropdown and added toggle for fields --- app/controllers/concerns/metadata.rb | 10 ++++++++++ app/controllers/concerns/metadata_templates.rb | 14 -------------- app/controllers/projects/samples_controller.rb | 5 ++--- app/helpers/url_helper.rb | 2 +- app/views/projects/samples/_table.html.erb | 4 ++-- .../projects/samples/index.turbo_stream.erb | 16 ++++++---------- 6 files changed, 21 insertions(+), 30 deletions(-) create mode 100644 app/controllers/concerns/metadata.rb delete mode 100644 app/controllers/concerns/metadata_templates.rb diff --git a/app/controllers/concerns/metadata.rb b/app/controllers/concerns/metadata.rb new file mode 100644 index 0000000000..cc4d887eca --- /dev/null +++ b/app/controllers/concerns/metadata.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +# Executes basic metadata template logic for controllers +module Metadata + extend ActiveSupport::Concern + + def get_fields(namespace = nil, template_id = 0) + @fields = template_id.zero? || namespace.nil? ? [] : namespace.metadata_summary.keys + end +end diff --git a/app/controllers/concerns/metadata_templates.rb b/app/controllers/concerns/metadata_templates.rb deleted file mode 100644 index 493abb7186..0000000000 --- a/app/controllers/concerns/metadata_templates.rb +++ /dev/null @@ -1,14 +0,0 @@ -# frozen_string_literal: true - -# Executes basic metadata template logic for controllers -module MetadataTemplates - extend ActiveSupport::Concern - - def templates - @templates = [{ id: 0, label: 'None' }, { id: 1, label: 'All' }] - end - - def template(namespace = nil, template_id = 0) - @template = template_id.zero? || namespace.nil? ? [] : namespace.metadata_summary.keys - end -end diff --git a/app/controllers/projects/samples_controller.rb b/app/controllers/projects/samples_controller.rb index aaa9626ee9..e3ae3107cc 100644 --- a/app/controllers/projects/samples_controller.rb +++ b/app/controllers/projects/samples_controller.rb @@ -3,13 +3,12 @@ module Projects # Controller actions for Samples class SamplesController < Projects::ApplicationController - include MetadataTemplates + include Metadata before_action :sample, only: %i[show edit update destroy] before_action :current_page - before_action :templates, only: %i[index] before_action only: %i[index] do - template(@project.namespace, params[:template].to_i) + get_fields(@project.namespace, params[:metadata].to_i) end def index diff --git a/app/helpers/url_helper.rb b/app/helpers/url_helper.rb index e181d1d201..8bc746eb90 100644 --- a/app/helpers/url_helper.rb +++ b/app/helpers/url_helper.rb @@ -8,6 +8,6 @@ def pagy_template_url_for(pagy, template) params = Rack::Utils.parse_query(uri.query) params['template'] = template uri.query = Rack::Utils.build_query(params) - uri.to_s + uri.to_s.gsub('samples.turbo_stream', 'samples') end end diff --git a/app/views/projects/samples/_table.html.erb b/app/views/projects/samples/_table.html.erb index ea9c691a65..74783c509d 100644 --- a/app/views/projects/samples/_table.html.erb +++ b/app/views/projects/samples/_table.html.erb @@ -16,7 +16,7 @@
- <% @template.each do |column| %> + <% @fields.each do |column| %> <% end %> <% if allowed_to?(:update_sample?, project) %> @@ -65,7 +65,7 @@ - <% @template.each do |column| %> + <% @fields.each do |column| %> diff --git a/app/views/projects/samples/index.turbo_stream.erb b/app/views/projects/samples/index.turbo_stream.erb index 51e54bdf12..884c123b5b 100644 --- a/app/views/projects/samples/index.turbo_stream.erb +++ b/app/views/projects/samples/index.turbo_stream.erb @@ -13,16 +13,12 @@ } %> <%= turbo_stream.update "project_metadata_template" do %> - <%= viral_dropdown(label: "Metadata", caret: true) do |dropdown| %> - <%= @templates.each do |template| %> - <%= dropdown.with_item( - label: template[:label], - url: pagy_template_url_for(@pagy, template[:id]).gsub("samples.turbo_stream", "samples"), - data: { - turbo_stream: true - } - ) %> - <% end %> + <%= form_with url: pagy_url_for(@pagy, @pagy.page).gsub("samples.turbo_stream", "samples"), method: "get" do |f| %> + <% end %> <% end %> From a4e22d1d1f23f4da10318fb67fa9474ed44af185 Mon Sep 17 00:00:00 2001 From: Josh Adam Date: Tue, 23 Jan 2024 11:19:05 -0600 Subject: [PATCH 37/64] chore: Created component for metadata fields toggle --- .../metadata_fields_toggle_component.html.erb | 7 +++++++ app/components/metadata_fields_toggle_component.rb | 8 ++++++++ app/components/metadata_fields_toggle_component.yml | 2 ++ app/controllers/concerns/metadata.rb | 2 +- app/controllers/projects/samples_controller.rb | 2 +- app/views/projects/samples/index.html.erb | 2 +- app/views/projects/samples/index.turbo_stream.erb | 10 ++-------- 7 files changed, 22 insertions(+), 11 deletions(-) create mode 100644 app/components/metadata_fields_toggle_component.html.erb create mode 100644 app/components/metadata_fields_toggle_component.rb create mode 100644 app/components/metadata_fields_toggle_component.yml diff --git a/app/components/metadata_fields_toggle_component.html.erb b/app/components/metadata_fields_toggle_component.html.erb new file mode 100644 index 0000000000..491905bfb3 --- /dev/null +++ b/app/components/metadata_fields_toggle_component.html.erb @@ -0,0 +1,7 @@ +<%= form_with url: @url, method: "get" do |f| %> + +<% end %> \ No newline at end of file diff --git a/app/components/metadata_fields_toggle_component.rb b/app/components/metadata_fields_toggle_component.rb new file mode 100644 index 0000000000..64c739a925 --- /dev/null +++ b/app/components/metadata_fields_toggle_component.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +class MetadataFieldsToggleComponent < Component + def initialize(url, checked) + @url = url + @checked = checked + end +end diff --git a/app/components/metadata_fields_toggle_component.yml b/app/components/metadata_fields_toggle_component.yml new file mode 100644 index 0000000000..d0598a4dfd --- /dev/null +++ b/app/components/metadata_fields_toggle_component.yml @@ -0,0 +1,2 @@ +en: + label: Metadata Fields \ No newline at end of file diff --git a/app/controllers/concerns/metadata.rb b/app/controllers/concerns/metadata.rb index cc4d887eca..ebca627df2 100644 --- a/app/controllers/concerns/metadata.rb +++ b/app/controllers/concerns/metadata.rb @@ -4,7 +4,7 @@ module Metadata extend ActiveSupport::Concern - def get_fields(namespace = nil, template_id = 0) + def fields_for_namespace(namespace = nil, template_id = 0) @fields = template_id.zero? || namespace.nil? ? [] : namespace.metadata_summary.keys end end diff --git a/app/controllers/projects/samples_controller.rb b/app/controllers/projects/samples_controller.rb index e3ae3107cc..8754e49ebf 100644 --- a/app/controllers/projects/samples_controller.rb +++ b/app/controllers/projects/samples_controller.rb @@ -8,7 +8,7 @@ class SamplesController < Projects::ApplicationController before_action :sample, only: %i[show edit update destroy] before_action :current_page before_action only: %i[index] do - get_fields(@project.namespace, params[:metadata].to_i) + fields_for_namespace(@project.namespace, params[:metadata].to_i) end def index diff --git a/app/views/projects/samples/index.html.erb b/app/views/projects/samples/index.html.erb index e1b585346c..b97f3b611a 100644 --- a/app/views/projects/samples/index.html.erb +++ b/app/views/projects/samples/index.html.erb @@ -54,7 +54,7 @@ <% end %> <%= turbo_frame_tag "project_samples_sort_dropdown" %> - <%= turbo_frame_tag "project_metadata_template" %> + <%= turbo_frame_tag "metadata_fields_toggle" %> <%= turbo_frame_tag "project_samples_list", diff --git a/app/views/projects/samples/index.turbo_stream.erb b/app/views/projects/samples/index.turbo_stream.erb index 884c123b5b..7a1c31ddb4 100644 --- a/app/views/projects/samples/index.turbo_stream.erb +++ b/app/views/projects/samples/index.turbo_stream.erb @@ -12,14 +12,8 @@ pagy: @pagy } %> -<%= turbo_stream.update "project_metadata_template" do %> - <%= form_with url: pagy_url_for(@pagy, @pagy.page).gsub("samples.turbo_stream", "samples"), method: "get" do |f| %> - - <% end %> +<%= turbo_stream.update "metadata_fields_toggle" do %> + <%= render MetadataFieldsToggleComponent.new(pagy_url_for(@pagy, @pagy.page).gsub(".turbo_stream", ""), params[:metadata].to_i == 1) %> <% end %> <%= turbo_stream.update "project_samples_hidden_values" do %> From 6479e85dc700c551e9dea9ad8d06b8840b7e75bb Mon Sep 17 00:00:00 2001 From: Josh Adam Date: Tue, 23 Jan 2024 11:35:24 -0600 Subject: [PATCH 38/64] chore: Removed from turbo response as does not need to be there --- app/controllers/projects/samples_controller.rb | 5 ++--- app/views/projects/samples/index.html.erb | 2 +- app/views/projects/samples/index.turbo_stream.erb | 4 ---- 3 files changed, 3 insertions(+), 8 deletions(-) diff --git a/app/controllers/projects/samples_controller.rb b/app/controllers/projects/samples_controller.rb index 8754e49ebf..fc0c33745e 100644 --- a/app/controllers/projects/samples_controller.rb +++ b/app/controllers/projects/samples_controller.rb @@ -16,13 +16,12 @@ def index @q = load_samples.ransack(params[:q]) set_default_sort + @pagy, @samples = pagy(@q.result) respond_to do |format| format.html do @has_samples = @q.result.count.positive? end - format.turbo_stream do - @pagy, @samples = pagy(@q.result) - end + format.turbo_stream end end diff --git a/app/views/projects/samples/index.html.erb b/app/views/projects/samples/index.html.erb index b97f3b611a..837eb0b333 100644 --- a/app/views/projects/samples/index.html.erb +++ b/app/views/projects/samples/index.html.erb @@ -54,7 +54,7 @@ <% end %> <%= turbo_frame_tag "project_samples_sort_dropdown" %> - <%= turbo_frame_tag "metadata_fields_toggle" %> + <%= render MetadataFieldsToggleComponent.new(pagy_url_for(@pagy, @pagy.page).gsub(".turbo_stream", ""), params[:metadata].to_i == 1) %> <%= turbo_frame_tag "project_samples_list", diff --git a/app/views/projects/samples/index.turbo_stream.erb b/app/views/projects/samples/index.turbo_stream.erb index 7a1c31ddb4..837e5514ca 100644 --- a/app/views/projects/samples/index.turbo_stream.erb +++ b/app/views/projects/samples/index.turbo_stream.erb @@ -12,10 +12,6 @@ pagy: @pagy } %> -<%= turbo_stream.update "metadata_fields_toggle" do %> - <%= render MetadataFieldsToggleComponent.new(pagy_url_for(@pagy, @pagy.page).gsub(".turbo_stream", ""), params[:metadata].to_i == 1) %> -<% end %> - <%= turbo_stream.update "project_samples_hidden_values" do %> <%= render Ransack::HiddenSortFieldComponent.new(@q) %> <%= hidden_field_tag "template", params[:template] %> From 2c01886c9a44e05858e0921e0a41765a7db3b3ca Mon Sep 17 00:00:00 2001 From: Josh Adam Date: Wed, 24 Jan 2024 07:40:53 -0600 Subject: [PATCH 39/64] chore: Updating groups samples page to use metadata fields --- app/controllers/groups/samples_controller.rb | 9 +++-- app/views/groups/samples/_table.html.erb | 38 +++++++++----------- app/views/groups/samples/index.html.erb | 19 +++++----- app/views/projects/samples/_table.html.erb | 2 +- app/views/projects/samples/index.html.erb | 6 ++-- 5 files changed, 37 insertions(+), 37 deletions(-) diff --git a/app/controllers/groups/samples_controller.rb b/app/controllers/groups/samples_controller.rb index aa9a2441e6..7f8acb44be 100644 --- a/app/controllers/groups/samples_controller.rb +++ b/app/controllers/groups/samples_controller.rb @@ -4,7 +4,11 @@ module Groups # Controller actions for Samples within a Group class SamplesController < ApplicationController layout 'groups' + include Metadata before_action :group, :current_page, only: %i[index] + before_action only: %i[index] do + fields_for_namespace(@group, params[:metadata].to_i) + end def index authorize! @group, to: :sample_listing? @@ -13,13 +17,12 @@ def index set_default_sort + @pagy, @samples = pagy(@q.result) respond_to do |format| format.html do @has_samples = @q.result.count.positive? end - format.turbo_stream do - @pagy, @samples = pagy(@q.result) - end + format.turbo_stream end end diff --git a/app/views/groups/samples/_table.html.erb b/app/views/groups/samples/_table.html.erb index b4bf1812d7..de49e45226 100644 --- a/app/views/groups/samples/_table.html.erb +++ b/app/views/groups/samples/_table.html.erb @@ -1,24 +1,10 @@
<%= render Ransack::SortComponent.new( @@ -43,9 +60,9 @@ <% samples.each do |sample| %>
<%= link_to sample.name, + <%= link_to sample.name, namespace_project_sample_path( id: sample.id, namespace_id: sample.project.namespace.parent.full_path, @@ -56,7 +73,7 @@ }, class: "text-grey-900 dark:text-grey-100 font-semibold hover:underline" %> + <%= viral_tooltip(title: project_path(sample.project)) do %> <%= link_to sample.project.abbreviated_path, project_path(sample.project), @@ -66,10 +83,10 @@ class: "text-grey-900 dark:text-grey-100 font-semibold hover:underline" %> <% end %> + <%= l(sample.created_at.localtime, format: :full_date) %> + <%= viral_time_ago(original_time: sample.updated_at) %>
<%= render Ransack::SortComponent.new(ransack_obj: @q, label: t(".sample"), url: sorting_url(@q, :name), field: :name) %>
+ <%= render Ransack::SortComponent.new(ransack_obj: @q, label: t(".sample"), url: sorting_url(@q, :name), field: :name) %> + <%= render Ransack::SortComponent.new(ransack_obj: @q, label: t(".created_at"), url: sorting_url(@q, :created_at), field: :created_at) %> + <%= render Ransack::SortComponent.new(ransack_obj: @q, label: t(".updated_at"), url: sorting_url(@q, :updated_at), field: :updated_at) %> <%= column %><%= column %><%= t(".action") %><%= t(".action") %>
<%= render Ransack::SortComponent.new(ransack_obj: @q, label: t(".updated_at"), url: sorting_url(@q, :updated_at), field: :updated_at) %> <%= column %> <%= viral_time_ago(original_time: sample.updated_at) %> <%= sample[column].present? ? sample[column] : sample.metadata[column] %>
+ class="text-xs text-slate-700 uppercase bg-slate-50 dark:bg-slate-700 dark:text-slate-400"> - - - + <% end %> + - + <% @fields.each do |column| %> + + <% end %> diff --git a/app/views/groups/samples/index.html.erb b/app/views/groups/samples/index.html.erb index 794cbc69e4..4040d1a1fe 100644 --- a/app/views/groups/samples/index.html.erb +++ b/app/views/groups/samples/index.html.erb @@ -14,11 +14,13 @@ border-slate-200 dark:text-slate-400 dark:border-slate-700 + items-center + space-x-2 " >
- <%= search_form_for @q, url: group_samples_url(**request.query_parameters), html: {"data-controller": "filters"} do |f| %> - + <%= search_form_for @q, url: group_samples_url(**request.query_parameters), html: { "data-controller": "filters" } do |f| %> + <%= f.label :name_cont, placeholder: t(".search.placeholder"), class: "sr-only" %>
<%= turbo_frame_tag "group_samples_hidden_search_value" %> <%= f.search_field :name_cont, - "data-action": "filters#submit", - class: - "block w-full p-2.5 pl-10 text-sm text-slate-900 border border-slate-300 rounded-lg bg-slate-50 focus:ring-primary-500 focus:border-primary-500 dark:bg-slate-700 dark:border-slate-600 dark:placeholder-slate-400 dark:text-white dark:focus:ring-primary-500 dark:focus:border-primary-500", - placeholder: t(".search.placeholder") %> + "data-action": "filters#submit", + class: + "block w-full p-2.5 pl-10 text-sm text-slate-900 border border-slate-300 rounded-lg bg-slate-50 focus:ring-primary-500 focus:border-primary-500 dark:bg-slate-700 dark:border-slate-600 dark:placeholder-slate-400 dark:text-white dark:focus:ring-primary-500 dark:focus:border-primary-500", + placeholder: t(".search.placeholder") %>
<% end %>
+ <%= render MetadataFieldsToggleComponent.new(pagy_url_for(@pagy, @pagy.page).gsub(".turbo_stream", ""), params[:metadata].to_i == 1) %>
<%= turbo_frame_tag "group_samples_list", - src: group_samples_path(@group, format: :turbo_stream, page: params[:page]), - loading: :lazy %> + src: group_samples_path(@group, format: :turbo_stream, page: params[:page]), + loading: :lazy %> <%= turbo_frame_tag "group_samples_pagination" %>
diff --git a/app/views/projects/samples/_table.html.erb b/app/views/projects/samples/_table.html.erb index 74783c509d..88d4814367 100644 --- a/app/views/projects/samples/_table.html.erb +++ b/app/views/projects/samples/_table.html.erb @@ -17,7 +17,7 @@ <%= render Ransack::SortComponent.new(ransack_obj: @q, label: t(".updated_at"), url: sorting_url(@q, :updated_at), field: :updated_at) %> <% @fields.each do |column| %> -
+ <% end %> <% if allowed_to?(:update_sample?, project) %> diff --git a/app/views/projects/samples/index.html.erb b/app/views/projects/samples/index.html.erb index 837eb0b333..f4cd322a43 100644 --- a/app/views/projects/samples/index.html.erb +++ b/app/views/projects/samples/index.html.erb @@ -54,15 +54,15 @@ <% end %> <%= turbo_frame_tag "project_samples_sort_dropdown" %> - <%= render MetadataFieldsToggleComponent.new(pagy_url_for(@pagy, @pagy.page).gsub(".turbo_stream", ""), params[:metadata].to_i == 1) %> + <%= render MetadataFieldsToggleComponent.new(pagy_url_for(@pagy, @pagy.page), params[:metadata].to_i == 1) %> <%= turbo_frame_tag "project_samples_list", src: project_samples_path(@project, format: :turbo_stream, **request.query_parameters), loading: :lazy do %> -
+ <%= render Ransack::SortComponent.new( ransack_obj: @q, label: t(".sample"), @@ -26,10 +12,13 @@ field: :name ) %> + <%= t(".project") %> + <% @fields.each do |column| %> + <%= column %> <%= render Ransack::SortComponent.new( ransack_obj: @q, label: t(".created_at"), @@ -37,7 +26,7 @@ field: :created_at ) %> + <%= render Ransack::SortComponent.new( ransack_obj: @q, label: t(".updated_at"), @@ -71,7 +60,7 @@ data: { turbo: false }, - class: "text-grey-900 dark:text-grey-100 font-semibold hover:underline" %> + class: "text-slate-900 dark:text-slate-100 font-semibold hover:underline" %> <%= viral_tooltip(title: project_path(sample.project)) do %> @@ -80,9 +69,14 @@ data: { turbo: false }, - class: "text-grey-900 dark:text-grey-100 font-semibold hover:underline" %> + class: "text-slate-900 dark:text-slate-100 font-semibold hover:underline" %> <% end %> + <%= sample[column].present? ? sample[column] : sample.metadata[column] %> + <%= l(sample.created_at.localtime, format: :full_date) %> <%= column %><%= column %><%= t(".action") %>
+
<% 15.times do %> From ec915ee70c41bc3aef958455185b3598dd702d07 Mon Sep 17 00:00:00 2001 From: Josh Adam Date: Wed, 24 Jan 2024 09:38:22 -0600 Subject: [PATCH 40/64] chore: Working on group samples --- app/views/groups/samples/index.html.erb | 2 +- app/views/groups/samples/index.turbo_stream.erb | 3 ++- app/views/projects/samples/index.turbo_stream.erb | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/views/groups/samples/index.html.erb b/app/views/groups/samples/index.html.erb index 4040d1a1fe..a4e4eb3ac5 100644 --- a/app/views/groups/samples/index.html.erb +++ b/app/views/groups/samples/index.html.erb @@ -45,7 +45,7 @@ <% end %> - <%= render MetadataFieldsToggleComponent.new(pagy_url_for(@pagy, @pagy.page).gsub(".turbo_stream", ""), params[:metadata].to_i == 1) %> + <%= render MetadataFieldsToggleComponent.new(pagy_url_for(@pagy, @pagy.page), params[:metadata].to_i == 1) %>
diff --git a/app/views/groups/samples/index.turbo_stream.erb b/app/views/groups/samples/index.turbo_stream.erb index 1661c54f44..ec7d165062 100644 --- a/app/views/groups/samples/index.turbo_stream.erb +++ b/app/views/groups/samples/index.turbo_stream.erb @@ -2,7 +2,7 @@ partial: "table", locals: { group: @group, - samples: @samples + samples: @samples, } %> <%= turbo_stream.update "group_samples_pagination", @@ -13,4 +13,5 @@ <%= turbo_stream.update "group_samples_hidden_search_value" do %> <%= render Ransack::HiddenSortFieldComponent.new(@q) %> + <%= hidden_field_tag "metadata", params[:metadata] %> <% end %> diff --git a/app/views/projects/samples/index.turbo_stream.erb b/app/views/projects/samples/index.turbo_stream.erb index 837e5514ca..58395bc4d7 100644 --- a/app/views/projects/samples/index.turbo_stream.erb +++ b/app/views/projects/samples/index.turbo_stream.erb @@ -14,5 +14,5 @@ <%= turbo_stream.update "project_samples_hidden_values" do %> <%= render Ransack::HiddenSortFieldComponent.new(@q) %> - <%= hidden_field_tag "template", params[:template] %> + <%= hidden_field_tag "metadata", params[:metadata] %> <% end %> From 3dc3d951d3e18ad261a4673564404b9a0a8a131c Mon Sep 17 00:00:00 2001 From: Josh Adam Date: Wed, 24 Jan 2024 11:48:22 -0600 Subject: [PATCH 41/64] chore: Fixed mutliple request issue. --- .../metadata_fields_toggle_component.html.erb | 7 -- .../metadata_fields_toggle_component.rb | 8 -- .../metadata_fields_toggle_component.yml | 2 - app/controllers/groups/samples_controller.rb | 9 +- .../projects/samples_controller.rb | 9 +- app/views/groups/samples/_table.html.erb | 102 ++++++++++++------ app/views/groups/samples/index.html.erb | 42 +++++++- app/views/projects/samples/index.html.erb | 70 +++++++++--- 8 files changed, 175 insertions(+), 74 deletions(-) delete mode 100644 app/components/metadata_fields_toggle_component.html.erb delete mode 100644 app/components/metadata_fields_toggle_component.rb delete mode 100644 app/components/metadata_fields_toggle_component.yml diff --git a/app/components/metadata_fields_toggle_component.html.erb b/app/components/metadata_fields_toggle_component.html.erb deleted file mode 100644 index 491905bfb3..0000000000 --- a/app/components/metadata_fields_toggle_component.html.erb +++ /dev/null @@ -1,7 +0,0 @@ -<%= form_with url: @url, method: "get" do |f| %> - -<% end %> \ No newline at end of file diff --git a/app/components/metadata_fields_toggle_component.rb b/app/components/metadata_fields_toggle_component.rb deleted file mode 100644 index 64c739a925..0000000000 --- a/app/components/metadata_fields_toggle_component.rb +++ /dev/null @@ -1,8 +0,0 @@ -# frozen_string_literal: true - -class MetadataFieldsToggleComponent < Component - def initialize(url, checked) - @url = url - @checked = checked - end -end diff --git a/app/components/metadata_fields_toggle_component.yml b/app/components/metadata_fields_toggle_component.yml deleted file mode 100644 index d0598a4dfd..0000000000 --- a/app/components/metadata_fields_toggle_component.yml +++ /dev/null @@ -1,2 +0,0 @@ -en: - label: Metadata Fields \ No newline at end of file diff --git a/app/controllers/groups/samples_controller.rb b/app/controllers/groups/samples_controller.rb index 7f8acb44be..7a81255e51 100644 --- a/app/controllers/groups/samples_controller.rb +++ b/app/controllers/groups/samples_controller.rb @@ -6,9 +6,6 @@ class SamplesController < ApplicationController layout 'groups' include Metadata before_action :group, :current_page, only: %i[index] - before_action only: %i[index] do - fields_for_namespace(@group, params[:metadata].to_i) - end def index authorize! @group, to: :sample_listing? @@ -17,12 +14,14 @@ def index set_default_sort - @pagy, @samples = pagy(@q.result) respond_to do |format| format.html do @has_samples = @q.result.count.positive? end - format.turbo_stream + format.turbo_stream do + @pagy, @samples = pagy(@q.result) + fields_for_namespace(@group, params[:q] ? params[:q][:metadata].to_i : 0) + end end end diff --git a/app/controllers/projects/samples_controller.rb b/app/controllers/projects/samples_controller.rb index fc0c33745e..15711daa4a 100644 --- a/app/controllers/projects/samples_controller.rb +++ b/app/controllers/projects/samples_controller.rb @@ -7,21 +7,20 @@ class SamplesController < Projects::ApplicationController before_action :sample, only: %i[show edit update destroy] before_action :current_page - before_action only: %i[index] do - fields_for_namespace(@project.namespace, params[:metadata].to_i) - end def index authorize! @project, to: :sample_listing? @q = load_samples.ransack(params[:q]) set_default_sort - @pagy, @samples = pagy(@q.result) respond_to do |format| format.html do @has_samples = @q.result.count.positive? end - format.turbo_stream + format.turbo_stream do + @pagy, @samples = pagy(@q.result) + fields_for_namespace(@project.namespace, params[:q] ? params[:q][:metadata].to_i : 0) + end end end diff --git a/app/views/groups/samples/_table.html.erb b/app/views/groups/samples/_table.html.erb index de49e45226..0cea457133 100644 --- a/app/views/groups/samples/_table.html.erb +++ b/app/views/groups/samples/_table.html.erb @@ -1,10 +1,39 @@ -
- +
+
+ - - <% @fields.each do |column| %> - + <% end %> - - + + <% samples.each do |sample| %> @@ -85,5 +120,6 @@ <% end %> - -
+ <%= render Ransack::SortComponent.new( ransack_obj: @q, label: t(".sample"), @@ -12,11 +41,17 @@ field: :name ) %> + <%= t(".project") %> <%= column %><%= column %> <%= render Ransack::SortComponent.new( @@ -35,40 +70,40 @@ ) %>
<%= link_to sample.name, - namespace_project_sample_path( - id: sample.id, - namespace_id: sample.project.namespace.parent.full_path, - project_id: sample.project.path - ), - data: { - turbo: false - }, + namespace_project_sample_path( + id: sample.id, + namespace_id: sample.project.namespace.parent.full_path, + project_id: sample.project.path + ), + data: { + turbo: false + }, class: "text-slate-900 dark:text-slate-100 font-semibold hover:underline" %> <%= viral_tooltip(title: project_path(sample.project)) do %> <%= link_to sample.project.abbreviated_path, - project_path(sample.project), - data: { - turbo: false - }, + project_path(sample.project), + data: { + turbo: false + }, class: "text-slate-900 dark:text-slate-100 font-semibold hover:underline" %> <% end %>
+
+
diff --git a/app/views/groups/samples/index.html.erb b/app/views/groups/samples/index.html.erb index a4e4eb3ac5..588e882353 100644 --- a/app/views/groups/samples/index.html.erb +++ b/app/views/groups/samples/index.html.erb @@ -43,9 +43,49 @@ "block w-full p-2.5 pl-10 text-sm text-slate-900 border border-slate-300 rounded-lg bg-slate-50 focus:ring-primary-500 focus:border-primary-500 dark:bg-slate-700 dark:border-slate-600 dark:placeholder-slate-400 dark:text-white dark:focus:ring-primary-500 dark:focus:border-primary-500", placeholder: t(".search.placeholder") %>
+ <% end %> - <%= render MetadataFieldsToggleComponent.new(pagy_url_for(@pagy, @pagy.page), params[:metadata].to_i == 1) %>
diff --git a/app/views/projects/samples/index.html.erb b/app/views/projects/samples/index.html.erb index f4cd322a43..b59d8b279f 100644 --- a/app/views/projects/samples/index.html.erb +++ b/app/views/projects/samples/index.html.erb @@ -35,26 +35,70 @@ <% end %> <% if @has_samples %>
<%= search_form_for @q, url: namespace_project_samples_url(**request.query_parameters), html: { "data-controller": "filters" } do |f| %> - <%= f.label :name_cont, placeholder: t(".search.placeholder"), class: "sr-only" %> -
-
- <%= viral_icon(name: "magnifying_glass", classes: "h-5 w-5") %> +
+ <%= f.label :name_cont, placeholder: t(".search.placeholder"), class: "sr-only" %> +
+
+
+ <%= viral_icon(name: "magnifying_glass", classes: "h-5 w-5") %> +
+ <%= turbo_frame_tag "project_samples_hidden_values" %> + <%= f.search_field :name_cont, + "data-action": "filters#submit", + class: + "block w-full p-2.5 pl-10 text-sm text-slate-900 border border-slate-300 rounded-lg bg-slate-50 focus:ring-primary-500 focus:border-primary-500 dark:bg-slate-700 dark:border-slate-600 dark:placeholder-slate-400 dark:text-white dark:focus:ring-primary-500 dark:focus:border-primary-500", + placeholder: t(".search.placeholder") %> +
+
+
- <%= turbo_frame_tag "project_samples_hidden_values" %> - <%= f.search_field :name_cont, - "data-action": "filters#submit", - class: - "block w-full p-2.5 pl-10 text-sm text-slate-900 border border-slate-300 rounded-lg bg-slate-50 focus:ring-primary-500 focus:border-primary-500 dark:bg-slate-700 dark:border-slate-600 dark:placeholder-slate-400 dark:text-white dark:focus:ring-primary-500 dark:focus:border-primary-500", - placeholder: t(".search.placeholder") %>
<% end %> - <%= turbo_frame_tag "project_samples_sort_dropdown" %> - <%= render MetadataFieldsToggleComponent.new(pagy_url_for(@pagy, @pagy.page), params[:metadata].to_i == 1) %>
<%= turbo_frame_tag "project_samples_list", From 3eef25fcbf0f1d936c0ae3c6f6ecdd3d14330d8b Mon Sep 17 00:00:00 2001 From: Josh Adam Date: Wed, 24 Jan 2024 14:23:29 -0600 Subject: [PATCH 42/64] chore: Fixed rubocop errors --- app/controllers/groups/samples_controller.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/controllers/groups/samples_controller.rb b/app/controllers/groups/samples_controller.rb index 7a81255e51..b4f8fc0ecf 100644 --- a/app/controllers/groups/samples_controller.rb +++ b/app/controllers/groups/samples_controller.rb @@ -7,13 +7,11 @@ class SamplesController < ApplicationController include Metadata before_action :group, :current_page, only: %i[index] - def index + def index # rubocop:disable Metrics/AbcSize authorize! @group, to: :sample_listing? @q = authorized_samples.ransack(params[:q]) - set_default_sort - respond_to do |format| format.html do @has_samples = @q.result.count.positive? From 59eadb47c960b9729c15992211f383c72cac54b7 Mon Sep 17 00:00:00 2001 From: Josh Adam Date: Wed, 24 Jan 2024 14:32:39 -0600 Subject: [PATCH 43/64] chore: Fixed linting issue --- app/controllers/projects/samples_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/projects/samples_controller.rb b/app/controllers/projects/samples_controller.rb index 15711daa4a..b1cbdf4224 100644 --- a/app/controllers/projects/samples_controller.rb +++ b/app/controllers/projects/samples_controller.rb @@ -8,7 +8,7 @@ class SamplesController < Projects::ApplicationController before_action :sample, only: %i[show edit update destroy] before_action :current_page - def index + def index # rubocop:disable Metrics/AbcSize authorize! @project, to: :sample_listing? @q = load_samples.ransack(params[:q]) From 8b08edf381b8c55e44f05cfbf0142dea636ffe94 Mon Sep 17 00:00:00 2001 From: Josh Adam Date: Wed, 24 Jan 2024 15:00:13 -0600 Subject: [PATCH 44/64] chore: Fixed response when deleting sample --- app/controllers/projects/samples_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/projects/samples_controller.rb b/app/controllers/projects/samples_controller.rb index b1cbdf4224..48c22e2ba0 100644 --- a/app/controllers/projects/samples_controller.rb +++ b/app/controllers/projects/samples_controller.rb @@ -78,6 +78,7 @@ def destroy # rubocop:disable Metrics/AbcSize,Metrics/MethodLength redirect_to namespace_project_samples_path(format: :html) end format.turbo_stream do + fields_for_namespace(@project.namespace, params[:q] ? params[:q][:metadata].to_i : 0) render status: :ok, locals: { type: 'success', message: t('.success', sample_name: @sample.name, project_name: @project.namespace.human_name) } From 20df0c7740864e2ff280211bd5d2f07ec8d43185 Mon Sep 17 00:00:00 2001 From: Josh Adam Date: Thu, 25 Jan 2024 07:22:43 -0600 Subject: [PATCH 45/64] chore: Fixed transfer table reload --- app/controllers/concerns/metadata.rb | 4 ++++ .../projects/samples/transfers_controller.rb | 2 -- .../samples/transfers/create.turbo_stream.erb | 12 ++++++------ 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/app/controllers/concerns/metadata.rb b/app/controllers/concerns/metadata.rb index ebca627df2..1b7a20d131 100644 --- a/app/controllers/concerns/metadata.rb +++ b/app/controllers/concerns/metadata.rb @@ -4,6 +4,10 @@ module Metadata extend ActiveSupport::Concern + included do + helper_method :fields_for_namespace + end + def fields_for_namespace(namespace = nil, template_id = 0) @fields = template_id.zero? || namespace.nil? ? [] : namespace.metadata_summary.keys end diff --git a/app/controllers/projects/samples/transfers_controller.rb b/app/controllers/projects/samples/transfers_controller.rb index 01d4291648..13e3d0a91c 100644 --- a/app/controllers/projects/samples/transfers_controller.rb +++ b/app/controllers/projects/samples/transfers_controller.rb @@ -6,8 +6,6 @@ module Samples class TransfersController < Projects::ApplicationController respond_to :turbo_stream before_action :projects - before_action :templates, only: %i[new create] - before_action :template, only: %i[new create] def new authorize! @project, to: :transfer_sample? diff --git a/app/views/projects/samples/transfers/create.turbo_stream.erb b/app/views/projects/samples/transfers/create.turbo_stream.erb index 456a659744..64c72147ef 100644 --- a/app/views/projects/samples/transfers/create.turbo_stream.erb +++ b/app/views/projects/samples/transfers/create.turbo_stream.erb @@ -18,12 +18,12 @@ open: false } %> -<%= turbo_stream.update "project_samples_list", - partial: "projects/samples/table", - locals: { - project: @project, - samples: @samples - } %> +<%= turbo_stream.replace "project_samples_list" do %> + <%= turbo_frame_tag "project_samples_list", src: project_samples_path( + @project, + format: :turbo_stream, + ) %> +<% end %> <%= turbo_stream.update "project_samples_pagination", partial: "projects/samples/pagination", From e4ade61632b15c96b391117dd804fb7bb71ca966 Mon Sep 17 00:00:00 2001 From: Josh Adam Date: Thu, 25 Jan 2024 08:55:10 -0600 Subject: [PATCH 46/64] chore: Fixed project sample UI testing --- test/system/projects/samples_test.rb | 80 ++++++++++++++++------------ 1 file changed, 45 insertions(+), 35 deletions(-) diff --git a/test/system/projects/samples_test.rb b/test/system/projects/samples_test.rb index 939d137714..3002749e82 100644 --- a/test/system/projects/samples_test.rb +++ b/test/system/projects/samples_test.rb @@ -219,7 +219,7 @@ class SamplesTest < ApplicationSystemTestCase assert_no_selector 'table#samples-table tbody tr', text: @sample1.name assert_selector 'h1', text: I18n.t(:'projects.samples.index.title'), count: 1 assert_selector 'table#samples-table tbody tr', count: 2 - within first('tbody tr td:nth-child(2)') do + within first('tbody tr td:first-child') do assert_text @sample2.name end end @@ -227,8 +227,10 @@ class SamplesTest < ApplicationSystemTestCase test 'should transfer samples' do project2 = projects(:project2) visit namespace_project_samples_url(@namespace, @project) - assert_selector 'table#samples-table tbody tr', count: 3 - all('input[type=checkbox]').each { |checkbox| checkbox.click unless checkbox.checked? } + within 'table#samples-table tbody' do + assert_selector 'tr', count: 3 + all('input[type=checkbox]').each { |checkbox| checkbox.click unless checkbox.checked? } + end click_link I18n.t('projects.samples.index.transfer_button'), match: :first within('span[data-controller-connected="true"] dialog') do select project2.full_path, from: I18n.t('projects.samples.transfers._transfer_modal.new_project_id') @@ -263,8 +265,10 @@ class SamplesTest < ApplicationSystemTestCase test 'should transfer some samples' do project25 = projects(:project25) visit namespace_project_samples_url(@namespace, @project) - assert_selector 'table#samples-table tbody tr', count: 3 - all('input[type=checkbox]').each { |checkbox| checkbox.click unless checkbox.checked? } + within 'table#samples-table tbody' do + assert_selector 'tr', count: 3 + all('input[type=checkbox]').each { |checkbox| checkbox.click unless checkbox.checked? } + end click_link I18n.t('projects.samples.index.transfer_button'), match: :first within('span[data-controller-connected="true"] dialog') do @@ -287,8 +291,10 @@ class SamplesTest < ApplicationSystemTestCase project2 = projects(:project2) visit namespace_project_samples_url(namespace_id: @namespace.path, project_id: @project.path) - assert_selector 'table#samples-table tbody tr', count: 3 - all('input[type=checkbox]').each { |checkbox| checkbox.click unless checkbox.checked? } + within 'table#samples-table tbody' do + assert_selector 'tr', count: 3 + all('input[type=checkbox]').each { |checkbox| checkbox.click unless checkbox.checked? } + end click_link I18n.t('projects.samples.index.transfer_button'), match: :first within('span[data-controller-connected="true"] dialog') do select project2.full_path, from: I18n.t('projects.samples.transfers._transfer_modal.new_project_id') @@ -305,8 +311,10 @@ class SamplesTest < ApplicationSystemTestCase namespace = groups(:group_hotel) project2 = projects(:projectHotel) visit namespace_project_samples_url(namespace, project2) - assert_selector 'table#samples-table tbody tr', count: 1 - all('input[type=checkbox]').each { |checkbox| checkbox.click unless checkbox.checked? } + within 'table#samples-table tbody' do + assert_selector 'tr', count: 1 + all('input[type=checkbox]').each { |checkbox| checkbox.click unless checkbox.checked? } + end click_link I18n.t('projects.samples.index.transfer_button'), match: :first within('span[data-controller-connected="true"] dialog') do assert_no_selector 'option' @@ -320,8 +328,10 @@ class SamplesTest < ApplicationSystemTestCase # Project is a part of Group 8 and not a part of the current project hierarchy project32 = projects(:project32) visit namespace_project_samples_url(namespace_id: @namespace.path, project_id: @project.path) - assert_selector 'table#samples-table tbody tr', count: 3 - all('input[type=checkbox]').each { |checkbox| checkbox.click unless checkbox.checked? } + within 'table#samples-table tbody' do + assert_selector 'tr', count: 3 + all('input[type=checkbox]').each { |checkbox| checkbox.click unless checkbox.checked? } + end click_link I18n.t('projects.samples.index.transfer_button'), match: :first within('span[data-controller-connected="true"] dialog') do @@ -430,58 +440,58 @@ class SamplesTest < ApplicationSystemTestCase click_on I18n.t('projects.samples.table.sample') - assert_selector 'table thead th:nth-child(2) svg.icon-arrow_up' + assert_selector 'table thead th:first-child svg.icon-arrow_up' assert_selector 'table#samples-table tbody tr', count: 3 within first('tbody') do - assert_selector 'tr:first-child td:nth-child(2)', text: @sample1.name - assert_selector 'tr:nth-child(2) td:nth-child(2)', text: @sample2.name - assert_selector 'tr:last-child td:nth-child(2)', text: @sample3.name + assert_selector 'tr:first-child td:first-child', text: @sample1.name + assert_selector 'tr:nth-child(2) td:first-child', text: @sample2.name + assert_selector 'tr:last-child td:first-child', text: @sample3.name end click_on I18n.t('projects.samples.table.sample') - assert_selector 'table thead th:nth-child(2) svg.icon-arrow_down' + assert_selector 'table thead th:first-child svg.icon-arrow_down' assert_selector 'table#samples-table tbody tr', count: 3 within first('tbody') do - assert_selector 'tr:first-child td:nth-child(2)', text: @sample3.name - assert_selector 'tr:nth-child(2) td:nth-child(2)', text: @sample2.name - assert_selector 'tr:last-child td:nth-child(2)', text: @sample1.name + assert_selector 'tr:first-child td:first-child', text: @sample3.name + assert_selector 'tr:nth-child(2) td:first-child', text: @sample2.name + assert_selector 'tr:last-child td:first-child', text: @sample1.name end click_on I18n.t('projects.samples.table.created_at') - assert_selector 'table thead th:nth-child(3) svg.icon-arrow_up' + assert_selector 'table thead th:nth-child(2) svg.icon-arrow_up' within first('tbody') do - assert_selector 'tr:first-child td:nth-child(2)', text: @sample3.name - assert_selector 'tr:nth-child(2) td:nth-child(2)', text: @sample2.name - assert_selector 'tr:last-child td:nth-child(2)', text: @sample1.name + assert_selector 'tr:first-child td:first-child', text: @sample3.name + assert_selector 'tr:nth-child(2) td:first-child', text: @sample2.name + assert_selector 'tr:last-child td:first-child', text: @sample1.name end click_on I18n.t('projects.samples.table.created_at') - assert_selector 'table thead th:nth-child(3) svg.icon-arrow_down' + assert_selector 'table thead th:nth-child(2) svg.icon-arrow_down' within first('tbody') do - assert_selector 'tr:first-child td:nth-child(2)', text: @sample1.name - assert_selector 'tr:nth-child(2) td:nth-child(2)', text: @sample2.name - assert_selector 'tr:last-child td:nth-child(2)', text: @sample3.name + assert_selector 'tr:first-child td:first-child', text: @sample1.name + assert_selector 'tr:nth-child(2) td:first-child', text: @sample2.name + assert_selector 'tr:last-child td:first-child', text: @sample3.name end click_on I18n.t('projects.samples.table.updated_at') - assert_selector 'table thead th:nth-child(4) svg.icon-arrow_up' + assert_selector 'table thead th:nth-child(3) svg.icon-arrow_up' within first('tbody') do - assert_selector 'tr:first-child td:nth-child(2)', text: @sample3.name - assert_selector 'tr:nth-child(2) td:nth-child(2)', text: @sample2.name - assert_selector 'tr:last-child td:nth-child(2)', text: @sample1.name + assert_selector 'tr:first-child td:first-child', text: @sample3.name + assert_selector 'tr:nth-child(2) td:first-child', text: @sample2.name + assert_selector 'tr:last-child td:first-child', text: @sample1.name end click_on I18n.t('projects.samples.table.updated_at') - assert_selector 'table thead th:nth-child(4) svg.icon-arrow_down' + assert_selector 'table thead th:nth-child(3) svg.icon-arrow_down' within first('tbody') do - assert_selector 'tr:first-child td:nth-child(2)', text: @sample1.name - assert_selector 'tr:nth-child(2) td:nth-child(2)', text: @sample2.name - assert_selector 'tr:last-child td:nth-child(2)', text: @sample3.name + assert_selector 'tr:first-child td:first-child', text: @sample1.name + assert_selector 'tr:nth-child(2) td:first-child', text: @sample2.name + assert_selector 'tr:last-child td:first-child', text: @sample3.name end end From 430149770cd0966aa7c96afb7f7b8baa296386b5 Mon Sep 17 00:00:00 2001 From: Josh Adam Date: Thu, 25 Jan 2024 10:27:47 -0600 Subject: [PATCH 47/64] chore: Added testing for metadata fields on project samples --- app/views/groups/samples/index.html.erb | 4 +++- app/views/projects/samples/index.html.erb | 4 +++- config/locales/en.yml | 2 ++ test/fixtures/samples.yml | 4 ++++ test/system/projects/samples_test.rb | 14 ++++++++++++++ 5 files changed, 26 insertions(+), 2 deletions(-) diff --git a/app/views/groups/samples/index.html.erb b/app/views/groups/samples/index.html.erb index 588e882353..d437d96cf2 100644 --- a/app/views/groups/samples/index.html.erb +++ b/app/views/groups/samples/index.html.erb @@ -82,7 +82,9 @@ peer-checked:bg-primary-600 " >
- FIELDS + + <%= t(:'.search.metadata') %> + <% end %>
diff --git a/app/views/projects/samples/index.html.erb b/app/views/projects/samples/index.html.erb index b59d8b279f..f849c24dae 100644 --- a/app/views/projects/samples/index.html.erb +++ b/app/views/projects/samples/index.html.erb @@ -94,7 +94,9 @@ peer-checked:bg-primary-600 " >
- FIELDS + + <%= t(:'.search.metadata') %> + diff --git a/config/locales/en.yml b/config/locales/en.yml index f75e5f5e09..f4e7c1a4fb 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -626,6 +626,7 @@ en: subtitle: These are the samples in %{namespace_type} %{namespace_name} search: placeholder: Filter by name + metadata: Metadata table: sample: Sample project: Project @@ -853,6 +854,7 @@ en: remove: Remove sample search: placeholder: Filter by name + metadata: Metadata update: success: Sample was successfully updated. edit: diff --git a/test/fixtures/samples.yml b/test/fixtures/samples.yml index 09b142dbc1..87bb57ddfa 100644 --- a/test/fixtures/samples.yml +++ b/test/fixtures/samples.yml @@ -7,6 +7,10 @@ sample1: puid: <%= Irida::PersistentUniqueId.generate(object_class: Sample, time: 1.week.ago) %> created_at: <%= 1.week.ago %> updated_at: <%= 1.day.ago %> + metadata: { 'metadatafield1': 'value1', 'metadatafield2': 'value2' } + metadata_provenance: { 'metadatafield1': { 'id': 1, 'source': 'analysis', + 'updated_at': <%= DateTime.new(2000,1,1) %> }, + 'metadatafield2': { 'id': 1, 'source': 'analysis', 'updated_at': <%= DateTime.new(2000,1,1) %> } } sample2: name: Project 1 Sample 2 diff --git a/test/system/projects/samples_test.rb b/test/system/projects/samples_test.rb index 3002749e82..09ad4b76e7 100644 --- a/test/system/projects/samples_test.rb +++ b/test/system/projects/samples_test.rb @@ -886,5 +886,19 @@ class SamplesTest < ApplicationSystemTestCase end end end + + test 'should be able to toggle metadata' do + visit namespace_project_samples_url(@namespace, @project) + assert_selector 'label', text: I18n.t('projects.samples.index.search.metadata'), count: 1 + assert_selector 'table#samples-table thead tr th', count: 4 + find('label', text: I18n.t('projects.samples.index.search.metadata')).click + assert_selector 'table#samples-table thead tr th', count: 6 + within first('table#samples-table tbody tr:first-child') do + assert_text @sample1.name + assert_selector 'td:nth-child(4)', text: 'value1' + assert_selector 'td:nth-child(5)', text: 'value2' + end + assert_selector 'label', text: I18n.t('projects.samples.index.search.metadata'), count: 1 + end end end From f04bf0b9f63a2e0f4beff04c3cd592ed2d58ecb9 Mon Sep 17 00:00:00 2001 From: Josh Adam Date: Thu, 25 Jan 2024 11:03:42 -0600 Subject: [PATCH 48/64] chore: Fixed layout for toggle on group samples --- app/views/groups/samples/index.html.erb | 115 ++++++++++------------ app/views/projects/samples/index.html.erb | 2 +- test/system/groups/samples_test.rb | 13 +++ test/system/projects/samples_test.rb | 1 - 4 files changed, 67 insertions(+), 64 deletions(-) diff --git a/app/views/groups/samples/index.html.erb b/app/views/groups/samples/index.html.erb index d437d96cf2..6081f62df5 100644 --- a/app/views/groups/samples/index.html.erb +++ b/app/views/groups/samples/index.html.erb @@ -4,56 +4,24 @@ <% if @has_samples %>
-
- <%= search_form_for @q, url: group_samples_url(**request.query_parameters), html: { "data-controller": "filters" } do |f| %> + <%= search_form_for @q, url: group_samples_url(**request.query_parameters), html: { "data-controller": "filters" } do |f| %> +
- <%= f.label :name_cont, placeholder: t(".search.placeholder"), class: "sr-only" %> -
-
- <%= viral_icon(name: "magnifying_glass", classes: "h-5 w-5") %> -
- <%= turbo_frame_tag "group_samples_hidden_search_value" %> - <%= f.search_field :name_cont, - "data-action": "filters#submit", - class: - "block w-full p-2.5 pl-10 text-sm text-slate-900 border border-slate-300 rounded-lg bg-slate-50 focus:ring-primary-500 focus:border-primary-500 dark:bg-slate-700 dark:border-slate-600 dark:placeholder-slate-400 dark:text-white dark:focus:ring-primary-500 dark:focus:border-primary-500", - placeholder: t(".search.placeholder") %> -
- - <% end %> -
-
+ +
+ <%= f.label :name_cont, placeholder: t(".search.placeholder"), class: "sr-only" %> +
+
+ <%= viral_icon(name: "magnifying_glass", classes: "h-5 w-5") %> +
+ <%= turbo_frame_tag "group_samples_hidden_search_value" %> + <%= f.search_field :name_cont, + "data-action": "filters#submit", + class: + "block w-full p-2.5 pl-10 text-sm text-slate-900 border border-slate-300 rounded-lg bg-slate-50 focus:ring-primary-500 focus:border-primary-500 dark:bg-slate-700 dark:border-slate-600 dark:placeholder-slate-400 dark:text-white dark:focus:ring-primary-500 dark:focus:border-primary-500", + placeholder: t(".search.placeholder") %> +
+ + + <% end %> -
-
-
- <%= turbo_frame_tag "group_samples_list", - src: group_samples_path(@group, format: :turbo_stream, page: params[:page]), - loading: :lazy %> - <%= turbo_frame_tag "group_samples_pagination" %> +
+
+
+ <%= turbo_frame_tag "group_samples_list", + src: group_samples_path(@group, format: :turbo_stream, page: params[:page]), + loading: :lazy %> + <%= turbo_frame_tag "group_samples_pagination" %> +
-
<% end %> diff --git a/app/views/projects/samples/index.html.erb b/app/views/projects/samples/index.html.erb index f849c24dae..34c6d946ea 100644 --- a/app/views/projects/samples/index.html.erb +++ b/app/views/projects/samples/index.html.erb @@ -35,7 +35,7 @@ <% end %> <% if @has_samples %>
<%= search_form_for @q, url: namespace_project_samples_url(**request.query_parameters), html: { "data-controller": "filters" } do |f| %> diff --git a/test/system/groups/samples_test.rb b/test/system/groups/samples_test.rb index 077c48d9b3..a2e798730e 100644 --- a/test/system/groups/samples_test.rb +++ b/test/system/groups/samples_test.rb @@ -176,5 +176,18 @@ def setup assert_no_text @sample2.name assert_no_text @sample9.name end + + test 'should be able to toggle metadata' do + visit group_samples_url(@group) + assert_selector 'label', text: I18n.t('groups.samples.index.search.metadata'), count: 1 + assert_selector 'table#samples-table thead tr th', count: 4 + find('label', text: I18n.t('groups.samples.index.search.metadata')).click + assert_selector 'table#samples-table thead tr th', count: 6 + within first('table#samples-table tbody tr:first-child') do + assert_text @sample1.name + assert_selector 'td:nth-child(4)', text: 'value1' + assert_selector 'td:nth-child(5)', text: 'value2' + end + end end end diff --git a/test/system/projects/samples_test.rb b/test/system/projects/samples_test.rb index 09ad4b76e7..2a72a68cc9 100644 --- a/test/system/projects/samples_test.rb +++ b/test/system/projects/samples_test.rb @@ -898,7 +898,6 @@ class SamplesTest < ApplicationSystemTestCase assert_selector 'td:nth-child(4)', text: 'value1' assert_selector 'td:nth-child(5)', text: 'value2' end - assert_selector 'label', text: I18n.t('projects.samples.index.search.metadata'), count: 1 end end end From aff596ece0d0559504bf148e0dc38c0dfb164630 Mon Sep 17 00:00:00 2001 From: Josh Adam Date: Thu, 25 Jan 2024 11:10:11 -0600 Subject: [PATCH 49/64] chore: Cleaned up layouts --- app/views/groups/samples/index.html.erb | 2 +- app/views/projects/samples/index.html.erb | 110 +++++++++++----------- 2 files changed, 56 insertions(+), 56 deletions(-) diff --git a/app/views/groups/samples/index.html.erb b/app/views/groups/samples/index.html.erb index 6081f62df5..73d683b845 100644 --- a/app/views/groups/samples/index.html.erb +++ b/app/views/groups/samples/index.html.erb @@ -4,7 +4,7 @@ <% if @has_samples %>
<%= search_form_for @q, url: group_samples_url(**request.query_parameters), html: { "data-controller": "filters" } do |f| %>
diff --git a/app/views/projects/samples/index.html.erb b/app/views/projects/samples/index.html.erb index 34c6d946ea..fe241f5830 100644 --- a/app/views/projects/samples/index.html.erb +++ b/app/views/projects/samples/index.html.erb @@ -35,37 +35,23 @@ <% end %> <% if @has_samples %>
-
- <%= search_form_for @q, url: namespace_project_samples_url(**request.query_parameters), html: { "data-controller": "filters" } do |f| %> + <%= search_form_for @q, url: namespace_project_samples_url(**request.query_parameters), html: { "data-controller": "filters" } do |f| %> +
- <%= f.label :name_cont, placeholder: t(".search.placeholder"), class: "sr-only" %> -
-
-
- <%= viral_icon(name: "magnifying_glass", classes: "h-5 w-5") %> -
- <%= turbo_frame_tag "project_samples_hidden_values" %> - <%= f.search_field :name_cont, - "data-action": "filters#submit", - class: - "block w-full p-2.5 pl-10 text-sm text-slate-900 border border-slate-300 rounded-lg bg-slate-50 focus:ring-primary-500 focus:border-primary-500 dark:bg-slate-700 dark:border-slate-600 dark:placeholder-slate-400 dark:text-white dark:focus:ring-primary-500 dark:focus:border-primary-500", - placeholder: t(".search.placeholder") %> -
-
-
+ +
+ <%= f.label :name_cont, placeholder: t(".search.placeholder"), class: "sr-only" %> +
+
+
+ <%= viral_icon(name: "magnifying_glass", classes: "h-5 w-5") %> +
+ <%= turbo_frame_tag "project_samples_hidden_values" %> + <%= f.search_field :name_cont, + "data-action": "filters#submit", + class: + "block w-full p-2.5 pl-10 text-sm text-slate-900 border border-slate-300 rounded-lg bg-slate-50 focus:ring-primary-500 focus:border-primary-500 dark:bg-slate-700 dark:border-slate-600 dark:placeholder-slate-400 dark:text-white dark:focus:ring-primary-500 dark:focus:border-primary-500", + placeholder: t(".search.placeholder") %> +
+
- <% end %> + <% end %>
-
- <%= turbo_frame_tag "project_samples_list", - src: project_samples_path(@project, format: :turbo_stream, **request.query_parameters), - loading: :lazy do %> - - - <% 15.times do %> - - + + <% end %> + +
-
-
-
-
+ <%= turbo_frame_tag "project_samples_list", + src: project_samples_path(@project, format: :turbo_stream, **request.query_parameters), + loading: :lazy do %> + + + <% 15.times do %> + + - - <% end %> - -
+
+
+
+
+
- -
- <% end %> - <%= turbo_frame_tag "project_samples_pagination" %> +
+ <% end %> + <%= turbo_frame_tag "project_samples_pagination" %> <% end %> From 1b2f59250f00cd05ba62a8d099155b2fb6734852 Mon Sep 17 00:00:00 2001 From: Josh Adam Date: Thu, 25 Jan 2024 11:13:27 -0600 Subject: [PATCH 50/64] chore: Testing for group samples --- test/system/groups/samples_test.rb | 12 +++++++----- test/system/projects/samples_test.rb | 2 ++ 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/test/system/groups/samples_test.rb b/test/system/groups/samples_test.rb index a2e798730e..0dd99edc08 100644 --- a/test/system/groups/samples_test.rb +++ b/test/system/groups/samples_test.rb @@ -180,14 +180,16 @@ def setup test 'should be able to toggle metadata' do visit group_samples_url(@group) assert_selector 'label', text: I18n.t('groups.samples.index.search.metadata'), count: 1 - assert_selector 'table#samples-table thead tr th', count: 4 + assert_selector 'table thead tr th', count: 4 find('label', text: I18n.t('groups.samples.index.search.metadata')).click - assert_selector 'table#samples-table thead tr th', count: 6 - within first('table#samples-table tbody tr:first-child') do + assert_selector 'table thead tr th', count: 6 + within first('table tbody tr:first-child') do assert_text @sample1.name - assert_selector 'td:nth-child(4)', text: 'value1' - assert_selector 'td:nth-child(5)', text: 'value2' + assert_selector 'td:nth-child(3)', text: 'value1' + assert_selector 'td:nth-child(4)', text: 'value2' end + find('label', text: I18n.t('groups.samples.index.search.metadata')).click + assert_selector 'table thead tr th', count: 4 end end end diff --git a/test/system/projects/samples_test.rb b/test/system/projects/samples_test.rb index 2a72a68cc9..1afbadd2fb 100644 --- a/test/system/projects/samples_test.rb +++ b/test/system/projects/samples_test.rb @@ -898,6 +898,8 @@ class SamplesTest < ApplicationSystemTestCase assert_selector 'td:nth-child(4)', text: 'value1' assert_selector 'td:nth-child(5)', text: 'value2' end + find('label', text: I18n.t('projects.samples.index.search.metadata')).click + assert_selector 'table#samples-table thead tr th', count: 4 end end end From 50aa4ee9f0ddab45963c3ba4fcc58eb74c579865 Mon Sep 17 00:00:00 2001 From: Josh Adam Date: Thu, 25 Jan 2024 11:35:08 -0600 Subject: [PATCH 51/64] chore: Fixed testing issue --- test/fixtures/samples.yml | 8 ++++---- test/system/groups/samples_test.rb | 4 +++- test/system/projects/samples_test.rb | 4 ++-- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/test/fixtures/samples.yml b/test/fixtures/samples.yml index 87bb57ddfa..061ce15e6d 100644 --- a/test/fixtures/samples.yml +++ b/test/fixtures/samples.yml @@ -7,10 +7,6 @@ sample1: puid: <%= Irida::PersistentUniqueId.generate(object_class: Sample, time: 1.week.ago) %> created_at: <%= 1.week.ago %> updated_at: <%= 1.day.ago %> - metadata: { 'metadatafield1': 'value1', 'metadatafield2': 'value2' } - metadata_provenance: { 'metadatafield1': { 'id': 1, 'source': 'analysis', - 'updated_at': <%= DateTime.new(2000,1,1) %> }, - 'metadatafield2': { 'id': 1, 'source': 'analysis', 'updated_at': <%= DateTime.new(2000,1,1) %> } } sample2: name: Project 1 Sample 2 @@ -117,6 +113,10 @@ sample30: puid: <%= Irida::PersistentUniqueId.generate(object_class: Sample, time: 33.weeks.ago) %> created_at: <%= 33.weeks.ago %> updated_at: <%= 33.days.ago %> + metadata: { 'metadatafield1': 'value1', 'metadatafield2': 'value2' } + metadata_provenance: { 'metadatafield1': { 'id': 1, 'source': 'analysis', + 'updated_at': <%= DateTime.new(2000,1,1) %> }, + 'metadatafield2': { 'id': 1, 'source': 'analysis', 'updated_at': <%= DateTime.new(2000,1,1) %> } } sample31: name: Sample 2 diff --git a/test/system/groups/samples_test.rb b/test/system/groups/samples_test.rb index 0dd99edc08..5824069b60 100644 --- a/test/system/groups/samples_test.rb +++ b/test/system/groups/samples_test.rb @@ -12,6 +12,7 @@ def setup @sample9 = samples(:sample9) @sample25 = samples(:sample25) @sample29 = samples(:sample29) + @sample30 = samples(:sample30) @sample31 = samples(:sample31) end @@ -179,12 +180,13 @@ def setup test 'should be able to toggle metadata' do visit group_samples_url(@group) + click_on I18n.t('groups.samples.table.updated_at') assert_selector 'label', text: I18n.t('groups.samples.index.search.metadata'), count: 1 assert_selector 'table thead tr th', count: 4 find('label', text: I18n.t('groups.samples.index.search.metadata')).click assert_selector 'table thead tr th', count: 6 within first('table tbody tr:first-child') do - assert_text @sample1.name + assert_text @sample30.name assert_selector 'td:nth-child(3)', text: 'value1' assert_selector 'td:nth-child(4)', text: 'value2' end diff --git a/test/system/projects/samples_test.rb b/test/system/projects/samples_test.rb index 1afbadd2fb..b0c4528ae6 100644 --- a/test/system/projects/samples_test.rb +++ b/test/system/projects/samples_test.rb @@ -893,8 +893,8 @@ class SamplesTest < ApplicationSystemTestCase assert_selector 'table#samples-table thead tr th', count: 4 find('label', text: I18n.t('projects.samples.index.search.metadata')).click assert_selector 'table#samples-table thead tr th', count: 6 - within first('table#samples-table tbody tr:first-child') do - assert_text @sample1.name + within first('table#samples-table tbody tr:nth-child(3)') do + assert_text @sample3.name assert_selector 'td:nth-child(4)', text: 'value1' assert_selector 'td:nth-child(5)', text: 'value2' end From f5ad7a7c5e029c1954b06e2eb2a1cf11e3df90e0 Mon Sep 17 00:00:00 2001 From: Josh Adam Date: Thu, 25 Jan 2024 14:09:28 -0600 Subject: [PATCH 52/64] chore: Removed unused file --- app/helpers/url_helper.rb | 13 ------------- 1 file changed, 13 deletions(-) delete mode 100644 app/helpers/url_helper.rb diff --git a/app/helpers/url_helper.rb b/app/helpers/url_helper.rb deleted file mode 100644 index 8bc746eb90..0000000000 --- a/app/helpers/url_helper.rb +++ /dev/null @@ -1,13 +0,0 @@ -# frozen_string_literal: true - -# Helper functions for anything to do with URLs -module UrlHelper - def pagy_template_url_for(pagy, template) - pagy_url = pagy_url_for(pagy, pagy.page) - uri = URI.parse(pagy_url) - params = Rack::Utils.parse_query(uri.query) - params['template'] = template - uri.query = Rack::Utils.build_query(params) - uri.to_s.gsub('samples.turbo_stream', 'samples') - end -end From d8e930d029dd1161916b04a4f4df4abef791c45a Mon Sep 17 00:00:00 2001 From: Josh Adam Date: Thu, 25 Jan 2024 14:53:03 -0600 Subject: [PATCH 53/64] chore: Removed unnecessarily include --- app/controllers/application_controller.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 4226b87724..320102fbfc 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -5,7 +5,6 @@ class ApplicationController < ActionController::Base include Irida::Auth include Pagy::Backend include RouteHelper - include UrlHelper add_flash_types :success, :info, :warning, :danger before_action :authenticate_user! From cafa8b4f6b53d698525dcc0c232cda4510d09701 Mon Sep 17 00:00:00 2001 From: Josh Adam Date: Thu, 25 Jan 2024 16:15:37 -0600 Subject: [PATCH 54/64] chore: Renamed turbo frame tag --- app/views/groups/samples/index.html.erb | 2 +- app/views/groups/samples/index.turbo_stream.erb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/groups/samples/index.html.erb b/app/views/groups/samples/index.html.erb index 73d683b845..c8384f58ea 100644 --- a/app/views/groups/samples/index.html.erb +++ b/app/views/groups/samples/index.html.erb @@ -70,7 +70,7 @@ > <%= viral_icon(name: "magnifying_glass", classes: "h-5 w-5") %>
- <%= turbo_frame_tag "group_samples_hidden_search_value" %> + <%= turbo_frame_tag "group_samples_hidden_values" %> <%= f.search_field :name_cont, "data-action": "filters#submit", class: diff --git a/app/views/groups/samples/index.turbo_stream.erb b/app/views/groups/samples/index.turbo_stream.erb index ec7d165062..c3f7735cae 100644 --- a/app/views/groups/samples/index.turbo_stream.erb +++ b/app/views/groups/samples/index.turbo_stream.erb @@ -11,7 +11,7 @@ pagy: @pagy } %> -<%= turbo_stream.update "group_samples_hidden_search_value" do %> +<%= turbo_stream.update "group_samples_hidden_values" do %> <%= render Ransack::HiddenSortFieldComponent.new(@q) %> <%= hidden_field_tag "metadata", params[:metadata] %> <% end %> From 569bddd8dbfbf548eea68d87e9434774c2f4fdde Mon Sep 17 00:00:00 2001 From: Josh Adam Date: Fri, 26 Jan 2024 07:26:01 -0600 Subject: [PATCH 55/64] chore: Fixed z-index for table header not to interfere with popover --- app/views/groups/samples/_table.html.erb | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/app/views/groups/samples/_table.html.erb b/app/views/groups/samples/_table.html.erb index 0cea457133..12798e284e 100644 --- a/app/views/groups/samples/_table.html.erb +++ b/app/views/groups/samples/_table.html.erb @@ -31,7 +31,7 @@ dark:bg-slate-700 sticky left-0 - z-20 + z-10 " > <%= render Ransack::SortComponent.new( @@ -86,16 +86,17 @@ id="<%= dom_id(sample) %>" class="bg-white border-b dark:bg-slate-800 dark:border-slate-700" > - <%= link_to sample.name, - namespace_project_sample_path( - id: sample.id, - namespace_id: sample.project.namespace.parent.full_path, - project_id: sample.project.path - ), - data: { - turbo: false - }, - class: "text-slate-900 dark:text-slate-100 font-semibold hover:underline" %> + + <%= link_to sample.name, + namespace_project_sample_path( + id: sample.id, + namespace_id: sample.project.namespace.parent.full_path, + project_id: sample.project.path + ), + data: { + turbo: false + }, + class: "text-slate-900 dark:text-slate-100 font-semibold hover:underline" %> <%= viral_tooltip(title: project_path(sample.project)) do %> From 2e86100b703a4c8e4f3e65c424d0cf393bf1d3d4 Mon Sep 17 00:00:00 2001 From: Josh Adam Date: Fri, 26 Jan 2024 07:28:06 -0600 Subject: [PATCH 56/64] chore: Removed unnecessary metadata param from hidden fields --- app/views/groups/samples/index.turbo_stream.erb | 1 - app/views/projects/samples/index.turbo_stream.erb | 1 - 2 files changed, 2 deletions(-) diff --git a/app/views/groups/samples/index.turbo_stream.erb b/app/views/groups/samples/index.turbo_stream.erb index c3f7735cae..2bb8f5c6d2 100644 --- a/app/views/groups/samples/index.turbo_stream.erb +++ b/app/views/groups/samples/index.turbo_stream.erb @@ -13,5 +13,4 @@ <%= turbo_stream.update "group_samples_hidden_values" do %> <%= render Ransack::HiddenSortFieldComponent.new(@q) %> - <%= hidden_field_tag "metadata", params[:metadata] %> <% end %> diff --git a/app/views/projects/samples/index.turbo_stream.erb b/app/views/projects/samples/index.turbo_stream.erb index 58395bc4d7..1c0e11721a 100644 --- a/app/views/projects/samples/index.turbo_stream.erb +++ b/app/views/projects/samples/index.turbo_stream.erb @@ -14,5 +14,4 @@ <%= turbo_stream.update "project_samples_hidden_values" do %> <%= render Ransack::HiddenSortFieldComponent.new(@q) %> - <%= hidden_field_tag "metadata", params[:metadata] %> <% end %> From 2b505ec6665d25ab9f6f8725b9350582067b7efa Mon Sep 17 00:00:00 2001 From: Josh Adam Date: Fri, 26 Jan 2024 07:43:18 -0600 Subject: [PATCH 57/64] chore: Removed redundant logic --- app/views/groups/samples/_table.html.erb | 2 +- app/views/projects/samples/_table.html.erb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/groups/samples/_table.html.erb b/app/views/groups/samples/_table.html.erb index 12798e284e..79504dc708 100644 --- a/app/views/groups/samples/_table.html.erb +++ b/app/views/groups/samples/_table.html.erb @@ -110,7 +110,7 @@ <% @fields.each do |column| %> - <%= sample[column].present? ? sample[column] : sample.metadata[column] %> + <%= sample.metadata[column] %> <% end %> diff --git a/app/views/projects/samples/_table.html.erb b/app/views/projects/samples/_table.html.erb index 88d4814367..1a8798dc95 100644 --- a/app/views/projects/samples/_table.html.erb +++ b/app/views/projects/samples/_table.html.erb @@ -67,7 +67,7 @@ <% @fields.each do |column| %> - <%= sample[column].present? ? sample[column] : sample.metadata[column] %> + <%= sample.metadata[column] %> <% end %> <% if allowed_to?(:update_sample?, project) %> From 70e64dd29cb8ffb9b1a0d057cbb9a0ad02adfa51 Mon Sep 17 00:00:00 2001 From: Josh Adam Date: Fri, 26 Jan 2024 07:49:50 -0600 Subject: [PATCH 58/64] chore: Cleaned up variable names for Metadata --- app/controllers/concerns/metadata.rb | 6 +++--- app/controllers/groups/samples_controller.rb | 2 +- app/controllers/projects/samples_controller.rb | 10 ++++++++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/app/controllers/concerns/metadata.rb b/app/controllers/concerns/metadata.rb index 1b7a20d131..fd4fe03923 100644 --- a/app/controllers/concerns/metadata.rb +++ b/app/controllers/concerns/metadata.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -# Executes basic metadata template logic for controllers +# Executes basic metadata logic for controllers module Metadata extend ActiveSupport::Concern @@ -8,7 +8,7 @@ module Metadata helper_method :fields_for_namespace end - def fields_for_namespace(namespace = nil, template_id = 0) - @fields = template_id.zero? || namespace.nil? ? [] : namespace.metadata_summary.keys + def fields_for_namespace(namespace: nil, show_fields: false) + @fields = !show_fields || namespace.nil? ? [] : namespace.metadata_summary.keys end end diff --git a/app/controllers/groups/samples_controller.rb b/app/controllers/groups/samples_controller.rb index b4f8fc0ecf..4e342cf836 100644 --- a/app/controllers/groups/samples_controller.rb +++ b/app/controllers/groups/samples_controller.rb @@ -18,7 +18,7 @@ def index # rubocop:disable Metrics/AbcSize end format.turbo_stream do @pagy, @samples = pagy(@q.result) - fields_for_namespace(@group, params[:q] ? params[:q][:metadata].to_i : 0) + fields_for_namespace(namespace: @group, show_fields: params[:q] && params[:q][:metadata].to_i == 1) end end end diff --git a/app/controllers/projects/samples_controller.rb b/app/controllers/projects/samples_controller.rb index 48c22e2ba0..8c906f9f85 100644 --- a/app/controllers/projects/samples_controller.rb +++ b/app/controllers/projects/samples_controller.rb @@ -19,7 +19,10 @@ def index # rubocop:disable Metrics/AbcSize end format.turbo_stream do @pagy, @samples = pagy(@q.result) - fields_for_namespace(@project.namespace, params[:q] ? params[:q][:metadata].to_i : 0) + fields_for_namespace( + namespace: @project.namespace, + show_fields: params[:q] && params[:q][:metadata].to_i == 1 + ) end end end @@ -78,7 +81,10 @@ def destroy # rubocop:disable Metrics/AbcSize,Metrics/MethodLength redirect_to namespace_project_samples_path(format: :html) end format.turbo_stream do - fields_for_namespace(@project.namespace, params[:q] ? params[:q][:metadata].to_i : 0) + fields_for_namespace( + namespace: @project.namespace, + show_fields: params[:q] && params[:q][:metadata].to_i == 1 + ) render status: :ok, locals: { type: 'success', message: t('.success', sample_name: @sample.name, project_name: @project.namespace.human_name) } From 68b4107d662df5110dbb3cd36e30d216b4f5a0e5 Mon Sep 17 00:00:00 2001 From: Josh Adam Date: Fri, 26 Jan 2024 07:54:02 -0600 Subject: [PATCH 59/64] chore: Fixed lookbook preview for time_ago --- .../current_time_input.html.erb | 4 +++- .../viral_time_ago_component_preview/default.html.erb | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/test/components/previews/viral_time_ago_component_preview/current_time_input.html.erb b/test/components/previews/viral_time_ago_component_preview/current_time_input.html.erb index af8013285b..f8c5c8d7bd 100644 --- a/test/components/previews/viral_time_ago_component_preview/current_time_input.html.erb +++ b/test/components/previews/viral_time_ago_component_preview/current_time_input.html.erb @@ -1 +1,3 @@ -<%= viral_time_ago(original_time: Time.now - 15.days, current_time: Time.now - 10.days) %> + + <%= viral_time_ago(original_time: Time.now - 15.days, current_time: Time.now - 10.days) %> + \ No newline at end of file diff --git a/test/components/previews/viral_time_ago_component_preview/default.html.erb b/test/components/previews/viral_time_ago_component_preview/default.html.erb index bd1cb8c8f5..6e3778a146 100644 --- a/test/components/previews/viral_time_ago_component_preview/default.html.erb +++ b/test/components/previews/viral_time_ago_component_preview/default.html.erb @@ -1 +1,3 @@ -<%= viral_time_ago(original_time: Time.now - 15.days) %> + + <%= viral_time_ago(original_time: Time.now - 15.days) %> + \ No newline at end of file From a420bdb0e0e7c58dad2a238470bb7e315314eb4c Mon Sep 17 00:00:00 2001 From: Josh Adam Date: Fri, 26 Jan 2024 07:58:28 -0600 Subject: [PATCH 60/64] chore: Ignore class length warning --- app/controllers/projects/samples_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/projects/samples_controller.rb b/app/controllers/projects/samples_controller.rb index 8c906f9f85..a0bd426096 100644 --- a/app/controllers/projects/samples_controller.rb +++ b/app/controllers/projects/samples_controller.rb @@ -2,7 +2,7 @@ module Projects # Controller actions for Samples - class SamplesController < Projects::ApplicationController + class SamplesController < Projects::ApplicationController # rubocop:disable Metrics/ClassLength include Metadata before_action :sample, only: %i[show edit update destroy] From b7d07e9f29eceb3690a12e9f2ce5255bfa7defb8 Mon Sep 17 00:00:00 2001 From: Josh Adam Date: Fri, 26 Jan 2024 08:15:24 -0600 Subject: [PATCH 61/64] chore: Fixed broken test for time ago --- test/components/viral/system/time_ago_component_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/components/viral/system/time_ago_component_test.rb b/test/components/viral/system/time_ago_component_test.rb index 0d5e0362ba..dd54334651 100644 --- a/test/components/viral/system/time_ago_component_test.rb +++ b/test/components/viral/system/time_ago_component_test.rb @@ -8,7 +8,7 @@ class TimeAgoComponentTest < ApplicationSystemTestCase freeze_time visit('/rails/view_components/viral_time_ago_component/default') assert_text '15 days ago' - within('.Viral-Preview > [data-controller-connected="true"]') do + within('.Viral-Preview [data-controller-connected="true"]') do assert_selector '[data-viral--tooltip-target="target"]', visible: false find('span', text: '15 days ago').hover assert_text (DateTime.now - 15.days).strftime('%B %d, %Y %H:%M') @@ -20,7 +20,7 @@ class TimeAgoComponentTest < ApplicationSystemTestCase freeze_time visit('/rails/view_components/viral_time_ago_component/current_time_input') assert_text '5 days ago' - within('.Viral-Preview > [data-controller-connected="true"]') do + within('.Viral-Preview [data-controller-connected="true"]') do assert_selector '[data-viral--tooltip-target="target"]', visible: false find('span', text: '5 days ago').hover assert_text (DateTime.now - 15.days).strftime('%B %d, %Y %H:%M') From 3414ef3038fc343d55913592721736dc172398b0 Mon Sep 17 00:00:00 2001 From: Josh Adam Date: Fri, 26 Jan 2024 10:18:46 -0600 Subject: [PATCH 62/64] chore: Fixed z-index --- app/views/projects/samples/_table.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/projects/samples/_table.html.erb b/app/views/projects/samples/_table.html.erb index 1a8798dc95..3c20903e41 100644 --- a/app/views/projects/samples/_table.html.erb +++ b/app/views/projects/samples/_table.html.erb @@ -7,7 +7,7 @@ > - + <%= render Ransack::SortComponent.new(ransack_obj: @q, label: t(".sample"), url: sorting_url(@q, :name), field: :name) %> From 0937d9b49ca84d22a60e882cd00a4ce36a98d7f9 Mon Sep 17 00:00:00 2001 From: Josh Adam Date: Fri, 26 Jan 2024 10:19:44 -0600 Subject: [PATCH 63/64] chore: Moved created and updated on groups table --- app/views/groups/samples/_table.html.erb | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/app/views/groups/samples/_table.html.erb b/app/views/groups/samples/_table.html.erb index 79504dc708..687bdf2957 100644 --- a/app/views/groups/samples/_table.html.erb +++ b/app/views/groups/samples/_table.html.erb @@ -47,12 +47,6 @@ > <%= t(".project") %> - <% @fields.each do |column| %> - <%= column %> - <% end %> <%= render Ransack::SortComponent.new( ransack_obj: @q, @@ -69,6 +63,12 @@ field: :updated_at ) %> + <% @fields.each do |column| %> + <%= column %> + <% end %> <% end %> - <% @fields.each do |column| %> - - <%= sample.metadata[column] %> - - <% end %> <%= l(sample.created_at.localtime, format: :full_date) %> <%= viral_time_ago(original_time: sample.updated_at) %> + <% @fields.each do |column| %> + + <%= sample.metadata[column] %> + + <% end %> <% end %> From 0b0986db735785f0f7c4b12ff9d7a5c4f34263a9 Mon Sep 17 00:00:00 2001 From: Josh Adam Date: Fri, 26 Jan 2024 10:20:38 -0600 Subject: [PATCH 64/64] chore: Fixed text --- test/system/groups/samples_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/system/groups/samples_test.rb b/test/system/groups/samples_test.rb index 5824069b60..12bf940972 100644 --- a/test/system/groups/samples_test.rb +++ b/test/system/groups/samples_test.rb @@ -187,8 +187,8 @@ def setup assert_selector 'table thead tr th', count: 6 within first('table tbody tr:first-child') do assert_text @sample30.name - assert_selector 'td:nth-child(3)', text: 'value1' - assert_selector 'td:nth-child(4)', text: 'value2' + assert_selector 'td:nth-child(5)', text: 'value1' + assert_selector 'td:nth-child(6)', text: 'value2' end find('label', text: I18n.t('groups.samples.index.search.metadata')).click assert_selector 'table thead tr th', count: 4