Initial commit
This commit is contained in:
13
src/app/json-path/json-path.component.html
Normal file
13
src/app/json-path/json-path.component.html
Normal 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>
|
||||
3
src/app/json-path/json-path.component.scss
Normal file
3
src/app/json-path/json-path.component.scss
Normal file
@@ -0,0 +1,3 @@
|
||||
mat-form-field {
|
||||
width: 100%;
|
||||
}
|
||||
23
src/app/json-path/json-path.component.spec.ts
Normal file
23
src/app/json-path/json-path.component.spec.ts
Normal 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();
|
||||
});
|
||||
});
|
||||
69
src/app/json-path/json-path.component.ts
Normal file
69
src/app/json-path/json-path.component.ts
Normal 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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user