From 3307e89d97839e90d9426e380b07379be6a560f9 Mon Sep 17 00:00:00 2001 From: Artem Dzhereleiko Date: Wed, 8 Nov 2023 11:14:43 +0200 Subject: [PATCH 1/3] UI: Save status include bundle --- .../export-widgets-bundle-dialog.component.ts | 11 +++++++++++ .../import-export/import-export.service.ts | 17 ++++++++++++++--- .../app/shared/models/user-settings.models.ts | 1 + 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/ui-ngx/src/app/modules/home/components/import-export/export-widgets-bundle-dialog.component.ts b/ui-ngx/src/app/modules/home/components/import-export/export-widgets-bundle-dialog.component.ts index 570beaf7e8..6b9d680815 100644 --- a/ui-ngx/src/app/modules/home/components/import-export/export-widgets-bundle-dialog.component.ts +++ b/ui-ngx/src/app/modules/home/components/import-export/export-widgets-bundle-dialog.component.ts @@ -22,9 +22,11 @@ import { FormControl } from '@angular/forms'; import { Router } from '@angular/router'; import { DialogComponent } from '@app/shared/components/dialog.component'; import { WidgetsBundle } from '@shared/models/widgets-bundle.model'; +import { ActionPreferencesPutUserSettings } from '@core/auth/auth.actions'; export interface ExportWidgetsBundleDialogData { widgetsBundle: WidgetsBundle; + includeBundleWidgetsInExport: boolean; } export interface ExportWidgetsBundleDialogResult { @@ -44,12 +46,18 @@ export class ExportWidgetsBundleDialogComponent extends DialogComponent, protected router: Router, @Inject(MAT_DIALOG_DATA) public data: ExportWidgetsBundleDialogData, public dialogRef: MatDialogRef) { super(store, router, dialogRef); this.widgetsBundle = data.widgetsBundle; + this.includeBundleWidgetsInExport = data.includeBundleWidgetsInExport; + if (this.includeBundleWidgetsInExport) { + this.exportWidgetsFormControl.patchValue(this.includeBundleWidgetsInExport, {emitEvent: false}); + } } ngOnInit(): void { @@ -60,6 +68,9 @@ export class ExportWidgetsBundleDialogComponent extends DialogComponent { + if(settings) { + includeBundleWidgetsInExport = settings; + } + }); + this.widgetService.getWidgetsBundle(widgetsBundleId).subscribe( (widgetsBundle) => { this.dialog.open { diff --git a/ui-ngx/src/app/shared/models/user-settings.models.ts b/ui-ngx/src/app/shared/models/user-settings.models.ts index bd64e0241b..28aedc7c14 100644 --- a/ui-ngx/src/app/shared/models/user-settings.models.ts +++ b/ui-ngx/src/app/shared/models/user-settings.models.ts @@ -18,6 +18,7 @@ export interface UserSettings { openedMenuSections?: string[]; notDisplayConnectivityAfterAddDevice?: boolean; notDisplayInstructionsAfterAddEdge?: boolean; + includeBundleWidgetsInExport?: boolean; } export const initialUserSettings: UserSettings = { From 68384b489df43ce899f7c1b34698b2caa6387084 Mon Sep 17 00:00:00 2001 From: Artem Dzhereleiko Date: Fri, 10 Nov 2023 15:13:50 +0200 Subject: [PATCH 2/3] UI: Refactoring save status include bundle --- .../export-widgets-bundle-dialog.component.ts | 10 ++------ .../import-export/import-export.service.ts | 24 +++++++++---------- 2 files changed, 14 insertions(+), 20 deletions(-) diff --git a/ui-ngx/src/app/modules/home/components/import-export/export-widgets-bundle-dialog.component.ts b/ui-ngx/src/app/modules/home/components/import-export/export-widgets-bundle-dialog.component.ts index 6b9d680815..728fa74157 100644 --- a/ui-ngx/src/app/modules/home/components/import-export/export-widgets-bundle-dialog.component.ts +++ b/ui-ngx/src/app/modules/home/components/import-export/export-widgets-bundle-dialog.component.ts @@ -46,17 +46,14 @@ export class ExportWidgetsBundleDialogComponent extends DialogComponent, protected router: Router, @Inject(MAT_DIALOG_DATA) public data: ExportWidgetsBundleDialogData, public dialogRef: MatDialogRef) { super(store, router, dialogRef); this.widgetsBundle = data.widgetsBundle; - this.includeBundleWidgetsInExport = data.includeBundleWidgetsInExport; - if (this.includeBundleWidgetsInExport) { - this.exportWidgetsFormControl.patchValue(this.includeBundleWidgetsInExport, {emitEvent: false}); + if (data.includeBundleWidgetsInExport) { + this.exportWidgetsFormControl.patchValue(data.includeBundleWidgetsInExport, {emitEvent: false}); } } @@ -68,9 +65,6 @@ export class ExportWidgetsBundleDialogComponent extends DialogComponent { - if(settings) { - includeBundleWidgetsInExport = settings; - } - }); + const tasks = { + includeBundleWidgetsInExport: this.store.pipe(select(selectUserSettingsProperty( 'includeBundleWidgetsInExport'))).pipe(take(1)), + widgetsBundle: this.widgetService.getWidgetsBundle(widgetsBundleId) + }; - this.widgetService.getWidgetsBundle(widgetsBundleId).subscribe( - (widgetsBundle) => { + forkJoin(tasks).subscribe({ + next: ({includeBundleWidgetsInExport, widgetsBundle}) => { this.dialog.open(ExportWidgetsBundleDialogComponent, { disableClose: true, @@ -337,6 +334,9 @@ export class ImportExportService { }).afterClosed().subscribe( (result) => { if (result) { + if (includeBundleWidgetsInExport !== result.exportWidgets) { + this.store.dispatch(new ActionPreferencesPutUserSettings({includeBundleWidgetsInExport: result.exportWidgets})); + } if (result.exportWidgets) { this.exportWidgetsBundleWithWidgetTypes(widgetsBundle); } else { @@ -346,10 +346,10 @@ export class ImportExportService { } ); }, - (e) => { + error: (e) => { this.handleExportError(e, 'widgets-bundle.export-failed-error'); } - ); + }); } private exportWidgetsBundleWithWidgetTypes(widgetsBundle: WidgetsBundle) { From ceec2d2d7248438d3d45b2c0c2637abeb562de70 Mon Sep 17 00:00:00 2001 From: Artem Dzhereleiko Date: Fri, 10 Nov 2023 15:15:46 +0200 Subject: [PATCH 3/3] UI: Optimize imports --- .../import-export/export-widgets-bundle-dialog.component.ts | 1 - .../home/components/import-export/import-export.service.ts | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/ui-ngx/src/app/modules/home/components/import-export/export-widgets-bundle-dialog.component.ts b/ui-ngx/src/app/modules/home/components/import-export/export-widgets-bundle-dialog.component.ts index 728fa74157..b6a4664aed 100644 --- a/ui-ngx/src/app/modules/home/components/import-export/export-widgets-bundle-dialog.component.ts +++ b/ui-ngx/src/app/modules/home/components/import-export/export-widgets-bundle-dialog.component.ts @@ -22,7 +22,6 @@ import { FormControl } from '@angular/forms'; import { Router } from '@angular/router'; import { DialogComponent } from '@app/shared/components/dialog.component'; import { WidgetsBundle } from '@shared/models/widgets-bundle.model'; -import { ActionPreferencesPutUserSettings } from '@core/auth/auth.actions'; export interface ExportWidgetsBundleDialogData { widgetsBundle: WidgetsBundle; diff --git a/ui-ngx/src/app/modules/home/components/import-export/import-export.service.ts b/ui-ngx/src/app/modules/home/components/import-export/import-export.service.ts index 7286746d0d..20eb26f7b6 100644 --- a/ui-ngx/src/app/modules/home/components/import-export/import-export.service.ts +++ b/ui-ngx/src/app/modules/home/components/import-export/import-export.service.ts @@ -38,7 +38,7 @@ import { forkJoin, Observable, of, Subject } from 'rxjs'; import { catchError, map, mergeMap, switchMap, take, tap } from 'rxjs/operators'; import { DashboardUtilsService } from '@core/services/dashboard-utils.service'; import { EntityService } from '@core/http/entity.service'; -import { Widget, WidgetSize, WidgetType, WidgetTypeDetails } from '@shared/models/widget.models'; +import { Widget, WidgetSize, WidgetTypeDetails } from '@shared/models/widget.models'; import { EntityAliasesDialogComponent, EntityAliasesDialogData