import {Component, OnInit} from "@angular/core"; import {ConverterRegistryService} from "./converterregistry.service"; import {InputComponentManagerService} from "./inputcomponentmanager.service"; import {Converter} from "./converter/converter"; import {NativeLibraryWrapperService} from "./nativelibrarywrapper.service"; @Component({ moduleId: module.id, selector: "den-app", templateUrl: "app.component.html", styleUrls: ["app.component.css"], providers: [ConverterRegistryService, InputComponentManagerService, NativeLibraryWrapperService] }) export class AppComponent extends OnInit { public steps:any[] = []; public converters:Converter[] = []; constructor(private converterRegistryService:ConverterRegistryService, private inputComponentManagerService:InputComponentManagerService) { super(); } convert(step:any, $event:any):void { step.selectedConverter = this.converterRegistryService.getConverter($event.target.selectedOptions[0].id); this.update(step); } update(step:any):void { let converter:Converter = step.selectedConverter; if (converter !== undefined) { let content:string = step.content; let result:string; try { result = converter.convert(content); } catch (error:Error) { if (typeof console === "object" && typeof console.log === "function") { console.log(error); } step.message = error.message; step.error = true; result = null; } if (result !== null) { step.message = ""; step.error = false; if (result !== "") { let nextComponent:any = this.inputComponentManagerService.getNext(step); nextComponent.content = result; this.update(nextComponent); } } } } ngOnInit():void { this.converters = this.converterRegistryService.getAllConverters(); this.steps = this.inputComponentManagerService.getAllComponents(); this.inputComponentManagerService.getFirst(); } }