From 56ccace5638adb718e4c515e126ddef40bbdc7d8 Mon Sep 17 00:00:00 2001 From: Manuel Friedli Date: Thu, 22 Sep 2016 00:15:11 +0200 Subject: [PATCH] created class for the input stuff --- app/app.component.ts | 9 +++++---- app/inputcomponentmanager.service.ts | 19 +++++++------------ app/step.ts | 12 ++++++++++++ 3 files changed, 24 insertions(+), 16 deletions(-) create mode 100644 app/step.ts diff --git a/app/app.component.ts b/app/app.component.ts index 12cf4e3..97a015e 100644 --- a/app/app.component.ts +++ b/app/app.component.ts @@ -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); } diff --git a/app/inputcomponentmanager.service.ts b/app/inputcomponentmanager.service.ts index a15b97c..4b93a70 100644 --- a/app/inputcomponentmanager.service.ts +++ b/app/inputcomponentmanager.service.ts @@ -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)); } } \ No newline at end of file diff --git a/app/step.ts b/app/step.ts new file mode 100644 index 0000000..fb4d584 --- /dev/null +++ b/app/step.ts @@ -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; + } +} \ No newline at end of file