קצת ארוך, תודה מראש על הסבלנות:
פתיחה של הדיאלוג:
public clickedToAddView() {
this._dialogService.open<SaveViewDialogComponent>(
{
title: $localizeSave View
,
content: SaveViewDialogComponent,
width: '375px !important',
height: 'auto',
},
(comp: SaveViewDialogComponent) => (
(comp.listStateKeys = this._listStateKeys$$.value)
)
);
}
הקומפוננטה של הדיאלוג:
export class SaveViewDialogComponent implements OnInit {
@Input() public listStateKeys: ListStateKeys<DataModelKey>;
public newViewFormGroup: UntypedFormGroup;
public errors: FormErrors<any>;
public viewVM: {
viewName: InputViewModel;
saveAsDefault: InputViewModel;
availableForAllUsers: InputViewModel;
};
constructor(
private _store: Store<GlobalState>,
private _logger: Logger,
private _formBuilder: UntypedFormBuilder
) {
this.newViewFormGroup = this._formBuilder.group({
viewName: new UntypedFormControl('', Validators.required),
saveAsDefault: new UntypedFormControl(false),
availableForAllUsers: new UntypedFormControl(true),
});
}
ngOnInit() {
this.viewVM = {
viewName: new InputViewModel({
formControl: this.newViewFormGroup.controls['viewName'],
type: InputType.text,
value: '',
showTitle: false,
error: this.errors ? this.errors['viewName'] : null,
maxLength: 30,
placeholder: $localizeView Name
,
}),
saveAsDefault: new InputViewModel({
formControl: this.newViewFormGroup.controls['saveAsDefault'],
title: $localizeSave as Default
,
type: InputType.boolean,
value: false,
error: this.errors ? this.errors['saveAsDefault'] : null,
titlePlace: 'after',
maxLength: 30,
}),
availableForAllUsers: new InputViewModel({
formControl: this.newViewFormGroup.controls['availableForAllUsers'],
title: $localizeAvailable for All Users
,
type: InputType.boolean,
value: false,
error: this.errors ? this.errors['availableForAllUsers'] : null,
titlePlace: 'after',
maxLength: 30,
}),
};
}
האפקט שסוגר את הדיאלוג:
public saveNewView$ = createEffect(() =>
this._actions$.pipe(
ofType(listActions.clickedToSaveNewView),
switchMap((action) =>
of(action).pipe(
withLatestFrom(
this._store.select(listSelectors.selectGridViewDto(action))
)
)
),
switchMap(([action, gridViewDto]) =>
this._listService.saveNewGridView(gridViewDto).pipe(
map((savedGridView) =>
listEffectsActions.gridViewSavedSuccessfully({
gridView: savedGridView,
listStateKeys: action.listStateKeys,
})
),
tap(() => {
this._dialogService.close();
}),
catchError((error: HttpErrorResponse) => {
this._logger.error(
An error occurred while saving new Grid View of ${action.listStateKeys.dataModelKey} list. context: ${action.listStateKeys.context}. error: ${error?.message}
);
return of(
listEffectsActions.gridViewSaveFailed({
listStateKeys: action.listStateKeys,
})
);
})
)
)
)
);