From 486dae75592bbcb6a303b5620593e6f6f26a1b6f Mon Sep 17 00:00:00 2001 From: aignatov-bio Date: Wed, 10 Feb 2021 14:50:42 +0100 Subject: [PATCH] Add task counter to experiment card [SCI-5467] --- app/assets/stylesheets/experiments.scss | 21 ++----------------- app/services/experiments_overview_service.rb | 6 ++++++ app/views/projects/show.html.erb | 2 +- .../projects/show/_experiment_card.html.erb | 10 ++++----- 4 files changed, 14 insertions(+), 25 deletions(-) diff --git a/app/assets/stylesheets/experiments.scss b/app/assets/stylesheets/experiments.scss index 6b7d4672b..0b77328dd 100644 --- a/app/assets/stylesheets/experiments.scss +++ b/app/assets/stylesheets/experiments.scss @@ -263,17 +263,13 @@ background-color: $color-alto; } - .dates-and-img-container { - .data-row { - line-height: 26px; - } - } - .progress-bar { background-color: $color-silver-chalice; } .description-cell { + width: 100%; + .description-text::after { background: linear-gradient(to right, transparent, $color-concrete 50%); } @@ -281,25 +277,12 @@ } &.list { - --list-columns-number: 8; .card.experiment-card { .archived-date-cell { grid-column: 5; } - .completed-task-cell { - grid-column: 6; - } - - .description-cell { - grid-column: 7; - } - - .actions-cell { - grid-column: 8; - } - &:hover { .description-text::after { background: linear-gradient(to right, transparent, $color-alto 50%); diff --git a/app/services/experiments_overview_service.rb b/app/services/experiments_overview_service.rb index d06ab1caa..3b4ca0a69 100644 --- a/app/services/experiments_overview_service.rb +++ b/app/services/experiments_overview_service.rb @@ -34,6 +34,12 @@ class ExperimentsOverviewService def fetch_records @project.experiments.joins(:project) + .left_joins(:my_modules) + .select('experiments.*') + .where('(my_modules.archived = FALSE OR my_modules.id IS NULL)') + .select('COUNT(DISTINCT my_modules.id) AS task_count') + .select('SUM(CASE WHEN my_modules.state = 1 THEN 1 ELSE 0 END) as completed_task_count') + .group('experiments.id, projects.archived_on') end def filter_records(records) diff --git a/app/views/projects/show.html.erb b/app/views/projects/show.html.erb index 667d4a864..285384417 100644 --- a/app/views/projects/show.html.erb +++ b/app/views/projects/show.html.erb @@ -28,7 +28,7 @@
<%= t('experiments.card.start_date') %>
<%= t('experiments.card.modified_date') %>
<%= t('experiments.card.archived_date') %>
-
<%= t('experiments.card.completed_task') %>
+
<%= t('experiments.card.completed_task') %>
<%= t('experiments.card.description') %>
diff --git a/app/views/projects/show/_experiment_card.html.erb b/app/views/projects/show/_experiment_card.html.erb index 83b80749b..f56e09ce4 100644 --- a/app/views/projects/show/_experiment_card.html.erb +++ b/app/views/projects/show/_experiment_card.html.erb @@ -40,18 +40,18 @@ <%= l(experiment.archived_on, format: :full_date) %> <% end %> -
+
<%= t('experiments.card.completed_task') %> - <%= t('experiments.card.completed_value', completed: 12, all: 16) %> + <%= t('experiments.card.completed_value', completed: experiment.completed_task_count, all: experiment.task_count) %>
-
- <%= t('experiments.card.completed_value', completed: 12, all: 16) %> +
+ <%= t('experiments.card.completed_value', completed: experiment.completed_task_count, all: experiment.task_count) %>
- <% percentage = 40 %> + <% percentage = experiment.task_count.positive? ? ((100/experiment.task_count) * experiment.completed_task_count) : 0 %>