From f67f1e3af01834cb20bedb69613cf61eff18d538 Mon Sep 17 00:00:00 2001 From: Dan Percic Date: Mon, 26 Apr 2021 21:09:07 +0300 Subject: [PATCH] add icon prop to filters & use checker and key for filters --- .../type-filter/type-filter.component.html | 32 ++--------------- .../type-filter/type-filter.component.ts | 34 +++++++++++++++++-- .../services/annotation-processing.service.ts | 7 ++-- .../components/filter/filter.component.ts | 9 +++-- .../components/filter/model/filter.model.ts | 1 + 5 files changed, 47 insertions(+), 36 deletions(-) diff --git a/apps/red-ui/src/app/modules/projects/components/type-filter/type-filter.component.html b/apps/red-ui/src/app/modules/projects/components/type-filter/type-filter.component.html index ad82d6e8c..d2d3b4ce1 100644 --- a/apps/red-ui/src/app/modules/projects/components/type-filter/type-filter.component.html +++ b/apps/red-ui/src/app/modules/projects/components/type-filter/type-filter.component.html @@ -3,39 +3,13 @@ - - - - - + + - + {{ filter.label | translate }} diff --git a/apps/red-ui/src/app/modules/projects/components/type-filter/type-filter.component.ts b/apps/red-ui/src/app/modules/projects/components/type-filter/type-filter.component.ts index e5e4a0304..58d6bdfd8 100644 --- a/apps/red-ui/src/app/modules/projects/components/type-filter/type-filter.component.ts +++ b/apps/red-ui/src/app/modules/projects/components/type-filter/type-filter.component.ts @@ -13,9 +13,39 @@ export class TypeFilterComponent implements OnInit { dictionaryColor: string; - constructor(public appStateService: AppStateService) {} + private _suggestionsKeys = [ + 'suggestion-remove', + 'suggestion', + 'suggestion-force-redaction', + 'suggestion-add', + 'suggestion-remove-dictionary', + 'suggestion-add-dictionary' + ]; + private _needsAnalysisKeys = ['add-dictionary', 'remove-dictionary', 'remove-only-here', 'pending-analysis', 'analysis']; + private _allKeys = [ + ...this._needsAnalysisKeys, + ...this._suggestionsKeys, + 'redaction', + 'recommendation', + 'hint', + 'manual-redaction', + 'skipped', + 'declined-suggestion', + 'none', + 'updated', + 'image' + ]; + + isSuggestion = (key: string) => this._suggestionsKeys.includes(key); + needsAnalysis = (key: string) => this._needsAnalysisKeys.includes(key); + isKey = (key: string) => this._allKeys.includes(key); + + constructor(private readonly _appStateService: AppStateService) {} ngOnInit(): void { - this.dictionaryColor = this.appStateService.getDictionaryColor(this.filter.key, this.appStateService.activeProject?.ruleSetId || DEFAULT_RUL_SET_UUID); + this.dictionaryColor = this._appStateService.getDictionaryColor( + this.filter.key, + this._appStateService.activeProject?.ruleSetId || DEFAULT_RUL_SET_UUID + ); } } diff --git a/apps/red-ui/src/app/modules/projects/services/annotation-processing.service.ts b/apps/red-ui/src/app/modules/projects/services/annotation-processing.service.ts index 82cfd20b2..65c6cb98f 100644 --- a/apps/red-ui/src/app/modules/projects/services/annotation-processing.service.ts +++ b/apps/red-ui/src/app/modules/projects/services/annotation-processing.service.ts @@ -72,14 +72,14 @@ export class AnnotationProcessingService { const obj = {}; const primaryFlatFilters = this._getFlatFilters(primaryFilters, (f) => f.checked); - const secondaryFlatFilters = this._getFlatFilters(secondaryFilters, (f) => f.checked && !!f.checker); + const secondaryFlatFilters = this._getFlatFilters(secondaryFilters, (f) => f.checked); for (const annotation of annotations) { if (!this._matchesOne(primaryFlatFilters, (f) => this._checkByFilterKey(f, annotation))) { continue; } - if (!this._matchesAll(secondaryFlatFilters, (f) => f.checker(annotation))) { + if (!this._matchesAll(secondaryFlatFilters, (f) => (!!f.checker && f.checker(annotation)) || this._checkByFilterKey(f, annotation))) { continue; } @@ -160,7 +160,8 @@ export class AnnotationProcessingService { static get secondaryAnnotationFilters(): FilterModel[] { return [ { - key: 'red:comment', + key: 'with-comments', + icon: 'red:comment', label: 'filter-menu.with-comments', checked: false, topLevelFilter: true, diff --git a/apps/red-ui/src/app/modules/shared/components/filter/filter.component.ts b/apps/red-ui/src/app/modules/shared/components/filter/filter.component.ts index 71457c8ce..d8e05b13e 100644 --- a/apps/red-ui/src/app/modules/shared/components/filter/filter.component.ts +++ b/apps/red-ui/src/app/modules/shared/components/filter/filter.component.ts @@ -72,7 +72,7 @@ export class FilterComponent implements OnChanges { } get hasActiveFilters(): boolean { - for (const filter of this.primaryFilters ? this.primaryFilters : []) { + for (const filter of this._allFilters) { if (filter.checked || filter.indeterminate) { return true; } @@ -90,7 +90,8 @@ export class FilterComponent implements OnChanges { } private _setAllFilters(value: boolean) { - this.primaryFilters?.forEach((f) => { + const filters = value ? this.primaryFilters : this._allFilters; + filters.forEach((f) => { f.checked = value; f.indeterminate = false; f.filters?.forEach((ff) => { @@ -99,6 +100,10 @@ export class FilterComponent implements OnChanges { }); } + private get _allFilters(): FilterModel[] { + return [...(this.primaryFilters ?? []), ...(this.secondaryFilters ?? [])]; + } + filterMouseEnter() { this.mouseOver = true; if (this.mouseOverTimeout) { diff --git a/apps/red-ui/src/app/modules/shared/components/filter/model/filter.model.ts b/apps/red-ui/src/app/modules/shared/components/filter/model/filter.model.ts index 717fa16d3..4f65e85cd 100644 --- a/apps/red-ui/src/app/modules/shared/components/filter/model/filter.model.ts +++ b/apps/red-ui/src/app/modules/shared/components/filter/model/filter.model.ts @@ -1,6 +1,7 @@ export interface FilterModel { key: string; label?: string; + icon?: string; checked?: boolean; indeterminate?: boolean; expanded?: boolean;