mirror of
https://github.com/GNS3/gns3-web-ui.git
synced 2025-05-09 20:12:53 +00:00
Merge pull request #555 from GNS3/Support-for-global-variables
Support for global variables
This commit is contained in:
commit
6b327316b7
@ -697,7 +697,7 @@ export class ProjectMapComponent implements OnInit, OnDestroy {
|
|||||||
|
|
||||||
editProject() {
|
editProject() {
|
||||||
const dialogRef = this.dialog.open(EditProjectDialogComponent, {
|
const dialogRef = this.dialog.open(EditProjectDialogComponent, {
|
||||||
width: '500px',
|
width: '600px',
|
||||||
autoFocus: false
|
autoFocus: false
|
||||||
});
|
});
|
||||||
let instance = dialogRef.componentInstance;
|
let instance = dialogRef.componentInstance;
|
||||||
|
@ -36,7 +36,8 @@ export class MockedProjectService {
|
|||||||
show_interface_labels: false,
|
show_interface_labels: false,
|
||||||
show_layers: false,
|
show_layers: false,
|
||||||
show_grid: false,
|
show_grid: false,
|
||||||
snap_to_grid: false
|
snap_to_grid: false,
|
||||||
|
variables: []
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -28,7 +28,8 @@ describe('ConfirmationDialogComponent', () => {
|
|||||||
show_interface_labels: false,
|
show_interface_labels: false,
|
||||||
show_layers: false,
|
show_layers: false,
|
||||||
show_grid: false,
|
show_grid: false,
|
||||||
snap_to_grid: false
|
snap_to_grid: false,
|
||||||
|
variables: []
|
||||||
};
|
};
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
<h1 mat-dialog-title>Edit project</h1>
|
<h1 mat-dialog-title>Edit project</h1>
|
||||||
|
|
||||||
|
<div class="modal-form-container">
|
||||||
|
<mat-tab-group>
|
||||||
|
<mat-tab label="General">
|
||||||
<form [formGroup]="formGroup">
|
<form [formGroup]="formGroup">
|
||||||
<mat-form-field class="form-field">
|
<mat-form-field class="form-field">
|
||||||
<input matInput formControlName="projectName" placeholder="Project name" type="text">
|
<input matInput formControlName="projectName" placeholder="Project name" type="text">
|
||||||
@ -37,6 +40,44 @@
|
|||||||
<mat-checkbox [ngModelOptions]="{standalone: true}" [(ngModel)]="project.show_interface_labels">
|
<mat-checkbox [ngModelOptions]="{standalone: true}" [(ngModel)]="project.show_interface_labels">
|
||||||
Show interface labels at start
|
Show interface labels at start
|
||||||
</mat-checkbox>
|
</mat-checkbox>
|
||||||
|
</mat-tab>
|
||||||
|
<mat-tab label="Global variables">
|
||||||
|
<form [formGroup]="variableFormGroup">
|
||||||
|
<mat-form-field class="form-field">
|
||||||
|
<input matInput formControlName="name" placeholder="Name" type="text">
|
||||||
|
</mat-form-field>
|
||||||
|
|
||||||
|
<mat-form-field class="form-field">
|
||||||
|
<input matInput formControlName="value" placeholder="Value" type="text">
|
||||||
|
</mat-form-field>
|
||||||
|
</form>
|
||||||
|
<button class="form-field" mat-button (click)="addVariable()" mat-raised-button color="primary">Add variable</button>
|
||||||
|
<table class="table" mat-table [dataSource]="variables">
|
||||||
|
<ng-container matColumnDef="name">
|
||||||
|
<th mat-header-cell *matHeaderCellDef>Name</th>
|
||||||
|
<td mat-cell *matCellDef="let element">{{element.name}} </td>
|
||||||
|
</ng-container>
|
||||||
|
|
||||||
|
<ng-container matColumnDef="value">
|
||||||
|
<th mat-header-cell *matHeaderCellDef>Value</th>
|
||||||
|
<td mat-cell *matCellDef="let element">{{element.value}}</td>
|
||||||
|
</ng-container>
|
||||||
|
|
||||||
|
<ng-container matColumnDef="actions">
|
||||||
|
<th mat-header-cell *matHeaderCellDef>Actions</th>
|
||||||
|
<td mat-cell *matCellDef="let element">
|
||||||
|
<button mat-icon-button matTooltip="Delete variable" (click)="deleteVariable(element)">
|
||||||
|
<mat-icon aria-label="Delete adapter">delete</mat-icon>
|
||||||
|
</button>
|
||||||
|
</td>
|
||||||
|
</ng-container>
|
||||||
|
|
||||||
|
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
|
||||||
|
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
|
||||||
|
</table>
|
||||||
|
</mat-tab>
|
||||||
|
</mat-tab-group>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div mat-dialog-actions>
|
<div mat-dialog-actions>
|
||||||
<button mat-button (click)="onNoClick()" color="accent">Cancel</button>
|
<button mat-button (click)="onNoClick()" color="accent">Cancel</button>
|
||||||
|
@ -1,3 +1,15 @@
|
|||||||
.form-field {
|
.form-field {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
th {
|
||||||
|
border: 0px!important;
|
||||||
|
}
|
||||||
|
|
||||||
|
th.mat-header-cell {
|
||||||
|
padding-bottom: 15px;
|
||||||
|
}
|
||||||
|
|
||||||
|
td.mat-cell {
|
||||||
|
padding-top: 15px;
|
||||||
|
}
|
||||||
|
@ -2,7 +2,7 @@ import { Component, OnInit, Injectable } from '@angular/core';
|
|||||||
import { MatDialogRef } from '@angular/material';
|
import { MatDialogRef } from '@angular/material';
|
||||||
import { FormGroup, FormBuilder, FormControl, Validators } from '@angular/forms';
|
import { FormGroup, FormBuilder, FormControl, Validators } from '@angular/forms';
|
||||||
import { Server } from '../../../models/server';
|
import { Server } from '../../../models/server';
|
||||||
import { Project } from '../../../models/project';
|
import { Project, ProjectVariable } from '../../../models/project';
|
||||||
import { ToasterService } from '../../../services/toaster.service';
|
import { ToasterService } from '../../../services/toaster.service';
|
||||||
import { NonNegativeValidator } from '../../../validators/non-negative-validator';
|
import { NonNegativeValidator } from '../../../validators/non-negative-validator';
|
||||||
import { ProjectService } from '../../../services/project.service';
|
import { ProjectService } from '../../../services/project.service';
|
||||||
@ -16,6 +16,11 @@ export class EditProjectDialogComponent implements OnInit {
|
|||||||
server: Server;
|
server: Server;
|
||||||
project: Project;
|
project: Project;
|
||||||
formGroup: FormGroup;
|
formGroup: FormGroup;
|
||||||
|
variableFormGroup: FormGroup;
|
||||||
|
projectVariables: ProjectVariable[];
|
||||||
|
|
||||||
|
displayedColumns: string[] = ['name', 'value', 'actions'];
|
||||||
|
variables: ProjectVariable[] = [];
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
public dialogRef: MatDialogRef<EditProjectDialogComponent>,
|
public dialogRef: MatDialogRef<EditProjectDialogComponent>,
|
||||||
@ -31,6 +36,11 @@ export class EditProjectDialogComponent implements OnInit {
|
|||||||
nodeGridSize: new FormControl('', [Validators.required, nonNegativeValidator.get]),
|
nodeGridSize: new FormControl('', [Validators.required, nonNegativeValidator.get]),
|
||||||
drawingGridSize: new FormControl('', [Validators.required, nonNegativeValidator.get])
|
drawingGridSize: new FormControl('', [Validators.required, nonNegativeValidator.get])
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.variableFormGroup = this.formBuilder.group({
|
||||||
|
name: new FormControl('', [Validators.required]),
|
||||||
|
value: new FormControl('', [Validators.required])
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
@ -39,6 +49,23 @@ export class EditProjectDialogComponent implements OnInit {
|
|||||||
this.formGroup.controls['height'].setValue(this.project.scene_height);
|
this.formGroup.controls['height'].setValue(this.project.scene_height);
|
||||||
this.formGroup.controls['nodeGridSize'].setValue(this.project.grid_size);
|
this.formGroup.controls['nodeGridSize'].setValue(this.project.grid_size);
|
||||||
this.formGroup.controls['drawingGridSize'].setValue(this.project.drawing_grid_size);
|
this.formGroup.controls['drawingGridSize'].setValue(this.project.drawing_grid_size);
|
||||||
|
this.project.variables.forEach(n => this.variables.push(n));
|
||||||
|
}
|
||||||
|
|
||||||
|
addVariable() {
|
||||||
|
if (this.variableFormGroup.valid) {
|
||||||
|
let variable: ProjectVariable = {
|
||||||
|
name: this.variableFormGroup.get('name').value,
|
||||||
|
value: this.variableFormGroup.get('value').value
|
||||||
|
};
|
||||||
|
this.variables = this.variables.concat([variable]);
|
||||||
|
} else {
|
||||||
|
this.toasterService.error(`Fill all required fields with correct values.`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
deleteVariable(variable: ProjectVariable) {
|
||||||
|
this.variables = this.variables.filter(elem => elem!== variable);
|
||||||
}
|
}
|
||||||
|
|
||||||
onNoClick() {
|
onNoClick() {
|
||||||
@ -52,6 +79,7 @@ export class EditProjectDialogComponent implements OnInit {
|
|||||||
this.project.scene_height = this.formGroup.get('height').value;
|
this.project.scene_height = this.formGroup.get('height').value;
|
||||||
this.project.drawing_grid_size = this.formGroup.get('drawingGridSize').value;
|
this.project.drawing_grid_size = this.formGroup.get('drawingGridSize').value;
|
||||||
this.project.grid_size = this.formGroup.get('nodeGridSize').value;
|
this.project.grid_size = this.formGroup.get('nodeGridSize').value;
|
||||||
|
this.project.variables = this.variables;
|
||||||
|
|
||||||
this.projectService.update(this.server, this.project).subscribe((project: Project) => {
|
this.projectService.update(this.server, this.project).subscribe((project: Project) => {
|
||||||
this.toasterService.success(`Project ${project.name} updated.`);
|
this.toasterService.success(`Project ${project.name} updated.`);
|
||||||
|
@ -41,7 +41,8 @@ export class MockedProjectService {
|
|||||||
show_interface_labels: false,
|
show_interface_labels: false,
|
||||||
show_layers: false,
|
show_layers: false,
|
||||||
show_grid: false,
|
show_grid: false,
|
||||||
snap_to_grid: false
|
snap_to_grid: false,
|
||||||
|
variables: []
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -16,4 +16,10 @@ export class Project {
|
|||||||
show_layers: boolean;
|
show_layers: boolean;
|
||||||
show_grid: boolean;
|
show_grid: boolean;
|
||||||
snap_to_grid: boolean;
|
snap_to_grid: boolean;
|
||||||
|
variables: ProjectVariable[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export class ProjectVariable {
|
||||||
|
name: string;
|
||||||
|
value: string;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user