mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-09-20 06:35:56 +08:00
Add sorting to storage locations [SCI-11060]
This commit is contained in:
parent
47b3a256fa
commit
9d65cdab31
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue