File

src/app/dialogs/create-interface-dialog/create-interface-dialog.component.ts

Metadata

selector app-create-interface-dialog
styleUrls ./create-interface-dialog.component.scss
templateUrl ./create-interface-dialog.component.html

Index

Properties
Methods
Inputs

Constructor

constructor(dialogRef: MatDialogRef<CreateInterfaceDialogComponent>, data: CreateInterfaceData, fb: FormBuilder, gs: IssueGraphStateService, authService: AuthenticationService, interfaceStore: InterfaceStoreService, notify: UserNotifyService)
Parameters :
Name Type Optional
dialogRef MatDialogRef<CreateInterfaceDialogComponent> No
data CreateInterfaceData No
fb FormBuilder No
gs IssueGraphStateService No
authService AuthenticationService No
interfaceStore InterfaceStoreService No
notify UserNotifyService No

Inputs

projectId
Type : string

Methods

afterAlertClose
afterAlertClose()
Returns : void
onNoClick
onNoClick()
Returns : void
onOkClick
onOkClick(name: string, description: string)
Parameters :
Name Type Optional
name string No
description string No
Returns : void

Properties

Public data
Type : CreateInterfaceData
Decorators :
@Inject(MAT_DIALOG_DATA)
Public dialogRef
Type : MatDialogRef<CreateInterfaceDialogComponent>
Public loading
Type : boolean
Public saveFailed
Type : boolean
validationDescription
Default value : new FormControl('', CCIMSValidators.contentValidator)
validationName
Default value : new FormControl('', [CCIMSValidators.nameFormatValidator, Validators.required])
import {Component, Inject, Input} from '@angular/core';
import {FormBuilder, FormControl, Validators} from '@angular/forms';
import {MAT_DIALOG_DATA, MatDialogRef} from '@angular/material/dialog';
import {AuthenticationService} from '@app/auth/authentication.service';
import {IssueGraphStateService} from '@app/data/issue-graph/issue-graph-state.service';
import {InterfaceStoreService} from '@app/data/interface/interface-store.service';
import {UserNotifyService} from '@app/user-notify/user-notify.service';
import {CCIMSValidators} from '@app/utils/validators';

@Component({
  selector: 'app-create-interface-dialog',
  templateUrl: './create-interface-dialog.component.html',
  styleUrls: ['./create-interface-dialog.component.scss']
})
export class CreateInterfaceDialogComponent {
  @Input()
  projectId: string;

  public loading: boolean;
  public saveFailed: boolean;
  validationName = new FormControl('', [CCIMSValidators.nameFormatValidator, Validators.required]);
  validationDescription = new FormControl('', CCIMSValidators.contentValidator);

  constructor(
    public dialogRef: MatDialogRef<CreateInterfaceDialogComponent>,
    @Inject(MAT_DIALOG_DATA) public data: CreateInterfaceData,
    private fb: FormBuilder,
    private gs: IssueGraphStateService,
    private authService: AuthenticationService,
    private interfaceStore: InterfaceStoreService,
    private notify: UserNotifyService
  ) {
    this.loading = false;
  }

  onNoClick(): void {
    this.dialogRef.close();
  }

  onOkClick(name: string, description: string): void {
    this.loading = true;

    // db mutation to create an interface
    this.interfaceStore.create(name, this.data.offeredById, description).subscribe(
      ({data}) => {
        this.loading = false;

        // close dialog and return the interface id of the created dialog
        this.dialogRef.close(data.createComponentInterface.componentInterface.id);
      },
      (error) => {
        this.notify.notifyError('Failed to create interface!', error);
        this.loading = false;
        this.saveFailed = true;
      }
    );
  }

  afterAlertClose(): void {
    this.saveFailed = false;
  }
}

export interface CreateInterfaceData {
  position: {x: number; y: number};
  offeredById: string;
}
<div class="dialog-wrapper">
  <h1 mat-dialog-title>Create Interface</h1>
  <div mat-dialog-content>
    <form>
      <mat-form-field class="stretch" appearance="outline">
        <mat-label>Name</mat-label>
        <input #name required matInput [formControl]="validationName" />
        <mat-error *ngIf="validationName.invalid">Invalid interface name</mat-error>
      </mat-form-field>

      <mat-form-field class="stretch" appearance="outline">
        <mat-label>Interface-Type</mat-label>
        <input #type matInput />
      </mat-form-field>

      <mat-form-field class="stretch" appearance="outline">
        <mat-label>Description</mat-label>
        <textarea style="height: 66px" #description matInput [formControl]="validationDescription"></textarea>
      </mat-form-field>

      <nz-alert
        *ngIf="this.saveFailed"
        class="error-message"
        nzType="error"
        nzMessage="Something went wrong"
        nzShowIcon
        nzCloseable
        (nzOnClose)="this.afterAlertClose()"
      ></nz-alert>
    </form>
  </div>
  <div mat-dialog-actions style="justify-content: flex-end">
    <button mat-raised-button color="warn" (click)="onNoClick()">Cancel</button>
    <button
      mat-raised-button
      color="success"
      [class.spinner]="loading"
      [disabled]="loading || validationName.invalid"
      (click)="onOkClick(name.value, description.value)"
    >
      Create
    </button>
  </div>
</div>

./create-interface-dialog.component.scss

@import "src/styles/dialog";

.dialog-wrapper {
  max-width: 600px;
}
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""