mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-02-23 07:13:57 +08:00
Added back backend code for table column sorting [SCI-10100]
This commit is contained in:
parent
caab8fbc38
commit
980468cb41
3 changed files with 49 additions and 2 deletions
|
@ -75,7 +75,10 @@ module Lists
|
|||
created_at: 'experiments.created_at',
|
||||
name: 'experiments.name',
|
||||
code: 'experiments.id',
|
||||
archived_on: 'COALESCE(experiments.archived_on, projects.archived_on)'
|
||||
archived_on: 'COALESCE(experiments.archived_on, projects.archived_on)',
|
||||
updated_at: 'experiments.updated_at',
|
||||
total_tasks: 'task_count',
|
||||
description: 'experiments.description'
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
|
@ -44,7 +44,13 @@ module Lists
|
|||
due_date: 'due_date',
|
||||
name: 'name',
|
||||
id: 'id',
|
||||
archived_on: 'archived_on'
|
||||
archived_on: 'archived_on',
|
||||
age: 'age',
|
||||
status: 'status',
|
||||
designated: 'designated',
|
||||
results: 'results',
|
||||
tags: 'tags',
|
||||
signatures: 'signatures'
|
||||
}
|
||||
end
|
||||
|
||||
|
@ -70,6 +76,40 @@ module Lists
|
|||
@records = @records.order(Arel.sql('COALESCE(my_modules.archived_on, my_modules.archived_on) ASC'))
|
||||
when 'archived_on_DESC'
|
||||
@records = @records.order(Arel.sql('COALESCE(my_modules.archived_on, my_modules.archived_on) DESC'))
|
||||
when 'age_ASC'
|
||||
@records = @records.order(:created_at)
|
||||
when 'age_DESC'
|
||||
@records = @records.order(created_at: :desc)
|
||||
when 'status_ASC'
|
||||
@records = @records.order(:my_module_status_id)
|
||||
when 'status_DESC'
|
||||
@records = @records.order(my_module_status_id: :desc)
|
||||
when 'designated_ASC'
|
||||
@records = @records.left_joins(:user_my_modules)
|
||||
.group('my_modules.id')
|
||||
.order(Arel.sql('COUNT(DISTINCT user_my_modules.id) ASC'))
|
||||
when 'designated_DESC'
|
||||
@records = @records.left_joins(:user_my_modules)
|
||||
.group('my_modules.id')
|
||||
.order(Arel.sql('COUNT(DISTINCT user_my_modules.id) DESC'))
|
||||
when 'results_ASC'
|
||||
@records = @records.left_joins(:results)
|
||||
.group('my_modules.id')
|
||||
.order(Arel.sql('COUNT(DISTINCT results.id) ASC'))
|
||||
when 'results_DESC'
|
||||
@records = @records.left_joins(:results)
|
||||
.group('my_modules.id')
|
||||
.order(Arel.sql('COUNT(DISTINCT results.id) DESC'))
|
||||
when 'tags_ASC'
|
||||
@records = @records.left_joins(:tags)
|
||||
.group('my_modules.id')
|
||||
.order(Arel.sql('COUNT(DISTINCT tags.id) ASC'))
|
||||
when 'tags_DESC'
|
||||
@records = @records.left_joins(:tags)
|
||||
.group('my_modules.id')
|
||||
.order(Arel.sql('COUNT(DISTINCT tags.id) DESC'))
|
||||
else
|
||||
__send__("#{sortable_columns[order_params[:column].to_sym]}_sort", sort_direction(order_params))
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -115,6 +115,10 @@ module Lists
|
|||
@records = @records.sort_by(&:archived_on)
|
||||
when 'archived_on_DESC'
|
||||
@records = @records.sort_by(&:archived_on).reverse!
|
||||
when 'users_ASC'
|
||||
@records = @records.sort_by { |project| project.users.count }
|
||||
when 'users_DESC'
|
||||
@records = @records.sort_by { |project| project.users.count }.reverse!
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue