converter/app/app.component.ts

61 lines
2.1 KiB
TypeScript
Raw Normal View History

import {Component, OnInit} from "@angular/core";
import {ConverterregistryService} from "./converterregistry.service";
import {InputcomponentmanagerService} from "./InputcomponentmanagerService";
import {Converter} from "./converter/converter";
2016-08-15 17:12:11 +02:00
@Component({
moduleId: module.id,
2016-08-15 17:12:11 +02:00
selector: "den-app",
templateUrl: "app.component.html",
styleUrls: ["app.component.css"],
providers: [ConverterregistryService, InputcomponentmanagerService]
})
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) {
2016-09-20 22:02:38 +02:00
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();
}
}