RED-7912: sorted filters.
This commit is contained in:
parent
f1c4748ba4
commit
00467b6a01
@ -20,6 +20,8 @@ import {
|
|||||||
AppConfig,
|
AppConfig,
|
||||||
DOSSIER_ID,
|
DOSSIER_ID,
|
||||||
File,
|
File,
|
||||||
|
FileAttributeConfigType,
|
||||||
|
FileAttributeConfigTypes,
|
||||||
IFileAttributeConfig,
|
IFileAttributeConfig,
|
||||||
ProcessingType,
|
ProcessingType,
|
||||||
StatusSorter,
|
StatusSorter,
|
||||||
@ -39,7 +41,7 @@ import { UserService } from '@users/user.service';
|
|||||||
import dayjs from 'dayjs';
|
import dayjs from 'dayjs';
|
||||||
import { BehaviorSubject, Observable } from 'rxjs';
|
import { BehaviorSubject, Observable } from 'rxjs';
|
||||||
import { map } from 'rxjs/operators';
|
import { map } from 'rxjs/operators';
|
||||||
import { annotationFilterChecker, RedactionFilterSorter } from '../../utils';
|
import { annotationFilterChecker, RedactionFilterSorter, sortByName, sortArray } from '../../utils';
|
||||||
import { DossiersDialogService } from '../shared-dossiers/services/dossiers-dialog.service';
|
import { DossiersDialogService } from '../shared-dossiers/services/dossiers-dialog.service';
|
||||||
import { BulkActionsService } from './services/bulk-actions.service';
|
import { BulkActionsService } from './services/bulk-actions.service';
|
||||||
|
|
||||||
@ -181,7 +183,7 @@ export class ConfigService {
|
|||||||
const allDistinctNeedsWork = new Set<string>();
|
const allDistinctNeedsWork = new Set<string>();
|
||||||
const allDistinctProcessingTypes = new Set<ProcessingType>();
|
const allDistinctProcessingTypes = new Set<ProcessingType>();
|
||||||
|
|
||||||
const dynamicFilters = new Map<string, Set<string>>();
|
const dynamicFilters = new Map<string, { type: FileAttributeConfigType; filterValue: Set<string> }>();
|
||||||
|
|
||||||
const filterGroups: IFilterGroup[] = [];
|
const filterGroups: IFilterGroup[] = [];
|
||||||
|
|
||||||
@ -219,14 +221,14 @@ export class ConfigService {
|
|||||||
const filterKey = `${config.id}:${config.label}`;
|
const filterKey = `${config.id}:${config.label}`;
|
||||||
let filters = dynamicFilters.get(filterKey);
|
let filters = dynamicFilters.get(filterKey);
|
||||||
if (!filters) {
|
if (!filters) {
|
||||||
dynamicFilters.set(filterKey, new Set<string>());
|
dynamicFilters.set(filterKey, { filterValue: new Set<string>(), type: config.type });
|
||||||
filters = dynamicFilters.get(filterKey);
|
filters = dynamicFilters.get(filterKey);
|
||||||
}
|
}
|
||||||
const filterValue = file.fileAttributes?.attributeIdToValue[config.id];
|
const filterValue = file.fileAttributes?.attributeIdToValue[config.id];
|
||||||
if (filterValue === undefined || filterValue === null) {
|
if (filterValue === undefined || filterValue === null) {
|
||||||
filters.add(undefined);
|
filters.filterValue.add(undefined);
|
||||||
} else {
|
} else {
|
||||||
filters.add(filterValue);
|
filters.filterValue.add(filterValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -262,7 +264,7 @@ export class ConfigService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.#sortByName([...allDistinctPeople]).forEach(userId => {
|
sortByName(this._userService, [...allDistinctPeople]).forEach(userId => {
|
||||||
peopleFilters.push(
|
peopleFilters.push(
|
||||||
new NestedFilter({
|
new NestedFilter({
|
||||||
id: userId,
|
id: userId,
|
||||||
@ -313,14 +315,14 @@ export class ConfigService {
|
|||||||
hide: true,
|
hide: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
dynamicFilters.forEach((filterValue: Set<string>, filterKey: string) => {
|
dynamicFilters.forEach((value: { filterValue: Set<string>; type: FileAttributeConfigType }, filterKey: string) => {
|
||||||
const id = filterKey.split(':')[0];
|
const id = filterKey.split(':')[0];
|
||||||
const key = filterKey.split(':')[1];
|
const key = filterKey.split(':')[1];
|
||||||
filterGroups.push({
|
filterGroups.push({
|
||||||
slug: key,
|
slug: key,
|
||||||
label: key,
|
label: key,
|
||||||
icon: 'red:template',
|
icon: 'red:template',
|
||||||
filters: [...filterValue].map(
|
filters: sortArray([...value.filterValue], value.type === FileAttributeConfigTypes.NUMBER).map(
|
||||||
(value?: string) =>
|
(value?: string) =>
|
||||||
new NestedFilter({
|
new NestedFilter({
|
||||||
// id shouldn't be undefined to work correctly
|
// id shouldn't be undefined to work correctly
|
||||||
@ -340,11 +342,11 @@ export class ConfigService {
|
|||||||
(checkedNotRequiredFilters().length === 0 || checkedNotRequiredFilters().reduce((acc, f) => acc || f.checker(file), false)),
|
(checkedNotRequiredFilters().length === 0 || checkedNotRequiredFilters().reduce((acc, f) => acc || f.checker(file), false)),
|
||||||
});
|
});
|
||||||
|
|
||||||
const filesNamesFilters = entities.map(
|
const filesNamesFilters = sortArray(entities.map(file => file.filename)).map(
|
||||||
file =>
|
filename =>
|
||||||
new NestedFilter({
|
new NestedFilter({
|
||||||
id: file.filename,
|
id: filename,
|
||||||
label: file.filename,
|
label: filename,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -472,8 +474,4 @@ export class ConfigService {
|
|||||||
#openEditDossierDialog(dossierId: string) {
|
#openEditDossierDialog(dossierId: string) {
|
||||||
this._dialogService.openDialog('editDossier', { dossierId });
|
this._dialogService.openDialog('editDossier', { dossierId });
|
||||||
}
|
}
|
||||||
|
|
||||||
#sortByName(ids: string[]) {
|
|
||||||
return ids.sort((a, b) => this._userService.getName(a).localeCompare(this._userService.getName(b)));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -19,7 +19,6 @@ import { PermissionsService } from '@services/permissions.service';
|
|||||||
import { SharedDialogService } from '@shared/services/dialog.service';
|
import { SharedDialogService } from '@shared/services/dialog.service';
|
||||||
import { workflowFileStatusTranslations } from '@translations/file-status-translations';
|
import { workflowFileStatusTranslations } from '@translations/file-status-translations';
|
||||||
import { workloadTranslations } from '@translations/workload-translations';
|
import { workloadTranslations } from '@translations/workload-translations';
|
||||||
import { UserPreferenceService } from '@users/user-preference.service';
|
|
||||||
import { UserService } from '@users/user.service';
|
import { UserService } from '@users/user.service';
|
||||||
import {
|
import {
|
||||||
dossierMemberChecker,
|
dossierMemberChecker,
|
||||||
@ -27,6 +26,8 @@ import {
|
|||||||
dossierOwnerQuickChecker,
|
dossierOwnerQuickChecker,
|
||||||
dossierStateChecker,
|
dossierStateChecker,
|
||||||
RedactionFilterSorter,
|
RedactionFilterSorter,
|
||||||
|
sortByName,
|
||||||
|
sortArray,
|
||||||
} from '../../utils';
|
} from '../../utils';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
@ -35,7 +36,6 @@ export class ConfigService {
|
|||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private readonly _translateService: TranslateService,
|
private readonly _translateService: TranslateService,
|
||||||
private readonly _userPreferenceService: UserPreferenceService,
|
|
||||||
private readonly _userService: UserService,
|
private readonly _userService: UserService,
|
||||||
private readonly _dossierStatsService: DossierStatsService,
|
private readonly _dossierStatsService: DossierStatsService,
|
||||||
private readonly _dossierStatesMapService: DossierStatesMapService,
|
private readonly _dossierStatesMapService: DossierStatesMapService,
|
||||||
@ -66,7 +66,7 @@ export class ConfigService {
|
|||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
label: _('dossier-listing.add-new'),
|
label: _('dossier-listing.add-new'),
|
||||||
action: () => this._openAddDossierDialog(dossierTemplate.id),
|
action: () => this.#openAddDossierDialog(dossierTemplate.id),
|
||||||
hide: !this._permissionsService.canCreateDossier(dossierTemplate),
|
hide: !this._permissionsService.canCreateDossier(dossierTemplate),
|
||||||
icon: 'iqser:plus',
|
icon: 'iqser:plus',
|
||||||
type: 'primary',
|
type: 'primary',
|
||||||
@ -144,10 +144,10 @@ export class ConfigService {
|
|||||||
label: this._translateService.instant('filters.documents-status'),
|
label: this._translateService.instant('filters.documents-status'),
|
||||||
icon: 'red:status',
|
icon: 'red:status',
|
||||||
filters: statusFilters,
|
filters: statusFilters,
|
||||||
checker: (dossier: Dossier, filter: INestedFilter) => this._dossierStatusChecker(dossier, filter),
|
checker: (dossier: Dossier, filter: INestedFilter) => this.#dossierStatusChecker(dossier, filter),
|
||||||
});
|
});
|
||||||
|
|
||||||
const peopleFilters = this._sortByName([...allDistinctPeople]).map(
|
const peopleFilters = sortByName(this._userService, [...allDistinctPeople]).map(
|
||||||
userId =>
|
userId =>
|
||||||
new NestedFilter({
|
new NestedFilter({
|
||||||
id: userId,
|
id: userId,
|
||||||
@ -182,22 +182,22 @@ export class ConfigService {
|
|||||||
icon: 'red:needs-work',
|
icon: 'red:needs-work',
|
||||||
filterTemplate: needsWorkFilterTemplate,
|
filterTemplate: needsWorkFilterTemplate,
|
||||||
filters: needsWorkFilters,
|
filters: needsWorkFilters,
|
||||||
checker: (dossier: Dossier, filter: INestedFilter) => this._annotationFilterChecker(dossier, filter),
|
checker: (dossier: Dossier, filter: INestedFilter) => this.#annotationFilterChecker(dossier, filter),
|
||||||
matchAll: true,
|
matchAll: true,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
filterGroups.push({
|
filterGroups.push({
|
||||||
slug: 'quickFilters',
|
slug: 'quickFilters',
|
||||||
filters: this._quickFilters(entities),
|
filters: this.#quickFilters(entities),
|
||||||
checker: (dw: Dossier, filter: NestedFilter) => filter.checked && filter.checker(dw),
|
checker: (dw: Dossier, filter: NestedFilter) => filter.checked && filter.checker(dw),
|
||||||
});
|
});
|
||||||
|
|
||||||
const dossierFilters = entities.map(
|
const dossierFilters = sortArray(entities.map(dossier => dossier.dossierName)).map(
|
||||||
dossier =>
|
dossierName =>
|
||||||
new NestedFilter({
|
new NestedFilter({
|
||||||
id: dossier.dossierName,
|
id: dossierName,
|
||||||
label: dossier.dossierName,
|
label: dossierName,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
filterGroups.push({
|
filterGroups.push({
|
||||||
@ -212,11 +212,11 @@ export class ConfigService {
|
|||||||
return filterGroups;
|
return filterGroups;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _openAddDossierDialog(dossierTemplateId: string): void {
|
#openAddDossierDialog(dossierTemplateId: string): void {
|
||||||
this._dialogService.openDialog('addDossier', { dossierTemplateId });
|
this._dialogService.openDialog('addDossier', { dossierTemplateId });
|
||||||
}
|
}
|
||||||
|
|
||||||
private _quickFilters(entities: Dossier[]): NestedFilter[] {
|
#quickFilters(entities: Dossier[]): NestedFilter[] {
|
||||||
const userId = this._currentUser.id;
|
const userId = this._currentUser.id;
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
@ -236,12 +236,12 @@ export class ConfigService {
|
|||||||
].map(filter => new NestedFilter(filter));
|
].map(filter => new NestedFilter(filter));
|
||||||
}
|
}
|
||||||
|
|
||||||
private _dossierStatusChecker = (dossier: Dossier, filter: INestedFilter) => {
|
#dossierStatusChecker = (dossier: Dossier, filter: INestedFilter) => {
|
||||||
const stats = this._dossierStatsService.get(dossier.id);
|
const stats = this._dossierStatsService.get(dossier.id);
|
||||||
return stats?.fileCountPerWorkflowStatus[filter.id];
|
return stats?.fileCountPerWorkflowStatus[filter.id];
|
||||||
};
|
};
|
||||||
|
|
||||||
private _annotationFilterChecker = (dossier: Dossier, filter: INestedFilter) => {
|
#annotationFilterChecker = (dossier: Dossier, filter: INestedFilter) => {
|
||||||
const stats = this._dossierStatsService.get(dossier.id);
|
const stats = this._dossierStatsService.get(dossier.id);
|
||||||
switch (filter.id) {
|
switch (filter.id) {
|
||||||
case 'redaction': {
|
case 'redaction': {
|
||||||
@ -255,8 +255,4 @@ export class ConfigService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private _sortByName(ids: string[]) {
|
|
||||||
return ids.sort((a, b) => this._userService.getName(a).localeCompare(this._userService.getName(b)));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
export * from './sorters/redaction-filter-sorter';
|
export * from './sorters/redaction-filter-sorter';
|
||||||
export * from './sorters/super-type-sorter';
|
export * from './sorters/super-type-sorter';
|
||||||
|
export * from './sorters/custom-sort';
|
||||||
|
|
||||||
export * from './date-inputs-utils';
|
export * from './date-inputs-utils';
|
||||||
export * from './file-download-utils';
|
export * from './file-download-utils';
|
||||||
|
|||||||
13
apps/red-ui/src/app/utils/sorters/custom-sort.ts
Normal file
13
apps/red-ui/src/app/utils/sorters/custom-sort.ts
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
import { moveElementInArray } from '@utils/functions';
|
||||||
|
import { UserService } from '@users/user.service';
|
||||||
|
|
||||||
|
export function sortArray(array: string[], numeric = false) {
|
||||||
|
array.sort((a: string, b: string) => a.localeCompare(b, undefined, { numeric: numeric }));
|
||||||
|
if (array.includes(undefined)) {
|
||||||
|
array = moveElementInArray(array, undefined, 0);
|
||||||
|
}
|
||||||
|
return array;
|
||||||
|
}
|
||||||
|
export function sortByName(userService: UserService, ids: string[]) {
|
||||||
|
return ids.sort((a, b) => userService.getName(a).localeCompare(userService.getName(b)));
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user