File
Metadata
selector |
app-create-interface-dialog |
styleUrls |
./create-interface-dialog.component.scss |
templateUrl |
./create-interface-dialog.component.html |
Index
Properties
|
|
Methods
|
|
Inputs
|
|
Methods
afterAlertClose
|
afterAlertClose()
|
|
|
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>
@import "src/styles/dialog";
.dialog-wrapper {
max-width: 600px;
}
Legend
Html element with directive