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,20 +451,14 @@ 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
disableClose: true,
data: {
name: this.applianceToInstall.name
}
});
dialogRef.componentInstance.server = this.server;
dialogRef.afterClosed().subscribe((answer: string) => {
@ -481,7 +475,6 @@ export class NewTemplateDialogComponent implements OnInit {
}
});
}
}
createIosTemplate(image: Image) {
let iosTemplate: IosTemplate = new IosTemplate();
@ -507,20 +500,14 @@ 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
disableClose: true,
data: {
name: this.applianceToInstall.name
}
});
dialogRef.componentInstance.server = this.server;
dialogRef.afterClosed().subscribe((answer: string) => {
@ -537,7 +524,6 @@ export class NewTemplateDialogComponent implements OnInit {
}
});
}
}
createDockerTemplate() {
let dockerTemplate: DockerTemplate = new DockerTemplate();
@ -552,20 +538,14 @@ 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
disableClose: true,
data: {
name: this.applianceToInstall.name
}
});
dialogRef.componentInstance.server = this.server;
dialogRef.afterClosed().subscribe((answer: string) => {
@ -582,7 +562,6 @@ export class NewTemplateDialogComponent implements OnInit {
}
});
}
}
createQemuTemplateFromVersion(version: Version) {
if (!this.checkImages(version)) {
@ -618,20 +597,15 @@ 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
disableClose: true,
data: {
name: this.applianceToInstall.name
}
});
dialogRef.componentInstance.server = this.server;
dialogRef.afterClosed().subscribe((answer: string) => {
@ -648,7 +622,6 @@ export class NewTemplateDialogComponent implements OnInit {
}
});
}
}
}
function compareNames(a: string, b: string, isAsc: boolean) {

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() {