converter/src/app/inputcomponentmanager.servi...

38 lines
791 B
TypeScript

import {Injectable} from '@angular/core';
import {Step} from './step';
@Injectable()
export class InputComponentManagerService {
private components: Step[] = [];
public constructor() {
}
public register(component: Step): void {
this.components.push(component);
}
public getAllComponents(): Step[] {
return this.components;
}
public getNext(component: Step): Step {
const index: number = component.index;
if (index === this.components.length - 1) {
this.addComponent();
}
return this.components[index + 1];
}
public getFirst(): Step {
if (this.components.length === 0) {
this.addComponent();
}
return this.components[0];
}
private addComponent(): void {
this.register(new Step(this.components.length));
}
}