Improved routing #130
This commit is contained in:
@@ -1,10 +1,45 @@
|
||||
import { Component } from '@angular/core';
|
||||
import { Component, OnInit } from "@angular/core";
|
||||
import { ActivatedRoute, Router } from "@angular/router";
|
||||
import { Server } from "../../../../models/data/server.model";
|
||||
import { Queries } from "../../../../models/graphql/queries.model";
|
||||
import { Query } from "../../../../models/graphql/query.model";
|
||||
import { SpinnerService } from "../../../../services/spinner/spinner.service";
|
||||
import { DataService } from "../../../../services/data/data.service";
|
||||
import { SidebarService } from "../../../../services/sidebar/sidebar.service";
|
||||
|
||||
@Component({
|
||||
selector: 'app-profile',
|
||||
templateUrl: './profile.component.html',
|
||||
styleUrls: ['./profile.component.scss']
|
||||
selector: "app-profile",
|
||||
templateUrl: "./profile.component.html",
|
||||
styleUrls: ["./profile.component.scss"]
|
||||
})
|
||||
export class ProfileComponent {
|
||||
export class ProfileComponent implements OnInit {
|
||||
|
||||
constructor(
|
||||
private route: ActivatedRoute,
|
||||
private router: Router,
|
||||
private spinner: SpinnerService,
|
||||
private data: DataService,
|
||||
private sidebar: SidebarService
|
||||
) {
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.spinner.showSpinner();
|
||||
if (!this.route.snapshot.params["serverId"]) {
|
||||
this.spinner.hideSpinner();
|
||||
this.router.navigate(['/dashboard']);
|
||||
return;
|
||||
}
|
||||
|
||||
this.data.query<Server>(Queries.serversQuery, {
|
||||
filter: { id: this.route.snapshot.params["serverId"] }
|
||||
},
|
||||
function(data: Query) {
|
||||
return data.servers.length > 0 ? data.servers[0] : null;
|
||||
}
|
||||
).subscribe(server => {
|
||||
this.sidebar.server$.next(server);
|
||||
this.spinner.hideSpinner();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user