mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-10-09 13:28:53 +08:00
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:
commit
ada9cdf696
3 changed files with 47 additions and 8 deletions
|
@ -112,8 +112,8 @@ export default {
|
||||||
{
|
{
|
||||||
field: 'sub_location_count',
|
field: 'sub_location_count',
|
||||||
headerName: this.i18n.t('storage_locations.index.table.sub_locations'),
|
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',
|
field: 'shared_label',
|
||||||
|
@ -138,7 +138,7 @@ export default {
|
||||||
{
|
{
|
||||||
field: 'description',
|
field: 'description',
|
||||||
headerName: this.i18n.t('storage_locations.index.table.description'),
|
headerName: this.i18n.t('storage_locations.index.table.description'),
|
||||||
sortable: true
|
sortable: false
|
||||||
}];
|
}];
|
||||||
|
|
||||||
return columns;
|
return columns;
|
||||||
|
|
|
@ -9,7 +9,7 @@ module Lists
|
||||||
:created_on, :urls, :metadata, :file_name, :sub_location_count, :is_empty
|
:created_on, :urls, :metadata, :file_name, :sub_location_count, :is_empty
|
||||||
|
|
||||||
def owned_by
|
def owned_by
|
||||||
object.team.name
|
object['team_name']
|
||||||
end
|
end
|
||||||
|
|
||||||
def is_empty
|
def is_empty
|
||||||
|
@ -28,7 +28,7 @@ module Lists
|
||||||
end
|
end
|
||||||
|
|
||||||
def created_by
|
def created_by
|
||||||
object.created_by.full_name
|
object['created_by_full_name']
|
||||||
end
|
end
|
||||||
|
|
||||||
def created_on
|
def created_on
|
||||||
|
|
|
@ -14,9 +14,15 @@ module Lists
|
||||||
@records =
|
@records =
|
||||||
StorageLocation.joins('LEFT JOIN storage_locations AS sub_locations ' \
|
StorageLocation.joins('LEFT JOIN storage_locations AS sub_locations ' \
|
||||||
'ON storage_locations.id = sub_locations.parent_id')
|
'ON storage_locations.id = sub_locations.parent_id')
|
||||||
|
.left_joins(:team, :created_by)
|
||||||
.viewable_by_user(@user, @team)
|
.viewable_by_user(@user, @team)
|
||||||
.select(shared_sql_select)
|
.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)
|
.group(:id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -37,7 +43,40 @@ module Lists
|
||||||
private
|
private
|
||||||
|
|
||||||
def sort_records
|
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
|
end
|
||||||
|
|
||||||
def shared_sql_select
|
def shared_sql_select
|
||||||
|
@ -72,7 +111,7 @@ module Lists
|
||||||
SQL
|
SQL
|
||||||
|
|
||||||
ActiveRecord::Base.sanitize_sql_array(
|
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
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue