All files / tools/ReFlex.TrackingServer/ClientApp/src/app/measure-surface/measure-controls measure-controls.component.ts

100% Statements 32/32
100% Branches 10/10
100% Functions 12/12
100% Lines 29/29

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 69 70 71 72 73 74 75 76 77 78 792x                     2x 2x 2x 2x                 62x 8x   8x   8x 8x 8x 8x         8x 8x 8x   23x   12x 12x 12x   12x   2x     20x 20x   20x               11x       2x       1x   1x 1x          
import { markViewForCheck } from 'src/shared/util/mark-view-for-check';
 
import {
  ChangeDetectionStrategy,
  ChangeDetectorRef,
  Component,
  OnDestroy,
  OnInit,
  inject
} from '@angular/core';
import { FormsModule } from '@angular/forms';
import { Observable, Subscription, timer } from 'rxjs';
import { catchError, concatMap, map } from 'rxjs/operators';
import { LogService } from 'src/app/log/log.service';
import { MeasureService } from 'src/shared/services/measure.service';
 
@Component({
  selector: 'app-measure-controls',
  templateUrl: './measure-controls.component.html',
  styleUrls: ['./measure-controls.component.scss'],
  changeDetection: ChangeDetectionStrategy.Eager,
  imports: [FormsModule]
})
export class MeasureControlsComponent implements OnInit, OnDestroy {
  public captureId = 0;
 
  public numFramesCaptured = 0;
 
  public isCapturing = false;
  private readonly changeDetector = inject(ChangeDetectorRef);
  private readonly measureService = inject(MeasureService);
  private readonly logService = inject(LogService);
 
  private captureState?: Subscription;
 
  public ngOnInit(): void {
    const isCapturing$ = this.measureService.isCapturing();
    const sampleIdx$ = this.measureService.getCurrentSampleIdx();
    this.captureState = timer(0, 500)
      .pipe(
        concatMap(() => isCapturing$),
        map((result) => {
          this.isCapturing = result;
          this.changeDetector.markForCheck();
          console.log(this.isCapturing);
        }),
        concatMap(() => sampleIdx$),
        map((result) => {
          this.numFramesCaptured = result;
        }),
        catchError((error: unknown, caught: Observable<void>) => {
          console.error(error);
          this.logService.sendErrorLog(`${error}`);
 
          return caught;
        })
      )
      .pipe(markViewForCheck(this.changeDetector))
      .subscribe();
  }
 
  public ngOnDestroy(): void {
    this.captureState?.unsubscribe();
  }
 
  public captureFrames(): void {
    this.measureService
      .startCapture(this.captureId)
      .pipe(markViewForCheck(this.changeDetector))
      .subscribe(
        (result) => console.info(result),
        (error: unknown) => {
          console.error(error);
          this.logService.sendErrorLog(`${error}`);
        }
      );
  }
}