From 87a0cac618c8ed4a09408273d0f5a468530e8062 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 24 May 2022 15:05:39 +0200 Subject: Improve admin users list table * Fix last login sort with null values * Remember last selected columns * Display last login date by default --- server/models/user/user.ts | 6 +++--- server/models/utils.ts | 22 ++++++++++++++++++++-- 2 files changed, 23 insertions(+), 5 deletions(-) (limited to 'server/models') diff --git a/server/models/user/user.ts b/server/models/user/user.ts index 326b2e789..20c2222a7 100644 --- a/server/models/user/user.ts +++ b/server/models/user/user.ts @@ -66,7 +66,7 @@ import { ActorModel } from '../actor/actor' import { ActorFollowModel } from '../actor/actor-follow' import { ActorImageModel } from '../actor/actor-image' import { OAuthTokenModel } from '../oauth/oauth-token' -import { getSort, throwIfNotValid } from '../utils' +import { getAdminUsersSort, throwIfNotValid } from '../utils' import { VideoModel } from '../video/video' import { VideoChannelModel } from '../video/video-channel' import { VideoImportModel } from '../video/video-import' @@ -461,7 +461,7 @@ export class UserModel extends Model>> { return this.count() } - static listForApi (parameters: { + static listForAdminApi (parameters: { start: number count: number sort: string @@ -497,7 +497,7 @@ export class UserModel extends Model>> { const query: FindOptions = { offset: start, limit: count, - order: getSort(sort), + order: getAdminUsersSort(sort), where } diff --git a/server/models/utils.ts b/server/models/utils.ts index b57290aff..88e31f22e 100644 --- a/server/models/utils.ts +++ b/server/models/utils.ts @@ -11,8 +11,6 @@ function getSort (value: string, lastSort: OrderItem = [ 'id', 'ASC' ]): OrderIt if (field.toLowerCase() === 'match') { // Search finalField = Sequelize.col('similarity') - } else if (field === 'videoQuotaUsed') { // Users list - finalField = Sequelize.col('videoQuotaUsed') } else { finalField = field } @@ -20,6 +18,25 @@ function getSort (value: string, lastSort: OrderItem = [ 'id', 'ASC' ]): OrderIt return [ [ finalField, direction ], lastSort ] } +function getAdminUsersSort (value: string): OrderItem[] { + const { direction, field } = buildDirectionAndField(value) + + let finalField: string | ReturnType + + if (field === 'videoQuotaUsed') { // Users list + finalField = Sequelize.col('videoQuotaUsed') + } else { + finalField = field + } + + const nullPolicy = direction === 'ASC' + ? 'NULLS FIRST' + : 'NULLS LAST' + + // FIXME: typings + return [ [ finalField as any, direction, nullPolicy ], [ 'id', 'ASC' ] ] +} + function getPlaylistSort (value: string, lastSort: OrderItem = [ 'id', 'ASC' ]): OrderItem[] { const { direction, field } = buildDirectionAndField(value) @@ -260,6 +277,7 @@ export { buildLocalAccountIdsIn, getSort, getCommentSort, + getAdminUsersSort, getVideoSort, getBlacklistSort, createSimilarityAttribute, -- cgit v1.2.3