converter/src/app/text-input-field/text-input-field.component.ts

49 lines
1.4 KiB
TypeScript

import {Component, Input} from '@angular/core';
import {Step} from '../step';
import {Converter} from '../converter/converter';
import {InputComponentManagerService} from '../input-component-manager.service';
import {FormsModule} from '@angular/forms';
@Component({
selector: 'app-text-input-field',
templateUrl: './text-input-field.component.html',
standalone: true,
styleUrls: ['./text-input-field.component.scss'],
imports: [FormsModule]
})
export class TextInputFieldComponent {
@Input()
public step!: Step;
constructor(private inputComponentManagerService: InputComponentManagerService) {
}
update(step: Step): void {
const converter: Converter | undefined = step.selectedConverter;
if (converter !== undefined) {
const content: string = step.content;
let result: string | null;
try {
result = converter.convert(content);
} catch (error) {
if (typeof console === 'object' && typeof console.log === 'function') {
console.log(error);
}
step.message = (error as 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);
}
}
}
}
}