This commit is contained in:
Dan Percic 2023-11-17 11:43:32 +02:00
parent 87e1c88452
commit 2bb459961a
3 changed files with 37 additions and 35 deletions

View File

@ -1,14 +1,14 @@
import { AfterViewInit, Directive, HostListener, inject, OnDestroy, signal } from '@angular/core';
import { MatDialog, MatDialogRef } from '@angular/material/dialog';
import { UntypedFormBuilder, UntypedFormGroup } from '@angular/forms';
import { hasFormChanged, IqserEventTarget } from '../utils';
import { ConfirmOptions } from '.';
import { ConfirmationDialogService } from './confirmation-dialog.service';
import { MatDialog, MatDialogRef } from '@angular/material/dialog';
import { debounceTime, firstValueFrom, fromEvent, merge, of, Subscription } from 'rxjs';
import { tap } from 'rxjs/operators';
import { ConfirmOptions } from '.';
import { IconButtonTypes } from '../buttons';
import { LoadingService } from '../loading';
import { Toaster } from '../services';
import { IconButtonTypes } from '../buttons';
import { tap } from 'rxjs/operators';
import { hasFormChanged, IqserEventTarget } from '../utils';
import { ConfirmationDialogService } from './confirmation-dialog.service';
const TARGET_NODE = 'mat-dialog-container';
@ -19,16 +19,21 @@ export interface SaveOptions {
@Directive()
export abstract class BaseDialogComponent implements AfterViewInit, OnDestroy {
readonly iconButtonTypes = IconButtonTypes;
form?: UntypedFormGroup;
initialFormValue!: Record<string, string>;
protected readonly _formBuilder = inject(UntypedFormBuilder);
protected readonly _loadingService = inject(LoadingService);
protected readonly _toaster = inject(Toaster);
protected readonly _subscriptions: Subscription = new Subscription();
readonly #confirmationDialogService = inject(ConfirmationDialogService);
readonly #dialog = inject(MatDialog);
readonly #hasErrors = signal(true);
protected readonly _formBuilder = inject(UntypedFormBuilder);
protected readonly _loadingService = inject(LoadingService);
protected readonly _toaster = inject(Toaster);
protected readonly _subscriptions = new Subscription();
readonly iconButtonTypes = IconButtonTypes;
form?: UntypedFormGroup;
initialFormValue!: Record<string, string>;
protected constructor(
protected readonly _dialogRef: MatDialogRef<BaseDialogComponent>,
private readonly _isInEditMode = false,
) {}
get valid(): boolean {
return !this.form || this.form.valid;
@ -42,11 +47,6 @@ export abstract class BaseDialogComponent implements AfterViewInit, OnDestroy {
return !this.valid || !this.changed || this.#hasErrors();
}
protected constructor(
protected readonly _dialogRef: MatDialogRef<BaseDialogComponent>,
private readonly _isInEditMode = false,
) {}
ngAfterViewInit() {
this._subscriptions.add(this._dialogRef.backdropClick().subscribe(() => this.close()));
const valueChanges = this.form?.valueChanges ?? of(null);

View File

@ -1,12 +1,12 @@
import { ChangeDetectionStrategy, Component, HostListener, inject, TemplateRef } from '@angular/core';
import { MAT_DIALOG_DATA, MatDialogModule, MatDialogRef } from '@angular/material/dialog';
import { TranslateModule, TranslateService } from '@ngx-translate/core';
import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
import { CircleButtonComponent, IconButtonComponent, IconButtonTypes } from '../../buttons';
import { NgForOf, NgIf, NgTemplateOutlet } from '@angular/common';
import { MatIconModule } from '@angular/material/icon';
import { ChangeDetectionStrategy, Component, HostListener, inject, TemplateRef } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { MatCheckboxModule } from '@angular/material/checkbox';
import { MAT_DIALOG_DATA, MatDialogModule, MatDialogRef } from '@angular/material/dialog';
import { MatIconModule } from '@angular/material/icon';
import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
import { TranslateModule, TranslateService } from '@ngx-translate/core';
import { CircleButtonComponent, IconButtonComponent, IconButtonTypes } from '../../buttons';
import { ValuesOf } from '../../utils';
export const TitleColors = {
@ -18,6 +18,7 @@ export type TitleColor = ValuesOf<typeof TitleColors>;
export const ConfirmOptions = {
CONFIRM: 1,
// TODO: this should be renamed to CONFIRM_WITH_ACTION
SECOND_CONFIRM: 2,
DISCARD_CHANGES: 3,
} as const;

View File

@ -1,29 +1,29 @@
import { HttpErrorResponse, HttpStatusCode } from '@angular/common/http';
import { inject, Injectable } from '@angular/core';
import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
import { KeycloakService } from 'keycloak-angular';
import { KeycloakProfile } from 'keycloak-js';
import { BehaviorSubject, firstValueFrom, Observable, throwError } from 'rxjs';
import { catchError, tap } from 'rxjs/operators';
import { BASE_HREF, List, mapEach } from '../../utils';
import { QueryParam, Toaster } from '../../services';
import { IProfile } from '../../../../../red-domain/src';
import { CacheApiService } from '../../caching';
import { EntitiesService } from '../../listing';
import { IIqserUser } from '../types/user.response';
import { IqserPermissionsService, IqserRolesService } from '../../permissions';
import { QueryParam, Toaster } from '../../services';
import { KeycloakStatusService } from '../../tenants';
import { BASE_HREF, List, mapEach } from '../../utils';
import { IqserUser } from '../iqser-user.model';
import { ICreateUserRequest } from '../types/create-user.request';
import { IResetPasswordRequest } from '../types/reset-password.request';
import { IMyProfileUpdateRequest } from '../types/my-profile-update.request';
import { IProfileUpdateRequest } from '../types/profile-update.request';
import { KeycloakProfile } from 'keycloak-js';
import { IqserUser } from '../iqser-user.model';
import { IqserPermissionsService, IqserRolesService } from '../../permissions';
import { HttpErrorResponse, HttpStatusCode } from '@angular/common/http';
import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
import { KeycloakStatusService } from '../../tenants';
import { IResetPasswordRequest } from '../types/reset-password.request';
import { IIqserUser } from '../types/user.response';
@Injectable()
export abstract class IqserUserService<
Interface extends IIqserUser = IIqserUser,
Class extends IqserUser & Interface = IqserUser & Interface,
> extends EntitiesService<Interface, Class> {
readonly currentUser$: Observable<Class | undefined>;
protected abstract readonly _defaultModelPath: string;
protected abstract readonly _permissionsFilter: (role: string) => boolean;
protected abstract readonly _rolesFilter: (role: string) => boolean;
@ -37,6 +37,7 @@ export abstract class IqserUserService<
protected readonly _rolesService = inject(IqserRolesService, { optional: true });
protected readonly _baseHref = inject(BASE_HREF);
protected readonly _serviceName: string = 'tenant-user-management';
readonly currentUser$: Observable<Class | undefined>;
constructor() {
super();