From 7a5437c29e73b80a1abcbef8611ec9bcd05bbdca Mon Sep 17 00:00:00 2001 From: piotrpekala7 <31202938+piotrpekala7@users.noreply.github.com> Date: Fri, 8 May 2020 17:02:13 +0200 Subject: [PATCH] Server type in template preferences --- .../add-docker-template.component.ts | 21 ++++++++++++---- .../add-vpcs-template.component.html | 5 ++++ .../add-vpcs-template.component.ts | 24 ++++++++++++++++++- 3 files changed, 45 insertions(+), 5 deletions(-) diff --git a/src/app/components/preferences/docker/add-docker-template/add-docker-template.component.ts b/src/app/components/preferences/docker/add-docker-template/add-docker-template.component.ts index 5d5827a6..16e3721c 100644 --- a/src/app/components/preferences/docker/add-docker-template/add-docker-template.component.ts +++ b/src/app/components/preferences/docker/add-docker-template/add-docker-template.component.ts @@ -10,6 +10,8 @@ import { DockerTemplate } from '../../../../models/templates/docker-template'; import { DockerService } from '../../../../services/docker.service'; import { DockerConfigurationService } from '../../../../services/docker-configuration.service'; import { DockerImage } from '../../../../models/docker/docker-image'; +import { ComputeService } from '../../../../services/compute.service'; +import { Compute } from '../../../../models/compute'; @Component({ @@ -21,7 +23,6 @@ export class AddDockerTemplateComponent implements OnInit { server: Server; dockerTemplate: DockerTemplate; consoleTypes: string[] = []; - isGns3VmChosen: boolean = false; isRemoteComputerChosen: boolean = false; dockerImages: DockerImage[] = []; newImageSelected: boolean = false; @@ -29,6 +30,10 @@ export class AddDockerTemplateComponent implements OnInit { virtualMachineForm: FormGroup; containerNameForm: FormGroup; networkAdaptersForm: FormGroup; + + isGns3VmAvailable: boolean = false; + isGns3VmChosen: boolean = false; + isLocalComputerChosen: boolean = true; constructor( private route: ActivatedRoute, @@ -38,7 +43,8 @@ export class AddDockerTemplateComponent implements OnInit { private router: Router, private formBuilder: FormBuilder, private templateMocksService: TemplateMocksService, - private configurationService: DockerConfigurationService + private configurationService: DockerConfigurationService, + private computeService: ComputeService ) { this.dockerTemplate = new DockerTemplate(); @@ -65,14 +71,20 @@ export class AddDockerTemplateComponent implements OnInit { this.templateMocksService.getDockerTemplate().subscribe((dockerTemplate: DockerTemplate) => { this.dockerTemplate = dockerTemplate; }) + + this.computeService.getComputes(server).subscribe((computes: Compute[]) => { + if (computes.filter(compute => compute.compute_id === 'vm').length > 0) this.isGns3VmAvailable = true; + }); }); } setServerType(serverType: string) { - if (serverType === 'gns3 vm') { + if (serverType === 'gns3 vm' && this.isGns3VmAvailable) { this.isGns3VmChosen = true; + this.isLocalComputerChosen = false; } else { - this.isRemoteComputerChosen = true; + this.isGns3VmChosen = false; + this.isLocalComputerChosen = true; } } @@ -90,6 +102,7 @@ export class AddDockerTemplateComponent implements OnInit { this.dockerTemplate.image = this.virtualMachineForm.get('filename').value; this.dockerTemplate.name = this.containerNameForm.get('templateName').value; this.dockerTemplate.adapters = this.networkAdaptersForm.get('adapters').value; + this.dockerTemplate.compute_id = this.isGns3VmChosen ? 'vm' : 'local'; this.dockerService.addTemplate(this.server, this.dockerTemplate).subscribe((template: DockerTemplate) => { this.goBack(); diff --git a/src/app/components/preferences/vpcs/add-vpcs-template/add-vpcs-template.component.html b/src/app/components/preferences/vpcs/add-vpcs-template/add-vpcs-template.component.html index d218196a..d9ce36af 100644 --- a/src/app/components/preferences/vpcs/add-vpcs-template/add-vpcs-template.component.html +++ b/src/app/components/preferences/vpcs/add-vpcs-template/add-vpcs-template.component.html @@ -6,6 +6,11 @@
+ + Run the VPCS node on your local computer + Run the VPCS node on the GNS3 VM + +
diff --git a/src/app/components/preferences/vpcs/add-vpcs-template/add-vpcs-template.component.ts b/src/app/components/preferences/vpcs/add-vpcs-template/add-vpcs-template.component.ts index a70ed2ac..3253ad95 100644 --- a/src/app/components/preferences/vpcs/add-vpcs-template/add-vpcs-template.component.ts +++ b/src/app/components/preferences/vpcs/add-vpcs-template/add-vpcs-template.component.ts @@ -8,6 +8,8 @@ import { ToasterService } from '../../../../services/toaster.service'; import { v4 as uuid } from 'uuid'; import { TemplateMocksService } from '../../../../services/template-mocks.service'; import { FormGroup, FormBuilder, FormControl, Validators } from '@angular/forms'; +import { ComputeService } from '../../../../services/compute.service'; +import { Compute } from '../../../../models/compute'; @Component({ @@ -19,6 +21,10 @@ export class AddVpcsTemplateComponent implements OnInit { server: Server; templateName: string = ''; templateNameForm: FormGroup + + isGns3VmAvailable: boolean = false; + isGns3VmChosen: boolean = false; + isLocalComputerChosen: boolean = true; constructor( private route: ActivatedRoute, @@ -27,7 +33,8 @@ export class AddVpcsTemplateComponent implements OnInit { private router: Router, private toasterService: ToasterService, private templateMocksService: TemplateMocksService, - private formBuilder: FormBuilder + private formBuilder: FormBuilder, + private computeService: ComputeService ) { this.templateNameForm = this.formBuilder.group({ templateName: new FormControl(null, [Validators.required]) @@ -38,9 +45,23 @@ export class AddVpcsTemplateComponent implements OnInit { const server_id = this.route.snapshot.paramMap.get("server_id"); this.serverService.get(parseInt(server_id, 10)).then((server: Server) => { this.server = server; + + this.computeService.getComputes(server).subscribe((computes: Compute[]) => { + if (computes.filter(compute => compute.compute_id === 'vm').length > 0) this.isGns3VmAvailable = true; + }); }); } + setServerType(serverType: string) { + if (serverType === 'gns3 vm' && this.isGns3VmAvailable) { + this.isGns3VmChosen = true; + this.isLocalComputerChosen = false; + } else { + this.isGns3VmChosen = false; + this.isLocalComputerChosen = true; + } + } + goBack() { this.router.navigate(['/server', this.server.id, 'preferences', 'vpcs', 'templates']); } @@ -57,6 +78,7 @@ export class AddVpcsTemplateComponent implements OnInit { vpcsTemplate.template_id = uuid(), vpcsTemplate.name = this.templateName, + vpcsTemplate.compute_id = this.isGns3VmChosen ? 'vm' : 'local'; this.vpcsService.addTemplate(this.server, vpcsTemplate).subscribe(() => { this.goBack();