All files / src/app/components/command-center command-center.component.ts

100% Statements 20/20
100% Branches 6/6
100% Functions 11/11
100% Lines 18/18

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 62 63 64 65 66 67 68                                  120x           24x     24x   24x 24x           12132x       3x 3x 1x 1x   2x   2x           46x   46x 22x 22x   24x   24x              
import { Component, OnInit } from '@angular/core';
import { NgIf } from '@angular/common';
import { SelectModule } from 'primeng/select';
import { FormsModule } from '@angular/forms';
 
import { SignalCommandComponent } from '../signal-command/signal-command.component';
import { Signal, SignalGroup } from '../../models/signals';
import { TwinpadApiService } from '../../services/twinpad-api.service';
import { first } from 'rxjs';
import { groupSignalIds } from '../../utils/utils';
 
@Component({
  selector: 'app-command-center',
  imports: [SignalCommandComponent, NgIf, SelectModule, FormsModule],
  templateUrl: './command-center.component.html',
  styleUrl: './command-center.component.scss'
})
export class CommandCenterComponent implements OnInit {
  signalIds: string[];
  signalIdsToDisplay: SignalGroup[];
  _selectedSignalId: string;
  signal: Signal | undefined;
 
  constructor(private twinpadApiService: TwinpadApiService) {}
 
  ngOnInit(): void {
    this.twinpadApiService.getSignalsIds().subscribe({
      next: signalIds => {
        this.signalIds = signalIds;
        this.filterSignalIds();
      }
    });
  }
 
  get selectedSignalId() {
    return this._selectedSignalId;
  }
 
  set selectedSignalId(newValue: string) {
    this._selectedSignalId = newValue;
    if (this._selectedSignalId === null) {
      this.signal = undefined;
      return;
    }
    this.twinpadApiService.getSignal(this._selectedSignalId).subscribe({
      next: signal => {
        this.signal = signal;
      }
    });
  }
 
  filterSignalIds() {
    this.twinpadApiService.devicesBehaviorSubject$.pipe(first()).subscribe({
      next: devices => {
        if (devices.length === 0) {
          setTimeout(() => this.filterSignalIds(), 50);
          return;
        }
        this.twinpadApiService.getConfigIds().subscribe({
          next: configs => {
            this.signalIdsToDisplay = groupSignalIds(devices, this.signalIds, configs);
          }
        });
      }
    });
  }
}