All files / app/component/playlist playlist.component.ts

52.38% Statements 11/21
55.55% Branches 10/18
33.33% Functions 3/9
42.85% Lines 6/14

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 4767x     67x             100x     67x         1x       1x                                                
import { Component, forwardRef, Input, OnChanges, SimpleChanges } from '@angular/core';
import { Ref } from '../../model/ref';
import { RefService } from '../../service/api/ref.service';
import { ViewerComponent } from '../viewer/viewer.component';
 
@Component({
  selector: 'app-playlist',
  templateUrl: './playlist.component.html',
  styleUrls: ['./playlist.component.scss'],
  imports: [
    forwardRef(() => ViewerComponent),
  ],
})
export class PlaylistComponent implements OnChanges {
 
  @Input()
  ref?: Ref;
 
  index = 0;
  page?: Ref;
 
  constructor(
    private refs: RefService,
  ) { }
 
  ngOnChanges(changes: SimpleChanges) {
    if (changes.ref?.currentValue?.sources?.length) {
      this.index = 0;
      this.fetch();
    }
  }
 
  fetch() {
    this.refs.getCurrent(this.ref!.sources![this.index]).subscribe(ref => this.page = ref);
  }
 
  back() {
    this.index = (this.index - 1 + this.ref!.sources!.length) % this.ref!.sources!.length;
    this.fetch();
  }
 
  next() {
    this.index = (this.index + 1) % this.ref!.sources!.length;
    this.fetch();
  }
}