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.template_type = 'iou';
if (this.templates.filter(t => t.name === this.applianceToInstall.name).length === 0) {
iouTemplate.name = this.applianceToInstall.name;
this.iouService.addTemplate(this.server, iouTemplate).subscribe((template) => {
this.templateService.newTemplateCreated.next(template);
this.toasterService.success('Template added');
this.dialogRef.close();
});
} else {
const dialogRef = this.dialog.open(TemplateNameDialogComponent, {
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;
}
});
}
const dialogRef = this.dialog.open(TemplateNameDialogComponent, {
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.templateService.newTemplateCreated.next(template);
this.toasterService.success('Template added');
this.dialogRef.close();
});
} else{
return false;
}
});
}
createIosTemplate(image: Image) {
@ -507,36 +500,29 @@ export class NewTemplateDialogComponent implements OnInit {
iosTemplate.image = image.filename;
iosTemplate.template_type = 'dynamips';
if (this.templates.filter(t => t.name === this.applianceToInstall.name).length === 0) {
iosTemplate.name = this.applianceToInstall.name;
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 {
const dialogRef = this.dialog.open(TemplateNameDialogComponent, {
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;
}
});
}
const dialogRef = this.dialog.open(TemplateNameDialogComponent, {
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.templateService.newTemplateCreated.next(template as any as Template);
this.toasterService.success('Template added');
this.dialogRef.close();
});
} else{
return false;
}
});
}
createDockerTemplate() {
@ -552,36 +538,29 @@ export class NewTemplateDialogComponent implements OnInit {
dockerTemplate.image = this.applianceToInstall.docker.image;
dockerTemplate.template_type = 'docker';
if (this.templates.filter(t => t.name === this.applianceToInstall.name).length === 0) {
dockerTemplate.name = this.applianceToInstall.name;
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 {
const dialogRef = this.dialog.open(TemplateNameDialogComponent, {
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;
}
});
}
const dialogRef = this.dialog.open(TemplateNameDialogComponent, {
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.templateService.newTemplateCreated.next(template as any as Template);
this.toasterService.success('Template added');
this.dialogRef.close();
});
} else{
return false;
}
});
}
createQemuTemplateFromVersion(version: Version) {
@ -618,36 +597,30 @@ export class NewTemplateDialogComponent implements OnInit {
qemuTemplate.template_type = 'qemu';
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) => {
this.templateService.newTemplateCreated.next(template as any as Template);
this.toasterService.success('Template added');
this.dialogRef.close();
});
} else {
const dialogRef = this.dialog.open(TemplateNameDialogComponent, {
width: '400px',
height: '250px',
autoFocus: false,
disableClose: true
});
dialogRef.componentInstance.server = this.server;
dialogRef.afterClosed().subscribe((answer: string) => {
if (answer) {
qemuTemplate.name = answer;
this.qemuService.addTemplate(this.server, qemuTemplate).subscribe((template) => {
this.templateService.newTemplateCreated.next(template as any as Template);
this.toasterService.success('Template added');
this.dialogRef.close();
});
} else{
return false;
}
});
}
const dialogRef = this.dialog.open(TemplateNameDialogComponent, {
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) {
qemuTemplate.name = answer;
this.qemuService.addTemplate(this.server, qemuTemplate).subscribe((template) => {
this.templateService.newTemplateCreated.next(template as any as Template);
this.toasterService.success('Template added');
this.dialogRef.close();
});
} else{
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 { 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 { Server } from '../../../../models/server';
import { v4 as uuid } from 'uuid';
@ -28,13 +28,19 @@ export class TemplateNameDialogComponent implements OnInit {
private toasterService: ToasterService,
private formBuilder: FormBuilder,
private templateNameValidator: ProjectNameValidator,
private templateService: TemplateService
private templateService: TemplateService,
@Inject(MAT_DIALOG_DATA) public data: any
) {}
ngOnInit() {
let name = this.data['name'];
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() {