diff --git a/kdb-web/src/app/app.component.ts b/kdb-web/src/app/app.component.ts index 1a2cf35f..8b919479 100644 --- a/kdb-web/src/app/app.component.ts +++ b/kdb-web/src/app/app.component.ts @@ -1,14 +1,21 @@ -import { Component, OnInit } from '@angular/core'; -import { TranslateService } from '@ngx-translate/core'; -import { PrimeNGConfig } from 'primeng/api'; -import { AuthService } from './services/auth/auth.service'; -import { SocketService } from './services/socket/socket.service'; -import { ThemeService } from './services/theme/theme.service'; +import { Component, OnInit } from "@angular/core"; +import { TranslateService } from "@ngx-translate/core"; +import { PrimeNGConfig } from "primeng/api"; +import { AuthService } from "./services/auth/auth.service"; +import { SocketService } from "./services/socket/socket.service"; +import { ThemeService } from "./services/theme/theme.service"; +import { ActivatedRoute, Router } from "@angular/router"; +import { SpinnerService } from "./services/spinner/spinner.service"; +import { DataService } from "./services/data/data.service"; +import { SidebarService } from "./services/sidebar/sidebar.service"; +import { Server } from "./models/data/server.model"; +import { Queries } from "./models/graphql/queries.model"; +import { Query } from "./models/graphql/query.model"; @Component({ - selector: 'app-root', - templateUrl: './app.component.html', - styleUrls: ['./app.component.scss'] + selector: "app-root", + templateUrl: "./app.component.html", + styleUrls: ["./app.component.scss"] }) export class AppComponent implements OnInit { @@ -22,7 +29,7 @@ export class AppComponent implements OnInit { private themeService: ThemeService, private socket: SocketService, private translateService: TranslateService, - private config: PrimeNGConfig + private config: PrimeNGConfig, ) { this.themeService.sidebarWidth$.subscribe(value => { this.sidebarWidth = value; @@ -36,7 +43,7 @@ export class AppComponent implements OnInit { } ngOnInit(): void { - this.translateService.setDefaultLang('en'); + this.translateService.setDefaultLang("en"); this.themeService.loadTheme(); this.socket.startSocket(); @@ -45,7 +52,7 @@ export class AppComponent implements OnInit { loadLang(): void { let lang = localStorage.getItem(`default_lang`); if (!lang) { - lang = 'en'; + lang = "en"; this.setLang(lang); } this.translate(lang); @@ -57,7 +64,7 @@ export class AppComponent implements OnInit { translate(lang: string) { this.translateService.use(lang); - this.translateService.get('primeng').subscribe(res => this.config.setTranslation(res)); + this.translateService.get("primeng").subscribe(res => this.config.setTranslation(res)); } diff --git a/kdb-web/src/app/modules/view/server/profile/profile.component.ts b/kdb-web/src/app/modules/view/server/profile/profile.component.ts index 16fa22f7..f366ee08 100644 --- a/kdb-web/src/app/modules/view/server/profile/profile.component.ts +++ b/kdb-web/src/app/modules/view/server/profile/profile.component.ts @@ -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(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(); + }); + } } diff --git a/kdb-web/src/app/services/sidebar/sidebar.service.ts b/kdb-web/src/app/services/sidebar/sidebar.service.ts index a8177851..79ef2cb4 100644 --- a/kdb-web/src/app/services/sidebar/sidebar.service.ts +++ b/kdb-web/src/app/services/sidebar/sidebar.service.ts @@ -38,6 +38,10 @@ export class SidebarService { if (!(event instanceof NavigationEnd)) { return; } + + if (!event.url.startsWith('/server/')) { + this.server$.next(null); + } }); }