Merge branch 'master' into Packet-capture-preferences

This commit is contained in:
Piotr Pekala 2019-03-26 08:17:51 -07:00
commit d4b09e15d1
12 changed files with 63 additions and 47 deletions

View File

@ -6,7 +6,7 @@ import { ServersComponent } from './components/servers/servers.component';
import { ProjectsComponent } from './components/projects/projects.component';
import { DefaultLayoutComponent } from './layouts/default-layout/default-layout.component';
import { SettingsComponent } from './components/settings/settings.component';
import { LocalServerComponent } from './components/local-server/local-server.component';
import { BundledServerFinderComponent } from './components/local-server/bundled-server-finder.component';
import { PreferencesComponent } from './components/preferences/preferences.component';
import { QemuPreferencesComponent } from './components/preferences/qemu/qemu-preferences/qemu-preferences.component';
import { QemuVmTemplatesComponent } from './components/preferences/qemu/qemu-vm-templates/qemu-vm-templates.component';
@ -59,7 +59,7 @@ const routes: Routes = [
children: [
{ path: '', redirectTo: 'servers', pathMatch: 'full' },
{ path: 'servers', component: ServersComponent },
{ path: 'local', component: LocalServerComponent },
{ path: 'bundled', component: BundledServerFinderComponent },
{ path: 'server/:server_id/projects', component: ProjectsComponent },
{ path: 'settings', component: SettingsComponent },
{ path: 'installed-software', component: InstalledSoftwareComponent },

View File

@ -58,7 +58,7 @@ import { ProjectMapShortcutsComponent } from './components/project-map/project-m
import { SettingsComponent } from './components/settings/settings.component';
import { SettingsService } from './services/settings.service';
import { LocalServerComponent } from './components/local-server/local-server.component';
import { BundledServerFinderComponent } from './components/local-server/bundled-server-finder.component';
import { ProgressComponent } from './common/progress/progress.component';
import { ProgressService } from './common/progress/progress.service';
import { version } from './version';
@ -219,7 +219,7 @@ if (environment.production) {
ProjectMapShortcutsComponent,
SettingsComponent,
PreferencesComponent,
LocalServerComponent,
BundledServerFinderComponent,
ProgressComponent,
ServerDiscoveryComponent,
NodeSelectInterfaceComponent,

View File

@ -0,0 +1 @@
<app-progress></app-progress>

View File

@ -1,17 +1,21 @@
import { async, ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';
import { Router } from '@angular/router';
import { LocalServerComponent } from './local-server.component';
import { BundledServerFinderComponent } from './bundled-server-finder.component';
import { ServerService } from '../../services/server.service';
import { MockedServerService } from '../../services/server.service.spec';
import { Server } from '../../models/server';
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { ProgressService } from '../../common/progress/progress.service';
import { MockedProgressService } from '../project-map/project-map.component.spec';
describe('LocalServerComponent', () => {
let component: LocalServerComponent;
let fixture: ComponentFixture<LocalServerComponent>;
describe('BundledServerFinderComponent', () => {
let component: BundledServerFinderComponent;
let fixture: ComponentFixture<BundledServerFinderComponent>;
let router: any;
let serverService: any;
let progressService: MockedProgressService = new MockedProgressService();
beforeEach(async(() => {
router = {
@ -25,12 +29,16 @@ describe('LocalServerComponent', () => {
spyOn(serverService, 'getLocalServer').and.returnValue(Promise.resolve(server));
TestBed.configureTestingModule({
providers: [{ provide: Router, useValue: router },
{ provide: ServerService, useValue: serverService }],
declarations: [LocalServerComponent]
providers: [
{ provide: Router, useValue: router },
{ provide: ServerService, useValue: serverService },
{ provide: ProgressService, useValue: progressService }
],
declarations: [BundledServerFinderComponent],
schemas: [NO_ERRORS_SCHEMA]
}).compileComponents();
fixture = TestBed.createComponent(LocalServerComponent);
fixture = TestBed.createComponent(BundledServerFinderComponent);
component = fixture.componentInstance;
fixture.detectChanges();
}));

View File

@ -0,0 +1,35 @@
import { Component, OnInit, Inject } from '@angular/core';
import { Router } from '@angular/router';
import { ServerService } from '../../services/server.service';
import { Server } from '../../models/server';
import { DOCUMENT } from '@angular/common';
import { ProgressService } from '../../common/progress/progress.service';
@Component({
selector: 'app-bundled-server-finder',
templateUrl: './bundled-server-finder.component.html',
styleUrls: ['./bundled-server-finder.component.scss']
})
export class BundledServerFinderComponent implements OnInit {
constructor(
private router: Router,
private serverService: ServerService,
private progressService: ProgressService,
@Inject(DOCUMENT) private document) {}
ngOnInit() {
this.progressService.activate();
setTimeout(() =>
{
this.serverService.getLocalServer(
this.document.location.hostname,
parseInt(this.document.location.port, 10))
.then((server: Server) => {
this.progressService.deactivate();
this.router.navigate(['/server', server.id, 'projects']);
});
},
100);
}
}

View File

@ -1,27 +0,0 @@
import { Component, OnInit, Inject } from '@angular/core';
import { Router } from '@angular/router';
import { ServerService } from '../../services/server.service';
import { Server } from '../../models/server';
import { DOCUMENT } from '@angular/common';
@Component({
selector: 'app-local-server',
templateUrl: './local-server.component.html',
styleUrls: ['./local-server.component.scss']
})
export class LocalServerComponent implements OnInit {
constructor(
private router: Router,
private serverService: ServerService,
@Inject(DOCUMENT) private document) {}
ngOnInit() {
this.serverService.getLocalServer(
this.document.location.hostname,
parseInt(this.document.location.port, 10))
.then((server: Server) => {
this.router.navigate(['/server', server.id, 'projects']);
});
}
}

View File

@ -45,6 +45,8 @@ import { LinkWidget } from '../../cartography/widgets/link';
export class MockedProgressService {
public activate() {}
public deactivate() {}
}
export class MockedNodeService {

View File

@ -1,5 +1,5 @@
export type ServerAuthorization = 'basic' | 'none';
export type ServerLocation = 'local' | 'remote';
export type ServerLocation = 'local' | 'remote' | 'bundled';
export type ServerStatus = 'stopped' | 'starting' | 'running';
export class Server {
@ -13,6 +13,5 @@ export class Server {
authorization: ServerAuthorization;
login: string;
password: string;
is_local: boolean;
status: ServerStatus;
}

View File

@ -151,8 +151,7 @@ describe('ServerService', () => {
expectedServer.name = 'local';
expectedServer.host = 'hostname';
expectedServer.port = 9999;
expectedServer.location = 'remote';
expectedServer.is_local = true;
expectedServer.location = 'bundled';
service.getLocalServer('hostname', 9999).then(() => {
expect(service.create).toHaveBeenCalledWith(expectedServer);
@ -165,7 +164,7 @@ describe('ServerService', () => {
server.name = 'local';
server.host = 'hostname';
server.port = 9999;
server.is_local = true;
server.location = 'bundled';
spyOn(db, 'getAll').and.returnValue(Promise.resolve([server]));
spyOn(service, 'update').and.returnValue(Promise.resolve(new Server()));

View File

@ -58,7 +58,7 @@ export class ServerService {
public getLocalServer(host: string, port: number) {
const promise = new Promise((resolve, reject) => {
this.findAll().then((servers: Server[]) => {
const local = servers.find(server => server.is_local);
const local = servers.find(server => server.location === 'bundled');
if (local) {
local.host = host;
local.port = port;
@ -70,8 +70,7 @@ export class ServerService {
server.name = 'local';
server.host = host;
server.port = port;
server.location = 'remote';
server.is_local = true;
server.location = 'bundled';
this.create(server).then(created => {
resolve(created);
}, reject);