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);
includeBundleWidgetsInExport: boolean;
constructor(protected store: Store<AppState>,
protected router: Router,
@Inject(MAT_DIALOG_DATA) public data: ExportWidgetsBundleDialogData,
public dialogRef: MatDialogRef<ExportWidgetsBundleDialogComponent, ExportWidgetsBundleDialogResult>) {
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<ExportWi
}
export(): void {
if (this.includeBundleWidgetsInExport !== this.exportWidgetsFormControl.value) {
this.store.dispatch(new ActionPreferencesPutUserSettings({includeBundleWidgetsInExport: this.exportWidgetsFormControl.value}));
}
this.dialogRef.close({
exportWidgets: this.exportWidgetsFormControl.value
});

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

@ -80,6 +80,7 @@ import {
ExportWidgetsBundleDialogResult
} from '@home/components/import-export/export-widgets-bundle-dialog.component';
import { selectUserSettingsProperty } from '@core/auth/auth.selectors';
import { ActionPreferencesPutUserSettings } from '@core/auth/auth.actions';
// @dynamic
@Injectable()
@ -315,17 +316,13 @@ export class ImportExportService {
}
public exportWidgetsBundle(widgetsBundleId: string) {
let includeBundleWidgetsInExport = false;
this.store.pipe(select(selectUserSettingsProperty( 'includeBundleWidgetsInExport'))).pipe(
take(1)
).subscribe((settings: boolean) => {
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, ExportWidgetsBundleDialogData,
ExportWidgetsBundleDialogResult>(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) {

Loading…
Cancel
Save