diff --git a/apps/red-ui/src/app/modules/admin/dialogs/file-attributes-csv-import-dialog/active-fields-listing/active-fields-listing.component.html b/apps/red-ui/src/app/modules/admin/dialogs/file-attributes-csv-import-dialog/active-fields-listing/active-fields-listing.component.html index 201646c69..e32368ef4 100644 --- a/apps/red-ui/src/app/modules/admin/dialogs/file-attributes-csv-import-dialog/active-fields-listing/active-fields-listing.component.html +++ b/apps/red-ui/src/app/modules/admin/dialogs/file-attributes-csv-import-dialog/active-fields-listing/active-fields-listing.component.html @@ -88,7 +88,7 @@
diff --git a/apps/red-ui/src/app/modules/admin/dialogs/file-attributes-csv-import-dialog/active-fields-listing/active-fields-listing.component.ts b/apps/red-ui/src/app/modules/admin/dialogs/file-attributes-csv-import-dialog/active-fields-listing/active-fields-listing.component.ts index e1301401a..cdaceeb4d 100644 --- a/apps/red-ui/src/app/modules/admin/dialogs/file-attributes-csv-import-dialog/active-fields-listing/active-fields-listing.component.ts +++ b/apps/red-ui/src/app/modules/admin/dialogs/file-attributes-csv-import-dialog/active-fields-listing/active-fields-listing.component.ts @@ -20,6 +20,7 @@ export class ActiveFieldsListingComponent extends BaseListingComponent im @Output() toggleFieldActive = new EventEmitter(); readonly typeOptions = [FileAttributeConfig.TypeEnum.TEXT, FileAttributeConfig.TypeEnum.NUMBER, FileAttributeConfig.TypeEnum.DATE]; + protected readonly _primaryKey = 'id'; constructor(protected readonly _injector: Injector) { super(_injector); diff --git a/apps/red-ui/src/app/modules/admin/dialogs/file-attributes-csv-import-dialog/file-attributes-csv-import-dialog.component.html b/apps/red-ui/src/app/modules/admin/dialogs/file-attributes-csv-import-dialog/file-attributes-csv-import-dialog.component.html index 1b5300bfd..c3d2ccc74 100644 --- a/apps/red-ui/src/app/modules/admin/dialogs/file-attributes-csv-import-dialog/file-attributes-csv-import-dialog.component.html +++ b/apps/red-ui/src/app/modules/admin/dialogs/file-attributes-csv-import-dialog/file-attributes-csv-import-dialog.component.html @@ -101,7 +101,7 @@ (click)="toggleFieldActive(field)" (mouseenter)="setHoveredColumn(field.csvColumn)" (mouseleave)="setHoveredColumn()" - *ngFor="let field of displayedEntities$ | async" + *ngFor="let field of displayedEntities$ | async; trackBy: trackByPrimaryKey" class="csv-header-pill-wrapper" >
@@ -109,7 +109,10 @@ {{ field.csvColumn }}
-
{{ getEntries(field.csvColumn) }} entries
+
+ {{ getEntries(field.csvColumn) }} + entries +
Sample: {{ getSample(field.csvColumn) }}
diff --git a/apps/red-ui/src/app/modules/admin/dialogs/file-attributes-csv-import-dialog/file-attributes-csv-import-dialog.component.ts b/apps/red-ui/src/app/modules/admin/dialogs/file-attributes-csv-import-dialog/file-attributes-csv-import-dialog.component.ts index d933b71e8..4de397f09 100644 --- a/apps/red-ui/src/app/modules/admin/dialogs/file-attributes-csv-import-dialog/file-attributes-csv-import-dialog.component.ts +++ b/apps/red-ui/src/app/modules/admin/dialogs/file-attributes-csv-import-dialog/file-attributes-csv-import-dialog.component.ts @@ -31,6 +31,8 @@ export interface Field { providers: [FilterService, SearchService, ScreenStateService, SortingService] }) export class FileAttributesCsvImportDialogComponent extends BaseListingComponent { + protected readonly _primaryKey = 'id'; + csvFile: File; dossierTemplateId: string; parseResult: { data: any[]; errors: any[]; meta: any; fields: Field[] }; @@ -50,10 +52,10 @@ export class FileAttributesCsvImportDialogComponent extends BaseListingComponent private readonly _translateService: TranslateService, private readonly _toaster: Toaster, private readonly _formBuilder: FormBuilder, - public dialogRef: MatDialogRef, + readonly dialogRef: MatDialogRef, protected readonly _injector: Injector, @Inject(MAT_DIALOG_DATA) - public data: { + readonly data: { csv: File; dossierTemplateId: string; existingConfiguration: FileAttributesConfig; diff --git a/apps/red-ui/src/app/modules/admin/screens/audit/audit-screen.component.html b/apps/red-ui/src/app/modules/admin/screens/audit/audit-screen.component.html index 9dafe7911..34b6c552b 100644 --- a/apps/red-ui/src/app/modules/admin/screens/audit/audit-screen.component.html +++ b/apps/red-ui/src/app/modules/admin/screens/audit/audit-screen.component.html @@ -22,10 +22,7 @@
- {{ - 'audit-screen.table-header.title' - | translate: { length: logs?.totalHits || 0 } - }} + {{ 'audit-screen.table-header.title' | translate: { length: logs?.totalHits || 0 } }}
- + {{ 'audit-screen.categories.' + category | translate }} @@ -56,10 +50,7 @@ [withName]="true" size="small" > -
+
-
+
ยท
- + - +
@@ -95,16 +76,9 @@
- + - +
@@ -113,31 +87,18 @@
- - + + - +
- +
@@ -148,11 +109,7 @@ {{ log.recordDate | date: 'd MMM. yyyy, hh:mm a' }}
- +
@@ -162,7 +119,3 @@
- - diff --git a/apps/red-ui/src/app/modules/admin/screens/audit/audit-screen.component.ts b/apps/red-ui/src/app/modules/admin/screens/audit/audit-screen.component.ts index 752b959ac..645c50334 100644 --- a/apps/red-ui/src/app/modules/admin/screens/audit/audit-screen.component.ts +++ b/apps/red-ui/src/app/modules/admin/screens/audit/audit-screen.component.ts @@ -1,10 +1,11 @@ -import { Component } from '@angular/core'; +import { Component, OnDestroy } from '@angular/core'; import { PermissionsService } from '@services/permissions.service'; import { FormBuilder, FormGroup } from '@angular/forms'; import { AuditControllerService, AuditResponse, AuditSearchRequest } from '@redaction/red-ui-http'; -import { TranslateService } from '@ngx-translate/core'; import { Moment } from 'moment'; import { applyIntervalConstraints } from '@utils/date-inputs-utils'; +import { LoadingService } from '../../../../services/loading.service'; +import { AutoUnsubscribeComponent } from '../../../shared/base/auto-unsubscribe.component'; const PAGE_SIZE = 50; @@ -13,16 +14,14 @@ const PAGE_SIZE = 50; templateUrl: './audit-screen.component.html', styleUrls: ['./audit-screen.component.scss'] }) -export class AuditScreenComponent { +export class AuditScreenComponent extends AutoUnsubscribeComponent implements OnDestroy { readonly ALL_CATEGORIES = 'all-categories'; readonly ALL_USERS = 'audit-screen.all-users'; filterForm: FormGroup; - viewReady = false; categories: string[] = []; userIds: Set; logs: AuditResponse; - currentPage = 1; private _previousFrom: Moment; private _previousTo: Moment; @@ -31,8 +30,9 @@ export class AuditScreenComponent { readonly permissionsService: PermissionsService, private readonly _formBuilder: FormBuilder, private readonly _auditControllerService: AuditControllerService, - private readonly _translateService: TranslateService + private readonly _loadingService: LoadingService ) { + super(); this.filterForm = this._formBuilder.group({ category: [this.ALL_CATEGORIES], userId: [this.ALL_USERS], @@ -40,7 +40,7 @@ export class AuditScreenComponent { to: [] }); - this.filterForm.valueChanges.subscribe(value => { + this.addSubscription = this.filterForm.valueChanges.subscribe(value => { if (!this._updateDateFilters(value)) { this._fetchData(); } @@ -61,16 +61,7 @@ export class AuditScreenComponent { } private _updateDateFilters(value): boolean { - if ( - applyIntervalConstraints( - value, - this._previousFrom, - this._previousTo, - this.filterForm, - 'from', - 'to' - ) - ) { + if (applyIntervalConstraints(value, this._previousFrom, this._previousTo, this.filterForm, 'from', 'to')) { return true; } @@ -80,7 +71,7 @@ export class AuditScreenComponent { } private _fetchData(page?: number) { - this.viewReady = false; + this._loadingService.start(); const promises = []; const category = this.filterForm.get('category').value; const userId = this.filterForm.get('userId').value; @@ -110,7 +101,7 @@ export class AuditScreenComponent { for (const id of this.logs.data.map(log => log.userId).filter(uid => !!uid)) { this.userIds.add(id); } - this.viewReady = true; + this._loadingService.stop(); }); } } diff --git a/apps/red-ui/src/app/modules/admin/screens/default-colors/default-colors-screen.component.html b/apps/red-ui/src/app/modules/admin/screens/default-colors/default-colors-screen.component.html index 0269cc400..0aa435152 100644 --- a/apps/red-ui/src/app/modules/admin/screens/default-colors/default-colors-screen.component.html +++ b/apps/red-ui/src/app/modules/admin/screens/default-colors/default-colors-screen.component.html @@ -22,14 +22,12 @@
- {{ 'default-colors-screen.table-header.title' | translate: { length: screenStateService.allEntitiesLength$ } }} + {{ 'default-colors-screen.table-header.title' | translate: { length: screenStateService.allEntitiesLength$ | async } }}
-
+
diff --git a/apps/red-ui/src/app/modules/admin/screens/default-colors/default-colors-screen.component.ts b/apps/red-ui/src/app/modules/admin/screens/default-colors/default-colors-screen.component.ts index 8b21ef348..03a7f0ec9 100644 --- a/apps/red-ui/src/app/modules/admin/screens/default-colors/default-colors-screen.component.ts +++ b/apps/red-ui/src/app/modules/admin/screens/default-colors/default-colors-screen.component.ts @@ -1,4 +1,4 @@ -import { Component, Injector, OnInit } from '@angular/core'; +import { ChangeDetectionStrategy, Component, Injector, OnInit } from '@angular/core'; import { AppStateService } from '@state/app-state.service'; import { Colors, DictionaryControllerService } from '@redaction/red-ui-http'; import { ActivatedRoute } from '@angular/router'; @@ -8,12 +8,13 @@ import { LoadingService } from '@services/loading.service'; import { FilterService } from '@shared/services/filter.service'; import { SearchService } from '@shared/services/search.service'; import { ScreenStateService } from '@shared/services/screen-state.service'; -import { ScreenNames, SortingService } from '@services/sorting.service'; import { BaseListingComponent } from '@shared/base/base-listing.component'; +import { SortingOrders, SortingService } from '../../../../services/sorting.service'; @Component({ templateUrl: './default-colors-screen.component.html', styleUrls: ['./default-colors-screen.component.scss'], + changeDetection: ChangeDetectionStrategy.OnPush, providers: [FilterService, SearchService, ScreenStateService, SortingService] }) export class DefaultColorsScreenComponent @@ -24,6 +25,7 @@ export class DefaultColorsScreenComponent implements OnInit { private _colorsObj: Colors; + protected readonly _primaryKey = 'key'; constructor( private readonly _appStateService: AppStateService, @@ -35,7 +37,6 @@ export class DefaultColorsScreenComponent protected readonly _injector: Injector ) { super(_injector); - this.sortingService.setScreenName(ScreenNames.DEFAULT_COLORS); _appStateService.activateDossierTemplate(_activatedRoute.snapshot.params.dossierTemplateId); } @@ -52,9 +53,7 @@ export class DefaultColorsScreenComponent colorKey: color.key, dossierTemplateId: this._appStateService.activeDossierTemplateId }, - async () => { - await this._loadColors(); - } + async () => await this._loadColors() ); } @@ -62,12 +61,12 @@ export class DefaultColorsScreenComponent this._loadingService.start(); const data = await this._dictionaryControllerService.getColors(this._appStateService.activeDossierTemplateId).toPromise(); this._colorsObj = data; - this.screenStateService.setEntities( - Object.keys(data).map(key => ({ - key, - value: data[key] - })) - ); + const entities = Object.keys(data).map(key => ({ + key, + value: data[key] + })); + this.screenStateService.setEntities(entities); + this.screenStateService.setDisplayedEntities(entities); this._loadingService.stop(); } } diff --git a/apps/red-ui/src/app/modules/admin/screens/dictionary-listing/dictionary-listing-screen.component.html b/apps/red-ui/src/app/modules/admin/screens/dictionary-listing/dictionary-listing-screen.component.html index bce3dd9d8..86d344cda 100644 --- a/apps/red-ui/src/app/modules/admin/screens/dictionary-listing/dictionary-listing-screen.component.html +++ b/apps/red-ui/src/app/modules/admin/screens/dictionary-listing/dictionary-listing-screen.component.html @@ -35,7 +35,7 @@
-
+
diff --git a/apps/red-ui/src/app/modules/admin/screens/dictionary-listing/dictionary-listing-screen.component.ts b/apps/red-ui/src/app/modules/admin/screens/dictionary-listing/dictionary-listing-screen.component.ts index b3bbee0e3..e9eaf4359 100644 --- a/apps/red-ui/src/app/modules/admin/screens/dictionary-listing/dictionary-listing-screen.component.ts +++ b/apps/red-ui/src/app/modules/admin/screens/dictionary-listing/dictionary-listing-screen.component.ts @@ -1,4 +1,4 @@ -import { Component, Injector, OnInit } from '@angular/core'; +import { ChangeDetectionStrategy, Component, Injector, OnInit } from '@angular/core'; import { DoughnutChartConfig } from '@shared/components/simple-doughnut-chart/simple-doughnut-chart.component'; import { DictionaryControllerService } from '@redaction/red-ui-http'; import { AppStateService } from '@state/app-state.service'; @@ -12,7 +12,7 @@ import { LoadingService } from '@services/loading.service'; import { FilterService } from '@shared/services/filter.service'; import { SearchService } from '@shared/services/search.service'; import { ScreenStateService } from '@shared/services/screen-state.service'; -import { ScreenNames, SortingService } from '@services/sorting.service'; +import { SortingService } from '../../../../services/sorting.service'; import { BaseListingComponent } from '@shared/base/base-listing.component'; import { AdminDialogService } from '../../services/admin-dialog.service'; @@ -31,6 +31,8 @@ const toChartConfig = (dict: TypeValueWrapper): DoughnutChartConfig => ({ export class DictionaryListingScreenComponent extends BaseListingComponent implements OnInit { chartData: DoughnutChartConfig[] = []; + protected readonly _primaryKey = 'label'; + constructor( private readonly _dialogService: AdminDialogService, private readonly _dictionaryControllerService: DictionaryControllerService, @@ -43,8 +45,6 @@ export class DictionaryListingScreenComponent extends BaseListingComponent
- +
@@ -111,5 +101,3 @@
- - diff --git a/apps/red-ui/src/app/modules/admin/screens/digital-signature/digital-signature-screen.component.ts b/apps/red-ui/src/app/modules/admin/screens/digital-signature/digital-signature-screen.component.ts index a5ac0a556..0a2777a7a 100644 --- a/apps/red-ui/src/app/modules/admin/screens/digital-signature/digital-signature-screen.component.ts +++ b/apps/red-ui/src/app/modules/admin/screens/digital-signature/digital-signature-screen.component.ts @@ -5,6 +5,7 @@ import { Toaster } from '../../../../services/toaster.service'; import { PermissionsService } from '@services/permissions.service'; import { lastIndexOfEnd } from '@utils/functions'; import { AutoUnsubscribeComponent } from '../../../shared/base/auto-unsubscribe.component'; +import { LoadingService } from '../../../../services/loading.service'; @Component({ selector: 'redaction-digital-signature-screen', @@ -15,13 +16,13 @@ export class DigitalSignatureScreenComponent extends AutoUnsubscribeComponent im digitalSignature: DigitalSignature; digitalSignatureForm: FormGroup; - viewReady = false; digitalSignatureExists = false; constructor( private readonly _digitalSignatureControllerService: DigitalSignatureControllerService, private readonly _toaster: Toaster, private readonly _formBuilder: FormBuilder, + private readonly _loadingService: LoadingService, readonly permissionsService: PermissionsService ) { super(); @@ -82,7 +83,7 @@ export class DigitalSignatureScreenComponent extends AutoUnsubscribeComponent im } loadDigitalSignatureAndInitializeForm() { - this.viewReady = false; + this._loadingService.start(); this.addSubscription = this._digitalSignatureControllerService .getDigitalSignature() .subscribe( @@ -97,7 +98,7 @@ export class DigitalSignatureScreenComponent extends AutoUnsubscribeComponent im ) .add(() => { this._initForm(); - this.viewReady = true; + this._loadingService.stop(); }); } diff --git a/apps/red-ui/src/app/modules/admin/screens/dossier-attributes-listing/dossier-attributes-listing-screen.component.html b/apps/red-ui/src/app/modules/admin/screens/dossier-attributes-listing/dossier-attributes-listing-screen.component.html index 5f7c5fe30..c81b649de 100644 --- a/apps/red-ui/src/app/modules/admin/screens/dossier-attributes-listing/dossier-attributes-listing-screen.component.html +++ b/apps/red-ui/src/app/modules/admin/screens/dossier-attributes-listing/dossier-attributes-listing-screen.component.html @@ -65,16 +65,12 @@
-
+
diff --git a/apps/red-ui/src/app/modules/admin/screens/dossier-attributes-listing/dossier-attributes-listing-screen.component.ts b/apps/red-ui/src/app/modules/admin/screens/dossier-attributes-listing/dossier-attributes-listing-screen.component.ts index 5fc724ce7..6f441ae13 100644 --- a/apps/red-ui/src/app/modules/admin/screens/dossier-attributes-listing/dossier-attributes-listing-screen.component.ts +++ b/apps/red-ui/src/app/modules/admin/screens/dossier-attributes-listing/dossier-attributes-listing-screen.component.ts @@ -5,7 +5,7 @@ import { AppStateService } from '@state/app-state.service'; import { ActivatedRoute } from '@angular/router'; import { AdminDialogService } from '../../services/admin-dialog.service'; import { LoadingService } from '@services/loading.service'; -import { ScreenNames, SortingService } from '@services/sorting.service'; +import { SortingService } from '../../../../services/sorting.service'; import { FilterService } from '@shared/services/filter.service'; import { SearchService } from '@shared/services/search.service'; import { ScreenStateService } from '@shared/services/screen-state.service'; @@ -18,6 +18,8 @@ import { DossierAttributesService } from '@shared/services/controller-wrappers/d providers: [FilterService, SearchService, ScreenStateService, SortingService] }) export class DossierAttributesListingScreenComponent extends BaseListingComponent implements OnInit { + protected readonly _primaryKey = 'label'; + constructor( protected readonly _injector: Injector, private readonly _appStateService: AppStateService, @@ -28,8 +30,6 @@ export class DossierAttributesListingScreenComponent extends BaseListingComponen readonly permissionsService: PermissionsService ) { super(_injector); - this.searchService.setSearchKey('label'); - this.sortingService.setScreenName(ScreenNames.DOSSIER_ATTRIBUTES_LISTING); _appStateService.activateDossierTemplate(_activatedRoute.snapshot.params.dossierTemplateId); } diff --git a/apps/red-ui/src/app/modules/admin/screens/dossier-template-listing/dossier-templates-listing-screen.component.html b/apps/red-ui/src/app/modules/admin/screens/dossier-template-listing/dossier-templates-listing-screen.component.html index 5c63de968..7a4d7b13a 100644 --- a/apps/red-ui/src/app/modules/admin/screens/dossier-template-listing/dossier-templates-listing-screen.component.html +++ b/apps/red-ui/src/app/modules/admin/screens/dossier-template-listing/dossier-templates-listing-screen.component.html @@ -4,17 +4,10 @@
- +
@@ -34,15 +27,13 @@ }} - - - +
+
diff --git a/apps/red-ui/src/app/modules/admin/screens/dossier-template-listing/dossier-templates-listing-screen.component.ts b/apps/red-ui/src/app/modules/admin/screens/dossier-template-listing/dossier-templates-listing-screen.component.ts index 7a3add35e..f08902968 100644 --- a/apps/red-ui/src/app/modules/admin/screens/dossier-template-listing/dossier-templates-listing-screen.component.ts +++ b/apps/red-ui/src/app/modules/admin/screens/dossier-template-listing/dossier-templates-listing-screen.component.ts @@ -9,8 +9,8 @@ import { DossierTemplateControllerService } from '@redaction/red-ui-http'; import { FilterService } from '@shared/services/filter.service'; import { SearchService } from '@shared/services/search.service'; import { ScreenStateService } from '@shared/services/screen-state.service'; -import { ScreenNames, SortingService } from '@services/sorting.service'; import { BaseListingComponent } from '@shared/base/base-listing.component'; +import { SortingService } from '../../../../services/sorting.service'; @Component({ templateUrl: './dossier-templates-listing-screen.component.html', @@ -19,6 +19,8 @@ import { BaseListingComponent } from '@shared/base/base-listing.component'; providers: [FilterService, SearchService, ScreenStateService, SortingService] }) export class DossierTemplatesListingScreenComponent extends BaseListingComponent implements OnInit { + protected _primaryKey = 'name'; + constructor( private readonly _dialogService: AdminDialogService, private readonly _appStateService: AppStateService, @@ -29,8 +31,6 @@ export class DossierTemplatesListingScreenComponent extends BaseListingComponent readonly userPreferenceService: UserPreferenceService ) { super(_injector); - this.sortingService.setScreenName(ScreenNames.DOSSIER_TEMPLATES_LISTING); - this.searchService.setSearchKey('name'); } ngOnInit(): void { 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 eacd843d3..ed54e5c43 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 @@ -37,7 +37,7 @@
implements OnInit { +export class FileAttributesListingScreenComponent extends BaseListingComponent implements OnInit, OnDestroy { + protected readonly _primaryKey = 'label'; + private _existingConfiguration: FileAttributesConfig; @ViewChild('fileInput') private _fileInput: ElementRef; @@ -31,8 +33,6 @@ export class FileAttributesListingScreenComponent extends BaseListingComponent -
- +
+
@@ -46,10 +31,7 @@
- {{ - 'license-info-screen.copyright-claim-text' - | translate: { currentYear: currentYear } - }} + {{ 'license-info-screen.copyright-claim-text' | translate: { currentYear: currentYear } }}
@@ -64,10 +46,7 @@ -
+
@@ -92,28 +71,18 @@
{{ currentInfo.numberOfAnalyzedPages }}
-
+
- {{ - 'license-info-screen.total-analyzed' - | translate: { date: totalInfo.startDate | date: 'longDate' } - }} + {{ 'license-info-screen.total-analyzed' | translate: { date: totalInfo.startDate | date: 'longDate' } }}
{{ totalInfo.numberOfAnalyzedPages }}
-
- {{ currentInfo.numberOfAnalyzedPages }} ({{ - analysisPercentageOfLicense | number: '1.0-2' - }}%) -
+
{{ currentInfo.numberOfAnalyzedPages }} ({{ analysisPercentageOfLicense | number: '1.0-2' }}%)
@@ -150,7 +119,3 @@
- - diff --git a/apps/red-ui/src/app/modules/admin/screens/license-information/license-information-screen.component.ts b/apps/red-ui/src/app/modules/admin/screens/license-information/license-information-screen.component.ts index 7dbf54d26..398f76664 100644 --- a/apps/red-ui/src/app/modules/admin/screens/license-information/license-information-screen.component.ts +++ b/apps/red-ui/src/app/modules/admin/screens/license-information/license-information-screen.component.ts @@ -4,6 +4,9 @@ import { LicenseReport, LicenseReportControllerService } from '@redaction/red-ui import { AppConfigService } from '@app-config/app-config.service'; import * as moment from 'moment'; import { TranslateService } from '@ngx-translate/core'; +import { LoadingService } from '../../../../services/loading.service'; +import { ButtonConfig } from '../../../shared/components/page-header/models/button-config.model'; +import { IconButtonTypes } from '../../../shared/components/buttons/icon-button/icon-button.component'; @Component({ selector: 'redaction-license-information-screen', @@ -16,7 +19,6 @@ export class LicenseInformationScreenComponent implements OnInit { unlicensedInfo: LicenseReport = {}; totalLicensedNumberOfPages = 0; analysisPercentageOfLicense = 100; - viewReady = false; barChart: any[] = []; lineChartSeries: any[] = []; yAxisLabel = this._translateService.instant('license-info-screen.chart.pages-per-month'); @@ -31,13 +33,23 @@ export class LicenseInformationScreenComponent implements OnInit { group: 'Ordinal', domain: ['#0389ec'] }; + buttonConfigs: ButtonConfig[] = [ + { + label: this._translateService.instant('license-info-screen.email-report'), + action: () => this.sendMail(), + type: IconButtonTypes.PRIMARY + } + ]; constructor( readonly permissionsService: PermissionsService, readonly appConfigService: AppConfigService, private readonly _licenseReportController: LicenseReportControllerService, - private readonly _translateService: TranslateService - ) {} + private readonly _translateService: TranslateService, + private readonly _loadingService: LoadingService + ) { + _loadingService.start(); + } get currentYear(): number { return new Date().getFullYear(); @@ -63,18 +75,15 @@ export class LicenseInformationScreenComponent implements OnInit { const unlicensedConfig = { startDate: endDate.toDate() }; - promises.push( - this._licenseReportController.licenseReport(unlicensedConfig).toPromise() - ); + promises.push(this._licenseReportController.licenseReport(unlicensedConfig).toPromise()); } Promise.all(promises).then(reports => { [this.currentInfo, this.totalInfo, this.unlicensedInfo] = reports; - this.viewReady = true; + this._loadingService.stop(); this.analysisPercentageOfLicense = this.totalLicensedNumberOfPages > 0 - ? (this.currentInfo.numberOfAnalyzedPages / this.totalLicensedNumberOfPages) * - 100 + ? (this.currentInfo.numberOfAnalyzedPages / this.totalLicensedNumberOfPages) * 100 : 100; }); } @@ -92,9 +101,7 @@ export class LicenseInformationScreenComponent implements OnInit { pages: this.totalLicensedNumberOfPages }) ].join('%0D%0A'); - window.location.href = `mailto:${this.appConfigService.getConfig( - 'LICENSE_EMAIL' - )}?subject=${subject}&body=${body}`; + window.location.href = `mailto:${this.appConfigService.getConfig('LICENSE_EMAIL')}?subject=${subject}&body=${body}`; } private async _setMonthlyStats(startDate: moment.Moment, endDate: moment.Moment) { diff --git a/apps/red-ui/src/app/modules/admin/screens/trash/trash-screen.component.html b/apps/red-ui/src/app/modules/admin/screens/trash/trash-screen.component.html index e77771430..9eeff7dcb 100644 --- a/apps/red-ui/src/app/modules/admin/screens/trash/trash-screen.component.html +++ b/apps/red-ui/src/app/modules/admin/screens/trash/trash-screen.component.html @@ -39,8 +39,6 @@
-
+
diff --git a/apps/red-ui/src/app/modules/admin/screens/trash/trash-screen.component.ts b/apps/red-ui/src/app/modules/admin/screens/trash/trash-screen.component.ts index b7f469d6c..1061895c5 100644 --- a/apps/red-ui/src/app/modules/admin/screens/trash/trash-screen.component.ts +++ b/apps/red-ui/src/app/modules/admin/screens/trash/trash-screen.component.ts @@ -8,7 +8,7 @@ import * as moment from 'moment'; import { FilterService } from '@shared/services/filter.service'; import { SearchService } from '@shared/services/search.service'; import { ScreenStateService } from '@shared/services/screen-state.service'; -import { ScreenNames, SortingService } from '@services/sorting.service'; +import { SortingService } from '../../../../services/sorting.service'; import { BaseListingComponent } from '@shared/base/base-listing.component'; import { DossiersService } from '../../../dossier/services/dossiers.service'; @@ -21,6 +21,7 @@ import { DossiersService } from '../../../dossier/services/dossiers.service'; export class TrashScreenComponent extends BaseListingComponent implements OnInit { readonly itemSize = 85; private readonly _deleteRetentionHours = this._appConfigService.getConfig(AppConfigKey.DELETE_RETENTION_HOURS); + protected readonly _primaryKey = 'dossierName'; constructor( private readonly _appStateService: AppStateService, @@ -32,7 +33,6 @@ export class TrashScreenComponent extends BaseListingComponent implemen private readonly _appConfigService: AppConfigService ) { super(_injector); - this.sortingService.setScreenName(ScreenNames.DOSSIER_LISTING); } async ngOnInit(): Promise { @@ -52,10 +52,6 @@ export class TrashScreenComponent extends BaseListingComponent implemen return moment(softDeletedTime).add(this._deleteRetentionHours, 'hours').toISOString(); } - trackById(index: number, dossier: Dossier): string { - return dossier.dossierId; - } - bulkDelete(dossierIds = this.screenStateService.selectedEntities.map(d => d.dossierId)) { this._loadingService.loadWhile(this._hardDelete(dossierIds)); } diff --git a/apps/red-ui/src/app/modules/admin/screens/user-listing/user-listing-screen.component.html b/apps/red-ui/src/app/modules/admin/screens/user-listing/user-listing-screen.component.html index 942ed9395..9ba8b390a 100644 --- a/apps/red-ui/src/app/modules/admin/screens/user-listing/user-listing-screen.component.html +++ b/apps/red-ui/src/app/modules/admin/screens/user-listing/user-listing-screen.component.html @@ -76,7 +76,7 @@ -
+
diff --git a/apps/red-ui/src/app/modules/admin/screens/user-listing/user-listing-screen.component.ts b/apps/red-ui/src/app/modules/admin/screens/user-listing/user-listing-screen.component.ts index e462094ab..ce7543fb2 100644 --- a/apps/red-ui/src/app/modules/admin/screens/user-listing/user-listing-screen.component.ts +++ b/apps/red-ui/src/app/modules/admin/screens/user-listing/user-listing-screen.component.ts @@ -23,6 +23,8 @@ import { map } from 'rxjs/operators'; providers: [FilterService, SearchService, ScreenStateService, SortingService] }) export class UserListingScreenComponent extends BaseListingComponent implements OnInit { + protected readonly _primaryKey = 'userId'; + collapsedDetails = false; chartData: DoughnutChartConfig[] = []; @ViewChildren(InitialsAvatarComponent) @@ -81,10 +83,6 @@ export class UserListingScreenComponent extends BaseListingComponent imple this.openDeleteUsersDialog(this.screenStateService.allEntities.filter(u => this.isSelected(u))); } - trackById(index: number, user: User) { - return user.userId; - } - private async _loadData() { this.screenStateService.setEntities(await this._userControllerService.getAllUsers().toPromise()); await this.userService.loadAllUsers(); diff --git a/apps/red-ui/src/app/modules/dossier/components/bulk-actions/dossier-overview-bulk-actions.component.html b/apps/red-ui/src/app/modules/dossier/components/bulk-actions/dossier-overview-bulk-actions.component.html index 0a0f8fc96..13e04a4d8 100644 --- a/apps/red-ui/src/app/modules/dossier/components/bulk-actions/dossier-overview-bulk-actions.component.html +++ b/apps/red-ui/src/app/modules/dossier/components/bulk-actions/dossier-overview-bulk-actions.component.html @@ -21,8 +21,7 @@ icon="red:assign-me" tooltip="dossier-overview.assign-me" type="dark-bg" - > - + > - + > - + > - + - + > - + > ) {} diff --git a/apps/red-ui/src/app/modules/dossier/components/dossier-details/dossier-details.component.ts b/apps/red-ui/src/app/modules/dossier/components/dossier-details/dossier-details.component.ts index f212e5115..4a65ccbaf 100644 --- a/apps/red-ui/src/app/modules/dossier/components/dossier-details/dossier-details.component.ts +++ b/apps/red-ui/src/app/modules/dossier/components/dossier-details/dossier-details.component.ts @@ -72,7 +72,7 @@ export class DossierDetailsComponent implements OnInit { key: key }); } - this.documentsChartData.sort(StatusSorter.byKey); + this.documentsChartData.sort(StatusSorter.byStatus); this.documentsChartData = this.translateChartService.translateStatus(this.documentsChartData); this._changeDetectorRef.detectChanges(); } diff --git a/apps/red-ui/src/app/modules/dossier/components/dossier-listing-actions/dossier-listing-actions.component.ts b/apps/red-ui/src/app/modules/dossier/components/dossier-listing-actions/dossier-listing-actions.component.ts index ae79b6868..e8f6d2469 100644 --- a/apps/red-ui/src/app/modules/dossier/components/dossier-listing-actions/dossier-listing-actions.component.ts +++ b/apps/red-ui/src/app/modules/dossier/components/dossier-listing-actions/dossier-listing-actions.component.ts @@ -2,7 +2,6 @@ import { Component, EventEmitter, Input, Output } from '@angular/core'; import { PermissionsService } from '@services/permissions.service'; import { DossierWrapper } from '@state/model/dossier.wrapper'; import { StatusSorter } from '@utils/sorters/status-sorter'; -import { FileManagementControllerService } from '@redaction/red-ui-http'; import { AppStateService } from '@state/app-state.service'; import { DossiersDialogService } from '../../services/dossiers-dialog.service'; @@ -19,16 +18,13 @@ export class DossierListingActionsComponent { constructor( readonly permissionsService: PermissionsService, readonly appStateService: AppStateService, - private readonly _dialogService: DossiersDialogService, - private readonly _fileManagementControllerService: FileManagementControllerService + private readonly _dialogService: DossiersDialogService ) {} openEditDossierDialog($event: MouseEvent, dossierWrapper: DossierWrapper) { this._dialogService.openDialog('editDossier', $event, { dossierWrapper, - afterSave: () => { - this.actionPerformed.emit(); - } + afterSave: () => this.actionPerformed.emit() }); } @@ -51,7 +47,7 @@ export class DossierListingActionsComponent { }, {}); return Object.keys(obj) - .sort((a, b) => StatusSorter[a] - StatusSorter[b]) + .sort(StatusSorter.byStatus) .map(status => ({ length: obj[status], color: status })); } } diff --git a/apps/red-ui/src/app/modules/dossier/screens/dossier-listing-screen/dossier-listing-screen.component.html b/apps/red-ui/src/app/modules/dossier/screens/dossier-listing-screen/dossier-listing-screen.component.html index 82508afd6..48c30411a 100644 --- a/apps/red-ui/src/app/modules/dossier/screens/dossier-listing-screen/dossier-listing-screen.component.html +++ b/apps/red-ui/src/app/modules/dossier/screens/dossier-listing-screen/dossier-listing-screen.component.html @@ -18,10 +18,8 @@
@@ -45,7 +43,7 @@
event instanceof NavigationStart && event.url !== '/main/dossiers'; @@ -39,6 +39,8 @@ const isLeavingScreen = event => event instanceof NavigationStart && event.url ! }) export class DossierListingScreenComponent extends BaseListingComponent implements OnInit, OnDestroy, OnAttach, OnDetach { readonly itemSize = 95; + protected readonly _primaryKey = 'dossierName'; + dossiersChartData: DoughnutChartConfig[] = []; documentsChartData: DoughnutChartConfig[] = []; buttonConfigs: ButtonConfig[] = [ @@ -68,8 +70,6 @@ export class DossierListingScreenComponent extends BaseListingComponent
implements OnInit, OnDestroy, OnDetach, OnAttach { - collapsedDetails = false; readonly itemSize = 80; + protected readonly _primaryKey = 'filename'; + collapsedDetails = false; actionConfigs: ActionConfig[]; dossierAttributes: DossierAttributeWithValue[] = []; @ViewChild(DossierDetailsComponent, { static: false }) @@ -73,8 +74,6 @@ export class DossierOverviewScreenComponent protected readonly _injector: Injector ) { super(_injector); - this.sortingService.setScreenName(ScreenNames.DOSSIER_OVERVIEW); - this.searchService.setSearchKey('searchField'); this._loadEntitiesFromState(); } @@ -82,8 +81,8 @@ export class DossierOverviewScreenComponent return this._appStateService.activeDossier; } - get user() { - return this._userService.user; + get userId() { + return this._userService.userId; } get checkedRequiredFilters() { @@ -170,10 +169,6 @@ export class DossierOverviewScreenComponent this._changeDetectorRef.detectChanges(); } - trackByFileId(index: number, item: FileStatusWrapper) { - return item.fileId; - } - @HostListener('drop', ['$event']) onDrop(event: DragEvent) { handleFileDrop(event, this.activeDossier, this._uploadFiles.bind(this)); @@ -272,7 +267,7 @@ export class DossierOverviewScreenComponent slug: 'statusFilters', label: this._translateService.instant('filters.status'), icon: 'red:status', - values: statusFilters.sort(StatusSorter.byKey), + values: statusFilters.sort(StatusSorter.byStatus), checker: keyChecker('status') }); @@ -348,7 +343,7 @@ export class DossierOverviewScreenComponent { key: 'assigned-to-me', label: this._translateService.instant('dossier-overview.quick-filters.assigned-to-me'), - checker: (file: FileStatusWrapper) => file.currentReviewer === this.user.id + checker: (file: FileStatusWrapper) => file.currentReviewer === this.userId }, { key: 'unassigned', @@ -358,7 +353,7 @@ export class DossierOverviewScreenComponent { key: 'assigned-to-others', label: this._translateService.instant('dossier-overview.quick-filters.assigned-to-others'), - checker: (file: FileStatusWrapper) => !!file.currentReviewer && file.currentReviewer !== this.user.id + checker: (file: FileStatusWrapper) => !!file.currentReviewer && file.currentReviewer !== this.userId } ]; } diff --git a/apps/red-ui/src/app/modules/shared/base/base-listing.component.ts b/apps/red-ui/src/app/modules/shared/base/base-listing.component.ts index 0f2973a1a..5fef97a9b 100644 --- a/apps/red-ui/src/app/modules/shared/base/base-listing.component.ts +++ b/apps/red-ui/src/app/modules/shared/base/base-listing.component.ts @@ -1,5 +1,5 @@ import { Component, Injector, OnDestroy, ViewChild } from '@angular/core'; -import { SortingOption, SortingService } from '@services/sorting.service'; +import { SortingOrders, SortingService } from '@services/sorting.service'; import { CdkVirtualScrollViewport } from '@angular/cdk/scrolling'; import { FilterService } from '../services/filter.service'; import { SearchService } from '../services/search.service'; @@ -20,13 +20,30 @@ export abstract class BaseListingComponent extends AutoUnsubscribeComponent i readonly searchService: SearchService; readonly screenStateService: ScreenStateService; + /** + * Key used in the *trackBy* function with **ngFor* or **cdkVirtualFor* + * and in the default sorting and as the search field + * @protected + */ + protected abstract _primaryKey: string; + protected constructor(protected readonly _injector: Injector) { super(); + this.trackByPrimaryKey = this.trackByPrimaryKey.bind(this); this.permissionsService = this._injector.get(PermissionsService); this.filterService = this._injector.get(FilterService); this.sortingService = this._injector.get(SortingService); this.searchService = this._injector.get(SearchService); this.screenStateService = this._injector.get>(ScreenStateService); + setTimeout(() => this.setInitialConfig()); + } + + setInitialConfig() { + this.sortingService.setSortingOption({ + column: this._primaryKey, + order: SortingOrders.ASC + }); + this.searchService.setSearchKey(this._primaryKey); } ngOnDestroy(): void { @@ -45,22 +62,16 @@ export abstract class BaseListingComponent extends AutoUnsubscribeComponent i return this.screenStateService.allEntities; } - get sortingOption(): SortingOption { - return this.sortingService.getSortingOption(); - } - get noMatch$(): Observable { return combineLatest([this.screenStateService.allEntitiesLength$, this.screenStateService.displayedLength$]).pipe( - map(res => res[0] && !res[1]) + map(([hasEntities, hasDisplayedEntities]) => hasEntities && !hasDisplayedEntities) ); } canBulkDelete$(hasPermission = true) { - return this.screenStateService.areSomeEntitiesSelected$.pipe(map(res => res && hasPermission)); - } - - toggleSort($event) { - this.sortingService.toggleSort($event); + return this.screenStateService.areSomeEntitiesSelected$.pipe( + map(areSomeEntitiesSelected => areSomeEntitiesSelected && hasPermission) + ); } toggleSelectAll() { @@ -75,4 +86,8 @@ export abstract class BaseListingComponent extends AutoUnsubscribeComponent i isSelected(entity: T): boolean { return this.screenStateService.isSelected(entity); } + + trackByPrimaryKey(index: number, item: T) { + return item[this._primaryKey]; + } } diff --git a/apps/red-ui/src/app/modules/shared/components/page-header/page-header.component.html b/apps/red-ui/src/app/modules/shared/components/page-header/page-header.component.html index ce63e7dbe..38eb57cda 100644 --- a/apps/red-ui/src/app/modules/shared/components/page-header/page-header.component.html +++ b/apps/red-ui/src/app/modules/shared/components/page-header/page-header.component.html @@ -16,31 +16,26 @@ -
+
- - - +
+ + + -
{ @Input() buttonConfigs: ButtonConfig[]; @Input() searchPlaceholder: string; - constructor( - readonly permissionsService: PermissionsService, - readonly filterService: FilterService, - readonly searchService: SearchService - ) {} + constructor(@Optional() readonly filterService: FilterService, @Optional() readonly searchService: SearchService) {} - get filters$() { - return this.filterService.allFilters$.pipe(map(all => all.filter(f => f.icon))); + get filters$(): Observable { + return this.filterService?.allFilters$.pipe(map(all => all.filter(f => f.icon))); } - resetFilters() { + get showResetFilters$(): Observable { + const filtersLength$ = this.filters$.pipe( + map(f => f.length), + distinctUntilChanged() + ); + return combineLatest([filtersLength$, this.filterService.showResetFilters$, this.searchService.valueChanges$]).pipe( + map(([hasFilters, showResetFilters, searchValue]) => hasFilters && (showResetFilters || !!searchValue)), + distinctUntilChanged() + ); + } + + resetFilters(): void { this.filterService.reset(); this.searchService.reset(); } - trackByLabel(index: number, item) { + trackByLabel(index: number, item: K): string { return item.label; } } diff --git a/apps/red-ui/src/app/modules/shared/components/table-col-name/table-col-name.component.html b/apps/red-ui/src/app/modules/shared/components/table-col-name/table-col-name.component.html index d34610c8a..8cacef41f 100644 --- a/apps/red-ui/src/app/modules/shared/components/table-col-name/table-col-name.component.html +++ b/apps/red-ui/src/app/modules/shared/components/table-col-name/table-col-name.component.html @@ -1,18 +1,13 @@ -
+
- +
- - + +
diff --git a/apps/red-ui/src/app/modules/shared/components/table-col-name/table-col-name.component.ts b/apps/red-ui/src/app/modules/shared/components/table-col-name/table-col-name.component.ts index 34328716e..d90b3d867 100644 --- a/apps/red-ui/src/app/modules/shared/components/table-col-name/table-col-name.component.ts +++ b/apps/red-ui/src/app/modules/shared/components/table-col-name/table-col-name.component.ts @@ -1,5 +1,5 @@ -import { Component, EventEmitter, Input, Output } from '@angular/core'; -import { SortingOption } from '@services/sorting.service'; +import { Component, Input, Optional } from '@angular/core'; +import { SortingService } from '@services/sorting.service'; @Component({ selector: 'redaction-table-col-name', @@ -7,7 +7,6 @@ import { SortingOption } from '@services/sorting.service'; styleUrls: ['./table-col-name.component.scss'] }) export class TableColNameComponent { - @Input() activeSortingOption: SortingOption; @Input() column: string; @Input() label: string; @Input() withSort = false; @@ -16,5 +15,5 @@ export class TableColNameComponent { @Input() rightIcon: string; @Input() rightIconTooltip: string; - @Output() toggleSort = new EventEmitter(); + constructor(@Optional() readonly sortingService: SortingService) {} } diff --git a/apps/red-ui/src/app/modules/shared/services/filter.service.ts b/apps/red-ui/src/app/modules/shared/services/filter.service.ts index b26f019ef..169e26655 100644 --- a/apps/red-ui/src/app/modules/shared/services/filter.service.ts +++ b/apps/red-ui/src/app/modules/shared/services/filter.service.ts @@ -24,7 +24,7 @@ export class FilterService { get showResetFilters$() { return this.allFilters$.pipe( map(all => this._toFlatFilters(all)), - filter(f => !!f.find(el => el.checked)), + map(f => !!f.find(el => el.checked)), distinctUntilChanged() ); } diff --git a/apps/red-ui/src/app/modules/shared/services/screen-state.service.ts b/apps/red-ui/src/app/modules/shared/services/screen-state.service.ts index 3a34ca3fe..80cc99002 100644 --- a/apps/red-ui/src/app/modules/shared/services/screen-state.service.ts +++ b/apps/red-ui/src/app/modules/shared/services/screen-state.service.ts @@ -74,7 +74,9 @@ export class ScreenStateService { } get areAllEntitiesSelected$(): Observable { - return combineLatest([this.displayedLength$, this.selectedLength$]).pipe(map(res => res[0] && res[0] === res[1])); + return combineLatest([this.displayedLength$, this.selectedLength$]).pipe( + map(([displayedLength, selectedLength]) => displayedLength && displayedLength === selectedLength) + ); } /** @@ -88,7 +90,9 @@ export class ScreenStateService { * Indicates that some entities are selected, but not all */ get notAllEntitiesSelected$(): Observable { - return combineLatest([this.areAllEntitiesSelected$, this.areSomeEntitiesSelected$]).pipe(map(res => !res[0] && res[1])); + return combineLatest([this.areAllEntitiesSelected$, this.areSomeEntitiesSelected$]).pipe( + map(([allEntitiesAreSelected, someEntitiesAreSelected]) => !allEntitiesAreSelected && someEntitiesAreSelected) + ); } isSelected(entity: T): boolean { diff --git a/apps/red-ui/src/app/modules/shared/services/search.service.ts b/apps/red-ui/src/app/modules/shared/services/search.service.ts index 25a8f19b7..78fbe8a0d 100644 --- a/apps/red-ui/src/app/modules/shared/services/search.service.ts +++ b/apps/red-ui/src/app/modules/shared/services/search.service.ts @@ -2,18 +2,24 @@ import { Injectable } from '@angular/core'; import { debounce } from '@utils/debounce'; import { ScreenStateService } from '@shared/services/screen-state.service'; import { FormBuilder } from '@angular/forms'; +import { BehaviorSubject } from 'rxjs'; @Injectable() export class SearchService { private _searchValue = ''; private _searchKey: string; + valueChanges$ = new BehaviorSubject(this._searchValue); + readonly searchForm = this._formBuilder.group({ query: [''] }); constructor(private readonly _screenStateService: ScreenStateService, private readonly _formBuilder: FormBuilder) { - this.searchForm.valueChanges.subscribe(() => this.executeSearch()); + this.searchForm.valueChanges.subscribe(() => { + this.valueChanges$.next(this.searchValue.toLowerCase()); + this.executeSearch(); + }); } @debounce(200) @@ -23,7 +29,9 @@ export class SearchService { } executeSearchImmediately(): void { - const displayed = this._screenStateService.filteredEntities || this._screenStateService.allEntities; + const displayed = this._screenStateService.filteredEntities.length + ? this._screenStateService.filteredEntities + : this._screenStateService.allEntities; if (!this._searchKey) { return this._screenStateService.setDisplayedEntities(displayed); @@ -39,10 +47,6 @@ export class SearchService { this._searchKey = value; } - get isSearchNeeded(): boolean { - return !!this._searchKey; - } - get searchValue(): string { return this.searchForm.get('query').value; } diff --git a/apps/red-ui/src/app/services/sorting.service.ts b/apps/red-ui/src/app/services/sorting.service.ts index b43f2ba56..c6f620aeb 100644 --- a/apps/red-ui/src/app/services/sorting.service.ts +++ b/apps/red-ui/src/app/services/sorting.service.ts @@ -13,40 +13,12 @@ export interface SortingOption { column: string; } -export type ScreenName = - | 'dossier-listing' - | 'dossier-overview' - | 'dictionary-listing' - | 'dossier-templates-listing' - | 'default-colors' - | 'file-attributes-listing' - | 'dossier-attributes-listing'; - -export const enum ScreenNames { - DOSSIER_LISTING = 'dossier-listing', - DOSSIER_OVERVIEW = 'dossier-overview', - DICTIONARY_LISTING = 'dictionary-listing', - DOSSIER_TEMPLATES_LISTING = 'dossier-templates-listing', - DEFAULT_COLORS = 'default-colors', - FILE_ATTRIBUTES_LISTING = 'file-attributes-listing', - DOSSIER_ATTRIBUTES_LISTING = 'dossier-attributes-listing' -} - @Injectable() export class SortingService { - private _currentScreenName: string; - private readonly _options: { [key in ScreenName]: SortingOption } = { - [ScreenNames.DOSSIER_LISTING]: { column: 'dossier.dossierName', order: SortingOrders.ASC }, - [ScreenNames.DOSSIER_OVERVIEW]: { column: 'filename', order: SortingOrders.ASC }, - [ScreenNames.DICTIONARY_LISTING]: { column: 'label', order: SortingOrders.ASC }, - [ScreenNames.DOSSIER_TEMPLATES_LISTING]: { column: 'name', order: SortingOrders.ASC }, - [ScreenNames.DEFAULT_COLORS]: { column: 'key', order: SortingOrders.ASC }, - [ScreenNames.FILE_ATTRIBUTES_LISTING]: { column: 'label', order: SortingOrders.ASC }, - [ScreenNames.DOSSIER_ATTRIBUTES_LISTING]: { column: 'label', order: 'asc' } - }; + private _sortingOption: SortingOption; - setScreenName(value: string) { - this._currentScreenName = value; + setSortingOption(value: SortingOption): void { + this._sortingOption = value; } sort(values: T[], order = '', column: string = ''): T[] { @@ -67,26 +39,26 @@ export class SortingService { } defaultSort(values: T[]) { - return this.sort(values, this.getSortingOption().order, this.getSortingOption().column); + return this.sort(values, this.sortingOption?.order, this.sortingOption?.column); } toggleSort(column: string) { - if (this._options[this._currentScreenName].column === column) { + if (this._sortingOption.column === column) { this._currentOrder = this._currentOrder === SortingOrders.ASC ? SortingOrders.DESC : SortingOrders.ASC; } else { - this._options[this._currentScreenName] = { column, order: SortingOrders.ASC }; + this._sortingOption = { column, order: SortingOrders.ASC }; } } - getSortingOption(): SortingOption { - return this._options[this._currentScreenName]; + get sortingOption(): SortingOption { + return this._sortingOption; } - private get _currentOrder(): string { - return this._options[this._currentScreenName].order; + private get _currentOrder(): SortingOrder { + return this._sortingOption.order; } - private set _currentOrder(value: string) { - this._options[this._currentScreenName].order = value; + private set _currentOrder(value: SortingOrder) { + this._sortingOption.order = value; } } diff --git a/apps/red-ui/src/app/utils/sorters/status-sorter.ts b/apps/red-ui/src/app/utils/sorters/status-sorter.ts index 94ec85387..bb840b6ef 100644 --- a/apps/red-ui/src/app/utils/sorters/status-sorter.ts +++ b/apps/red-ui/src/app/utils/sorters/status-sorter.ts @@ -1,3 +1,13 @@ +type StatusSorterItem = { key?: string } | string; + +const byStatus = (a: StatusSorterItem, b: StatusSorterItem) => { + if (typeof a !== typeof b) return; + + const x = typeof a === 'string' ? a : a.key; + const y = typeof b === 'string' ? b : b.key; + return (StatusSorter[x] = StatusSorter[y]); +}; + export const StatusSorter = { ERROR: 0, UNPROCESSED: 1, @@ -9,5 +19,5 @@ export const StatusSorter = { UNDER_REVIEW: 15, UNDER_APPROVAL: 20, APPROVED: 25, - byKey: (a: { key?: string }, b: { key?: string }) => StatusSorter[a.key] - StatusSorter[b.key] + byStatus: byStatus };