mirror of
https://github.com/GNS3/gns3-web-ui.git
synced 2025-02-07 03:40:11 +00:00
Local server support
This commit is contained in:
parent
f1493800cd
commit
0cb1b4197a
@ -8,6 +8,7 @@ import { ServersComponent } from "./servers/servers.component";
|
|||||||
import { ProjectsComponent } from "./projects/projects.component";
|
import { ProjectsComponent } from "./projects/projects.component";
|
||||||
import { DefaultLayoutComponent } from "./default-layout/default-layout.component";
|
import { DefaultLayoutComponent } from "./default-layout/default-layout.component";
|
||||||
import { SettingsComponent } from "./settings/settings.component";
|
import { SettingsComponent } from "./settings/settings.component";
|
||||||
|
import { LocalServerComponent } from "./local-server/local-server.component";
|
||||||
|
|
||||||
|
|
||||||
const routes: Routes = [
|
const routes: Routes = [
|
||||||
@ -15,6 +16,7 @@ const routes: Routes = [
|
|||||||
children: [
|
children: [
|
||||||
{ path: '', redirectTo: 'servers', pathMatch: 'full'},
|
{ path: '', redirectTo: 'servers', pathMatch: 'full'},
|
||||||
{ path: 'servers', component: ServersComponent },
|
{ path: 'servers', component: ServersComponent },
|
||||||
|
{ path: 'local', component: LocalServerComponent },
|
||||||
{ path: 'server/:server_id/projects', component: ProjectsComponent },
|
{ path: 'server/:server_id/projects', component: ProjectsComponent },
|
||||||
{ path: 'settings', component: SettingsComponent },
|
{ path: 'settings', component: SettingsComponent },
|
||||||
]
|
]
|
||||||
|
@ -75,6 +75,7 @@ import { SettingsComponent } from './settings/settings.component';
|
|||||||
import { SettingsService } from "./shared/services/settings.service";
|
import { SettingsService } from "./shared/services/settings.service";
|
||||||
|
|
||||||
import { RavenErrorHandler } from "./raven-error-handler";
|
import { RavenErrorHandler } from "./raven-error-handler";
|
||||||
|
import { LocalServerComponent } from './local-server/local-server.component';
|
||||||
|
|
||||||
Raven
|
Raven
|
||||||
.config('https://b2b1cfd9b043491eb6b566fd8acee358@sentry.io/842726')
|
.config('https://b2b1cfd9b043491eb6b566fd8acee358@sentry.io/842726')
|
||||||
@ -102,6 +103,7 @@ Raven
|
|||||||
MoveLayerUpActionComponent,
|
MoveLayerUpActionComponent,
|
||||||
ProjectMapShortcutsComponent,
|
ProjectMapShortcutsComponent,
|
||||||
SettingsComponent,
|
SettingsComponent,
|
||||||
|
LocalServerComponent,
|
||||||
],
|
],
|
||||||
imports: [
|
imports: [
|
||||||
NgbModule.forRoot(),
|
NgbModule.forRoot(),
|
||||||
|
0
src/app/local-server/local-server.component.html
Normal file
0
src/app/local-server/local-server.component.html
Normal file
0
src/app/local-server/local-server.component.scss
Normal file
0
src/app/local-server/local-server.component.scss
Normal file
25
src/app/local-server/local-server.component.spec.ts
Normal file
25
src/app/local-server/local-server.component.spec.ts
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { LocalServerComponent } from './local-server.component';
|
||||||
|
|
||||||
|
describe('LocalServerComponent', () => {
|
||||||
|
let component: LocalServerComponent;
|
||||||
|
let fixture: ComponentFixture<LocalServerComponent>;
|
||||||
|
|
||||||
|
beforeEach(async(() => {
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
declarations: [ LocalServerComponent ]
|
||||||
|
})
|
||||||
|
.compileComponents();
|
||||||
|
}));
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
fixture = TestBed.createComponent(LocalServerComponent);
|
||||||
|
component = fixture.componentInstance;
|
||||||
|
fixture.detectChanges();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create', () => {
|
||||||
|
expect(component).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
27
src/app/local-server/local-server.component.ts
Normal file
27
src/app/local-server/local-server.component.ts
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
import { Component, OnInit } from '@angular/core';
|
||||||
|
import { Location } from "@angular/common";
|
||||||
|
import { Router } from "@angular/router";
|
||||||
|
|
||||||
|
import { ServerService } from "../shared/services/server.service";
|
||||||
|
import { Server } from "../shared/models/server";
|
||||||
|
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-local-server',
|
||||||
|
templateUrl: './local-server.component.html',
|
||||||
|
styleUrls: ['./local-server.component.scss']
|
||||||
|
})
|
||||||
|
export class LocalServerComponent implements OnInit {
|
||||||
|
|
||||||
|
constructor(private location: Location,
|
||||||
|
private router: Router,
|
||||||
|
private serverService: ServerService) { }
|
||||||
|
|
||||||
|
ngOnInit() {
|
||||||
|
this.serverService.getLocalServer(location.hostname, parseInt(location.port, 10))
|
||||||
|
.then((server: Server) => {
|
||||||
|
this.router.navigate(['/server', server.id, 'projects']);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -46,7 +46,7 @@ export class ProjectsComponent implements OnInit {
|
|||||||
this.route.paramMap
|
this.route.paramMap
|
||||||
.switchMap((params: ParamMap) => {
|
.switchMap((params: ParamMap) => {
|
||||||
const server_id = params.get('server_id');
|
const server_id = params.get('server_id');
|
||||||
return this.serverService.getLocalOrRemote(server_id);
|
return this.serverService.get(parseInt(server_id, 10));
|
||||||
})
|
})
|
||||||
.subscribe((server: Server) => {
|
.subscribe((server: Server) => {
|
||||||
this.server = server;
|
this.server = server;
|
||||||
|
@ -8,4 +8,5 @@ export class Server {
|
|||||||
authorization: ServerAuthorization;
|
authorization: ServerAuthorization;
|
||||||
login: string;
|
login: string;
|
||||||
password: string;
|
password: string;
|
||||||
|
is_local: boolean;
|
||||||
}
|
}
|
||||||
|
@ -22,15 +22,6 @@ export class ServerService {
|
|||||||
this.indexedDbService.get().getByKey(this.tablename, id));
|
this.indexedDbService.get().getByKey(this.tablename, id));
|
||||||
}
|
}
|
||||||
|
|
||||||
public getLocalOrRemote(id: string) {
|
|
||||||
if (id === 'local') {
|
|
||||||
const server = new Server();
|
|
||||||
server.name = 'local';
|
|
||||||
return Observable.of(server);
|
|
||||||
}
|
|
||||||
return this.get(parseInt(id, 10));
|
|
||||||
}
|
|
||||||
|
|
||||||
public create(server: Server) {
|
public create(server: Server) {
|
||||||
return this.onReady(() => {
|
return this.onReady(() => {
|
||||||
const promise = new Promise((resolve, reject) => {
|
const promise = new Promise((resolve, reject) => {
|
||||||
@ -43,6 +34,17 @@ export class ServerService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public update(server: Server) {
|
||||||
|
return this.onReady(() => {
|
||||||
|
const promise = new Promise((resolve, reject) => {
|
||||||
|
this.indexedDbService.get().update(this.tablename, server).then((updated) => {
|
||||||
|
resolve(server);
|
||||||
|
}, reject);
|
||||||
|
});
|
||||||
|
return promise;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public findAll() {
|
public findAll() {
|
||||||
return this.onReady(() =>
|
return this.onReady(() =>
|
||||||
this.indexedDbService.get().getAll(this.tablename));
|
this.indexedDbService.get().getAll(this.tablename));
|
||||||
@ -53,6 +55,32 @@ export class ServerService {
|
|||||||
this.indexedDbService.get().delete(this.tablename, server.id));
|
this.indexedDbService.get().delete(this.tablename, server.id));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public getLocalServer(ip: string, port: number) {
|
||||||
|
const promise = new Promise((resolve, reject) => {
|
||||||
|
this.findAll().then((servers: Server[]) => {
|
||||||
|
const local = servers.find((server) => server.is_local);
|
||||||
|
if (local) {
|
||||||
|
local.ip = ip;
|
||||||
|
local.port = port;
|
||||||
|
this.update(local).then((updated) => {
|
||||||
|
resolve(updated);
|
||||||
|
}, reject);
|
||||||
|
} else {
|
||||||
|
const server = new Server();
|
||||||
|
server.name = 'local';
|
||||||
|
server.ip = ip;
|
||||||
|
server.port = port;
|
||||||
|
server.is_local = true;
|
||||||
|
this.create(server).then((created) => {
|
||||||
|
resolve(created);
|
||||||
|
}, reject);
|
||||||
|
}
|
||||||
|
}, reject);
|
||||||
|
});
|
||||||
|
|
||||||
|
return promise;
|
||||||
|
}
|
||||||
|
|
||||||
private onReady(query) {
|
private onReady(query) {
|
||||||
const promise = new Promise((resolve, reject) => {
|
const promise = new Promise((resolve, reject) => {
|
||||||
this.ready.then(() => {
|
this.ready.then(() => {
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
export const environment = {
|
export const environment = {
|
||||||
production: true
|
production: true,
|
||||||
|
electron: false,
|
||||||
|
githubio: false
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user