mirror of
https://github.com/GNS3/gns3-web-ui.git
synced 2025-02-01 08:48:04 +00:00
Server type in template preferences
This commit is contained in:
parent
c684577c57
commit
7a5437c29e
@ -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;
|
||||
@ -30,6 +31,10 @@ export class AddDockerTemplateComponent implements OnInit {
|
||||
containerNameForm: FormGroup;
|
||||
networkAdaptersForm: FormGroup;
|
||||
|
||||
isGns3VmAvailable: boolean = false;
|
||||
isGns3VmChosen: boolean = false;
|
||||
isLocalComputerChosen: boolean = true;
|
||||
|
||||
constructor(
|
||||
private route: ActivatedRoute,
|
||||
private serverService: ServerService,
|
||||
@ -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();
|
||||
|
@ -6,6 +6,11 @@
|
||||
</div>
|
||||
<div class="default-content">
|
||||
<mat-card class="matCard">
|
||||
<mat-radio-group class="radio-group">
|
||||
<mat-radio-button class="radio-button" value="1" (click)="setServerType('local')" checked>Run the VPCS node on your local computer</mat-radio-button>
|
||||
<mat-radio-button [disabled]="!isGns3VmAvailable" class="radio-button" value="2" (click)="setServerType('gns3 vm')">Run the VPCS node on the GNS3 VM</mat-radio-button>
|
||||
</mat-radio-group>
|
||||
|
||||
<form [formGroup]="templateNameForm">
|
||||
<mat-form-field class="form-field">
|
||||
<input matInput formControlName="templateName" type="text" placeholder="Template name">
|
||||
|
@ -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({
|
||||
@ -20,6 +22,10 @@ export class AddVpcsTemplateComponent implements OnInit {
|
||||
templateName: string = '';
|
||||
templateNameForm: FormGroup
|
||||
|
||||
isGns3VmAvailable: boolean = false;
|
||||
isGns3VmChosen: boolean = false;
|
||||
isLocalComputerChosen: boolean = true;
|
||||
|
||||
constructor(
|
||||
private route: ActivatedRoute,
|
||||
private serverService: ServerService,
|
||||
@ -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,7 +45,21 @@ 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() {
|
||||
@ -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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user