Merge pull request #708 from GNS3/Changes-with-add-node-dialog

Updating add node dialog
This commit is contained in:
piotrpekala7 2020-02-25 15:10:04 +01:00 committed by GitHub
commit 8fc1505a96
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 11 deletions

View File

@ -427,10 +427,10 @@ export class ProjectMapComponent implements OnInit, OnDestroy {
return;
}
this.nodeService.createFromTemplate(this.server, this.project, nodeAddedEvent.template, nodeAddedEvent.x, nodeAddedEvent.y, nodeAddedEvent.server).subscribe((node: Node) => {
if (nodeAddedEvent.name !== nodeAddedEvent.template.name) {
node.name = nodeAddedEvent.name;
this.nodeService.updateNode(this.server, node).subscribe(()=>{});
}
// if (nodeAddedEvent.name !== nodeAddedEvent.template.name) {
// node.name = nodeAddedEvent.name;
// this.nodeService.updateNode(this.server, node).subscribe(()=>{});
// }
this.projectService.nodes(this.server, this.project.project_id).subscribe((nodes: Node[]) => {
nodes.filter((node) => node.label.style === null).forEach((node) => {

View File

@ -39,9 +39,9 @@
<h6>Configuration</h6>
</div>
<form [formGroup]="configurationForm">
<mat-form-field class="form-field">
<!-- <mat-form-field class="form-field">
<input type="text" matInput formControlName="name" placeholder="Enter name (default is taken from template)" />
</mat-form-field>
</mat-form-field> -->
<mat-form-field class="form-field">
<input type="number" matInput formControlName="numberOfNodes" placeholder="Enter number of nodes (default value is 1)" />
</mat-form-field>

View File

@ -41,7 +41,7 @@ export class TemplateListDialogComponent implements OnInit {
this.server = data['server'];
this.project = data['project'];
this.configurationForm = this.formBuilder.group({
name: new FormControl('new node', Validators.required),
// name: new FormControl('new node', Validators.required),
numberOfNodes: new FormControl(1, [Validators.required, nonNegativeValidator.get])
});
this.positionForm = this.formBuilder.group({
@ -70,13 +70,13 @@ export class TemplateListDialogComponent implements OnInit {
chooseTemplate(event) {
this.selectedTemplate = event.value;
this.configurationForm.controls['name'].setValue(this.selectedTemplate.default_name_format);
// this.configurationForm.controls['name'].setValue(this.selectedTemplate.default_name_format);
}
onAddClick(): void {
if (!this.selectedTemplate || this.filteredTemplates.length === 0) {
this.toasterService.error('Please firstly choose template.');
} else if (!this.positionForm.valid || !this.configurationForm.valid) {
} else if (!this.positionForm.valid || !this.configurationForm.valid || !this.selectedTemplate.compute_id) {
this.toasterService.error('Please fill all required fields.');
} else {
let x: number = this.positionForm.get('left').value;
@ -87,7 +87,7 @@ export class TemplateListDialogComponent implements OnInit {
let event: NodeAddedEvent = {
template: this.selectedTemplate,
server: this.selectedTemplate.compute_id,
name: this.configurationForm.get('name').value,
// name: this.configurationForm.get('name').value,
numberOfNodes: this.configurationForm.get('numberOfNodes').value,
x: x,
y: y
@ -101,7 +101,7 @@ export class TemplateListDialogComponent implements OnInit {
export interface NodeAddedEvent {
template: Template,
server: string,
name: string,
name?: string,
numberOfNodes: number;
x: number;
y: number;

View File

@ -46,6 +46,13 @@ export class NodeService {
}
createFromTemplate(server: Server, project: Project, template: Template, x: number, y: number, compute_id: string): Observable<Node> {
if (!compute_id) {
return this.httpServer.post(server, `/projects/${project.project_id}/templates/${template.template_id}`, {
x: Math.round(x),
y: Math.round(y),
compute_id: 'local'
});
}
return this.httpServer.post(server, `/projects/${project.project_id}/templates/${template.template_id}`, {
x: Math.round(x),
y: Math.round(y),