From 7726eae4da243f95911abb9d1607b7cfb4763d29 Mon Sep 17 00:00:00 2001 From: aignatov-bio Date: Tue, 2 Feb 2021 11:17:29 +0100 Subject: [PATCH] Add experiments page load logic and connect filters [SCI-5457] --- app/assets/javascripts/projects/show.js | 61 ++++++++++++++++++- app/controllers/projects_controller.rb | 31 +++++++--- app/services/experiments_overview_service.rb | 5 ++ app/views/projects/index/_header.html.erb | 39 ++++++------ app/views/projects/show.html.erb | 9 +-- .../projects/show/_experiments_list.html.erb | 5 ++ app/views/projects/show/_header.html.erb | 17 +++--- config/routes.rb | 4 +- 8 files changed, 123 insertions(+), 48 deletions(-) create mode 100644 app/views/projects/show/_experiments_list.html.erb diff --git a/app/assets/javascripts/projects/show.js b/app/assets/javascripts/projects/show.js index ad2af0384..10af36bb7 100644 --- a/app/assets/javascripts/projects/show.js +++ b/app/assets/javascripts/projects/show.js @@ -1,5 +1,9 @@ /* global filterDropdown */ (function() { + var cardsWrapper = '#cardsWrapper' + + var selectedExperiments = []; + let experimentsCurrentSort; let experimentsViewSearch; let startedOnFromFilter; @@ -41,7 +45,7 @@ archivedOnToFilter = $archivedOnToFilter.val(); experimentsViewSearch = $textFilter.val(); appliedFiltersMark(); - //refreshCurrentView(); + refreshCurrentView(); }); // Clear filters @@ -56,6 +60,59 @@ }); } + function updateExperimentsToolbar() { + + } + + function initSorting() { + $('#sortMenuDropdown a').click(function() { + if (experimentsCurrentSort !== $(this).data('sort')) { + $('#sortMenuDropdown a').removeClass('selected'); + experimentsCurrentSort = $(this).data('sort'); + refreshCurrentView(); + $(this).addClass('selected'); + $('#sortMenu').dropdown('toggle'); + } + }); + } + + function refreshCurrentView() { + loadCardsView(); + Sidebar.reload({ + sort: experimentsCurrentSort, + view_mode: 'active' + }); + } + + function loadCardsView() { + var viewContainer = $(cardsWrapper); + $.ajax({ + url: viewContainer.data('experiments-cards-url'), + type: 'GET', + dataType: 'json', + data: { + view_mode: 'active', + sort: experimentsCurrentSort, + search: experimentsViewSearch, + created_on_from: startedOnFromFilter, + created_on_to: startedOnToFilter, + updated_on_from: modifiedOnFromFilter, + updated_on_to: modifiedOnToFilter, + archived_on_from: archivedOnFromFilter, + archived_on_to: archivedOnToFilter + }, + success: function(data) { + viewContainer.find('.card').remove(); + viewContainer.append(data.cards_html); + selectedExperiments.length = 0; + updateExperimentsToolbar(); + }, + error: function() { + viewContainer.html('Error loading project list'); + } + }); + } + function init() { $('.workflowimg-container').each(function() { let container = $(this); @@ -77,6 +134,8 @@ }); initExperimentsFilters(); + initSorting() + loadCardsView(); } init(); diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index e2121f07c..8453e55ae 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -10,9 +10,9 @@ class ProjectsController < ApplicationController helper_method :current_folder before_action :switch_team_with_param, only: :index - before_action :load_vars, only: %i(show edit update notifications experiment_archive sidebar) + before_action :load_vars, only: %i(show edit update notifications experiment_archive sidebar experiments_cards) before_action :load_current_folder, only: %i(index cards new show experiment_archive) - before_action :check_view_permissions, only: %i(show notifications experiment_archive sidebar) + before_action :check_view_permissions, only: %i(show notifications experiment_archive sidebar experiments_cards) before_action :check_create_permissions, only: %i(new create) before_action :check_manage_permissions, only: :edit before_action :set_inline_name_editing, only: %i(show) @@ -53,15 +53,15 @@ class ProjectsController < ApplicationController end def sidebar - respond_to do |format| - format.json do - render json: { - html: render_to_string( - partial: 'shared/sidebar/experiments.html.erb', locals: { project: @project } - ) + @current_sort = @project.current_view_state(current_user).state.dig('experiments', params[:view_mode], 'sort') + render json: { + html: render_to_string( + partial: 'shared/sidebar/experiments.html.erb', locals: { + project: @project, + archived: params[:view_mode] == 'archived' } - end - end + ) + } end def new @@ -258,6 +258,17 @@ class ProjectsController < ApplicationController current_team_switch(@project.team) end + def experiments_cards + overview_service = ExperimentsOverviewService.new(@project, current_user, params) + render json: { + cards_html: render_to_string( + partial: 'projects/show/experiments_list.html.erb', + locals: { cards: overview_service.experiments } + ) + } + + end + def notifications @modules = @project .assigned_modules(current_user) diff --git a/app/services/experiments_overview_service.rb b/app/services/experiments_overview_service.rb index 762723c0a..d06ab1caa 100644 --- a/app/services/experiments_overview_service.rb +++ b/app/services/experiments_overview_service.rb @@ -46,6 +46,11 @@ class ExperimentsOverviewService records = records.where('experiments.created_at > ?', @params[:created_on_from]) end records = records.where('experiments.created_at < ?', @params[:created_on_to]) if @params[:created_on_to].present? + if @params[:updated_on_from].present? + records = records.where('experiments.updated_at > ?', @params[:updated_on_from]) + end + records = records.where('experiments.updated_at < ?', @params[:updated_on_to]) if @params[:updated_on_to].present? + if @params[:archived_on_from].present? records = records.where('COALESCE(experiments.archived_on, projects.archived_on) > ?', @params[:archived_on_from]) end diff --git a/app/views/projects/index/_header.html.erb b/app/views/projects/index/_header.html.erb index 3434cc89d..766e8ee10 100644 --- a/app/views/projects/index/_header.html.erb +++ b/app/views/projects/index/_header.html.erb @@ -48,27 +48,26 @@ <%= t("projects.index.filters_modal.folders.popover_html") %> - - <% end %> - - diff --git a/app/views/projects/show.html.erb b/app/views/projects/show.html.erb index 6f48d6516..b012eb6ae 100644 --- a/app/views/projects/show.html.erb +++ b/app/views/projects/show.html.erb @@ -1,6 +1,6 @@ <% provide(:head_title, t("projects.show.head_title", project: h(@project.name)).html_safe) %> <% provide(:sidebar_title, t("sidebar.experiments.sidebar_title")) %> -<% provide(:sidebar_url, project_sidebar_path(@project)) %> +<% provide(:sidebar_url, sidebar_project_path(@project)) %> <% provide(:container_class, 'no-second-nav-container') %> <%= content_for :sidebar do %> @@ -15,7 +15,7 @@ <%= render partial: 'projects/show/header' %>
-
+
@@ -31,11 +31,6 @@
<%= t('experiments.card.description') %>
- - <% @project.sorted_experiments(@current_sort).each do |experiment| %> - <%= render partial: 'projects/show/experiment_card', - locals: { experiment: experiment } %> - <% end %>
diff --git a/app/views/projects/show/_experiments_list.html.erb b/app/views/projects/show/_experiments_list.html.erb new file mode 100644 index 000000000..13009eb54 --- /dev/null +++ b/app/views/projects/show/_experiments_list.html.erb @@ -0,0 +1,5 @@ +<% cards.each do |card| %> + <% cache [current_user, card] do %> + <%= render partial: 'projects/show/experiment_card', locals: { experiment: card } %> + <% end %> +<% end %> diff --git a/app/views/projects/show/_header.html.erb b/app/views/projects/show/_header.html.erb index 4ad677fa0..7e45a6114 100644 --- a/app/views/projects/show/_header.html.erb +++ b/app/views/projects/show/_header.html.erb @@ -50,18 +50,19 @@ -
diff --git a/config/routes.rb b/config/routes.rb index 8f2d9f7f7..5920ba330 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -285,14 +285,14 @@ Rails.application.routes.draw do # Notifications popup for individual project in projects index get 'notifications' get 'experiment_archive' # Experiment archive for single project + get 'experiments_cards' + get 'sidebar' end # This route is defined outside of member block # to preserve original :project_id parameter in URL. get 'users/edit', to: 'user_projects#index_edit' - get 'sidebar', to: 'projects#sidebar', as: 'sidebar' - collection do get 'cards', to: 'projects#cards' get 'users_filter'