server reolver for projects page

This commit is contained in:
piotrpekala7 2020-02-10 11:52:39 +01:00
parent e11281ddf6
commit f5ee039510
5 changed files with 28 additions and 18 deletions

View File

@ -61,6 +61,7 @@ import { PageNotFoundComponent } from './components/page-not-found/page-not-foun
import { Gns3vmComponent } from './components/preferences/gns3vm/gns3vm.component';
import { DirectLinkComponent } from './components/direct-link/direct-link.component';
import { SystemStatusComponent } from './components/system-status/system-status.component';
import { ServerResolve } from './resolvers/server-resolve';
const routes: Routes = [
{
@ -70,7 +71,11 @@ const routes: Routes = [
{ path: '', redirectTo: 'servers', pathMatch: 'full' },
{ path: 'servers', component: ServersComponent },
{ path: 'bundled', component: BundledServerFinderComponent },
{ path: 'server/:server_id/projects', component: ProjectsComponent },
{
path: 'server/:server_id/projects',
component: ProjectsComponent,
resolve: { server : ServerResolve }
},
{ path: 'help', component: HelpComponent },
{ path: 'settings', component: SettingsComponent },
{ path: 'settings/console', component: ConsoleComponent },

View File

@ -266,6 +266,7 @@ import { StatusChartComponent } from './components/system-status/status-chart/st
import { NgCircleProgressModule } from 'ng-circle-progress';
import { OpenFileExplorerActionComponent } from './components/project-map/context-menu/actions/open-file-explorer/open-file-explorer-action.component';
import { NgxChildProcessModule } from 'ngx-childprocess';
import { ServerResolve } from './resolvers/server-resolve';
if (environment.production) {
Raven.config('https://b2b1cfd9b043491eb6b566fd8acee358@sentry.io/842726', {
@ -538,7 +539,8 @@ if (environment.production) {
NotificationService,
Gns3vmService,
ThemeService,
GoogleAnalyticsService
GoogleAnalyticsService,
ServerResolve
],
entryComponents: [
AddServerDialogComponent,

View File

@ -41,7 +41,6 @@ export class ProjectsComponent implements OnInit {
constructor(
private route: ActivatedRoute,
private serverService: ServerService,
private projectService: ProjectService,
private settingsService: SettingsService,
private progressService: ProgressService,
@ -53,24 +52,13 @@ export class ProjectsComponent implements OnInit {
) {}
ngOnInit() {
this.server = this.route.snapshot.data['server'];
this.refresh();
this.sort.sort(<MatSortable>{
id: 'name',
start: 'asc'
});
this.dataSource = new ProjectDataSource(this.projectDatabase, this.sort);
this.route.paramMap
.pipe(
switchMap((params: ParamMap) => {
const server_id = params.get('server_id');
return this.serverService.get(parseInt(server_id, 10));
})
)
.subscribe((server: Server) => {
this.server = server;
this.refresh();
});
this.settings = this.settingsService.getAll();
let gns3vmConfig = localStorage.getItem('gns3vmConfig');

View File

@ -0,0 +1,15 @@
import { Injectable } from "@angular/core";
import { Resolve, ActivatedRouteSnapshot } from '@angular/router';
import { ServerService } from '../services/server.service';
import { Server } from '../models/server';
@Injectable()
export class ServerResolve implements Resolve<Server> {
constructor(
private serverService: ServerService
) {}
resolve(route: ActivatedRouteSnapshot) {
return this.serverService.get(parseInt(route.params['server_id']));
}
}

View File

@ -18,8 +18,8 @@ export class ServerService {
});
}
public get(id: number) {
return this.onReady(() => this.indexedDbService.get().getByKey(this.tablename, id));
public get(id: number): Promise<Server> {
return this.onReady(() => this.indexedDbService.get().getByKey(this.tablename, id)) as Promise<Server>;
}
public create(server: Server) {