launcher.component.ts 3.41 KB
Newer Older
Chris Hines's avatar
Chris Hines committed
1
2
3
4
5
import { Component, OnInit, NgModule, Inject, Input } from '@angular/core';
import { MatDialog, MatDialogRef, MAT_DIALOG_DATA, MatDialogModule, MatDialogConfig } from '@angular/material';
import { Location } from '@angular/common';
// import { HttpClientModule, HttpClient, HttpHeaders, HttpErrorResponse } from '@angular/common/http';
import { Observable } from 'rxjs/Observable';
Chris Hines's avatar
Chris Hines committed
6
import { Subscription } from 'rxjs';
Chris Hines's avatar
Chris Hines committed
7
8
9
import { fromEvent } from 'rxjs';
import { timer } from 'rxjs/observable/timer';
import { repeat } from 'rxjs/operators';
Chris Hines's avatar
Chris Hines committed
10
import { Router, NavigationStart } from '@angular/router';
Chris Hines's avatar
Chris Hines committed
11

Chris Hines's avatar
Chris Hines committed
12
13
14
import {Strudelapp} from '../strudelapp';
import { StrudelappsService } from '../strudelapps.service';
import { TesService } from '../tes.service';
Chris Hines's avatar
Chris Hines committed
15
import {BackendSelectionService } from '../backend-selection.service';
Chris Hines's avatar
Chris Hines committed
16
import { AuthorisationService } from '../authorisation.service';
Chris Hines's avatar
Chris Hines committed
17
import { Identity } from '../identity';
18
import { Computesite, Health } from '../computesite';
Chris Hines's avatar
Chris Hines committed
19
import { LogoutdialogComponent } from '../logoutdialog/logoutdialog.component';
20

Chris Hines's avatar
Chris Hines committed
21
import { SshAuthzServer } from '../identity';
Chris Hines's avatar
Chris Hines committed
22
import { ComputesitesService } from '../computesites.service';
23
24
import { BehaviorSubject } from 'rxjs/BehaviorSubject';

Chris Hines's avatar
Chris Hines committed
25

26
27


Chris Hines's avatar
Chris Hines committed
28
29
30
31
32
33
34
35
36



@Component({
  selector: 'app-launcher',
  templateUrl: './launcher.component.html',
  styleUrls: ['./launcher.component.css']
})
export class LauncherComponent implements OnInit {
37
  public strudelapps: Strudelapp[];
Chris Hines's avatar
Chris Hines committed
38
  @Input() menuopen: boolean;
Chris Hines's avatar
Chris Hines committed
39

Chris Hines's avatar
Chris Hines committed
40
  public appSubject: BehaviorSubject<Strudelapp>;
41
  public authorised: boolean;
Chris Hines's avatar
Chris Hines committed
42
43
  //public identity: Identity;
  public identitySubject: BehaviorSubject<Identity>;
Chris Hines's avatar
Chris Hines committed
44

45
  public identities: Identity[];
Chris Hines's avatar
Chris Hines committed
46
47
48
  public sshauthzservers: SshAuthzServer[];
  private launchwindow: any;
  private launchwindowWatcher: any;
Chris Hines's avatar
Chris Hines committed
49
  private subscriptions: Subscription[];
Chris Hines's avatar
Chris Hines committed
50
51

  constructor( public dialog: MatDialog,
Chris Hines's avatar
Chris Hines committed
52
                public tesService: TesService,
Chris Hines's avatar
Chris Hines committed
53
                public backendSelectionService: BackendSelectionService,
Chris Hines's avatar
Chris Hines committed
54
                public authService: AuthorisationService,
Chris Hines's avatar
Chris Hines committed
55
                public computeSitesService: ComputesitesService,
Chris Hines's avatar
Chris Hines committed
56
                private router: Router,
57
                ) {
Chris Hines's avatar
Chris Hines committed
58
59
60
61
62
63
64
65
      this.subscriptions = [];
      this.subscriptions.push(this.authService.sshAuthzServers.subscribe(o => {this.updateSshAuthZServers(o)}));
      this.subscriptions.push(this.computeSitesService.appidentities.subscribe(o => this.navLogin(o)));
      this.subscriptions.push(this.computeSitesService.appidentities.subscribe(o => this.getHealth(o)));
      this.appSubject = new BehaviorSubject<Strudelapp>(null);
      this.identitySubject = new BehaviorSubject<Identity>(null);
  }

66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
  countErrors(a: Health[], b: Health[]) {
    var count: number = 0
    var h: Health;
    for (h of a) {
      if (h.stat == 'error') {
        count++;
      }
    }
    for (h of b) {
      if (h.stat == 'error') {
        count++;
      }
    }
    return count;
  }


Chris Hines's avatar
Chris Hines committed
83
84
85
86
  navLogin(o) {
    if (o.length == 0) {
      this.router.navigate(['/login']);
    }
Chris Hines's avatar
Chris Hines committed
87
88
  }

Chris Hines's avatar
Chris Hines committed
89
90
91
92
  getHealth(o) {
    for (let id of o) {
      this.tesService.getHealthAlerts(id);
    }
93
94
95
96
97
98
  }

  updateSshAuthZServers(o) {
    this.sshauthzservers = o;
  }

Chris Hines's avatar
Chris Hines committed
99
100
  ngOnInit() {
    this.strudelapps = [];
Chris Hines's avatar
Chris Hines committed
101

102
  }
Chris Hines's avatar
Chris Hines committed
103

Chris Hines's avatar
Chris Hines committed
104
105
106
107
  ngOnDestroy() {
    for (let s of this.subscriptions) {
      s.unsubscribe();
    }
108
109
  }

Chris Hines's avatar
Chris Hines committed
110
111
112
  selectId(id: Identity) {
    this.identitySubject.next(id);
    this.appSubject.next(null);
113
  }
Chris Hines's avatar
Chris Hines committed
114

Chris Hines's avatar
Chris Hines committed
115
116
  selectApp(app: Strudelapp) {
    this.appSubject.next(app);
117
118
  }

Chris Hines's avatar
Chris Hines committed
119

Chris Hines's avatar
Chris Hines committed
120
}