Local server support

This commit is contained in:
ziajka 2018-06-26 11:13:09 +02:00
parent f1493800cd
commit 0cb1b4197a
10 changed files with 98 additions and 11 deletions

View File

@ -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 },
]

View File

@ -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(),

View 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();
});
});

View 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']);
});
}
}

View File

@ -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;

View File

@ -8,4 +8,5 @@ export class Server {
authorization: ServerAuthorization;
login: string;
password: string;
is_local: boolean;
}

View File

@ -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(() => {

View File

@ -1,3 +1,5 @@
export const environment = {
production: true
production: true,
electron: false,
githubio: false
};