46 lines
1.3 KiB
TypeScript
46 lines
1.3 KiB
TypeScript
import {Component, Input} from '@angular/core';
|
|
import {Step} from '../step';
|
|
import {Converter} from '../converter/converter';
|
|
import {InputComponentManagerService} from '../input-component-manager.service';
|
|
|
|
@Component({
|
|
selector: 'app-text-input-field',
|
|
templateUrl: './text-input-field.component.html',
|
|
styleUrls: ['./text-input-field.component.scss']
|
|
})
|
|
export class TextInputFieldComponent {
|
|
@Input()
|
|
public step: Step;
|
|
|
|
constructor(private inputComponentManagerService: InputComponentManagerService) {
|
|
}
|
|
|
|
update(step: Step): void {
|
|
const converter: Converter = step.selectedConverter;
|
|
|
|
if (converter !== undefined) {
|
|
const 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 !== '') {
|
|
const nextComponent: Step = this.inputComponentManagerService.getNext(step);
|
|
nextComponent.content = result;
|
|
this.update(nextComponent);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|