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 @@
<app-layout></app-layout>

View File

View File

@@ -0,0 +1,23 @@
import { TestBed } from '@angular/core/testing';
import { AppComponent } from './app.component';
describe('AppComponent', () => {
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [AppComponent],
}).compileComponents();
});
it('should create the app', () => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.componentInstance;
expect(app).toBeTruthy();
});
it('should render title', () => {
const fixture = TestBed.createComponent(AppComponent);
fixture.detectChanges();
const compiled = fixture.nativeElement as HTMLElement;
expect(compiled.querySelector('h1')?.textContent).toContain('Hello, DevDisciples.Json.Tools.App');
});
});

13
src/app/app.component.ts Normal file
View File

@@ -0,0 +1,13 @@
import { Component } from '@angular/core';
import { RouterOutlet } from '@angular/router';
import {LayoutComponent} from "./layout/layout.component";
@Component({
selector: 'app-root',
standalone: true,
imports: [RouterOutlet, LayoutComponent],
templateUrl: './app.component.html',
styleUrl: './app.component.scss'
})
export class AppComponent {
}

16
src/app/app.config.ts Normal file
View File

@@ -0,0 +1,16 @@
import {ApplicationConfig, importProvidersFrom, provideZoneChangeDetection} from '@angular/core';
import { provideRouter } from '@angular/router';
import { routes } from './app.routes';
import { provideAnimationsAsync } from '@angular/platform-browser/animations/async';
import {MonacoEditorModule} from "ngx-monaco-editor-v2";
import {HttpClientModule, provideHttpClient} from "@angular/common/http";
export const appConfig: ApplicationConfig = {
providers: [
provideZoneChangeDetection({ eventCoalescing: true }),
provideRouter(routes), provideAnimationsAsync(),
importProvidersFrom(MonacoEditorModule.forRoot()),
provideHttpClient(),
]
};

14
src/app/app.routes.ts Normal file
View File

@@ -0,0 +1,14 @@
import { Routes } from '@angular/router';
import {HomeComponent} from "./home/home.component";
import {BeautifyComponent} from "./beautify/beautify.component";
import {UglifyComponent} from "./uglify/uglify.component";
import {Json2CsharpComponent} from "./json2csharp/json2-csharp.component";
import {JsonPathComponent} from "./json-path/json-path.component";
export const routes: Routes = [
{ path: 'home', component: HomeComponent },
{ path: 'beautify', component: BeautifyComponent },
{ path: 'uglify', component: UglifyComponent },
{ path: 'json2csharp', component: Json2CsharpComponent },
{ path: 'jsonpath', component: JsonPathComponent },
];

View 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>

View File

View 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();
});
});

View 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);
}
}

26
src/app/defaults.ts Normal file
View File

@@ -0,0 +1,26 @@
export const MonacoJsonConfig = {
theme: 'vs-dark',
language: 'json',
readOnly: false,
automaticLayout: true
};
export const ReadOnlyMonacoJsonConfig = {
theme: 'vs-dark',
language: 'json',
readOnly: true,
automaticLayout: true
};
export const ReadOnlyMonacoCSharpConfig = {
theme: 'vs-dark',
language: 'csharp',
readOnly: false,
automaticLayout: true
};
export const GenerateDefaultJsonObjectString = (space: number = 0): string => {
return JSON.stringify({first_name: "John", last_name: "Doe"}, null, space);
}
export const DebounceTime: number = 750;

View File

@@ -0,0 +1 @@
<p>home works!</p>

View File

View File

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

View File

@@ -0,0 +1,12 @@
import { Component } from '@angular/core';
@Component({
selector: 'app-home',
standalone: true,
imports: [],
templateUrl: './home.component.html',
styleUrl: './home.component.scss'
})
export class HomeComponent {
}

View File

@@ -0,0 +1,15 @@
<main>
<section id="left">
<h3>Input</h3>
<ngx-monaco-editor (ngModelChange)="handleInputChange($event)"
[options]="inputOptions"
[(ngModel)]="input">
</ngx-monaco-editor>
</section>
<section id="right">
<h3>Output</h3>
<ngx-monaco-editor [options]="outputOptions"
[(ngModel)]="output">
</ngx-monaco-editor>
</section>
</main>

View File

@@ -0,0 +1,19 @@
main {
display: flex;
flex-direction: row;
height: 100%;
width: 100%;
#left {
flex: 0.5;
}
#right {
flex: 0.5;
}
ngx-monaco-editor {
height: 100%;
width: 100%;
}
}

View File

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

View File

@@ -0,0 +1,25 @@
import {Component, EventEmitter, Input, Output} from '@angular/core';
import {EditorComponent} from "ngx-monaco-editor-v2";
import {FormsModule} from "@angular/forms";
@Component({
selector: 'app-input-output',
standalone: true,
imports: [
EditorComponent,
FormsModule
],
templateUrl: './input-output.component.html',
styleUrl: './input-output.component.scss'
})
export class InputOutputComponent {
@Input() input!: string;
@Input() inputOptions!: any;
@Output() onInputChange = new EventEmitter();
@Input() output!: string;
@Input() outputOptions!: any;
handleInputChange($event: string) {
this.onInputChange.emit($event);
}
}

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);
}
}

View File

@@ -0,0 +1,16 @@
import { TestBed } from '@angular/core/testing';
import { JsonTransformService } from './json-transform.service';
describe('JsonTransformService', () => {
let service: JsonTransformService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(JsonTransformService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});

View File

@@ -0,0 +1,29 @@
import {Injectable} from '@angular/core';
import {HttpClient, HttpResponse} from "@angular/common/http";
import {Observable} from "rxjs";
@Injectable({
providedIn: 'root'
})
export class JsonTransformService {
private url: string = "https://localhost:5001";
constructor(private http: HttpClient) {
}
public beautify(source: string): Observable<HttpResponse<any>> {
return this.http.post(`${this.url}/api/transform/beautify`, {Source: source}, {observe: "response"});
}
public uglify(source: string): Observable<HttpResponse<any>> {
return this.http.post(`${this.url}/api/transform/uglify`, {Source: source}, {observe: "response"});
}
public json2csharp(source: string): Observable<HttpResponse<any>> {
return this.http.post(`${this.url}/api/transform/json2csharp`, {Source: source}, {observe: "response"});
}
public jsonPath(source: string, path: string): Observable<HttpResponse<any>> {
return this.http.post(`${this.url}/api/transform/jsonpath`, {source: source, path: path}, {observe: "response"});
}
}

View File

@@ -0,0 +1,8 @@
<h1>JSON to C#</h1>
<app-input-output [input]="$input.value"
[inputOptions]="inputOptions"
(onInputChange)="handleInputChange($event)"
[output]="output"
[outputOptions]="outputOptions">
</app-input-output>

View File

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

View File

@@ -0,0 +1,60 @@
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);
}
}

View File

@@ -0,0 +1,26 @@
<mat-sidenav-container class="sidenav-container">
<mat-sidenav #drawer class="sidenav" mode="side" opened>
<mat-toolbar>Menu</mat-toolbar>
<mat-nav-list>
<mat-list-item routerLink="/home">Home</mat-list-item>
<mat-list-item routerLink="/beautify">Beautify</mat-list-item>
<mat-list-item routerLink="/uglify">Uglify</mat-list-item>
<mat-list-item routerLink="/json2csharp">JSON to C#</mat-list-item>
<mat-list-item routerLink="/jsonpath">JSON Path</mat-list-item>
</mat-nav-list>
</mat-sidenav>
<mat-sidenav-content>
<mat-toolbar color="primary">
<button mat-icon-button (click)="drawer.toggle()">
<mat-icon>menu</mat-icon>
</button>
<span>JSON Transform</span>
</mat-toolbar>
<main>
<!-- Add your dashboard content here -->
<router-outlet></router-outlet>
</main>
</mat-sidenav-content>
</mat-sidenav-container>

View File

@@ -0,0 +1,16 @@
mat-sidenav-container {
height: 100%;
}
mat-sidenav-content {
overflow: hidden;
}
mat-sidenav {
width: 250px;
}
main {
height: 100%;
padding: 20px;
}

View File

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

View File

@@ -0,0 +1,27 @@
import { Component } from '@angular/core';
import {MatSidenavContainer, MatSidenavModule} from "@angular/material/sidenav";
import {MatToolbarModule} from "@angular/material/toolbar";
import {MatListItem, MatNavList} from "@angular/material/list";
import {RouterLink, RouterOutlet} from "@angular/router";
import {MatIconButton} from "@angular/material/button";
import {MatIconModule} from "@angular/material/icon";
@Component({
selector: 'app-layout',
standalone: true,
imports: [
MatSidenavContainer,
MatToolbarModule,
MatNavList,
MatListItem,
MatSidenavModule,
RouterLink,
MatIconButton,
MatIconModule,
RouterOutlet
],
templateUrl: './layout.component.html',
styleUrl: './layout.component.scss'
})
export class LayoutComponent {
}

View File

@@ -0,0 +1,8 @@
<h1>JSON Uglify</h1>
<app-input-output [input]="$input.value"
[inputOptions]="inputOptions"
(onInputChange)="handleInputChange($event)"
[output]="output"
[outputOptions]="outputOptions">
</app-input-output>

View File

View File

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

View File

@@ -0,0 +1,61 @@
import {Component, OnInit} from '@angular/core';
import {JsonTransformService} from "../json-transform.service";
import {InputOutputComponent} from "../input-output/input-output.component";
import {
DebounceTime,
GenerateDefaultJsonObjectString,
MonacoJsonConfig,
ReadOnlyMonacoJsonConfig
} from "../defaults";
import {debounceTime, BehaviorSubject} from "rxjs";
@Component({
selector: 'app-uglify',
standalone: true,
imports: [
InputOutputComponent
],
templateUrl: './uglify.component.html',
styleUrl: './uglify.component.scss'
})
export class UglifyComponent implements OnInit {
// input: string = ;
$input: BehaviorSubject<string> = new BehaviorSubject<string>(GenerateDefaultJsonObjectString(2));
inputOptions = MonacoJsonConfig;
output: string = GenerateDefaultJsonObjectString();
outputOptions = ReadOnlyMonacoJsonConfig;
constructor(private service: JsonTransformService) {
}
ngOnInit(): void {
this.$input
.pipe(debounceTime(DebounceTime))
.subscribe(input => {
this.update(input)
});
}
update(input: string): void {
this.service
.uglify(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);
}
}