47 lines
1.6 KiB
TypeScript
47 lines
1.6 KiB
TypeScript
import {Component, OnInit} from "@angular/core";
|
|
import {ConverterRegistryService} from "./converterregistry.service";
|
|
import {Converter} from "./converter/converter";
|
|
import {InputComponentManagerService} from "./inputcomponentmanager.service";
|
|
|
|
|
|
@Component({
|
|
moduleId: module.id,
|
|
selector: "den-inputarea",
|
|
templateUrl: "inputarea.component.html",
|
|
styleUrls: ["inputarea.component.css"]
|
|
})
|
|
export class InputareaComponent extends OnInit {
|
|
public converters:Converter[] = [];
|
|
public content:string = '';
|
|
private selectedConverter:Converter;
|
|
|
|
constructor(private converterRegistryService:ConverterRegistryService, private inputComponentManagerService:InputComponentManagerService) {
|
|
super();
|
|
}
|
|
|
|
public convert(e):void {
|
|
this.selectedConverter = this.converterRegistryService.getConverter(e.target.selectedOptions[0].id);
|
|
this.update();
|
|
}
|
|
|
|
public update():void {
|
|
if (this.selectedConverter !== undefined) {
|
|
let result:string = this.selectedConverter.convert(this.content);
|
|
let nextComponent:InputareaComponent = this.inputComponentManagerService.getNext(this);
|
|
if (nextComponent !== undefined) {
|
|
nextComponent.setContent(result);
|
|
}
|
|
}
|
|
}
|
|
|
|
public setContent(content:string):void {
|
|
this.content = content;
|
|
this.update();
|
|
}
|
|
|
|
ngOnInit():void {
|
|
this.converters = this.converterRegistryService.getAllConverters();
|
|
this.selectedConverter = undefined;
|
|
this.inputComponentManagerService.register(this);
|
|
}
|
|
}
|