Merge branch 'RED-7912' into 'master'
RED-7912: sorted filters. See merge request redactmanager/red-ui!229
This commit is contained in:
commit
5834ccdf9d
@ -20,6 +20,8 @@ import {
|
||||
AppConfig,
|
||||
DOSSIER_ID,
|
||||
File,
|
||||
FileAttributeConfigType,
|
||||
FileAttributeConfigTypes,
|
||||
IFileAttributeConfig,
|
||||
ProcessingType,
|
||||
StatusSorter,
|
||||
@ -39,7 +41,7 @@ import { UserService } from '@users/user.service';
|
||||
import dayjs from 'dayjs';
|
||||
import { BehaviorSubject, Observable } from 'rxjs';
|
||||
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 { BulkActionsService } from './services/bulk-actions.service';
|
||||
|
||||
@ -181,7 +183,7 @@ export class ConfigService {
|
||||
const allDistinctNeedsWork = new Set<string>();
|
||||
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[] = [];
|
||||
|
||||
@ -219,14 +221,14 @@ export class ConfigService {
|
||||
const filterKey = `${config.id}:${config.label}`;
|
||||
let filters = dynamicFilters.get(filterKey);
|
||||
if (!filters) {
|
||||
dynamicFilters.set(filterKey, new Set<string>());
|
||||
dynamicFilters.set(filterKey, { filterValue: new Set<string>(), type: config.type });
|
||||
filters = dynamicFilters.get(filterKey);
|
||||
}
|
||||
const filterValue = file.fileAttributes?.attributeIdToValue[config.id];
|
||||
if (filterValue === undefined || filterValue === null) {
|
||||
filters.add(undefined);
|
||||
filters.filterValue.add(undefined);
|
||||
} 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(
|
||||
new NestedFilter({
|
||||
id: userId,
|
||||
@ -313,14 +315,14 @@ export class ConfigService {
|
||||
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 key = filterKey.split(':')[1];
|
||||
filterGroups.push({
|
||||
slug: key,
|
||||
label: key,
|
||||
icon: 'red:template',
|
||||
filters: [...filterValue].map(
|
||||
filters: sortArray([...value.filterValue], value.type === FileAttributeConfigTypes.NUMBER).map(
|
||||
(value?: string) =>
|
||||
new NestedFilter({
|
||||
// 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)),
|
||||
});
|
||||
|
||||
const filesNamesFilters = entities.map(
|
||||
file =>
|
||||
const filesNamesFilters = sortArray(entities.map(file => file.filename)).map(
|
||||
filename =>
|
||||
new NestedFilter({
|
||||
id: file.filename,
|
||||
label: file.filename,
|
||||
id: filename,
|
||||
label: filename,
|
||||
}),
|
||||
);
|
||||
|
||||
@ -472,8 +474,4 @@ export class ConfigService {
|
||||
#openEditDossierDialog(dossierId: string) {
|
||||
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 { workflowFileStatusTranslations } from '@translations/file-status-translations';
|
||||
import { workloadTranslations } from '@translations/workload-translations';
|
||||
import { UserPreferenceService } from '@users/user-preference.service';
|
||||
import { UserService } from '@users/user.service';
|
||||
import {
|
||||
dossierMemberChecker,
|
||||
@ -27,6 +26,8 @@ import {
|
||||
dossierOwnerQuickChecker,
|
||||
dossierStateChecker,
|
||||
RedactionFilterSorter,
|
||||
sortByName,
|
||||
sortArray,
|
||||
} from '../../utils';
|
||||
|
||||
@Injectable()
|
||||
@ -35,7 +36,6 @@ export class ConfigService {
|
||||
|
||||
constructor(
|
||||
private readonly _translateService: TranslateService,
|
||||
private readonly _userPreferenceService: UserPreferenceService,
|
||||
private readonly _userService: UserService,
|
||||
private readonly _dossierStatsService: DossierStatsService,
|
||||
private readonly _dossierStatesMapService: DossierStatesMapService,
|
||||
@ -66,7 +66,7 @@ export class ConfigService {
|
||||
return [
|
||||
{
|
||||
label: _('dossier-listing.add-new'),
|
||||
action: () => this._openAddDossierDialog(dossierTemplate.id),
|
||||
action: () => this.#openAddDossierDialog(dossierTemplate.id),
|
||||
hide: !this._permissionsService.canCreateDossier(dossierTemplate),
|
||||
icon: 'iqser:plus',
|
||||
type: 'primary',
|
||||
@ -144,10 +144,10 @@ export class ConfigService {
|
||||
label: this._translateService.instant('filters.documents-status'),
|
||||
icon: 'red:status',
|
||||
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 =>
|
||||
new NestedFilter({
|
||||
id: userId,
|
||||
@ -182,22 +182,22 @@ export class ConfigService {
|
||||
icon: 'red:needs-work',
|
||||
filterTemplate: needsWorkFilterTemplate,
|
||||
filters: needsWorkFilters,
|
||||
checker: (dossier: Dossier, filter: INestedFilter) => this._annotationFilterChecker(dossier, filter),
|
||||
checker: (dossier: Dossier, filter: INestedFilter) => this.#annotationFilterChecker(dossier, filter),
|
||||
matchAll: true,
|
||||
});
|
||||
}
|
||||
|
||||
filterGroups.push({
|
||||
slug: 'quickFilters',
|
||||
filters: this._quickFilters(entities),
|
||||
filters: this.#quickFilters(entities),
|
||||
checker: (dw: Dossier, filter: NestedFilter) => filter.checked && filter.checker(dw),
|
||||
});
|
||||
|
||||
const dossierFilters = entities.map(
|
||||
dossier =>
|
||||
const dossierFilters = sortArray(entities.map(dossier => dossier.dossierName)).map(
|
||||
dossierName =>
|
||||
new NestedFilter({
|
||||
id: dossier.dossierName,
|
||||
label: dossier.dossierName,
|
||||
id: dossierName,
|
||||
label: dossierName,
|
||||
}),
|
||||
);
|
||||
filterGroups.push({
|
||||
@ -212,11 +212,11 @@ export class ConfigService {
|
||||
return filterGroups;
|
||||
}
|
||||
|
||||
private _openAddDossierDialog(dossierTemplateId: string): void {
|
||||
#openAddDossierDialog(dossierTemplateId: string): void {
|
||||
this._dialogService.openDialog('addDossier', { dossierTemplateId });
|
||||
}
|
||||
|
||||
private _quickFilters(entities: Dossier[]): NestedFilter[] {
|
||||
#quickFilters(entities: Dossier[]): NestedFilter[] {
|
||||
const userId = this._currentUser.id;
|
||||
return [
|
||||
{
|
||||
@ -236,12 +236,12 @@ export class ConfigService {
|
||||
].map(filter => new NestedFilter(filter));
|
||||
}
|
||||
|
||||
private _dossierStatusChecker = (dossier: Dossier, filter: INestedFilter) => {
|
||||
#dossierStatusChecker = (dossier: Dossier, filter: INestedFilter) => {
|
||||
const stats = this._dossierStatsService.get(dossier.id);
|
||||
return stats?.fileCountPerWorkflowStatus[filter.id];
|
||||
};
|
||||
|
||||
private _annotationFilterChecker = (dossier: Dossier, filter: INestedFilter) => {
|
||||
#annotationFilterChecker = (dossier: Dossier, filter: INestedFilter) => {
|
||||
const stats = this._dossierStatsService.get(dossier.id);
|
||||
switch (filter.id) {
|
||||
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/super-type-sorter';
|
||||
export * from './sorters/custom-sort';
|
||||
|
||||
export * from './date-inputs-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