converter/app/app.component.ts

61 lines
2.2 KiB
TypeScript

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) {
if (typeof console === "object" && typeof console.log === "function") {
console.log(error);
}
result = null;
}
if (result === null) {
step.message = "Error converting. Not applicable?";
step.error = true;
} else {
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();
}
}