mirror of
https://github.com/GNS3/gns3-web-ui.git
synced 2025-02-20 17:52:46 +00:00
Limit number of local servers to one, Fixes: #322
This commit is contained in:
parent
23819b48c0
commit
7ccc9db33b
@ -3,6 +3,7 @@ import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material';
|
||||
import { Server } from '../../../models/server';
|
||||
import { ElectronService } from 'ngx-electron';
|
||||
import { FormGroup, FormControl, Validators } from '@angular/forms';
|
||||
import { ServerService } from '../../../services/server.service';
|
||||
|
||||
|
||||
@Component({
|
||||
@ -27,25 +28,35 @@ export class AddServerDialogComponent implements OnInit {
|
||||
constructor(
|
||||
public dialogRef: MatDialogRef<AddServerDialogComponent>,
|
||||
private electronService: ElectronService,
|
||||
private serverService: ServerService,
|
||||
@Inject(MAT_DIALOG_DATA) public data: any,
|
||||
) {}
|
||||
|
||||
getLocations() {
|
||||
async getLocations() {
|
||||
const localServers = await this.numberOfLocalServers();
|
||||
|
||||
let locations = [];
|
||||
if(this.electronService.isElectronApp) {
|
||||
if(this.electronService.isElectronApp && localServers === 0) {
|
||||
locations.push({ key: 'local', name: 'Local' });
|
||||
}
|
||||
locations.push({ key: 'remote', name: 'Remote' });
|
||||
return locations
|
||||
}
|
||||
|
||||
getDefaultLocation() {
|
||||
if(this.electronService.isElectronApp) {
|
||||
|
||||
async getDefaultLocation() {
|
||||
const localServers = await this.numberOfLocalServers();
|
||||
if(this.electronService.isElectronApp && localServers === 0) {
|
||||
return 'local';
|
||||
}
|
||||
return 'remote';
|
||||
}
|
||||
|
||||
async numberOfLocalServers() {
|
||||
const servers = await this.serverService.findAll();
|
||||
return servers.filter((server) => server.location === 'local').length;
|
||||
}
|
||||
|
||||
getDefaultHost() {
|
||||
return '127.0.0.1';
|
||||
}
|
||||
@ -62,7 +73,7 @@ export class AddServerDialogComponent implements OnInit {
|
||||
}
|
||||
|
||||
async ngOnInit() {
|
||||
this.locations = this.getLocations();
|
||||
this.locations = await this.getLocations();
|
||||
|
||||
const defaultLocalServerPath = await this.getDefaultLocalServerPath();
|
||||
|
||||
@ -105,7 +116,8 @@ export class AddServerDialogComponent implements OnInit {
|
||||
})
|
||||
});
|
||||
|
||||
this.serverForm.get('location').setValue(this.getDefaultLocation());
|
||||
const defaultLocation = await this.getDefaultLocation();
|
||||
this.serverForm.get('location').setValue(defaultLocation);
|
||||
this.serverForm.get('host').setValue(this.getDefaultHost());
|
||||
this.serverForm.get('port').setValue(this.getDefaultPort());
|
||||
this.serverForm.get('authorization').setValue('none');
|
||||
|
@ -48,7 +48,7 @@ export class ServerService {
|
||||
}
|
||||
|
||||
public findAll() {
|
||||
return this.onReady(() => this.indexedDbService.get().getAll(this.tablename));
|
||||
return this.onReady(() => this.indexedDbService.get().getAll(this.tablename)) as Promise<Server[]>;
|
||||
}
|
||||
|
||||
public delete(server: Server) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user