navigation-panel.component.ts 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import { Component, ViewChild } from '@angular/core';
  2. import { Router } from '@angular/router';
  3. import { NavigationPanelService } from 'src/services/navigationPanel/navigation-panel.service';
  4. @Component({
  5. selector: 'navigation-panel',
  6. templateUrl: './navigation-panel.component.html',
  7. styleUrl: './navigation-panel.component.scss',
  8. })
  9. export class NavigationPanelComponent {
  10. @ViewChild('navigationBackdrop') backdrop: any;
  11. @ViewChild('navigationPanel') panel: any;
  12. public active: number = 1;
  13. constructor(
  14. private navigation: NavigationPanelService,
  15. private router: Router
  16. ) {}
  17. public ngOnInit(): void {
  18. this.navigation.showNavigationPanel$.subscribe((state) => {
  19. if (state) {
  20. this.openPanel();
  21. } else {
  22. this.closePanel();
  23. }
  24. });
  25. this.checkForActiveTab();
  26. }
  27. public openPanel(): void {
  28. this.backdrop.nativeElement.classList.add('backdrop--open');
  29. this.panel.nativeElement.classList.add('panel--open');
  30. }
  31. public closePanel(): void {
  32. this.backdrop?.nativeElement.classList.remove('backdrop--open');
  33. this.panel?.nativeElement.classList.remove('panel--open');
  34. }
  35. private checkForActiveTab(): void {
  36. const tab = this.router.url.split('/')[2];
  37. switch (tab) {
  38. case 'stats':
  39. this.active = 1;
  40. break;
  41. case 'character':
  42. this.active = 2;
  43. break;
  44. case 'inventory':
  45. this.active = 3;
  46. break;
  47. case 'spellcards':
  48. this.active = 4;
  49. break;
  50. case 'notes':
  51. this.active = 5;
  52. break;
  53. case 'spellbook':
  54. this.active = 6;
  55. break;
  56. case 'quests':
  57. this.active = 7;
  58. break;
  59. case 'npcs':
  60. this.active = 8;
  61. break;
  62. case 'places':
  63. this.active = 9;
  64. break;
  65. case 'maps':
  66. this.active = 10;
  67. break;
  68. case 'ruleset':
  69. this.active = 11;
  70. break;
  71. default:
  72. this.active = 1;
  73. break;
  74. }
  75. }
  76. public setActiveProperty(number: number) {
  77. this.active = number;
  78. }
  79. }