31 lines
1.0 KiB
TypeScript
31 lines
1.0 KiB
TypeScript
import { Injectable } from '@angular/core';
|
|
import { BehaviorSubject, Observable } from 'rxjs';
|
|
|
|
import { WorkflowStep } from '../enums/workflow-step.enum';
|
|
|
|
@Injectable({
|
|
providedIn: 'root',
|
|
})
|
|
export class WorkflowService {
|
|
private steps = [WorkflowStep.DESCRIPTION, WorkflowStep.CHOICES, WorkflowStep.CONFIGURATION];
|
|
|
|
private _currentStep: BehaviorSubject<WorkflowStep> = new BehaviorSubject<WorkflowStep>(WorkflowStep[0]);
|
|
public readonly currentStep: Observable<WorkflowStep> = this._currentStep.asObservable();
|
|
|
|
constructor() {}
|
|
|
|
public loadNextStep(): void {
|
|
this._currentStep.next(WorkflowStep[this.getNewIndex(1)]);
|
|
}
|
|
|
|
public loadPriorStep(): void {
|
|
this._currentStep.next(WorkflowStep[this.getNewIndex(-1)]);
|
|
}
|
|
|
|
private getNewIndex(way: number): number {
|
|
const currentIndex: number = Object.keys(WorkflowStep).indexOf(this._currentStep.getValue());
|
|
const newIndex: number = currentIndex + way;
|
|
return 0 <= newIndex && newIndex <= Object.keys(WorkflowStep).length ? newIndex : currentIndex;
|
|
}
|
|
}
|