app.component.ts 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import { Component, OnInit } from '@angular/core';
  2. import { ActivationEnd, Router } from '@angular/router';
  3. import { faAngleDown, faAngleRight, faChalkboard, faServer } from '@fortawesome/free-solid-svg-icons';
  4. import { filter, Subscription } from 'rxjs';
  5. import { ServerApiService } from './services/server-api.service';
  6. @Component({
  7. selector: 'app-root',
  8. templateUrl: './app.component.html',
  9. styleUrls: ['./app.component.scss']
  10. })
  11. export class AppComponent implements OnInit {
  12. private subscriptions: Subscription[] = [];
  13. public fa = { faAngleDown, faAngleRight, faChalkboard, faServer };
  14. public serverConfigs: ServerConfig[] = [];
  15. public currentUrl: string = '/';
  16. constructor(private apiService: ServerApiService, router: Router) {
  17. this.subscriptions.push(
  18. this.apiService.serverConfigs$.subscribe({ next: this.onServerConfigs.bind(this) }),
  19. router.events.pipe(filter(e => e instanceof ActivationEnd)).subscribe({
  20. next: e => {
  21. this.currentUrl = '/' + (e as ActivationEnd).snapshot.url.map(seg => seg.path).join('/');
  22. }
  23. })
  24. );
  25. }
  26. async ngOnInit() {
  27. try {
  28. const servers = await this.apiService.getAllServerConfigs();
  29. servers.forEach(server => this.apiService.getServerDataTypes(server.id));
  30. } catch (err) {
  31. console.error(err);
  32. }
  33. }
  34. private onServerConfigs(data: ServerConfig[]) {
  35. this.serverConfigs = data;
  36. }
  37. }