2016-09-20 20:30:39 +02:00
|
|
|
import {Component, OnInit} from "@angular/core";
|
2016-09-20 22:34:31 +02:00
|
|
|
import {ConverterRegistryService} from "./converterregistry.service";
|
|
|
|
import {InputComponentManagerService} from "./inputcomponentmanager.service";
|
2016-09-20 20:30:39 +02:00
|
|
|
import {Converter} from "./converter/converter";
|
2016-09-20 22:34:31 +02:00
|
|
|
import {NativeLibraryWrapperService} from "./nativelibrarywrapper.service";
|
2016-08-15 17:12:11 +02:00
|
|
|
|
2016-06-06 15:56:19 +02:00
|
|
|
@Component({
|
2016-09-15 12:55:13 +02:00
|
|
|
moduleId: module.id,
|
2016-08-15 17:12:11 +02:00
|
|
|
selector: "den-app",
|
2016-09-15 12:55:13 +02:00
|
|
|
templateUrl: "app.component.html",
|
2016-09-15 20:43:37 +02:00
|
|
|
styleUrls: ["app.component.css"],
|
2016-09-20 22:34:31 +02:00
|
|
|
providers: [ConverterRegistryService, InputComponentManagerService, NativeLibraryWrapperService]
|
2016-06-06 15:56:19 +02:00
|
|
|
})
|
2016-09-15 20:43:37 +02:00
|
|
|
export class AppComponent extends OnInit {
|
2016-09-20 20:30:39 +02:00
|
|
|
public steps:any[] = [];
|
|
|
|
public converters:Converter[] = [];
|
|
|
|
|
2016-09-20 22:34:31 +02:00
|
|
|
constructor(private converterRegistryService:ConverterRegistryService, private inputComponentManagerService:InputComponentManagerService) {
|
2016-09-15 20:43:37 +02:00
|
|
|
super();
|
|
|
|
}
|
|
|
|
|
2016-09-20 20:30:39 +02:00
|
|
|
convert(step:any, $event:any):void {
|
2016-09-20 22:34:31 +02:00
|
|
|
step.selectedConverter = this.converterRegistryService.getConverter($event.target.selectedOptions[0].id);
|
2016-09-20 20:30:39 +02:00
|
|
|
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);
|
2016-09-21 13:36:39 +02:00
|
|
|
} catch (error:Error) {
|
2016-09-20 22:02:38 +02:00
|
|
|
if (typeof console === "object" && typeof console.log === "function") {
|
|
|
|
console.log(error);
|
|
|
|
}
|
2016-09-21 13:36:39 +02:00
|
|
|
step.message = error.message;
|
|
|
|
step.error = true;
|
2016-09-20 20:30:39 +02:00
|
|
|
result = null;
|
|
|
|
}
|
2016-09-21 13:36:39 +02:00
|
|
|
if (result !== null) {
|
2016-09-20 20:30:39 +02:00
|
|
|
step.message = "";
|
|
|
|
step.error = false;
|
|
|
|
if (result !== "") {
|
2016-09-20 22:34:31 +02:00
|
|
|
let nextComponent:any = this.inputComponentManagerService.getNext(step);
|
2016-09-20 20:30:39 +02:00
|
|
|
nextComponent.content = result;
|
|
|
|
this.update(nextComponent);
|
|
|
|
}
|
|
|
|
}
|
2016-09-15 20:43:37 +02:00
|
|
|
}
|
|
|
|
}
|
2016-09-20 20:30:39 +02:00
|
|
|
|
|
|
|
ngOnInit():void {
|
2016-09-20 22:34:31 +02:00
|
|
|
this.converters = this.converterRegistryService.getAllConverters();
|
|
|
|
this.steps = this.inputComponentManagerService.getAllComponents();
|
|
|
|
this.inputComponentManagerService.getFirst();
|
2016-09-20 20:30:39 +02:00
|
|
|
}
|
2016-06-06 15:56:19 +02:00
|
|
|
}
|