Merge pull request #4793 from aignatov-bio/ai-sci-7704-experiment-update-navigation-panel-along-with-table

Update sidebar along with experiment table [SCI-7704]
This commit is contained in:
aignatov-bio 2023-01-10 14:56:04 +01:00 committed by GitHub
commit 7503bd7af8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 44 additions and 17 deletions

View file

@ -1,4 +1,5 @@
/* global I18n GLOBAL_CONSTANTS InfiniteScroll initBSTooltips filterDropdown dropdownSelector HelperModule */
/* global I18n GLOBAL_CONSTANTS InfiniteScroll
initBSTooltips filterDropdown dropdownSelector Sidebar HelperModule */
var ExperimnetTable = {
permissions: ['editable', 'archivable', 'restorable', 'moveable'],
@ -528,6 +529,12 @@ var ExperimnetTable = {
var dataUrl = $(this.table).data('my-modules-url');
$(this.table).find('.table-row').remove();
this.loadPlaceholder();
Sidebar.reload({
sort: this.myModulesCurrentSort,
view_mode: $('#experimentTable').hasClass('archived') ? 'archived' : ''
});
$.get(dataUrl, tableParams, (result) => {
$(this.table).find('.table-row-placeholder, .table-row-placeholder-divider').remove();
this.appendRows(result.data);

View file

@ -89,18 +89,7 @@ class ExperimentsController < ApplicationController
end
def table
view_state = @experiment.current_view_state(current_user)
view_mode = params[:view_mode] || 'active'
@current_sort = view_state.state.dig('my_modules', view_mode, 'sort') || 'atoz'
@project = @experiment.project
@my_modules = if @experiment.archived_branch?
@experiment.my_modules.order(:name)
elsif params[:view_mode] == 'archived'
@experiment.my_modules.archived.order(:name)
else
@experiment.my_modules.active.order(:name)
end
@my_module_visible_table_columns = current_user.my_module_visible_table_columns
end
@ -396,11 +385,23 @@ class ExperimentsController < ApplicationController
end
def sidebar
view_state = @experiment.current_view_state(current_user)
view_mode = params[:view_mode].presence || 'active'
default_sort = view_state.state.dig('my_modules', view_mode, 'sort') || 'atoz'
my_modules = if @experiment.archived_branch?
@experiment.my_modules
elsif params[:view_mode] == 'archived'
@experiment.my_modules.archived
else
@experiment.my_modules.active
end
my_modules = sort_my_modules(my_modules, params[:sort].presence || default_sort)
respond_to do |format|
format.json do
render json: {
html: render_to_string(
partial: 'shared/sidebar/my_modules.html.erb', locals: { experiment: @experiment }
partial: 'shared/sidebar/my_modules.html.erb', locals: { experiment: @experiment, my_modules: my_modules }
)
}
end
@ -596,4 +597,23 @@ class ExperimentsController < ApplicationController
table_experiment_path(@experiment, view_mode: params[:view_mode])
end
end
def sort_my_modules(records, sort)
case sort
when 'due_first'
records.order(:due_date)
when 'due_last'
records.order(Arel.sql("COALESCE(due_date, DATE '1900-01-01') DESC"))
when 'atoz'
records.order(:name)
when 'ztoa'
records.order(name: :desc)
when 'archived_old'
records.order(Arel.sql('COALESCE(my_modules.archived_on, my_modules.archived_on) ASC'))
when 'archived_new'
records.order(Arel.sql('COALESCE(my_modules.archived_on, my_modules.archived_on) DESC'))
else
records
end
end
end

View file

@ -5,9 +5,9 @@
<%= content_for :sidebar do %>
<% if params[:view_mode] == 'archived' %>
<%= render partial: 'shared/sidebar/archived_my_modules.html.erb', locals: { experiment: @experiment, my_modules: @my_modules } %>
<%= render partial: 'shared/sidebar/archived_my_modules.html.erb', locals: { experiment: @experiment, my_modules: nil } %>
<% else %>
<%= render partial: 'shared/sidebar/my_modules.html.erb', locals: { experiment: @experiment, my_modules: @my_modules } %>
<%= render partial: 'shared/sidebar/my_modules.html.erb', locals: { experiment: @experiment, my_modules: nil } %>
<% end %>
<% end %>

View file

@ -12,7 +12,7 @@
<% end %>
</li>
<% end %>
<% my_modules.each do |my_module| %>
<% my_modules&.each do |my_module| %>
<li class="sidebar-leaf">
<%= link_to my_module.name,
protocols_my_module_url(my_module),

View file

@ -8,7 +8,7 @@
<li class="sidebar-leaf">
<%= link_to t('sidebar.my_modules.back_button'), project_url(experiment.project), class: 'sidebar-link back-button' %>
</li>
<% my_modules.readable_by_user(current_user).each do |my_module| %>
<% my_modules&.readable_by_user(current_user)&.each do |my_module| %>
<li class="sidebar-leaf">
<%= link_to my_module.name,
protocols_my_module_url(my_module),