61 lines
2.2 KiB
TypeScript
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";
|
|
import {Step} from "./step";
|
|
|
|
@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:Step[] = [];
|
|
public converters:Converter[] = [];
|
|
|
|
constructor(private converterRegistryService:ConverterRegistryService, private inputComponentManagerService:InputComponentManagerService) {
|
|
super();
|
|
}
|
|
|
|
convert(step:Step, $event:any):void {
|
|
step.selectedConverter = this.converterRegistryService.getConverter($event.target.selectedOptions[0].id);
|
|
this.update(step);
|
|
}
|
|
|
|
update(step:Step):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);
|
|
}
|
|
step.message = error.message;
|
|
step.error = true;
|
|
result = null;
|
|
}
|
|
if (result !== null) {
|
|
step.message = "";
|
|
step.error = false;
|
|
if (result !== "") {
|
|
let nextComponent:Step = 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();
|
|
}
|
|
}
|