mirror of
https://github.com/GNS3/gns3-web-ui.git
synced 2024-12-20 05:27:56 +00:00
Merge pull request #889 from GNS3/Strange-behavior-with-Firefox
Strange behavior with firefox
This commit is contained in:
commit
41f5af2b90
@ -24,22 +24,26 @@ export class DirectLinkComponent implements OnInit {
|
||||
const serverIp = this.route.snapshot.paramMap.get('server_ip');
|
||||
const serverPort = +this.route.snapshot.paramMap.get('server_port');
|
||||
const projectId = this.route.snapshot.paramMap.get('project_id');
|
||||
|
||||
this.serverService.serviceInitialized.subscribe(async (value: boolean) => {
|
||||
if (value) {
|
||||
const servers = await this.serverService.findAll();
|
||||
const server = servers.filter(server => server.host === serverIp && server.port === serverPort)[0];
|
||||
|
||||
const servers = await this.serverService.findAll();
|
||||
const server = servers.filter(server => server.host === serverIp && server.port === serverPort)[0];
|
||||
|
||||
if (server) {
|
||||
this.router.navigate(['/server', server.id, 'project', projectId]);
|
||||
} else {
|
||||
let serverToAdd: Server = new Server();
|
||||
serverToAdd.host = serverIp;
|
||||
serverToAdd.port = serverPort;
|
||||
serverToAdd.location = 'bundled';
|
||||
serverToAdd.name = serverIp;
|
||||
|
||||
this.serverService.create(serverToAdd).then((addedServer: Server) => {
|
||||
this.router.navigate(['/server', addedServer.id, 'project', projectId]);
|
||||
});
|
||||
}
|
||||
if (server) {
|
||||
this.router.navigate(['/server', server.id, 'project', projectId]);
|
||||
} else {
|
||||
let serverToAdd: Server = new Server();
|
||||
serverToAdd.host = serverIp;
|
||||
serverToAdd.port = serverPort;
|
||||
serverToAdd.location = 'bundled';
|
||||
serverToAdd.name = serverIp;
|
||||
|
||||
this.serverService.create(serverToAdd).then((addedServer: Server) => {
|
||||
this.router.navigate(['/server', addedServer.id, 'project', projectId]);
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -57,6 +57,7 @@ export class AddServerDialogComponent implements OnInit {
|
||||
|
||||
async numberOfLocalServers() {
|
||||
const servers = await this.serverService.findAll();
|
||||
|
||||
return servers.filter((server) => server.location === 'local').length;
|
||||
}
|
||||
|
||||
|
@ -32,7 +32,11 @@ export class ServerDiscoveryComponent implements OnInit {
|
||||
) {}
|
||||
|
||||
ngOnInit() {
|
||||
this.discoverFirstAvailableServer();
|
||||
this.serverService.serviceInitialized.subscribe(async (value: boolean) => {
|
||||
if (value) {
|
||||
this.discoverFirstAvailableServer();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
discoverFirstAvailableServer() {
|
||||
|
@ -40,24 +40,28 @@ export class ServersComponent implements OnInit, OnDestroy {
|
||||
this.isElectronApp = this.electronService.isElectronApp;
|
||||
const runningServersNames = this.serverManagement.getRunningServers();
|
||||
|
||||
this.serverService.findAll().then((servers: Server[]) => {
|
||||
servers.forEach((server) => {
|
||||
const serverIndex = runningServersNames.findIndex((serverName) => server.name === serverName);
|
||||
if(serverIndex >= 0) {
|
||||
server.status = 'running';
|
||||
}
|
||||
});
|
||||
|
||||
servers.forEach((server) => {
|
||||
this.serverService.checkServerVersion(server).subscribe(
|
||||
(serverInfo) => {
|
||||
if ((serverInfo.version.split('.')[1]>=2) && (serverInfo.version.split('.')[0]>=2)) {
|
||||
if (!this.serverDatabase.find(server.name)) this.serverDatabase.addServer(server);
|
||||
this.serverService.serviceInitialized.subscribe(async (value: boolean) => {
|
||||
if (value) {
|
||||
this.serverService.findAll().then((servers: Server[]) => {
|
||||
servers.forEach((server) => {
|
||||
const serverIndex = runningServersNames.findIndex((serverName) => server.name === serverName);
|
||||
if(serverIndex >= 0) {
|
||||
server.status = 'running';
|
||||
}
|
||||
},
|
||||
error => {}
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
servers.forEach((server) => {
|
||||
this.serverService.checkServerVersion(server).subscribe(
|
||||
(serverInfo) => {
|
||||
if ((serverInfo.version.split('.')[1]>=2) && (serverInfo.version.split('.')[0]>=2)) {
|
||||
if (!this.serverDatabase.find(server.name)) this.serverDatabase.addServer(server);
|
||||
}
|
||||
},
|
||||
error => {}
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
this.dataSource = new ServerDataSource(this.serverDatabase);
|
||||
|
@ -1,28 +1,58 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Injectable, EventEmitter } from '@angular/core';
|
||||
import { IndexedDbService } from './indexed-db.service';
|
||||
import { Server } from '../models/server';
|
||||
import { Observable } from 'rxjs';
|
||||
import { HttpServer } from './http-server.service';
|
||||
import { ToasterService } from './toaster.service';
|
||||
|
||||
@Injectable()
|
||||
export class ServerService {
|
||||
private tablename = 'servers';
|
||||
private ready: Promise<any>;
|
||||
private isIncognitoMode: boolean = false;
|
||||
private serverIdsInIncognitoMode: string[] = [];
|
||||
public serviceInitialized: EventEmitter<boolean> = new EventEmitter<boolean>();
|
||||
|
||||
constructor(
|
||||
private indexedDbService: IndexedDbService,
|
||||
private httpServer: HttpServer
|
||||
private httpServer: HttpServer,
|
||||
private toasterService: ToasterService
|
||||
) {
|
||||
this.ready = indexedDbService.get().openDatabase(1, evt => {
|
||||
evt.currentTarget.result.createObjectStore(this.tablename, { keyPath: 'id', autoIncrement: true });
|
||||
this.indexedDbService.get().openDatabase(1).then(() => {
|
||||
this.ready = indexedDbService.get().openDatabase(1, evt => {
|
||||
evt.currentTarget.result.createObjectStore(this.tablename, { keyPath: 'id', autoIncrement: true });
|
||||
});
|
||||
}).catch(() => {
|
||||
this.isIncognitoMode = true;
|
||||
}).finally(() => {
|
||||
this.serviceInitialized.emit(true);
|
||||
});
|
||||
}
|
||||
|
||||
public get(id: number): Promise<Server> {
|
||||
if (this.isIncognitoMode) {
|
||||
let server: Server = JSON.parse(localStorage.getItem(`server-${id}`));
|
||||
let promise = new Promise<Server>(resolve => {
|
||||
resolve(server);
|
||||
});
|
||||
return promise;
|
||||
}
|
||||
|
||||
return this.onReady(() => this.indexedDbService.get().getByKey(this.tablename, id)) as Promise<Server>;
|
||||
}
|
||||
|
||||
public create(server: Server) {
|
||||
if (this.isIncognitoMode) {
|
||||
server.id = this.serverIdsInIncognitoMode.length + 1;
|
||||
localStorage.setItem(`server-${server.id}`, JSON.stringify(server));
|
||||
this.serverIdsInIncognitoMode.push(`server-${server.id}`);
|
||||
|
||||
let promise = new Promise<Server>(resolve => {
|
||||
resolve(server);
|
||||
});
|
||||
return promise;
|
||||
}
|
||||
|
||||
return this.onReady(() => {
|
||||
const promise = new Promise((resolve, reject) => {
|
||||
this.indexedDbService
|
||||
@ -38,6 +68,16 @@ export class ServerService {
|
||||
}
|
||||
|
||||
public update(server: Server) {
|
||||
if (this.isIncognitoMode) {
|
||||
localStorage.removeItem(`server-${server.id}`);
|
||||
localStorage.setItem(`server-${server.id}`, JSON.stringify(server));
|
||||
|
||||
let promise = new Promise<Server>(resolve => {
|
||||
resolve(server);
|
||||
});
|
||||
return promise;
|
||||
}
|
||||
|
||||
return this.onReady(() => {
|
||||
const promise = new Promise((resolve, reject) => {
|
||||
this.indexedDbService
|
||||
@ -52,10 +92,32 @@ export class ServerService {
|
||||
}
|
||||
|
||||
public findAll() {
|
||||
if (this.isIncognitoMode) {
|
||||
let promise = new Promise<Server[]>(resolve => {
|
||||
let servers: Server[] = [];
|
||||
this.serverIdsInIncognitoMode.forEach(n => {
|
||||
let server: Server = JSON.parse(localStorage.getItem(n));
|
||||
servers.push(server);
|
||||
});
|
||||
resolve(servers);
|
||||
});
|
||||
return promise;
|
||||
}
|
||||
|
||||
return this.onReady(() => this.indexedDbService.get().getAll(this.tablename)) as Promise<Server[]>;
|
||||
}
|
||||
|
||||
public delete(server: Server) {
|
||||
if (this.isIncognitoMode) {
|
||||
localStorage.removeItem(`server-${server.id}`);
|
||||
this.serverIdsInIncognitoMode = this.serverIdsInIncognitoMode.filter(n => n !== `server-${server.id}`);
|
||||
|
||||
let promise = new Promise(resolve => {
|
||||
resolve(server.id);
|
||||
});
|
||||
return promise;
|
||||
}
|
||||
|
||||
return this.onReady(() => this.indexedDbService.get().delete(this.tablename, server.id));
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user