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";
|
2016-09-20 20:30:39 +02:00
|
|
|
import {Converter} from "./converter/converter";
|
2016-09-20 22:34:31 +02:00
|
|
|
import {InputComponentManagerService} from "./inputcomponentmanager.service";
|
2016-08-15 17:12:11 +02:00
|
|
|
|
|
|
|
|
|
|
|
@Component({
|
2016-09-15 12:55:13 +02:00
|
|
|
moduleId: module.id,
|
2016-08-15 17:12:11 +02:00
|
|
|
selector: "den-inputarea",
|
2016-09-15 12:55:13 +02:00
|
|
|
templateUrl: "inputarea.component.html",
|
|
|
|
styleUrls: ["inputarea.component.css"]
|
2016-08-15 17:12:11 +02:00
|
|
|
})
|
2016-09-20 20:30:39 +02:00
|
|
|
export class InputareaComponent extends OnInit {
|
|
|
|
public converters:Converter[] = [];
|
|
|
|
public content:string = '';
|
|
|
|
private selectedConverter:Converter;
|
2016-09-15 12:55:13 +02:00
|
|
|
|
2016-09-20 22:34:31 +02:00
|
|
|
constructor(private converterRegistryService:ConverterRegistryService, private inputComponentManagerService:InputComponentManagerService) {
|
2016-09-20 20:30:39 +02:00
|
|
|
super();
|
2016-08-15 17:12:11 +02:00
|
|
|
}
|
2016-09-15 12:55:13 +02:00
|
|
|
|
2016-09-20 20:30:39 +02:00
|
|
|
public convert(e):void {
|
2016-09-20 22:34:31 +02:00
|
|
|
this.selectedConverter = this.converterRegistryService.getConverter(e.target.selectedOptions[0].id);
|
2016-09-20 20:30:39 +02:00
|
|
|
this.update();
|
2016-08-15 17:12:11 +02:00
|
|
|
}
|
2016-09-15 12:55:13 +02:00
|
|
|
|
2016-09-20 20:30:39 +02:00
|
|
|
public update():void {
|
|
|
|
if (this.selectedConverter !== undefined) {
|
|
|
|
let result:string = this.selectedConverter.convert(this.content);
|
2016-09-20 22:34:31 +02:00
|
|
|
let nextComponent:InputareaComponent = this.inputComponentManagerService.getNext(this);
|
2016-09-20 20:30:39 +02:00
|
|
|
if (nextComponent !== undefined) {
|
|
|
|
nextComponent.setContent(result);
|
|
|
|
}
|
2016-08-15 17:12:11 +02:00
|
|
|
}
|
|
|
|
}
|
2016-09-15 12:55:13 +02:00
|
|
|
|
2016-09-20 20:30:39 +02:00
|
|
|
public setContent(content:string):void {
|
|
|
|
this.content = content;
|
|
|
|
this.update();
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit():void {
|
2016-09-20 22:34:31 +02:00
|
|
|
this.converters = this.converterRegistryService.getAllConverters();
|
2016-09-20 20:30:39 +02:00
|
|
|
this.selectedConverter = undefined;
|
2016-09-20 22:34:31 +02:00
|
|
|
this.inputComponentManagerService.register(this);
|
2016-08-15 17:12:11 +02:00
|
|
|
}
|
|
|
|
}
|