File
Description
This component provides a dialog for the project creation
The user can set a name and description
Metadata
selector |
app-create-project-dialog |
styleUrls |
./create-project-dialog.component.scss |
templateUrl |
./create-project-dialog.component.html |
Index
Properties
|
|
Methods
|
|
Inputs
|
|
Methods
afterAlertClose
|
afterAlertClose()
|
|
|
descriptionValidator
|
Default value : new FormControl('', CCIMSValidators.contentValidator)
|
|
nameValidator
|
Default value : new FormControl('', [CCIMSValidators.nameFormatValidator, Validators.required])
|
|
import {Component, Input} from '@angular/core';
import {MatDialogRef} from '@angular/material/dialog';
import {FormBuilder, FormControl, Validators} from '@angular/forms';
import {ProjectStoreService} from '@app/data/project/project-store.service';
import {UserNotifyService} from '@app/user-notify/user-notify.service';
import {CCIMSValidators} from '@app/utils/validators';
/**
* This component provides a dialog for the project creation
* The user can set a name and description
*
*/
@Component({
selector: 'app-create-project-dialog',
templateUrl: './create-project-dialog.component.html',
styleUrls: ['./create-project-dialog.component.scss']
})
export class CreateProjectDialogComponent {
@Input() name: string;
@Input() description: string;
public loading: boolean;
public saveFailed: boolean;
constructor(
public dialogRef: MatDialogRef<CreateProjectDialogComponent>,
private ps: ProjectStoreService,
private fb: FormBuilder,
private notify: UserNotifyService
) {
this.loading = false;
}
nameValidator = new FormControl('', [CCIMSValidators.nameFormatValidator, Validators.required]);
descriptionValidator = new FormControl('', CCIMSValidators.contentValidator);
onNoClick(): void {
this.dialogRef.close();
}
afterAlertClose(): void {
this.saveFailed = false;
}
// after the user clicked on the create button the project creation mutation is fired
onOkClick(name: string, description: string): void {
this.loading = true;
this.ps.create(name, description).subscribe(
({data}) => {
this.loading = false;
this.dialogRef.close({
createdProjectId: data.createProject.project.id
});
},
(error) => {
this.notify.notifyError('Failed to create project!', error);
this.loading = false;
this.saveFailed = true;
}
);
}
}
<!--Create Project dialog-->
<h1 mat-dialog-title>Create Project</h1>
<!--Contents-->
<div mat-dialog-content>
<form>
<!--Project Name input field-->
<mat-form-field class="stretch" appearance="outline">
<mat-label>Name</mat-label>
<input #name required matInput [formControl]="nameValidator" />
<mat-error *ngIf="nameValidator.invalid"> Invalid project name </mat-error>
</mat-form-field>
<!--Project Description input field-->
<mat-form-field class="stretch" appearance="outline">
<mat-label>Description</mat-label>
<textarea style="height: 200px" #description matInput [formControl]="descriptionValidator"></textarea>
<mat-error *ngIf="nameValidator.invalid">Invalid project description</mat-error>
</mat-form-field>
<!--Save Failed error message-->
<nz-alert
*ngIf="this.saveFailed"
class="error-message"
nzType="error"
nzMessage="Something went wrong"
nzShowIcon
nzCloseable
(nzOnClose)="afterAlertClose()"
></nz-alert>
</form>
</div>
<!--Actions-->
<div mat-dialog-actions class="actions" style="justify-content: flex-end">
<!--Cancel button-->
<button mat-raised-button color="warn" (click)="onNoClick()">Cancel</button>
<!--Create button-->
<button
mat-raised-button
color="success"
[class.spinner]="loading"
[disabled]="
loading || nameValidator.invalid || descriptionValidator.invalid
"
(click)="onOkClick(name.value, description.value)"
>
Create
</button>
</div>
@import "src/styles/dialog";
Legend
Html element with directive