mirror of
https://github.com/GNS3/gns3-web-ui.git
synced 2025-01-19 11:16:41 +00:00
Before connection to the server we need to check minimal supported version
This commit is contained in:
parent
58a02c7066
commit
91fa54cf9b
@ -4,6 +4,7 @@ import { Server } from '../../../models/server';
|
||||
import { ElectronService } from 'ngx-electron';
|
||||
import { FormGroup, FormControl, Validators } from '@angular/forms';
|
||||
import { ServerService } from '../../../services/server.service';
|
||||
import { ToasterService } from '../../../services/toaster.service';
|
||||
|
||||
|
||||
@Component({
|
||||
@ -30,6 +31,7 @@ export class AddServerDialogComponent implements OnInit {
|
||||
public dialogRef: MatDialogRef<AddServerDialogComponent>,
|
||||
private electronService: ElectronService,
|
||||
private serverService: ServerService,
|
||||
private toasterService: ToasterService,
|
||||
@Inject(MAT_DIALOG_DATA) public data: any,
|
||||
) {}
|
||||
|
||||
@ -145,7 +147,21 @@ export class AddServerDialogComponent implements OnInit {
|
||||
}
|
||||
|
||||
const server: Server = Object.assign({}, this.serverForm.value);
|
||||
this.dialogRef.close(server);
|
||||
this.serverService.checkServerVersion(server).subscribe(
|
||||
(serverInfo) => {
|
||||
if ((serverInfo.version.split('.')[1]>=2) && (serverInfo.version.split('.')[0]>=2)) {
|
||||
this.dialogRef.close(server);
|
||||
this.toasterService.success(`Server ${server.name} added.`)
|
||||
} else {
|
||||
this.dialogRef.close();
|
||||
this.toasterService.error(`Server version is not supported.`)
|
||||
}
|
||||
},
|
||||
error => {
|
||||
this.dialogRef.close();
|
||||
this.toasterService.error('Cannot connect to the server.')
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
onNoClick(): void {
|
||||
|
@ -39,7 +39,17 @@ export class ServersComponent implements OnInit, OnDestroy {
|
||||
server.status = 'running';
|
||||
}
|
||||
});
|
||||
this.serverDatabase.addServers(servers);
|
||||
|
||||
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);
|
||||
|
@ -2,7 +2,6 @@ import { Injectable } from '@angular/core';
|
||||
import { Project } from '../models/project';
|
||||
import { Node } from '../cartography/models/node';
|
||||
import { Observable } from 'rxjs';
|
||||
|
||||
import { Link } from '../models/link';
|
||||
import { Server } from '../models/server';
|
||||
import { HttpServer } from './http-server.service';
|
||||
|
@ -5,6 +5,8 @@ import { Server } from '../models/server';
|
||||
import { IndexedDbService } from './indexed-db.service';
|
||||
import { AngularIndexedDB } from 'angular2-indexeddb';
|
||||
import Spy = jasmine.Spy;
|
||||
import { HttpServer, ServerErrorHandler } from '../services/http-server.service';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
|
||||
export class MockedServerService {
|
||||
public servers: Server[] = [];
|
||||
@ -46,6 +48,7 @@ describe('ServerService', () => {
|
||||
let db: AngularIndexedDB;
|
||||
let service: ServerService;
|
||||
let openDatabaseSpy: Spy;
|
||||
let httpServer = new HttpServer({} as HttpClient, {} as ServerErrorHandler);
|
||||
|
||||
beforeEach(() => {
|
||||
indexedDbService = new IndexedDbService();
|
||||
@ -55,7 +58,11 @@ describe('ServerService', () => {
|
||||
openDatabaseSpy = spyOn(db, 'openDatabase').and.returnValue(Promise.resolve(true));
|
||||
|
||||
TestBed.configureTestingModule({
|
||||
providers: [ServerService, { provide: IndexedDbService, useValue: indexedDbService }]
|
||||
providers: [
|
||||
ServerService,
|
||||
{ provide: IndexedDbService, useValue: indexedDbService },
|
||||
{ provide: HttpServer, useValue: httpServer }
|
||||
]
|
||||
});
|
||||
|
||||
service = TestBed.get(ServerService);
|
||||
|
@ -1,14 +1,18 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
|
||||
import { IndexedDbService } from './indexed-db.service';
|
||||
import { Server } from '../models/server';
|
||||
import { Observable } from 'rxjs';
|
||||
import { HttpServer } from './http-server.service';
|
||||
|
||||
@Injectable()
|
||||
export class ServerService {
|
||||
private tablename = 'servers';
|
||||
private ready: Promise<any>;
|
||||
|
||||
constructor(private indexedDbService: IndexedDbService) {
|
||||
constructor(
|
||||
private indexedDbService: IndexedDbService,
|
||||
private httpServer: HttpServer
|
||||
) {
|
||||
this.ready = indexedDbService.get().openDatabase(1, evt => {
|
||||
evt.currentTarget.result.createObjectStore(this.tablename, { keyPath: 'id', autoIncrement: true });
|
||||
});
|
||||
@ -59,6 +63,10 @@ export class ServerService {
|
||||
return `http://${server.host}:${server.port}/`;
|
||||
}
|
||||
|
||||
public checkServerVersion(server: Server): Observable<any> {
|
||||
return this.httpServer.get(server, '/version');
|
||||
}
|
||||
|
||||
public getLocalServer(host: string, port: number) {
|
||||
const promise = new Promise((resolve, reject) => {
|
||||
this.findAll().then((servers: Server[]) => {
|
||||
|
Loading…
Reference in New Issue
Block a user