File
Metadata
selector |
app-create-component-dialog |
styleUrls |
./create-component-dialog.component.scss |
templateUrl |
./create-component-dialog.component.html |
Index
Properties
|
|
Methods
|
|
Inputs
|
|
Methods
checkImsType
|
checkImsType(returnFromSelect: string)
|
|
Parameters :
Name |
Type |
Optional |
returnFromSelect |
string
|
No
|
Returns : ImsType
|
queryComponent
|
Type : QueryComponent
|
Decorators :
@ViewChild(QueryComponent)
|
|
validationDescription
|
Default value : new FormControl('', CCIMSValidators.contentValidator)
|
|
validationIMS
|
Default value : new FormControl('', [CCIMSValidators.urlValidator, Validators.required])
|
|
validationName
|
Default value : new FormControl('', [CCIMSValidators.nameFormatValidator, Validators.required])
|
|
validationProvider
|
Default value : new FormControl('', Validators.required)
|
|
validationUrl
|
Default value : new FormControl('', [CCIMSValidators.urlValidator, Validators.required])
|
|
import {Component, Inject, Input, ViewChild} from '@angular/core';
import {MAT_DIALOG_DATA, MatDialogRef} from '@angular/material/dialog';
import {FormBuilder, FormControl, Validators} from '@angular/forms';
import {CreateComponentInput, ImsType} from 'src/generated/graphql';
import {IssueGraphStateService} from '@app/data/issue-graph/issue-graph-state.service';
import {ComponentStoreService} from '@app/data/component/component-store.service';
import {CCIMSValidators} from '@app/utils/validators';
import {QueryComponent} from '@app/utils/query-component/query.component';
@Component({
selector: 'app-create-component-dialog',
templateUrl: './create-component-dialog.component.html',
styleUrls: ['./create-component-dialog.component.scss']
})
export class CreateComponentDialogComponent {
@Input() projectId: string;
@ViewChild(QueryComponent) queryComponent: QueryComponent;
constructor(
public dialogRef: MatDialogRef<CreateComponentDialogComponent>,
@Inject(MAT_DIALOG_DATA) public data: CreateComponentData,
private fb: FormBuilder,
private gs: IssueGraphStateService,
private componentStore: ComponentStoreService
) {}
// define validations
validationName = new FormControl('', [CCIMSValidators.nameFormatValidator, Validators.required]);
validationUrl = new FormControl('', [CCIMSValidators.urlValidator, Validators.required]);
validationIMS = new FormControl('', [CCIMSValidators.urlValidator, Validators.required]);
validationProvider = new FormControl('', Validators.required);
validationDescription = new FormControl('', CCIMSValidators.contentValidator);
// close dialog on cancel
onNoClick(): void {
this.dialogRef.close();
}
// callback method for component creation
onOkClick(name: string, url: string, description: string): void {
// define the input for the database mutation - required fields are specified by the graphQL schema
// TODO: Add component to IMS?
const input: CreateComponentInput = {
name,
projects: [this.data.projectId],
description,
repositoryURL: url
};
this.queryComponent.listenTo(this.componentStore.createComponent(input), () => this.dialogRef.close());
}
checkImsType(returnFromSelect: string): ImsType {
if (returnFromSelect.localeCompare(ImsType.Github) === 0) {
return ImsType.Github;
}
}
}
interface CreateComponentData {
projectId: string;
}
<div class="dialog-wrapper">
<h1 mat-dialog-title>Create Component</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 component name</mat-error>
</mat-form-field>
<mat-form-field class="stretch" appearance="outline">
<mat-label>Repository-URL</mat-label>
<input #url required matInput [formControl]="validationUrl" />
<mat-error *ngIf="validationUrl.invalid">Enter a valid URL</mat-error>
</mat-form-field>
<mat-form-field appearance="outline">
<mat-label>Provider Type (IMS)</mat-label>
<mat-select #provider [formControl]="validationProvider" required>
<mat-option value="GITHUB">GitHub</mat-option>
</mat-select>
<mat-error *ngIf="validationProvider.invalid">Select the Provider</mat-error>
</mat-form-field>
<mat-form-field class="stretch" appearance="outline">
<mat-label>IMS-URL</mat-label>
<input #ims required matInput [formControl]="validationIMS" />
<mat-error *ngIf="validationIMS.invalid">Enter a valid URL</mat-error>
</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>
</form>
</div>
<div mat-dialog-actions class="actions" style="justify-content: flex-end">
<button mat-raised-button color="warn" (click)="onNoClick()">Cancel</button>
<app-query-component errorMessage="Failed to create component!">
<button
appQueryButton
mat-raised-button
color="success"
[disabled]="
validationName.invalid ||
validationUrl.invalid ||
validationIMS.invalid ||
validationProvider.invalid
"
(click)="
onOkClick(
name.value,
url.value,
description.value
)
"
>
Create
</button>
</app-query-component>
</div>
</div>
@import "src/styles/dialog";
.dialog-wrapper {
max-width: 600px;
}
Legend
Html element with directive