diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index 3691417b..59d1ae19 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -8,6 +8,7 @@ import { ServersComponent } from "./servers/servers.component"; import { ProjectsComponent } from "./projects/projects.component"; import { DefaultLayoutComponent } from "./default-layout/default-layout.component"; import { SettingsComponent } from "./settings/settings.component"; +import { LocalServerComponent } from "./local-server/local-server.component"; const routes: Routes = [ @@ -15,6 +16,7 @@ const routes: Routes = [ children: [ { path: '', redirectTo: 'servers', pathMatch: 'full'}, { path: 'servers', component: ServersComponent }, + { path: 'local', component: LocalServerComponent }, { path: 'server/:server_id/projects', component: ProjectsComponent }, { path: 'settings', component: SettingsComponent }, ] diff --git a/src/app/app.module.ts b/src/app/app.module.ts index dc43ce8c..7c4ba936 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -75,6 +75,7 @@ import { SettingsComponent } from './settings/settings.component'; import { SettingsService } from "./shared/services/settings.service"; import { RavenErrorHandler } from "./raven-error-handler"; +import { LocalServerComponent } from './local-server/local-server.component'; Raven .config('https://b2b1cfd9b043491eb6b566fd8acee358@sentry.io/842726') @@ -102,6 +103,7 @@ Raven MoveLayerUpActionComponent, ProjectMapShortcutsComponent, SettingsComponent, + LocalServerComponent, ], imports: [ NgbModule.forRoot(), diff --git a/src/app/local-server/local-server.component.html b/src/app/local-server/local-server.component.html new file mode 100644 index 00000000..e69de29b diff --git a/src/app/local-server/local-server.component.scss b/src/app/local-server/local-server.component.scss new file mode 100644 index 00000000..e69de29b diff --git a/src/app/local-server/local-server.component.spec.ts b/src/app/local-server/local-server.component.spec.ts new file mode 100644 index 00000000..04c04a2b --- /dev/null +++ b/src/app/local-server/local-server.component.spec.ts @@ -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; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ LocalServerComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(LocalServerComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/local-server/local-server.component.ts b/src/app/local-server/local-server.component.ts new file mode 100644 index 00000000..fd1a8964 --- /dev/null +++ b/src/app/local-server/local-server.component.ts @@ -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']); + }); + } + +} diff --git a/src/app/projects/projects.component.ts b/src/app/projects/projects.component.ts index f66f200c..5c9a3711 100644 --- a/src/app/projects/projects.component.ts +++ b/src/app/projects/projects.component.ts @@ -46,7 +46,7 @@ export class ProjectsComponent implements OnInit { this.route.paramMap .switchMap((params: ParamMap) => { const server_id = params.get('server_id'); - return this.serverService.getLocalOrRemote(server_id); + return this.serverService.get(parseInt(server_id, 10)); }) .subscribe((server: Server) => { this.server = server; diff --git a/src/app/shared/models/server.ts b/src/app/shared/models/server.ts index e3a381a0..fcac8277 100644 --- a/src/app/shared/models/server.ts +++ b/src/app/shared/models/server.ts @@ -8,4 +8,5 @@ export class Server { authorization: ServerAuthorization; login: string; password: string; + is_local: boolean; } diff --git a/src/app/shared/services/server.service.ts b/src/app/shared/services/server.service.ts index 36d3313d..f9ad00ae 100644 --- a/src/app/shared/services/server.service.ts +++ b/src/app/shared/services/server.service.ts @@ -22,15 +22,6 @@ export class ServerService { 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) { return this.onReady(() => { 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() { return this.onReady(() => this.indexedDbService.get().getAll(this.tablename)); @@ -53,6 +55,32 @@ export class ServerService { 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) { const promise = new Promise((resolve, reject) => { this.ready.then(() => { diff --git a/src/environments/environment.prod.ts b/src/environments/environment.prod.ts index 3612073b..cbe10f98 100644 --- a/src/environments/environment.prod.ts +++ b/src/environments/environment.prod.ts @@ -1,3 +1,5 @@ export const environment = { - production: true + production: true, + electron: false, + githubio: false };