Merge pull request #7859 from aignatov-bio/ai-sci-11060-add-sorting-to-storage-locations

Add sorting to storage locations [SCI-11060]
This commit is contained in:
Martin Artnik 2024-09-17 15:29:16 +02:00 committed by GitHub
commit ada9cdf696
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 47 additions and 8 deletions

View file

@ -112,8 +112,8 @@ export default {
{
field: 'sub_location_count',
headerName: this.i18n.t('storage_locations.index.table.sub_locations'),
width: 250,
sortable: true
sortable: true,
cellRenderer: (params) => params.data.sub_location_count
},
{
field: 'shared_label',
@ -138,7 +138,7 @@ export default {
{
field: 'description',
headerName: this.i18n.t('storage_locations.index.table.description'),
sortable: true
sortable: false
}];
return columns;

View file

@ -9,7 +9,7 @@ module Lists
:created_on, :urls, :metadata, :file_name, :sub_location_count, :is_empty
def owned_by
object.team.name
object['team_name']
end
def is_empty
@ -28,7 +28,7 @@ module Lists
end
def created_by
object.created_by.full_name
object['created_by_full_name']
end
def created_on

View file

@ -14,9 +14,15 @@ module Lists
@records =
StorageLocation.joins('LEFT JOIN storage_locations AS sub_locations ' \
'ON storage_locations.id = sub_locations.parent_id')
.left_joins(:team, :created_by)
.viewable_by_user(@user, @team)
.select(shared_sql_select)
.select('storage_locations.*, COUNT(sub_locations.id) AS sub_location_count')
.select(
'storage_locations.*,
MAX(teams.name) as team_name,
MAX(users.full_name) as created_by_full_name,
CASE WHEN storage_locations.container THEN -1 ELSE COUNT(sub_locations.id) END AS sub_location_count'
)
.group(:id)
end
@ -37,7 +43,40 @@ module Lists
private
def sort_records
return
return unless @params[:order]
sort = "#{order_params[:column]}_#{sort_direction(order_params)}"
case sort
when 'code_ASC'
@records = @records.order(id: :asc)
when 'code_DESC'
@records = @records.order(id: :desc)
when 'name_ASC'
@records = @records.order(name: :asc)
when 'name_DESC'
@records = @records.order(name: :desc)
when 'sub_location_count_ASC'
@records = @records.order(sub_location_count: :asc)
when 'sub_location_count_DESC'
@records = @records.order(sub_location_count: :desc)
when 'owned_by_ASC'
@records = @records.order('team_name ASC')
when 'owned_by_DESC'
@records = @records.order('team_name DESC')
when 'shared_label_ASC'
@records = @records.order('shared ASC')
when 'shared_label_DESC'
@records = @records.order('shared DESC')
when 'created_on_ASC'
@records = @records.order(created_at: :asc)
when 'created_on_DESC'
@records = @records.order(created_at: :desc)
when 'created_by_ASC'
@records = @records.order('created_by_full_name ASC')
when 'created_by_DESC'
@records = @records.order('created_by_full_name DESC')
end
end
def shared_sql_select
@ -72,7 +111,7 @@ module Lists
SQL
ActiveRecord::Base.sanitize_sql_array(
[case_statement, { team_id: team_id , shared_write_value: shared_write_value }]
[case_statement, { team_id: team_id, shared_write_value: shared_write_value }]
)
end
end