diff --git a/apps/red-ui/src/app/modules/admin/screens/file-attributes-listing/file-attributes-listing-screen.component.html b/apps/red-ui/src/app/modules/admin/screens/file-attributes-listing/file-attributes-listing-screen.component.html index 1b9582206..003f33814 100644 --- a/apps/red-ui/src/app/modules/admin/screens/file-attributes-listing/file-attributes-listing-screen.component.html +++ b/apps/red-ui/src/app/modules/admin/screens/file-attributes-listing/file-attributes-listing-screen.component.html @@ -15,18 +15,13 @@
+ - - {{ 'file-attributes-listing.table-header.title' | translate: { length: displayedAttributes.length } }} + {{ 'file-attributes-listing.table-header.title' | translate: { length: displayedEntities.length } }}
-
+
@@ -89,20 +84,20 @@
- + -
-
-
- +
+
+
+
diff --git a/apps/red-ui/src/app/modules/admin/screens/file-attributes-listing/file-attributes-listing-screen.component.ts b/apps/red-ui/src/app/modules/admin/screens/file-attributes-listing/file-attributes-listing-screen.component.ts index 7c5ffafeb..e6da31163 100644 --- a/apps/red-ui/src/app/modules/admin/screens/file-attributes-listing/file-attributes-listing-screen.component.ts +++ b/apps/red-ui/src/app/modules/admin/screens/file-attributes-listing/file-attributes-listing-screen.component.ts @@ -1,23 +1,22 @@ -import { Component, ElementRef, OnInit, ViewChild } from '@angular/core'; +import { Component, ElementRef, Injector, OnInit, ViewChild } from '@angular/core'; import { PermissionsService } from '../../../../services/permissions.service'; -import { FormBuilder, FormGroup } from '@angular/forms'; import { FileAttributeConfig, FileAttributesControllerService } from '@redaction/red-ui-http'; import { AppStateService } from '../../../../state/app-state.service'; import { ActivatedRoute } from '@angular/router'; -import { debounce } from '../../../../utils/debounce'; -import { SortingOption, SortingService } from '../../../../services/sorting.service'; import { AdminDialogService } from '../../services/admin-dialog.service'; +import { BaseListingComponent } from '../../../shared/base/base-listing.component'; @Component({ selector: 'redaction-file-attributes-listing-screen', templateUrl: './file-attributes-listing-screen.component.html', styleUrls: ['./file-attributes-listing-screen.component.scss'] }) -export class FileAttributesListingScreenComponent implements OnInit { - public searchForm: FormGroup; - public attributes: FileAttributeConfig[] = []; - public displayedAttributes: FileAttributeConfig[] = []; - public selectedFileAttributeIds: string[] = []; +export class FileAttributesListingScreenComponent extends BaseListingComponent implements OnInit { + protected readonly _searchKey = 'label'; + protected readonly _selectionKey = 'id'; + protected readonly _sortKey = 'file-attributes-listing'; + + public allEntities: FileAttributeConfig[] = []; public viewReady = false; public loading = false; @@ -25,20 +24,14 @@ export class FileAttributesListingScreenComponent implements OnInit { constructor( public readonly permissionsService: PermissionsService, - public readonly _sortingService: SortingService, - private readonly _formBuilder: FormBuilder, private readonly _fileAttributesService: FileAttributesControllerService, private readonly _appStateService: AppStateService, private readonly _activatedRoute: ActivatedRoute, - private readonly _dialogService: AdminDialogService + private readonly _dialogService: AdminDialogService, + protected readonly _injector: Injector ) { + super(_injector); this._appStateService.activateRuleSet(_activatedRoute.snapshot.params.ruleSetId); - - this.searchForm = this._formBuilder.group({ - query: [''] - }); - - this.searchForm.valueChanges.subscribe((value) => this._executeSearch(value)); } async ngOnInit() { @@ -48,34 +41,15 @@ export class FileAttributesListingScreenComponent implements OnInit { private async _loadData() { try { const response = await this._fileAttributesService.getFileAttributesConfiguration(this._appStateService.activeRuleSetId).toPromise(); - this.attributes = response?.fileAttributeConfigs || []; + this.allEntities = response?.fileAttributeConfigs || []; } catch (e) { } finally { - // Remove potentially deleted items - this.selectedFileAttributeIds = this.selectedFileAttributeIds.filter((id) => !!this.attributes.find((attr) => attr.id === id)); - this._executeSearch(); this.viewReady = true; this.loading = false; } } - public get sortingOption(): SortingOption { - return this._sortingService.getSortingOption('file-attributes-listing'); - } - - public toggleSort($event) { - this._sortingService.toggleSort('file-attributes-listing', $event); - } - - @debounce(200) - private _executeSearch(value?: { query: string }) { - if (!value) { - value = { query: this.searchForm.get('query').value }; - } - this.displayedAttributes = this.attributes.filter((attribute) => attribute.label.toLowerCase().includes(value.query.toLowerCase())); - } - public openAddEditAttributeDialog($event: MouseEvent, fileAttribute?: FileAttributeConfig) { $event.stopPropagation(); this._dialogService.openAddEditFileAttributeDialog(fileAttribute, this._appStateService.activeRuleSetId, async (newValue: FileAttributeConfig) => { @@ -92,42 +66,12 @@ export class FileAttributesListingScreenComponent implements OnInit { if (!!fileAttribute) { await this._fileAttributesService.deleteFileAttribute(this._appStateService.activeRuleSetId, fileAttribute.id).toPromise(); } else { - await this._fileAttributesService.deleteFileAttributes(this.selectedFileAttributeIds, this._appStateService.activeRuleSetId).toPromise(); + await this._fileAttributesService.deleteFileAttributes(this.selectedEntitiesIds, this._appStateService.activeRuleSetId).toPromise(); } await this._loadData(); }); } - public toggleAttributeSelected($event: MouseEvent, attribute: FileAttributeConfig) { - $event.stopPropagation(); - const idx = this.selectedFileAttributeIds.indexOf(attribute.id); - if (idx === -1) { - this.selectedFileAttributeIds.push(attribute.id); - } else { - this.selectedFileAttributeIds.splice(idx, 1); - } - } - - public toggleSelectAll() { - if (this.areSomeAttributesSelected) { - this.selectedFileAttributeIds = []; - } else { - this.selectedFileAttributeIds = this.displayedAttributes.map((a) => a.id); - } - } - - public get areAllAttributesSelected() { - return this.displayedAttributes.length !== 0 && this.selectedFileAttributeIds.length === this.displayedAttributes.length; - } - - public get areSomeAttributesSelected() { - return this.selectedFileAttributeIds.length > 0; - } - - public isAttributeSelected(attribute: FileAttributeConfig) { - return this.selectedFileAttributeIds.indexOf(attribute.id) !== -1; - } - public importCSV(files: FileList | File[]) { const csvFile = files[0]; this._fileInput.nativeElement.value = null; diff --git a/apps/red-ui/src/app/services/sorting.service.ts b/apps/red-ui/src/app/services/sorting.service.ts index 58eeb969e..66ab9fb99 100644 --- a/apps/red-ui/src/app/services/sorting.service.ts +++ b/apps/red-ui/src/app/services/sorting.service.ts @@ -17,7 +17,7 @@ export class SortingService { 'dictionary-listing': { column: 'label', order: 'asc' }, 'rule-sets-listing': { column: 'name', order: 'asc' }, 'default-colors': { column: 'key', order: 'asc' }, - 'file-attributes-listing': { column: 'name', order: 'asc' } + 'file-attributes-listing': { column: 'label', order: 'asc' } }; constructor() {}