From 860cc91abc1e9ae96b338f8406eae365cd1c94e2 Mon Sep 17 00:00:00 2001 From: Edi Cziszter Date: Fri, 11 Feb 2022 14:59:49 +0200 Subject: [PATCH] fixed doughnut charts --- .../app/modules/admin/admin-routing.module.ts | 3 +- ...delete-dossier-state-dialog.component.html | 2 +- ...ssier-states-listing-screen.component.html | 180 +++++++++--------- ...dossier-states-listing-screen.component.ts | 26 +-- .../edit-dossier-general-info.component.html | 4 +- .../dossiers-listing-details.component.ts | 22 ++- .../simple-doughnut-chart.component.ts | 2 +- .../entity-services/dossiers.service.ts | 16 +- 8 files changed, 143 insertions(+), 112 deletions(-) diff --git a/apps/red-ui/src/app/modules/admin/admin-routing.module.ts b/apps/red-ui/src/app/modules/admin/admin-routing.module.ts index 71dc59af3..6ce27d21f 100644 --- a/apps/red-ui/src/app/modules/admin/admin-routing.module.ts +++ b/apps/red-ui/src/app/modules/admin/admin-routing.module.ts @@ -22,7 +22,6 @@ import { DICTIONARY_TYPE, DOSSIER_TEMPLATE_ID } from '@utils/constants'; import { DossierTemplateExistsGuard } from '../../guards/dossier-template-exists.guard'; import { DictionaryExistsGuard } from '../../guards/dictionary-exists.guard'; import { DossierStatesListingScreenComponent } from './screens/dossier-states-listing/dossier-states-listing-screen.component'; -import { DossiersGuard } from '../../guards/dossiers.guard'; const routes: Routes = [ { path: '', redirectTo: 'dossier-templates', pathMatch: 'full' }, @@ -121,7 +120,7 @@ const routes: Routes = [ component: DossierStatesListingScreenComponent, canActivate: [CompositeRouteGuard], data: { - routeGuards: [AuthGuard, RedRoleGuard, AppStateGuard, DossiersGuard], + routeGuards: [AuthGuard, RedRoleGuard, AppStateGuard], }, }, { diff --git a/apps/red-ui/src/app/modules/admin/dialogs/confirm-delete-dossier-state-dialog/confirm-delete-dossier-state-dialog.component.html b/apps/red-ui/src/app/modules/admin/dialogs/confirm-delete-dossier-state-dialog/confirm-delete-dossier-state-dialog.component.html index 0d2dc5004..174896a32 100644 --- a/apps/red-ui/src/app/modules/admin/dialogs/confirm-delete-dossier-state-dialog/confirm-delete-dossier-state-dialog.component.html +++ b/apps/red-ui/src/app/modules/admin/dialogs/confirm-delete-dossier-state-dialog/confirm-delete-dossier-state-dialog.component.html @@ -26,7 +26,7 @@
-
diff --git a/apps/red-ui/src/app/modules/admin/screens/dossier-states-listing/dossier-states-listing-screen.component.html b/apps/red-ui/src/app/modules/admin/screens/dossier-states-listing/dossier-states-listing-screen.component.html index 21f948e7f..eff14a34f 100644 --- a/apps/red-ui/src/app/modules/admin/screens/dossier-states-listing/dossier-states-listing-screen.component.html +++ b/apps/red-ui/src/app/modules/admin/screens/dossier-states-listing/dossier-states-listing-screen.component.html @@ -1,94 +1,98 @@ -
-
+ + +
+ + + +
+
+ + +
+
+
+
+
{{ state.name }}
+
+
+ +
+ {{ state.dossierCount }} +
+ +
+
+ + +
+
+
+
+ diff --git a/apps/red-ui/src/app/modules/admin/screens/dossier-states-listing/dossier-states-listing-screen.component.ts b/apps/red-ui/src/app/modules/admin/screens/dossier-states-listing/dossier-states-listing-screen.component.ts index 1fe749dfe..3b532f3e0 100644 --- a/apps/red-ui/src/app/modules/admin/screens/dossier-states-listing/dossier-states-listing-screen.component.ts +++ b/apps/red-ui/src/app/modules/admin/screens/dossier-states-listing/dossier-states-listing-screen.component.ts @@ -44,7 +44,7 @@ export class DossierStatesListingScreenComponent extends ListingComponent { if (value) { - await firstValueFrom(this._dossierStateService.deleteAndReplace(dossierState.dossierStatusId, value)); + await firstValueFrom(this.dossierStateService.deleteAndReplace(dossierState.dossierStatusId, value)); } - await firstValueFrom(this._dossierStateService.loadAllForAllTemplates()); await this._appStateService.refreshDossierTemplate(templateId); await this._loadData(); }); } private async _createNewDossierStateAndRefreshView(newValue: IDossierState): Promise { - await firstValueFrom(this._dossierStateService.setDossierState(newValue)).catch(error => { + await firstValueFrom(this.dossierStateService.setDossierState(newValue)).catch(error => { if (error.status === HttpStatusCode.Conflict) { this._toaster.error(_('dossier-states-listing.error.conflict')); } else { this._toaster.error(_('dossier-states-listing.error.generic')); } }); - await firstValueFrom(this._dossierStateService.loadAllForAllTemplates()); await this._appStateService.refreshDossierTemplate(this._dossierTemplatesService.activeDossierTemplateId); await this._loadData(); } - private async _loadData() { + private async _loadData(): Promise { this._loadingService.start(); + await firstValueFrom(this._dossiersService.loadAll()); try { const templateId = this._dossierTemplatesService.activeDossierTemplateId; - const dossierStates = this._dossierStateService.all.filter(d => d.dossierTemplateId === templateId); - const dossiers = this._dossiersService.all; - this._dossierStateService.all.forEach( - state => (state.dossierCount = dossiers.filter(dossier => dossier.dossierStatusId === state.dossierStatusId).length), - ); + const dossierStates = this.dossierStateService.all.filter(d => d.dossierTemplateId === templateId); + this._setStatesCount(); this.chartData = this._loadChartData(); this.entitiesService.setEntities(dossierStates || []); } catch (e) {} @@ -117,10 +113,16 @@ export class DossierStatesListingScreenComponent extends ListingComponent { + this.dossierStateService.all.forEach(state => { config.push({ value: state.dossierCount, label: state.name, key: state.name, color: state.description }); }); return config; } + + private _setStatesCount(): void { + this.dossierStateService.all.forEach( + state => (state.dossierCount = this._dossiersService.getCountWithState(state.dossierStatusId)), + ); + } } diff --git a/apps/red-ui/src/app/modules/dossier/dialogs/edit-dossier-dialog/general-info/edit-dossier-general-info.component.html b/apps/red-ui/src/app/modules/dossier/dialogs/edit-dossier-dialog/general-info/edit-dossier-general-info.component.html index 7f632e2a0..7faada51b 100644 --- a/apps/red-ui/src/app/modules/dossier/dialogs/edit-dossier-dialog/general-info/edit-dossier-general-info.component.html +++ b/apps/red-ui/src/app/modules/dossier/dialogs/edit-dossier-dialog/general-info/edit-dossier-general-info.component.html @@ -57,7 +57,9 @@ diff --git a/apps/red-ui/src/app/modules/dossier/screens/dossiers-listing/components/dossiers-listing-details/dossiers-listing-details.component.ts b/apps/red-ui/src/app/modules/dossier/screens/dossiers-listing/components/dossiers-listing-details/dossiers-listing-details.component.ts index 68f053b36..d27fd37e3 100644 --- a/apps/red-ui/src/app/modules/dossier/screens/dossiers-listing/components/dossiers-listing-details/dossiers-listing-details.component.ts +++ b/apps/red-ui/src/app/modules/dossier/screens/dossiers-listing/components/dossiers-listing-details/dossiers-listing-details.component.ts @@ -7,8 +7,9 @@ import { Dossier, DossierStats, FileCountPerWorkflowStatus, StatusSorter } from import { workflowFileStatusTranslations } from '../../../../translations/file-status-translations'; import { TranslateChartService } from '@services/translate-chart.service'; import { filter, map, switchMap } from 'rxjs/operators'; -import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker'; import { DossierStatsService } from '@services/entity-services/dossier-stats.service'; +import { DossierStateService } from '../../../../../../services/entity-services/dossier-state.service'; +import { TranslateService } from '@ngx-translate/core'; @Component({ selector: 'redaction-dossiers-listing-details', @@ -25,6 +26,8 @@ export class DossiersListingDetailsComponent { readonly dossiersService: DossiersService, private readonly _dossierStatsMap: DossierStatsService, private readonly _translateChartService: TranslateChartService, + private readonly _dossierStateService: DossierStateService, + private readonly _translateService: TranslateService, ) { this.documentsChartData$ = this.dossiersService.all$.pipe( mapEach(dossier => _dossierStatsMap.watch$(dossier.dossierId)), @@ -37,12 +40,19 @@ export class DossiersListingDetailsComponent { } private async _toDossierChartData(dossiers: Dossier[]): Promise { + const config: DoughnutChartConfig[] = []; + this._dossierStateService.all.forEach(state => { + state.dossierCount = this.dossiersService.getCountWithState(state.dossierStatusId); + config.push({ value: state.dossierCount, label: state.name, color: state.description }); + }); + const notAssignedLength = this.dossiersService.all.length - config.map(v => v.value).reduce((acc, val) => acc + val, 0); + config.push({ + value: notAssignedLength, + label: this._translateService.instant('edit-dossier-dialog.general-info.form.dossier-status.placeholder'), + color: '#D8DAE0', + }); // TODO: deleted dossiers count should come with stats - // const deletedDossiers = await this.dossiersService.getDeleted(); - return [ - { value: dossiers.length, color: 'ACTIVE', label: _('active') }, - // { value: deletedDossiers.length, color: 'DELETED', label: _('archived') }, - ]; + return config; } private _toChartData(stats: DossierStats[]) { diff --git a/apps/red-ui/src/app/modules/shared/components/simple-doughnut-chart/simple-doughnut-chart.component.ts b/apps/red-ui/src/app/modules/shared/components/simple-doughnut-chart/simple-doughnut-chart.component.ts index bbe3ff3d9..ccea0ce17 100644 --- a/apps/red-ui/src/app/modules/shared/components/simple-doughnut-chart/simple-doughnut-chart.component.ts +++ b/apps/red-ui/src/app/modules/shared/components/simple-doughnut-chart/simple-doughnut-chart.component.ts @@ -51,7 +51,7 @@ export class SimpleDoughnutChartComponent implements OnChanges, OnInit { } get displayedDataTotal() { - return this.totalType === 'count' ? this.config.length : this.dataTotal; + return this.totalType === 'sum' ? this.dataTotal : this.config.length; } ngOnInit() { diff --git a/apps/red-ui/src/app/services/entity-services/dossiers.service.ts b/apps/red-ui/src/app/services/entity-services/dossiers.service.ts index 7760c7a7d..234707713 100644 --- a/apps/red-ui/src/app/services/entity-services/dossiers.service.ts +++ b/apps/red-ui/src/app/services/entity-services/dossiers.service.ts @@ -62,7 +62,17 @@ export class DossiersService extends EntitiesService { } loadAllIfChanged(): Observable { - return this.hasChangesDetails$().pipe(switchMap(changes => this.loadAll().pipe(mapTo(changes)))); + return this.hasChangesDetails$().pipe( + catchError(err => { + console.log('aaa', err); + return of(err); + }), + switchMap(changes => this.loadAll().pipe(mapTo(changes))), + catchError(err => { + console.log('bbb', err); + return of(err); + }), + ); } hasChangesDetails$(): Observable { @@ -111,6 +121,10 @@ export class DossiersService extends EntitiesService { return firstValueFrom(super.delete(body, 'deleted-dossiers/hard-delete', body)); } + getCountWithState(dossierStatusId: string): number { + return this.all.filter(dossier => dossier.dossierStatusId === dossierStatusId).length; + } + private _emitFileChanges(changes: ChangesDetails): void { changes.dossierChanges.filter(change => change.fileChanges).forEach(change => this.dossierFileChanges$.next(change.dossierId)); }