Initial commit

This commit is contained in:
2024-10-18 14:38:57 +02:00
commit 376c42c3e6
50 changed files with 15555 additions and 0 deletions

View File

@@ -0,0 +1,13 @@
<h1>JSON to C#</h1>
<mat-form-field>
<mat-label>Path</mat-label>
<input matInput placeholder="$.*" [value]="$path.value" (input)="handlePathChange($event)">
</mat-form-field>
<app-input-output [input]="$input.value"
[inputOptions]="inputOptions"
(onInputChange)="handleInputChange($event)"
[output]="output"
[outputOptions]="outputOptions">
</app-input-output>

View File

@@ -0,0 +1,3 @@
mat-form-field {
width: 100%;
}

View File

@@ -0,0 +1,23 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { JsonPathComponent } from './json-path.component';
describe('JsonPathComponent', () => {
let component: JsonPathComponent;
let fixture: ComponentFixture<JsonPathComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [JsonPathComponent]
})
.compileComponents();
fixture = TestBed.createComponent(JsonPathComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@@ -0,0 +1,69 @@
import {Component, OnInit} from '@angular/core';
import {InputOutputComponent} from "../input-output/input-output.component";
import {DebounceTime, GenerateDefaultJsonObjectString, MonacoJsonConfig, ReadOnlyMonacoCSharpConfig} from "../defaults";
import {BehaviorSubject, debounceTime} from "rxjs";
import {JsonTransformService} from "../json-transform.service";
import {MatFormField} from "@angular/material/form-field";
import {MatInputModule} from "@angular/material/input";
@Component({
selector: 'app-json-path',
standalone: true,
imports: [
InputOutputComponent,
MatFormField,
MatInputModule
],
templateUrl: './json-path.component.html',
styleUrl: './json-path.component.scss'
})
export class JsonPathComponent implements OnInit {
$path: BehaviorSubject<string> = new BehaviorSubject<string>("$.*");
$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.$path.value));
this.$path
.pipe(debounceTime(DebounceTime))
.subscribe(path => this.update(this.$input.value, path));
this.update(this.$input.value, this.$path.value);
}
update(input: string, path: string): void {
this.service
.jsonPath(input, path)
.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);
}
}
});
}
handlePathChange($event: any): void {
console.log($event);
this.$path.next($event.target.value);
}
handleInputChange($event: any): void {
console.log($event);
this.$input.next($event);
}
}