/**
 * Created by marc on 09.01.17.
 */ import { Directive , Output , HostListener , EventEmitter , Input , Optional } from '@angular/core' ; import { WizardComponent } from '../components/wizard.component' ; import { isStepOffset , StepOffset } from '../util/step-offset.interface' ; import { isNumber , isString } from 'util' ; import { WizardStep } from '../util/wizard-step.interface' ; author Marc Arndt
  @ Directive ( { selector : '[goToStep]' , } ) export class GoToStepDirective { type { EventEmitter } @ Output ( ) public finalize = new EventEmitter ( ) ; /**
     * The destination step, to which the wizard should navigate, after the component, having this directive has been activated.
     * This destination step can be given either as a [[WizardStep]] containing the step directly,
     * a [[StepOffset]] between the current step and the `wizardStep`, in which this directive has been used,
     * or a step index as a number or string
     */ @ Input ( ) private goToStep : WizardStep | StepOffset | number | string ; param wizard param wizardStep constructor ( private wizard , @ Optional ( ) private wizardStep ) { } returns { number } throws get destinationStep ( ) : number { let destinationStep ; if ( isNumber ( this . goToStep ) ) { destinationStep = this . goToStep as number ; } else if ( isString ( this . goToStep ) ) { destinationStep = parseInt ( this . goToStep as string , 10 ) ; } else if ( isStepOffset ( this . goToStep ) && this . wizardStep !== null ) { destinationStep = this . wizard . getIndexOfStep ( this . wizardStep ) + this . goToStep . stepOffset ; } else if ( this . goToStep instanceof WizardStep ) { destinationStep = this . wizard . getIndexOfStep ( this . goToStep ) ; } else { throw new Error ( `Input 'goToStep' is neither a WizardStep, StepOffset, number or string` ) ; } return destinationStep ; } /**
     * Listener method for `click` events on the component with this directive.
     * After this method is called the wizard will try to transition to the `destinationStep`
     */ @ HostListener ( 'click' , [ '$event' ] ) onClick ( ) { if ( this . wizard . canGoToStep ( this . destinationStep ) ) { this . finalize . emit ( ) ; this . wizard . goToStep ( this . destinationStep ) ; } } }