File

src/app/shared/components/dialogs/edit-audit-dialog/edit-audit-dialog.component.ts

Implements

OnInit AfterViewInit

Metadata

selector app-edit-audit-dialog
styleUrls ./edit-audit-dialog.component.scss
templateUrl ./edit-audit-dialog.component.html

Index

Properties
Methods

Constructor

constructor(dialogService: NbDialogService, store: Store, location: Location)
Parameters :
Name Type Optional
dialogService NbDialogService No
store Store No
location Location No

Methods

ngAfterViewInit
ngAfterViewInit()
Returns : void
ngOnInit
ngOnInit()
Returns : void
onCancel
onCancel()
Returns : void
onSubmit
onSubmit(audit: Audit)
Parameters :
Name Type Optional
audit Audit No
Returns : void

Properties

audit$
Type : Observable<Audit>
auditId
Type : number
auditId$
Type : Observable<number>
Decorators :
@Select(AppRouterState.auditId)
contactPersons$
Type : Observable<ContactPerson[]>
Decorators :
@Select(ContactPersonState.contactPersons)
dialog
Type : TemplateRef<any>
Decorators :
@ViewChild('dialog')
dialogRef
Type : NbDialogRef<any>
import { Component, OnInit, TemplateRef, ViewChild, AfterViewInit } from '@angular/core';
import { NbDialogRef, NbDialogService } from '@nebular/theme';
import { Store, Select } from '@ngxs/store';
import { Observable } from 'rxjs';
import { Location } from '@angular/common';
import { defaultDialogOptions } from '../default-dialog-options';
import { Audit } from 'src/app/core/data/models/audit.model';
import { AuditState } from 'src/app/core/ngxs/audit.state';
import { UpdateAudit } from 'src/app/core/ngxs/actions/audit.actions';
import { ContactPerson } from 'src/app/core/data/models/contact-person.model';
import { ContactPersonState } from 'src/app/core/ngxs/contact-person.state';
import { AppRouterState } from 'src/app/core/ngxs/app-router.state';

@Component({
  selector: 'app-edit-audit-dialog',
  templateUrl: './edit-audit-dialog.component.html',
  styleUrls: ['./edit-audit-dialog.component.scss'],
})
export class EditAuditDialogComponent implements OnInit, AfterViewInit {
  @ViewChild('dialog') dialog: TemplateRef<any>;
  @Select(ContactPersonState.contactPersons) contactPersons$: Observable<ContactPerson[]>;
  @Select(AppRouterState.auditId) auditId$: Observable<number>;

  dialogRef: NbDialogRef<any>;
  audit$: Observable<Audit>;
  auditId: number;

  constructor(
    private dialogService: NbDialogService,
    private store: Store,
    private location: Location,
  ) {}

  ngOnInit(): void {
    this.auditId$.subscribe(id => {
      this.auditId = id;
      this.audit$ = this.store.select(AuditState.audit(id));
    });
  }

  ngAfterViewInit() {
    this.dialogRef = this.dialogService.open(this.dialog, defaultDialogOptions);

    this.dialogRef.onClose.subscribe(() => {
      this.location.back();
    });

    this.audit$.subscribe(audit => audit ?? this.dialogRef.close());
  }

  onSubmit(audit: Audit) {
    this.store
      .dispatch(new UpdateAudit(this.auditId, audit))
      .subscribe(() => this.dialogRef.close());
  }

  onCancel() {
    this.dialogRef.close();
  }
}
<ng-template #dialog let-data let-ref="dialogRef">
  <div class="scrollable-container">
    <app-audit-form (cancelled)="onCancel()" (formSubmitted)="onSubmit($event)" [audit]="audit$ | async" [submitButtonName]="'speichern'" cancelButtonName="abbrechen"> </app-audit-form>
  </div>
</ng-template>

./edit-audit-dialog.component.scss

.scrollable-container {
  overflow-y: auto !important;
  max-width: 95vw;
  max-height: 95vh;
}
Legend
Html element
Component
Html element with directive

result-matching ""

    No results matching ""