credentials.component.ts 1.58 KB
Newer Older
Lukas Burgey's avatar
Lukas Burgey committed
1 2
import { Component, OnInit, Inject } from '@angular/core';
import { MAT_DIALOG_DATA, MatTableDataSource } from '@angular/material';
3

4 5
import { Observable } from 'rxjs';

6
import { UserService } from '../../user.service';
Lukas Burgey's avatar
Lukas Burgey committed
7
import { LanguageService } from '../../language.service';
Lukas Burgey's avatar
Lukas Burgey committed
8
import { DeploymentState, Service, CredentialState } from '../../types/types.module';
9 10 11 12 13 14 15

@Component({
  selector: 'app-credentials',
  templateUrl: './credentials.component.html',
  styleUrls: ['./credentials.component.css']
})
export class CredentialsComponent implements OnInit {
Lukas Burgey's avatar
Lukas Burgey committed
16

17
  public columns = ["name", "value"];
18
  public stateItem$: Observable<DeploymentState>;
Lukas Burgey's avatar
Lukas Burgey committed
19
  public service: Service;
20 21 22 23 24
  public credentialCount: number = 0;
  public table: MatTableDataSource<any>;

  constructor(
    public userService: UserService,
Lukas Burgey's avatar
Lukas Burgey committed
25
    public lang: LanguageService,
26 27
    @Inject(MAT_DIALOG_DATA) public data: any,
  ) {
28 29 30
    if (data) {
      this.stateItem$ = data.stateItem$;
    }
31 32 33
  }

  ngOnInit() {
34 35 36 37
    if (this.stateItem$) {
      this.stateItem$.subscribe(
        (stateItem: DeploymentState) => {
          this.service = stateItem.service;
Lukas Burgey's avatar
Lukas Burgey committed
38

39 40 41 42 43 44 45 46 47
          const credentialList = [];
          for (const key in stateItem.credentials) {
            if (stateItem.credentials.hasOwnProperty(key)) {
              credentialList.push(
                {
                  name: key,
                  value: stateItem.credentials[key],
                }
              );
Lukas Burgey's avatar
Lukas Burgey committed
48
            }
49 50 51
          }
          this.credentialCount = credentialList.length;
          this.table =  new MatTableDataSource(credentialList);
Lukas Burgey's avatar
Lukas Burgey committed
52
        }
53
      );
54 55 56
    }
  }
}