mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-01-27 10:08:11 +08:00
Add sorting options to experiment task table view [SCI-9120] (#6102)
This commit is contained in:
parent
8cecdd86ea
commit
a25e6fdda3
3 changed files with 11 additions and 5 deletions
|
@ -122,8 +122,9 @@ class Experiment < ApplicationRecord
|
|||
|
||||
def validate_view_state(view_state)
|
||||
if %w(canvas table).exclude?(view_state.state.dig('my_modules', 'view_type')) ||
|
||||
%w(atoz ztoa due_first due_last).exclude?(view_state.state.dig('my_modules', 'active', 'sort')) ||
|
||||
%w(atoz ztoa due_first due_last
|
||||
id_asc id_desc).exclude?(view_state.state.dig('my_modules', 'active', 'sort')) ||
|
||||
%w(atoz ztoa due_first due_last id_asc id_desc
|
||||
archived_old archived_new).exclude?(view_state.state.dig('my_modules', 'archived', 'sort'))
|
||||
view_state.errors.add(:state, :wrong_state)
|
||||
end
|
||||
|
|
|
@ -219,8 +219,9 @@ module Experiments
|
|||
@view_state = experiment.current_view_state(@user)
|
||||
@view_mode = @params[:view_mode] || 'active'
|
||||
@sort = @view_state.state.dig('my_modules', @view_mode, 'sort') || 'atoz'
|
||||
if @params[:sort] && @sort != @params[:sort] && %w(due_first due_last atoz ztoa
|
||||
archived_old archived_new).include?(@params[:sort])
|
||||
if @params[:sort] &&
|
||||
@sort != @params[:sort] &&
|
||||
%w(due_first due_last atoz ztoa id_asc id_desc archived_old archived_new).include?(@params[:sort])
|
||||
@view_state.state['my_modules'].merge!(Hash[@view_mode, { 'sort': @params[:sort] }.stringify_keys])
|
||||
@view_state.save!
|
||||
@sort = @view_state.state.dig('my_modules', @view_mode, 'sort')
|
||||
|
@ -237,6 +238,10 @@ module Experiments
|
|||
records.order(:name)
|
||||
when 'ztoa'
|
||||
records.order(name: :desc)
|
||||
when 'id_asc'
|
||||
records.order(:id)
|
||||
when 'id_desc'
|
||||
records.order(id: :desc)
|
||||
when 'archived_old'
|
||||
records.order(Arel.sql('COALESCE(my_modules.archived_on, my_modules.archived_on) ASC'))
|
||||
when 'archived_new'
|
||||
|
|
|
@ -27,9 +27,9 @@
|
|||
<i class="sn-icon sn-icon-sort-up"></i>
|
||||
</button>
|
||||
<ul id="sortMenuDropdown" class="dropdown-menu sort-task-menu <%= params[:view_mode] %> dropdown-menu-right" aria-labelledby="sortMenu">
|
||||
<% %w(atoz ztoa due_first due_last archived_old archived_new).each_with_index do |sort, i| %>
|
||||
<% %w(atoz ztoa due_first due_last id_asc id_desc archived_old archived_new).each_with_index do |sort, i| %>
|
||||
<% if i.even? && i.positive? %>
|
||||
<li class="divider" <%= i > 3 ? 'data-view-mode=archived' : '' %>></li>
|
||||
<li class="divider" <%= i > 5 ? '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 %>"
|
||||
|
|
Loading…
Reference in a new issue