mirror of
https://github.com/GNS3/gns3-web-ui.git
synced 2024-12-20 05:27:56 +00:00
Code refactored
This commit is contained in:
parent
ca9cb13c2b
commit
07722cf8ea
@ -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 },
|
||||
|
@ -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';
|
||||
@ -206,7 +206,7 @@ if (environment.production) {
|
||||
ProjectMapShortcutsComponent,
|
||||
SettingsComponent,
|
||||
PreferencesComponent,
|
||||
LocalServerComponent,
|
||||
BundledServerFinderComponent,
|
||||
ProgressComponent,
|
||||
ServerDiscoveryComponent,
|
||||
NodeSelectInterfaceComponent,
|
||||
|
@ -0,0 +1 @@
|
||||
<app-progress></app-progress>
|
@ -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();
|
||||
}));
|
@ -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);
|
||||
}
|
||||
}
|
@ -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']);
|
||||
});
|
||||
}
|
||||
}
|
@ -43,6 +43,8 @@ import { Project } from '../../models/project';
|
||||
|
||||
export class MockedProgressService {
|
||||
public activate() {}
|
||||
|
||||
public deactivate() {}
|
||||
}
|
||||
|
||||
export class MockedNodeService {
|
||||
|
Loading…
Reference in New Issue
Block a user