2017-04-15 19:04:49 +02:00
|
|
|
import {Component, OnInit} from '@angular/core';
|
2018-08-31 22:53:50 +02:00
|
|
|
import {ConverterRegistryService} from './converter-registry.service';
|
2018-08-31 22:56:18 +02:00
|
|
|
import {InputComponentManagerService} from './input-component-manager.service';
|
2017-04-15 19:04:49 +02:00
|
|
|
import {Step} from './step';
|
|
|
|
import {Converter} from './converter/converter';
|
2017-03-14 17:35:36 +01:00
|
|
|
|
2016-06-06 15:56:19 +02:00
|
|
|
@Component({
|
2017-04-08 00:24:44 +02:00
|
|
|
selector: 'app-root',
|
|
|
|
templateUrl: './app.component.html',
|
2017-11-07 23:29:36 +01:00
|
|
|
styleUrls: ['./app.component.scss']
|
2016-06-06 15:56:19 +02:00
|
|
|
})
|
2017-04-08 00:24:44 +02:00
|
|
|
export class AppComponent implements OnInit {
|
|
|
|
public steps: Step[] = [];
|
|
|
|
public converters: Converter[] = [];
|
2016-09-20 20:30:39 +02:00
|
|
|
|
2017-04-15 19:04:49 +02:00
|
|
|
constructor(private converterRegistryService: ConverterRegistryService,
|
|
|
|
private inputComponentManagerService: InputComponentManagerService) {
|
2017-04-08 00:24:44 +02:00
|
|
|
}
|
2016-09-15 20:43:37 +02:00
|
|
|
|
2017-04-08 00:24:44 +02:00
|
|
|
convert(step: Step, $event: any): void {
|
|
|
|
step.selectedConverter = this.converterRegistryService.getConverter($event.target.selectedOptions[0].id);
|
|
|
|
this.update(step);
|
|
|
|
}
|
2016-09-20 20:30:39 +02:00
|
|
|
|
2017-04-08 00:24:44 +02:00
|
|
|
update(step: Step): void {
|
2017-04-15 19:04:49 +02:00
|
|
|
const converter: Converter = step.selectedConverter;
|
2016-09-20 20:30:39 +02:00
|
|
|
|
2017-04-08 00:24:44 +02:00
|
|
|
if (converter !== undefined) {
|
2017-04-15 19:04:49 +02:00
|
|
|
const content: string = step.content;
|
2017-04-08 00:24:44 +02:00
|
|
|
let result: string;
|
|
|
|
try {
|
|
|
|
result = converter.convert(content);
|
|
|
|
} catch (error) {
|
2017-04-15 19:04:49 +02:00
|
|
|
if (typeof console === 'object' && typeof console.log === 'function') {
|
2017-04-08 00:24:44 +02:00
|
|
|
console.log(error);
|
|
|
|
}
|
|
|
|
step.message = error.message;
|
|
|
|
step.error = true;
|
|
|
|
result = null;
|
|
|
|
}
|
|
|
|
if (result !== null) {
|
2017-04-15 19:04:49 +02:00
|
|
|
step.message = '';
|
2017-04-08 00:24:44 +02:00
|
|
|
step.error = false;
|
2017-04-15 19:04:49 +02:00
|
|
|
if (result !== '') {
|
|
|
|
const nextComponent: Step = this.inputComponentManagerService.getNext(step);
|
2017-04-08 00:24:44 +02:00
|
|
|
nextComponent.content = result;
|
|
|
|
this.update(nextComponent);
|
2016-09-15 20:43:37 +02:00
|
|
|
}
|
2017-04-08 00:24:44 +02:00
|
|
|
}
|
2016-09-15 20:43:37 +02:00
|
|
|
}
|
2017-04-08 00:24:44 +02:00
|
|
|
}
|
2016-09-20 20:30:39 +02:00
|
|
|
|
2017-04-08 00:24:44 +02:00
|
|
|
ngOnInit(): void {
|
|
|
|
this.converters = this.converterRegistryService.getAllConverters();
|
|
|
|
this.steps = this.inputComponentManagerService.getAllComponents();
|
|
|
|
this.inputComponentManagerService.getFirst();
|
|
|
|
}
|
2016-06-06 15:56:19 +02:00
|
|
|
}
|