converter/app/inputcomponentmanager.service.ts

37 lines
855 B
TypeScript
Raw Normal View History

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