mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-12-26 09:42:46 +08:00
Add experiments page load logic and connect filters [SCI-5457]
This commit is contained in:
parent
259d7d5e7c
commit
7726eae4da
8 changed files with 123 additions and 48 deletions
|
@ -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();
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -48,27 +48,26 @@
|
|||
<%= t("projects.index.filters_modal.folders.popover_html") %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<div class="dropdown sort-menu">
|
||||
<button class="btn btn-light dropdown-toggle" type="button" id="sortMenu" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
|
||||
<span><i class="fas fa-sort-amount-down"></i></span>
|
||||
<span class="caret"></span>
|
||||
</button>
|
||||
<ul id="sortMenuDropdown" class="dropdown-menu sort-projects-menu dropdown-menu-right" aria-labelledby="sortMenu">
|
||||
<% %w(new old atoz ztoa archived_new archived_old).each_with_index do |sort, i| %>
|
||||
<% if i.even? && i.positive? %>
|
||||
<li class="divider" <%= i > 3 ? 'data-view-mode=archived' : '' %>></li>
|
||||
<% end %>
|
||||
<div class="dropdown sort-menu">
|
||||
<button class="btn btn-light dropdown-toggle" type="button" id="sortMenu" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
|
||||
<span><i class="fas fa-sort-amount-down"></i></span>
|
||||
<span class="caret"></span>
|
||||
</button>
|
||||
<ul id="sortMenuDropdown" class="dropdown-menu sort-projects-menu dropdown-menu-right" aria-labelledby="sortMenu">
|
||||
<% %w(new old atoz ztoa archived_new archived_old).each_with_index do |sort, i| %>
|
||||
<% if i.even? && i.positive? %>
|
||||
<li class="divider" <%= i > 3 ? 'data-view-mode=archived' : '' %>></li>
|
||||
<% end %>
|
||||
<li <%= %w(archived_new archived_old).include?(sort) ? 'data-view-mode=archived' : '' %>>
|
||||
<a class="<%= 'selected' if @current_sort == sort %>"
|
||||
data-sort="<%= sort %>" >
|
||||
<%= t("general.sort.#{sort}_html") %>
|
||||
</a>
|
||||
</li>
|
||||
<% end %>
|
||||
<li <%= %w(archived_new archived_old).include?(sort) ? 'data-view-mode=archived' : '' %>>
|
||||
<a class="<%= 'selected' if @current_sort == sort %>"
|
||||
data-sort="<%= sort %>" >
|
||||
<%= t("general.sort.#{sort}_html") %>
|
||||
</a>
|
||||
</li>
|
||||
<% end %>
|
||||
</ul>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -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' %>
|
||||
|
||||
<div class="project-show-container">
|
||||
<div class="cards-wrapper" id="cardsWrapper">
|
||||
<div class="cards-wrapper" id="cardsWrapper" data-experiments-cards-url="<%= experiments_cards_project_path(@project) %>">
|
||||
<!-- list -->
|
||||
<div class="table-header">
|
||||
<div class="table-header-cell select-all-checkboxes">
|
||||
|
@ -31,11 +31,6 @@
|
|||
<div class="table-header-cell"><%= t('experiments.card.description') %></div>
|
||||
<div class="table-header-cell"></div>
|
||||
</div>
|
||||
<!-- cards -->
|
||||
<% @project.sorted_experiments(@current_sort).each do |experiment| %>
|
||||
<%= render partial: 'projects/show/experiment_card',
|
||||
locals: { experiment: experiment } %>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
5
app/views/projects/show/_experiments_list.html.erb
Normal file
5
app/views/projects/show/_experiments_list.html.erb
Normal file
|
@ -0,0 +1,5 @@
|
|||
<% cards.each do |card| %>
|
||||
<% cache [current_user, card] do %>
|
||||
<%= render partial: 'projects/show/experiment_card', locals: { experiment: card } %>
|
||||
<% end %>
|
||||
<% end %>
|
|
@ -50,18 +50,19 @@
|
|||
<button class="btn btn-light icon-btn dropdown-toggle" type="button" id="sortMenu" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
|
||||
<i class="fas fa-sort-amount-up"></i>
|
||||
</button>
|
||||
<ul class="dropdown-menu dropdown-menu-right" aria-labelledby="sortMenu">
|
||||
<% ["new", "old", "atoz", "ztoa", "archived_new", "archived_old"].each_with_index do |sort, i| %>
|
||||
<% unless action_name != 'experiment_archive' && sort.include?('arch') %>
|
||||
<ul id="sortMenuDropdown" class="dropdown-menu sort-experiments-menu dropdown-menu-right" aria-labelledby="sortMenu">
|
||||
<% %w(new old atoz ztoa archived_new archived_old).each_with_index do |sort, i| %>
|
||||
<% if i.even? && i.positive? %>
|
||||
<li class="divider"></li>
|
||||
<li class="divider" <%= i > 3 ? 'data-view-mode=archived' : '' %>></li>
|
||||
<% end %>
|
||||
<li>
|
||||
<a class="<%= 'selected' if @current_sort == sort %>" href="?<%= {sort: sort}.reject{|v| v.to_s == "0"}.to_query %>"><%= t("general.sort.#{sort}_html") %></a>
|
||||
<li <%= %w(archived_new archived_old).include?(sort) ? 'data-view-mode=archived' : '' %>>
|
||||
<a class="<%= 'selected' if @current_sort == sort %>"
|
||||
data-sort="<%= sort %>" >
|
||||
<%= t("general.sort.#{sort}_html") %>
|
||||
</a>
|
||||
</li>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</ul>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -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'
|
||||
|
|
Loading…
Reference in a new issue