2017-04-15 19:04:49 +02:00
|
|
|
import {Injectable} from '@angular/core';
|
|
|
|
import {Step} from './step';
|
2016-09-20 22:34:31 +02:00
|
|
|
|
2016-09-20 20:30:39 +02:00
|
|
|
@Injectable()
|
2016-09-20 22:34:31 +02:00
|
|
|
export class InputComponentManagerService {
|
2017-04-15 18:51:22 +02:00
|
|
|
private components: Step[] = [];
|
2016-09-20 20:30:39 +02:00
|
|
|
|
2017-04-15 18:51:22 +02:00
|
|
|
public constructor() {
|
|
|
|
}
|
2016-09-20 20:30:39 +02:00
|
|
|
|
2017-04-15 18:51:22 +02:00
|
|
|
public register(component: Step): void {
|
|
|
|
this.components.push(component);
|
|
|
|
}
|
2016-09-20 20:30:39 +02:00
|
|
|
|
2017-04-15 18:51:22 +02:00
|
|
|
public getAllComponents(): Step[] {
|
|
|
|
return this.components;
|
|
|
|
}
|
2016-09-20 20:30:39 +02:00
|
|
|
|
2017-04-15 18:51:22 +02:00
|
|
|
public getNext(component: Step): Step {
|
2017-04-15 19:04:49 +02:00
|
|
|
const index: number = component.index;
|
|
|
|
if (index === this.components.length - 1) {
|
2017-04-15 18:51:22 +02:00
|
|
|
this.addComponent();
|
2016-09-20 20:30:39 +02:00
|
|
|
}
|
2017-04-15 18:51:22 +02:00
|
|
|
return this.components[index + 1];
|
|
|
|
}
|
2016-09-20 20:30:39 +02:00
|
|
|
|
2017-04-15 18:51:22 +02:00
|
|
|
public getFirst(): Step {
|
2017-04-15 19:04:49 +02:00
|
|
|
if (this.components.length === 0) {
|
2017-04-15 18:51:22 +02:00
|
|
|
this.addComponent();
|
2016-09-20 20:30:39 +02:00
|
|
|
}
|
2017-04-15 18:51:22 +02:00
|
|
|
return this.components[0];
|
|
|
|
}
|
2016-09-20 20:30:39 +02:00
|
|
|
|
2017-04-15 18:51:22 +02:00
|
|
|
private addComponent(): void {
|
|
|
|
this.register(new Step(this.components.length));
|
|
|
|
}
|
|
|
|
}
|