All files / services/guided-tour guided-tour.service.ts

16.66% Statements 3/18
0% Branches 0/16
33.33% Functions 2/6
17.64% Lines 3/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                      2x   2x       1x                                                                        
import { Injectable } from '@angular/core';
 
import { AppGuidedTourDirective } from '../../components/guided-tour/guided-tour.directive';
 
/**
 * @title Guided tour service.
 * @description This service should be injected once for each tour. Use component `providers` array to declare.
 */
@Injectable({
  providedIn: 'any',
})
export class AppGuidedTourService {
  /** Guider tour steps. */
  private steps: AppGuidedTourDirective[] = [];
 
  /** Guided tour step configuration. */
  public set configuration(steps: AppGuidedTourDirective[]) {
    this.steps = steps.sort((x, y) => (x.appGuidedTour?.index ?? 0) - (y.appGuidedTour?.index ?? 0));
  }
 
  /** Active step. */
  public active?: AppGuidedTourDirective;
 
  /** Activate next step. */
  public next() {
    this.active?.dispose();
    const stepIndex = (this.active?.appGuidedTour?.index ?? -1) + 1;
    if (stepIndex <= this.steps.length - 1) {
      this.active = this.steps.at(stepIndex);
      if (typeof this.active !== 'undefined') {
        this.active.display();
      }
    }
  }
 
  /** Activate previous step. */
  public previous() {
    this.active?.dispose();
    const stepIndex = (this.active?.appGuidedTour?.index ?? -1) - 1;
    if (stepIndex >= 0) {
      this.active = this.steps.at(stepIndex);
      if (typeof this.active !== 'undefined') {
        this.active.display();
      }
    }
  }
 
  /** End tour. */
  public end() {
    this.active?.dispose();
    this.active = void 0;
  }
}