app.component.ts 2.75 KB
Newer Older
1
import { Component } from '@angular/core';
Chris Hines's avatar
Chris Hines committed
2
import { TesService } from './tes.service';
3
import { AuthorisationService} from './authorisation.service';
Chris Hines's avatar
Chris Hines committed
4
5
6
import { ComputesitesService} from './computesites.service';
import {BehaviorSubject} from 'rxjs/BehaviorSubject';
import { MatSnackBar } from '@angular/material';
Chris Hines's avatar
Chris Hines committed
7
import { Computesite, Health } from './computesite';
8
import {SettingsService } from './settings.service';
9
import {BrowserWindowService} from './browser-window.service';
Chris Hines's avatar
Chris Hines committed
10
import {OverlayContainer} from '@angular/cdk/overlay';
11
import {NotificationsService} from './notifications.service';
12
13
import {ActivatedRoute, Router, NavigationEnd } from '@angular/router';
import {filter} from 'rxjs/operators';
14

Chris Hines's avatar
Chris Hines committed
15

16
17
18
19
20
21
22

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
Chris Hines's avatar
Chris Hines committed
23
  title = 'Strudelv2';
Chris Hines's avatar
Chris Hines committed
24
  private snackBarRef: any;
25
  private currentroute: string = '';
26
27
  public loggedin: number = 0;
  public loggedout: number = 0;
Chris Hines's avatar
Chris Hines committed
28

Chris Hines's avatar
Chris Hines committed
29
30
  constructor(private tesService: TesService,
              private authService: AuthorisationService,
31
              private computeSitesService: ComputesitesService,
Chris Hines's avatar
Chris Hines committed
32
              public settingsService: SettingsService,
33
              private browserWindowService: BrowserWindowService,
Chris Hines's avatar
Chris Hines committed
34
              public snackBar: MatSnackBar,
35
              private overlayContainer: OverlayContainer,
36
37
              private route: ActivatedRoute,
              private router: Router,
38
              private notifications: NotificationsService) {
Chris Hines's avatar
Chris Hines committed
39

Chris Hines's avatar
Chris Hines committed
40
41
42
   };

  ngOnInit() {
43
    const isdefined = filter(v  => v !== null && v !== undefined)
44
    this.notifications.getMsg().subscribe(msg => this.displayMessage(msg));
45
    this.settingsService.theme$.subscribe((v) => this.setTheme(v))
46
47
    this.authService.loggedInAuthZ.pipe(
      isdefined
Chris Hines's avatar
Chris Hines committed
48
    ).subscribe((v) => { this.loggedin = (<[]>v).length } );
49
50
    this.authService.loggedOutAuthZ.pipe(
      isdefined
Chris Hines's avatar
Chris Hines committed
51
    ).subscribe((v) => { this.loggedout = (<[]>v).length } );
Chris Hines's avatar
Chris Hines committed
52
53
  }

54
55
56
57
58
59
60
61
  toggleMenu() {
    if (this.settingsService.menuToggle$.value == true) {
      this.settingsService.menuToggle$.next(false);
      return
    }
    this.settingsService.menuToggle$.next(true);
  }

Chris Hines's avatar
Chris Hines committed
62
63
64
65
66
67
68
69
70
71

  private displayMessage(msg) {
   if (msg === null || msg == "") {
     if (this.snackBarRef != undefined) {
       this.snackBarRef.dismiss()
     }
   } else {
     this.snackBarRef = this.snackBar.open(msg,'Dismiss');
   }
 }
72
  setTheme(theme: string)  {
73
    if (theme == null) {
74
      theme = 'strudel-light-theme';
75
    }
Chris Hines's avatar
Chris Hines committed
76
77
    let container = document.querySelector('app-root');
    let classList = container.classList;
78
79
80
81
82
83
84
85
    var c;
    for (c of classList.value.split(' ')) {
      if (c.indexOf('strudel-') == 0) {
        classList.remove(c);
      }
    }
    classList.add(theme);
  }
86

87
}