All files / src/app/components/leftbar leftbar.component.ts

83.33% Statements 15/18
50% Branches 2/4
70% Functions 7/10
82.35% Lines 14/17

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61                          197x 87x   87x   87x 87x       87x   85x             87x   214x       87x   159x       87x   84x                       110x    
import { Component, OnInit, inject } from '@angular/core';
import { RouterLink } from '@angular/router';
import { NgClass } from '@angular/common';
import { Device } from '../../models/devices';
import { StatusCountPipe } from '../../status-count.pipe';
import { TwinpadApiService } from '../../services/twinpad-api.service';
 
@Component({
    selector: 'app-leftbar',
    imports: [RouterLink, NgClass, StatusCountPipe],
    templateUrl: './leftbar.component.html',
    styleUrl: './leftbar.component.scss'
})
export class LeftbarComponent implements OnInit {
  private twinpadApiService = inject(TwinpadApiService);
 
  showSubMenu = false;
  isCloudReachable: boolean;
  displayDeployers: boolean = false;
  devices: Device[] | undefined = undefined;
  addCustomView: string;
 
  constructor(){
    this.twinpadApiService.getProfile().subscribe({
      next: value => {
        this.addCustomView = "/customViewsBuilder/"+value.id+"/new";
      },
      error: _ => {}
    });
  }
 
  ngOnInit(): void {
    this.twinpadApiService.devicesBehaviorSubject$.subscribe({
      next: devices => {
        this.devices = devices;
      }
    });
 
    this.twinpadApiService.cloudStatusBehaviorSubject$.subscribe({
      next: cloudStatus => {
        this.isCloudReachable = cloudStatus.services.backend === "up";
      }
    });
 
    this.twinpadApiService.getDeviceDeployers().subscribe({
      next: _ => {
        this.displayDeployers = true;
      },
      error: err => {
        if (err.status !== 404) {
          this.displayDeployers = true;
        }
      }
    });
  }
 
  toggleSubMenu(){
    this.showSubMenu = !this.showSubMenu;
  }
}