mirror of
https://github.com/GNS3/gns3-web-ui.git
synced 2025-06-16 22:08:08 +00:00
Improvements for template name dialog
This commit is contained in:
@ -451,20 +451,14 @@ 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) {
|
|
||||||
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, {
|
const dialogRef = this.dialog.open(TemplateNameDialogComponent, {
|
||||||
width: '400px',
|
width: '400px',
|
||||||
height: '250px',
|
height: '250px',
|
||||||
autoFocus: false,
|
autoFocus: false,
|
||||||
disableClose: true
|
disableClose: true,
|
||||||
|
data: {
|
||||||
|
name: this.applianceToInstall.name
|
||||||
|
}
|
||||||
});
|
});
|
||||||
dialogRef.componentInstance.server = this.server;
|
dialogRef.componentInstance.server = this.server;
|
||||||
dialogRef.afterClosed().subscribe((answer: string) => {
|
dialogRef.afterClosed().subscribe((answer: string) => {
|
||||||
@ -481,7 +475,6 @@ export class NewTemplateDialogComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
createIosTemplate(image: Image) {
|
createIosTemplate(image: Image) {
|
||||||
let iosTemplate: IosTemplate = new IosTemplate();
|
let iosTemplate: IosTemplate = new IosTemplate();
|
||||||
@ -507,20 +500,14 @@ 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) {
|
|
||||||
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, {
|
const dialogRef = this.dialog.open(TemplateNameDialogComponent, {
|
||||||
width: '400px',
|
width: '400px',
|
||||||
height: '250px',
|
height: '250px',
|
||||||
autoFocus: false,
|
autoFocus: false,
|
||||||
disableClose: true
|
disableClose: true,
|
||||||
|
data: {
|
||||||
|
name: this.applianceToInstall.name
|
||||||
|
}
|
||||||
});
|
});
|
||||||
dialogRef.componentInstance.server = this.server;
|
dialogRef.componentInstance.server = this.server;
|
||||||
dialogRef.afterClosed().subscribe((answer: string) => {
|
dialogRef.afterClosed().subscribe((answer: string) => {
|
||||||
@ -537,7 +524,6 @@ export class NewTemplateDialogComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
createDockerTemplate() {
|
createDockerTemplate() {
|
||||||
let dockerTemplate: DockerTemplate = new DockerTemplate();
|
let dockerTemplate: DockerTemplate = new DockerTemplate();
|
||||||
@ -552,20 +538,14 @@ 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) {
|
|
||||||
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, {
|
const dialogRef = this.dialog.open(TemplateNameDialogComponent, {
|
||||||
width: '400px',
|
width: '400px',
|
||||||
height: '250px',
|
height: '250px',
|
||||||
autoFocus: false,
|
autoFocus: false,
|
||||||
disableClose: true
|
disableClose: true,
|
||||||
|
data: {
|
||||||
|
name: this.applianceToInstall.name
|
||||||
|
}
|
||||||
});
|
});
|
||||||
dialogRef.componentInstance.server = this.server;
|
dialogRef.componentInstance.server = this.server;
|
||||||
dialogRef.afterClosed().subscribe((answer: string) => {
|
dialogRef.afterClosed().subscribe((answer: string) => {
|
||||||
@ -582,7 +562,6 @@ export class NewTemplateDialogComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
createQemuTemplateFromVersion(version: Version) {
|
createQemuTemplateFromVersion(version: Version) {
|
||||||
if (!this.checkImages(version)) {
|
if (!this.checkImages(version)) {
|
||||||
@ -618,20 +597,15 @@ 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) => {
|
|
||||||
this.templateService.newTemplateCreated.next(template as any as Template);
|
|
||||||
this.toasterService.success('Template added');
|
|
||||||
this.dialogRef.close();
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
const dialogRef = this.dialog.open(TemplateNameDialogComponent, {
|
const dialogRef = this.dialog.open(TemplateNameDialogComponent, {
|
||||||
width: '400px',
|
width: '400px',
|
||||||
height: '250px',
|
height: '250px',
|
||||||
autoFocus: false,
|
autoFocus: false,
|
||||||
disableClose: true
|
disableClose: true,
|
||||||
|
data: {
|
||||||
|
name: this.applianceToInstall.name
|
||||||
|
}
|
||||||
});
|
});
|
||||||
dialogRef.componentInstance.server = this.server;
|
dialogRef.componentInstance.server = this.server;
|
||||||
dialogRef.afterClosed().subscribe((answer: string) => {
|
dialogRef.afterClosed().subscribe((answer: string) => {
|
||||||
@ -649,7 +623,6 @@ export class NewTemplateDialogComponent implements OnInit {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
function compareNames(a: string, b: string, isAsc: boolean) {
|
function compareNames(a: string, b: string, isAsc: boolean) {
|
||||||
a = a.toLowerCase();
|
a = a.toLowerCase();
|
||||||
|
@ -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() {
|
||||||
|
Reference in New Issue
Block a user