Merge branch '11-convert-any-input-data-holder-to-a-class' into 'develop'

created class for the input stuff

Closes #11

See merge request !7
This commit is contained in:
Manuel Friedli 2016-09-22 00:20:37 +02:00
commit f2940b2cb0
3 changed files with 24 additions and 16 deletions

View file

@ -3,6 +3,7 @@ import {ConverterRegistryService} from "./converterregistry.service";
import {InputComponentManagerService} from "./inputcomponentmanager.service";
import {Converter} from "./converter/converter";
import {NativeLibraryWrapperService} from "./nativelibrarywrapper.service";
import {Step} from "./step";
@Component({
moduleId: module.id,
@ -12,19 +13,19 @@ import {NativeLibraryWrapperService} from "./nativelibrarywrapper.service";
providers: [ConverterRegistryService, InputComponentManagerService, NativeLibraryWrapperService]
})
export class AppComponent extends OnInit {
public steps:any[] = [];
public steps:Step[] = [];
public converters:Converter[] = [];
constructor(private converterRegistryService:ConverterRegistryService, private inputComponentManagerService:InputComponentManagerService) {
super();
}
convert(step:any, $event:any):void {
convert(step:Step, $event:any):void {
step.selectedConverter = this.converterRegistryService.getConverter($event.target.selectedOptions[0].id);
this.update(step);
}
update(step:any):void {
update(step:Step):void {
let converter:Converter = step.selectedConverter;
if (converter !== undefined) {
@ -44,7 +45,7 @@ export class AppComponent extends OnInit {
step.message = "";
step.error = false;
if (result !== "") {
let nextComponent:any = this.inputComponentManagerService.getNext(step);
let nextComponent:Step = this.inputComponentManagerService.getNext(step);
nextComponent.content = result;
this.update(nextComponent);
}

View file

@ -1,21 +1,22 @@
import {Injectable} from "@angular/core";
import {Step} from "./step";
@Injectable()
export class InputComponentManagerService {
private components:any[] = [];
private components:Step[] = [];
public constructor() {
}
public register(component:any):void {
public register(component:Step):void {
this.components.push(component);
}
public getAllComponents():any[] {
public getAllComponents():Step[] {
return this.components;
}
public getNext(component:any):any {
public getNext(component:Step):Step {
let index:number = component.index;
if (index == this.components.length - 1) {
this.addComponent();
@ -23,7 +24,7 @@ export class InputComponentManagerService {
return this.components[index + 1];
}
public getFirst():any {
public getFirst():Step {
if (this.components.length == 0) {
this.addComponent();
}
@ -31,12 +32,6 @@ export class InputComponentManagerService {
}
private addComponent():void {
this.register({
content: "",
selectedConverter: undefined,
index: this.components.length,
error: false,
message: ""
});
this.register(new Step(this.components.length));
}
}

12
app/step.ts Normal file
View file

@ -0,0 +1,12 @@
import {Converter} from "./converter/converter";
export class Step {
public content:string = "";
public selectedConverter:Converter = undefined;
public index:number;
public error:boolean = false;
public message:string = "";
constructor(index:number) {
this.index = index;
}
}