Improvements for template name dialog

This commit is contained in:
piotrpekala7
2020-09-09 23:43:54 +02:00
parent cf725931f9
commit dd7dcf4dab
2 changed files with 103 additions and 124 deletions

View File

@ -451,36 +451,29 @@ export class NewTemplateDialogComponent implements OnInit {
iouTemplate.path = image.filename; iouTemplate.path = image.filename;
iouTemplate.template_type = 'iou'; iouTemplate.template_type = 'iou';
if (this.templates.filter(t => t.name === this.applianceToInstall.name).length === 0) { const dialogRef = this.dialog.open(TemplateNameDialogComponent, {
iouTemplate.name = this.applianceToInstall.name; width: '400px',
height: '250px',
autoFocus: false,
disableClose: true,
data: {
name: this.applianceToInstall.name
}
});
dialogRef.componentInstance.server = this.server;
dialogRef.afterClosed().subscribe((answer: string) => {
if (answer) {
iouTemplate.name = answer;
this.iouService.addTemplate(this.server, iouTemplate).subscribe((template) => { this.iouService.addTemplate(this.server, iouTemplate).subscribe((template) => {
this.templateService.newTemplateCreated.next(template); this.templateService.newTemplateCreated.next(template);
this.toasterService.success('Template added'); this.toasterService.success('Template added');
this.dialogRef.close(); this.dialogRef.close();
}); });
} else { } else{
const dialogRef = this.dialog.open(TemplateNameDialogComponent, { return false;
width: '400px', }
height: '250px', });
autoFocus: false,
disableClose: true
});
dialogRef.componentInstance.server = this.server;
dialogRef.afterClosed().subscribe((answer: string) => {
if (answer) {
iouTemplate.name = answer;
this.iouService.addTemplate(this.server, iouTemplate).subscribe((template) => {
this.templateService.newTemplateCreated.next(template);
this.toasterService.success('Template added');
this.dialogRef.close();
});
} else{
return false;
}
});
}
} }
createIosTemplate(image: Image) { createIosTemplate(image: Image) {
@ -507,36 +500,29 @@ export class NewTemplateDialogComponent implements OnInit {
iosTemplate.image = image.filename; iosTemplate.image = image.filename;
iosTemplate.template_type = 'dynamips'; iosTemplate.template_type = 'dynamips';
if (this.templates.filter(t => t.name === this.applianceToInstall.name).length === 0) { const dialogRef = this.dialog.open(TemplateNameDialogComponent, {
iosTemplate.name = this.applianceToInstall.name; width: '400px',
height: '250px',
autoFocus: false,
disableClose: true,
data: {
name: this.applianceToInstall.name
}
});
dialogRef.componentInstance.server = this.server;
dialogRef.afterClosed().subscribe((answer: string) => {
if (answer) {
iosTemplate.name = answer;
this.iosService.addTemplate(this.server, iosTemplate).subscribe((template) => { this.iosService.addTemplate(this.server, iosTemplate).subscribe((template) => {
this.templateService.newTemplateCreated.next(template as any as Template); this.templateService.newTemplateCreated.next(template as any as Template);
this.toasterService.success('Template added'); this.toasterService.success('Template added');
this.dialogRef.close(); this.dialogRef.close();
}); });
} else { } else{
const dialogRef = this.dialog.open(TemplateNameDialogComponent, { return false;
width: '400px', }
height: '250px', });
autoFocus: false,
disableClose: true
});
dialogRef.componentInstance.server = this.server;
dialogRef.afterClosed().subscribe((answer: string) => {
if (answer) {
iosTemplate.name = answer;
this.iosService.addTemplate(this.server, iosTemplate).subscribe((template) => {
this.templateService.newTemplateCreated.next(template as any as Template);
this.toasterService.success('Template added');
this.dialogRef.close();
});
} else{
return false;
}
});
}
} }
createDockerTemplate() { createDockerTemplate() {
@ -552,36 +538,29 @@ export class NewTemplateDialogComponent implements OnInit {
dockerTemplate.image = this.applianceToInstall.docker.image; dockerTemplate.image = this.applianceToInstall.docker.image;
dockerTemplate.template_type = 'docker'; dockerTemplate.template_type = 'docker';
if (this.templates.filter(t => t.name === this.applianceToInstall.name).length === 0) { const dialogRef = this.dialog.open(TemplateNameDialogComponent, {
dockerTemplate.name = this.applianceToInstall.name; width: '400px',
height: '250px',
autoFocus: false,
disableClose: true,
data: {
name: this.applianceToInstall.name
}
});
dialogRef.componentInstance.server = this.server;
dialogRef.afterClosed().subscribe((answer: string) => {
if (answer) {
dockerTemplate.name = answer;
this.dockerService.addTemplate(this.server, dockerTemplate).subscribe((template) => { this.dockerService.addTemplate(this.server, dockerTemplate).subscribe((template) => {
this.templateService.newTemplateCreated.next(template as any as Template); this.templateService.newTemplateCreated.next(template as any as Template);
this.toasterService.success('Template added'); this.toasterService.success('Template added');
this.dialogRef.close(); this.dialogRef.close();
}); });
} else { } else{
const dialogRef = this.dialog.open(TemplateNameDialogComponent, { return false;
width: '400px', }
height: '250px', });
autoFocus: false,
disableClose: true
});
dialogRef.componentInstance.server = this.server;
dialogRef.afterClosed().subscribe((answer: string) => {
if (answer) {
dockerTemplate.name = answer;
this.dockerService.addTemplate(this.server, dockerTemplate).subscribe((template) => {
this.templateService.newTemplateCreated.next(template as any as Template);
this.toasterService.success('Template added');
this.dialogRef.close();
});
} else{
return false;
}
});
}
} }
createQemuTemplateFromVersion(version: Version) { createQemuTemplateFromVersion(version: Version) {
@ -618,36 +597,30 @@ export class NewTemplateDialogComponent implements OnInit {
qemuTemplate.template_type = 'qemu'; qemuTemplate.template_type = 'qemu';
qemuTemplate.usage = this.applianceToInstall.usage; qemuTemplate.usage = this.applianceToInstall.usage;
if (this.templates.filter(t => t.name === this.applianceToInstall.name).length === 0) {
qemuTemplate.name = this.applianceToInstall.name;
this.qemuService.addTemplate(this.server, qemuTemplate).subscribe((template) => { const dialogRef = this.dialog.open(TemplateNameDialogComponent, {
this.templateService.newTemplateCreated.next(template as any as Template); width: '400px',
this.toasterService.success('Template added'); height: '250px',
this.dialogRef.close(); autoFocus: false,
}); disableClose: true,
} else { data: {
const dialogRef = this.dialog.open(TemplateNameDialogComponent, { name: this.applianceToInstall.name
width: '400px', }
height: '250px', });
autoFocus: false, dialogRef.componentInstance.server = this.server;
disableClose: true dialogRef.afterClosed().subscribe((answer: string) => {
}); if (answer) {
dialogRef.componentInstance.server = this.server; qemuTemplate.name = answer;
dialogRef.afterClosed().subscribe((answer: string) => {
if (answer) {
qemuTemplate.name = answer;
this.qemuService.addTemplate(this.server, qemuTemplate).subscribe((template) => { this.qemuService.addTemplate(this.server, qemuTemplate).subscribe((template) => {
this.templateService.newTemplateCreated.next(template as any as Template); this.templateService.newTemplateCreated.next(template as any as Template);
this.toasterService.success('Template added'); this.toasterService.success('Template added');
this.dialogRef.close(); this.dialogRef.close();
}); });
} else{ } else{
return false; return false;
} }
}); });
}
} }
} }

View File

@ -1,6 +1,6 @@
import { Component, OnInit, EventEmitter } from '@angular/core'; import { Component, OnInit, EventEmitter, Inject } from '@angular/core';
import { Router } from '@angular/router'; import { Router } from '@angular/router';
import { MatDialog, MatDialogRef } from '@angular/material/dialog'; import { MatDialog, MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
import { FormBuilder, FormGroup, Validators, FormControl } from '@angular/forms'; import { FormBuilder, FormGroup, Validators, FormControl } from '@angular/forms';
import { Server } from '../../../../models/server'; import { Server } from '../../../../models/server';
import { v4 as uuid } from 'uuid'; import { v4 as uuid } from 'uuid';
@ -28,13 +28,19 @@ export class TemplateNameDialogComponent implements OnInit {
private toasterService: ToasterService, private toasterService: ToasterService,
private formBuilder: FormBuilder, private formBuilder: FormBuilder,
private templateNameValidator: ProjectNameValidator, private templateNameValidator: ProjectNameValidator,
private templateService: TemplateService private templateService: TemplateService,
@Inject(MAT_DIALOG_DATA) public data: any
) {} ) {}
ngOnInit() { ngOnInit() {
let name = this.data['name'];
this.templateNameForm = this.formBuilder.group({ this.templateNameForm = this.formBuilder.group({
templateName: new FormControl(null, [Validators.required, this.templateNameValidator.get], [templateNameAsyncValidator(this.server, this.templateService)]) templateName: new FormControl(name, [Validators.required, this.templateNameValidator.get], [templateNameAsyncValidator(this.server, this.templateService)])
}); });
setTimeout(() => {
this.templateNameForm.controls['templateName'].markAsTouched();
}, 100);
} }
get form() { get form() {