57 lines
2 KiB
TypeScript
57 lines
2 KiB
TypeScript
import {Component, OnInit} from "@angular/core";
|
|
import {ConverterregistryService} from "./converterregistry.service";
|
|
import {InputcomponentmanagerService} from "./InputcomponentmanagerService";
|
|
import {Converter} from "./converter/converter";
|
|
|
|
@Component({
|
|
moduleId: module.id,
|
|
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) {
|
|
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();
|
|
}
|
|
}
|