61 lines
1.6 KiB
TypeScript
61 lines
1.6 KiB
TypeScript
import {Component, OnInit} from '@angular/core';
|
|
import {InputOutputComponent} from "../input-output/input-output.component";
|
|
import {JsonTransformService} from "../json-transform.service";
|
|
import {
|
|
DebounceTime,
|
|
GenerateDefaultJsonObjectString,
|
|
MonacoJsonConfig,
|
|
ReadOnlyMonacoCSharpConfig
|
|
} from "../defaults";
|
|
import {BehaviorSubject, debounceTime} from "rxjs";
|
|
|
|
@Component({
|
|
selector: 'app-json2csharp',
|
|
standalone: true,
|
|
imports: [
|
|
InputOutputComponent
|
|
],
|
|
templateUrl: './json2-csharp.component.html',
|
|
styleUrl: './json2-csharp.component.scss'
|
|
})
|
|
export class Json2CsharpComponent implements OnInit {
|
|
$input: BehaviorSubject<string> = new BehaviorSubject<string>(GenerateDefaultJsonObjectString(2));
|
|
inputOptions = MonacoJsonConfig;
|
|
output: string = "";
|
|
outputOptions = ReadOnlyMonacoCSharpConfig;
|
|
|
|
constructor(private service: JsonTransformService) {
|
|
}
|
|
|
|
ngOnInit(): void {
|
|
this.$input
|
|
.pipe(debounceTime(DebounceTime))
|
|
.subscribe(input => this.update(input));
|
|
|
|
this.update(this.$input.value);
|
|
}
|
|
|
|
update(input: string): void {
|
|
this.service
|
|
.json2csharp(input)
|
|
.subscribe({
|
|
next: response => {
|
|
console.log(response);
|
|
this.output = response.body.result;
|
|
},
|
|
error: response => {
|
|
console.log(response)
|
|
if (response.status === 499) {
|
|
this.output = response.error.detail;
|
|
console.log(response.error.detail);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
handleInputChange($event: any): void {
|
|
console.log($event);
|
|
this.$input.next($event);
|
|
}
|
|
}
|