From 07722cf8eaf0bac682e2a0c3c151efe633810b66 Mon Sep 17 00:00:00 2001 From: Piotr Pekala Date: Tue, 26 Mar 2019 07:41:28 -0700 Subject: [PATCH] Code refactored --- src/app/app-routing.module.ts | 4 +-- src/app/app.module.ts | 4 +-- .../bundled-server-finder.component.html | 1 + ...l => bundled-server-finder.component.scss} | 0 ...> bundled-server-finder.component.spec.ts} | 24 ++++++++----- .../bundled-server-finder.component.ts | 35 +++++++++++++++++++ .../local-server/local-server.component.scss | 0 .../local-server/local-server.component.ts | 27 -------------- .../project-map/project-map.component.spec.ts | 2 ++ 9 files changed, 58 insertions(+), 39 deletions(-) create mode 100644 src/app/components/local-server/bundled-server-finder.component.html rename src/app/components/local-server/{local-server.component.html => bundled-server-finder.component.scss} (100%) rename src/app/components/local-server/{local-server.component.spec.ts => bundled-server-finder.component.spec.ts} (54%) create mode 100644 src/app/components/local-server/bundled-server-finder.component.ts delete mode 100644 src/app/components/local-server/local-server.component.scss delete mode 100644 src/app/components/local-server/local-server.component.ts diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index a84f3e7a..9cfa01b1 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -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 }, diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 30493562..d48aa042 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -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, diff --git a/src/app/components/local-server/bundled-server-finder.component.html b/src/app/components/local-server/bundled-server-finder.component.html new file mode 100644 index 00000000..8e6c47ac --- /dev/null +++ b/src/app/components/local-server/bundled-server-finder.component.html @@ -0,0 +1 @@ + diff --git a/src/app/components/local-server/local-server.component.html b/src/app/components/local-server/bundled-server-finder.component.scss similarity index 100% rename from src/app/components/local-server/local-server.component.html rename to src/app/components/local-server/bundled-server-finder.component.scss diff --git a/src/app/components/local-server/local-server.component.spec.ts b/src/app/components/local-server/bundled-server-finder.component.spec.ts similarity index 54% rename from src/app/components/local-server/local-server.component.spec.ts rename to src/app/components/local-server/bundled-server-finder.component.spec.ts index 665f0850..872561ca 100644 --- a/src/app/components/local-server/local-server.component.spec.ts +++ b/src/app/components/local-server/bundled-server-finder.component.spec.ts @@ -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; +describe('BundledServerFinderComponent', () => { + let component: BundledServerFinderComponent; + let fixture: ComponentFixture; 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(); })); diff --git a/src/app/components/local-server/bundled-server-finder.component.ts b/src/app/components/local-server/bundled-server-finder.component.ts new file mode 100644 index 00000000..52923732 --- /dev/null +++ b/src/app/components/local-server/bundled-server-finder.component.ts @@ -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); + } +} diff --git a/src/app/components/local-server/local-server.component.scss b/src/app/components/local-server/local-server.component.scss deleted file mode 100644 index e69de29b..00000000 diff --git a/src/app/components/local-server/local-server.component.ts b/src/app/components/local-server/local-server.component.ts deleted file mode 100644 index 32de87a5..00000000 --- a/src/app/components/local-server/local-server.component.ts +++ /dev/null @@ -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']); - }); - } -} diff --git a/src/app/components/project-map/project-map.component.spec.ts b/src/app/components/project-map/project-map.component.spec.ts index 68a856df..1a3d2c4e 100644 --- a/src/app/components/project-map/project-map.component.spec.ts +++ b/src/app/components/project-map/project-map.component.spec.ts @@ -43,6 +43,8 @@ import { Project } from '../../models/project'; export class MockedProgressService { public activate() {} + + public deactivate() {} } export class MockedNodeService {