Browse Source

UI: Refactoring save status include bundle

pull/9579/head
Artem Dzhereleiko 3 years ago
parent
commit
68384b489d
  1. 10
      ui-ngx/src/app/modules/home/components/import-export/export-widgets-bundle-dialog.component.ts
  2. 24
      ui-ngx/src/app/modules/home/components/import-export/import-export.service.ts

10
ui-ngx/src/app/modules/home/components/import-export/export-widgets-bundle-dialog.component.ts

@ -46,17 +46,14 @@ export class ExportWidgetsBundleDialogComponent extends DialogComponent<ExportWi
exportWidgetsFormControl = new FormControl(false); exportWidgetsFormControl = new FormControl(false);
includeBundleWidgetsInExport: boolean;
constructor(protected store: Store<AppState>, constructor(protected store: Store<AppState>,
protected router: Router, protected router: Router,
@Inject(MAT_DIALOG_DATA) public data: ExportWidgetsBundleDialogData, @Inject(MAT_DIALOG_DATA) public data: ExportWidgetsBundleDialogData,
public dialogRef: MatDialogRef<ExportWidgetsBundleDialogComponent, ExportWidgetsBundleDialogResult>) { public dialogRef: MatDialogRef<ExportWidgetsBundleDialogComponent, ExportWidgetsBundleDialogResult>) {
super(store, router, dialogRef); super(store, router, dialogRef);
this.widgetsBundle = data.widgetsBundle; this.widgetsBundle = data.widgetsBundle;
this.includeBundleWidgetsInExport = data.includeBundleWidgetsInExport; if (data.includeBundleWidgetsInExport) {
if (this.includeBundleWidgetsInExport) { this.exportWidgetsFormControl.patchValue(data.includeBundleWidgetsInExport, {emitEvent: false});
this.exportWidgetsFormControl.patchValue(this.includeBundleWidgetsInExport, {emitEvent: false});
} }
} }
@ -68,9 +65,6 @@ export class ExportWidgetsBundleDialogComponent extends DialogComponent<ExportWi
} }
export(): void { export(): void {
if (this.includeBundleWidgetsInExport !== this.exportWidgetsFormControl.value) {
this.store.dispatch(new ActionPreferencesPutUserSettings({includeBundleWidgetsInExport: this.exportWidgetsFormControl.value}));
}
this.dialogRef.close({ this.dialogRef.close({
exportWidgets: this.exportWidgetsFormControl.value exportWidgets: this.exportWidgetsFormControl.value
}); });

24
ui-ngx/src/app/modules/home/components/import-export/import-export.service.ts

@ -80,6 +80,7 @@ import {
ExportWidgetsBundleDialogResult ExportWidgetsBundleDialogResult
} from '@home/components/import-export/export-widgets-bundle-dialog.component'; } from '@home/components/import-export/export-widgets-bundle-dialog.component';
import { selectUserSettingsProperty } from '@core/auth/auth.selectors'; import { selectUserSettingsProperty } from '@core/auth/auth.selectors';
import { ActionPreferencesPutUserSettings } from '@core/auth/auth.actions';
// @dynamic // @dynamic
@Injectable() @Injectable()
@ -315,17 +316,13 @@ export class ImportExportService {
} }
public exportWidgetsBundle(widgetsBundleId: string) { public exportWidgetsBundle(widgetsBundleId: string) {
let includeBundleWidgetsInExport = false; const tasks = {
this.store.pipe(select(selectUserSettingsProperty( 'includeBundleWidgetsInExport'))).pipe( includeBundleWidgetsInExport: this.store.pipe(select(selectUserSettingsProperty( 'includeBundleWidgetsInExport'))).pipe(take(1)),
take(1) widgetsBundle: this.widgetService.getWidgetsBundle(widgetsBundleId)
).subscribe((settings: boolean) => { };
if(settings) {
includeBundleWidgetsInExport = settings;
}
});
this.widgetService.getWidgetsBundle(widgetsBundleId).subscribe( forkJoin(tasks).subscribe({
(widgetsBundle) => { next: ({includeBundleWidgetsInExport, widgetsBundle}) => {
this.dialog.open<ExportWidgetsBundleDialogComponent, ExportWidgetsBundleDialogData, this.dialog.open<ExportWidgetsBundleDialogComponent, ExportWidgetsBundleDialogData,
ExportWidgetsBundleDialogResult>(ExportWidgetsBundleDialogComponent, { ExportWidgetsBundleDialogResult>(ExportWidgetsBundleDialogComponent, {
disableClose: true, disableClose: true,
@ -337,6 +334,9 @@ export class ImportExportService {
}).afterClosed().subscribe( }).afterClosed().subscribe(
(result) => { (result) => {
if (result) { if (result) {
if (includeBundleWidgetsInExport !== result.exportWidgets) {
this.store.dispatch(new ActionPreferencesPutUserSettings({includeBundleWidgetsInExport: result.exportWidgets}));
}
if (result.exportWidgets) { if (result.exportWidgets) {
this.exportWidgetsBundleWithWidgetTypes(widgetsBundle); this.exportWidgetsBundleWithWidgetTypes(widgetsBundle);
} else { } else {
@ -346,10 +346,10 @@ export class ImportExportService {
} }
); );
}, },
(e) => { error: (e) => {
this.handleExportError(e, 'widgets-bundle.export-failed-error'); this.handleExportError(e, 'widgets-bundle.export-failed-error');
} }
); });
} }
private exportWidgetsBundleWithWidgetTypes(widgetsBundle: WidgetsBundle) { private exportWidgetsBundleWithWidgetTypes(widgetsBundle: WidgetsBundle) {

Loading…
Cancel
Save