Initial commit
This commit is contained in:
8
src/app/beautify/beautify.component.html
Normal file
8
src/app/beautify/beautify.component.html
Normal file
@@ -0,0 +1,8 @@
|
||||
<h1>JSON Beautify</h1>
|
||||
|
||||
<app-input-output [input]="$input.value"
|
||||
[inputOptions]="inputOptions"
|
||||
(onInputChange)="handleInputChange($event)"
|
||||
[output]="output"
|
||||
[outputOptions]="outputOptions">
|
||||
</app-input-output>
|
||||
0
src/app/beautify/beautify.component.scss
Normal file
0
src/app/beautify/beautify.component.scss
Normal file
23
src/app/beautify/beautify.component.spec.ts
Normal file
23
src/app/beautify/beautify.component.spec.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { BeautifyComponent } from './beautify.component';
|
||||
|
||||
describe('BeautifyComponent', () => {
|
||||
let component: BeautifyComponent;
|
||||
let fixture: ComponentFixture<BeautifyComponent>;
|
||||
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [BeautifyComponent]
|
||||
})
|
||||
.compileComponents();
|
||||
|
||||
fixture = TestBed.createComponent(BeautifyComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
66
src/app/beautify/beautify.component.ts
Normal file
66
src/app/beautify/beautify.component.ts
Normal file
@@ -0,0 +1,66 @@
|
||||
import {Component, OnInit} from '@angular/core';
|
||||
import {EditorComponent} from "ngx-monaco-editor-v2";
|
||||
import {FormsModule} from "@angular/forms";
|
||||
import {InputOutputComponent} from "../input-output/input-output.component";
|
||||
import {JsonTransformService} from "../json-transform.service";
|
||||
import {
|
||||
DebounceTime,
|
||||
GenerateDefaultJsonObjectString,
|
||||
MonacoJsonConfig,
|
||||
ReadOnlyMonacoJsonConfig
|
||||
} from "../defaults";
|
||||
import {BehaviorSubject, debounceTime} from "rxjs";
|
||||
|
||||
@Component({
|
||||
selector: 'app-beautify',
|
||||
standalone: true,
|
||||
imports: [
|
||||
EditorComponent,
|
||||
FormsModule,
|
||||
InputOutputComponent
|
||||
],
|
||||
templateUrl: './beautify.component.html',
|
||||
styleUrl: './beautify.component.scss'
|
||||
})
|
||||
export class BeautifyComponent implements OnInit {
|
||||
// input: string = ;
|
||||
$input: BehaviorSubject<string> = new BehaviorSubject<string>(GenerateDefaultJsonObjectString());
|
||||
inputOptions = MonacoJsonConfig;
|
||||
output: string = GenerateDefaultJsonObjectString(2);
|
||||
outputOptions = ReadOnlyMonacoJsonConfig;
|
||||
// error: string = "";
|
||||
|
||||
constructor(private service: JsonTransformService) {
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.$input
|
||||
.pipe(debounceTime(DebounceTime))
|
||||
.subscribe(input => {
|
||||
this.update(input)
|
||||
});
|
||||
}
|
||||
|
||||
update(input: string): void {
|
||||
this.service
|
||||
.beautify(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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user