Skip to content

Commit e23ae75

Browse files
committed
feat: beautify checkbox
- json beautify - xml beautify
1 parent 105bb71 commit e23ae75

File tree

2 files changed

+18
-26
lines changed

2 files changed

+18
-26
lines changed

Frontend/src/app/serialized-tool/serialized-tool.component.html

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,19 @@ <h2>Serialized Tool</h2>
1010
<label class="form-label">From</label>
1111
<div class="form-check ">
1212
<input class="form-check-input" type="radio" name="fromRadio" id="fromJson" value="json" [(ngModel)]="fromLang" (change)="convert()">
13-
<label class="form-check-label" for="fromJson">
14-
JSON
15-
</label>
13+
<label class="form-check-label" for="fromJson">JSON</label>
1614
</div>
1715
<div class="form-check">
1816
<input class="form-check-input" type="radio" name="fromRadio" id="fromXml" value="xml" [(ngModel)]="fromLang" (change)="convert()">
19-
<label class="form-check-label" for="fromXml">
20-
XML
21-
</label>
17+
<label class="form-check-label" for="fromXml">XML</label>
2218
</div>
2319
<div class="form-check">
2420
<input class="form-check-input" type="radio" name="fromRadio" id="fromYaml" value="yaml" [(ngModel)]="fromLang" (change)="convert()">
25-
<label class="form-check-label" for="fromYaml">
26-
YAML
27-
</label>
21+
<label class="form-check-label" for="fromYaml">YAML</label>
2822
</div>
2923
<div class="form-check">
3024
<input class="form-check-input" type="radio" name="fromRadio" id="fromToml" value="toml" [(ngModel)]="fromLang" (change)="convert()">
31-
<label class="form-check-label" for="fromToml">
32-
TOML
33-
</label>
25+
<label class="form-check-label" for="fromToml">TOML</label>
3426
</div>
3527
</div>
3628
<div class="code-border" [@hasError]="hasError">
@@ -44,27 +36,26 @@ <h2>Serialized Tool</h2>
4436
<label class="form-label">To</label>
4537
<div class="form-check ">
4638
<input class="form-check-input" type="radio" name="toRadio" id="toJson" value="json" [(ngModel)]="toLang" (change)="convert()">
47-
<label class="form-check-label" for="toJson">
48-
JSON
49-
</label>
39+
<label class="form-check-label" for="toJson">JSON</label>
5040
</div>
5141
<div class="form-check">
5242
<input class="form-check-input" type="radio" name="toRadio" id="toXml" value="xml" [(ngModel)]="toLang" (change)="convert()">
53-
<label class="form-check-label" for="toXml">
54-
XML
55-
</label>
43+
<label class="form-check-label" for="toXml">XML</label>
5644
</div>
5745
<div class="form-check">
5846
<input class="form-check-input" type="radio" name="toRadio" id="toYaml" value="yaml" [(ngModel)]="toLang" (change)="convert()">
59-
<label class="form-check-label" for="toYaml">
60-
YAML
61-
</label>
47+
<label class="form-check-label" for="toYaml">YAML</label>
6248
</div>
6349
<div class="form-check">
6450
<input class="form-check-input" type="radio" name="toRadio" id="toToml" value="toml" [(ngModel)]="toLang" (change)="convert()">
65-
<label class="form-check-label" for="toToml">
66-
TOML
67-
</label>
51+
<label class="form-check-label" for="toToml">TOML</label>
52+
</div>
53+
54+
<div class="flex-fill d-flex justify-content-end">
55+
<div class="form-check form-switch">
56+
<input class="form-check-input" type="checkbox" id="beautify" [(ngModel)]="beautify" (change)="convert()">
57+
<label class="form-check-label" for="beautify">Beautify</label>
58+
</div>
6859
</div>
6960
</div>
7061
<div class="code-border" [@valueChangeAnim]="status">

Frontend/src/app/serialized-tool/serialized-tool.component.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export class SerializedToolComponent implements AfterContentInit {
3434
protected toLang: string = "xml";
3535
protected status: boolean = false;
3636
protected hasError: boolean = false;
37+
protected beautify: boolean = true;
3738

3839
protected inputDebouncer = new Subject<string>();
3940

@@ -77,10 +78,10 @@ export class SerializedToolComponent implements AfterContentInit {
7778

7879
switch (this.toLang) {
7980
case "json":
80-
this.toCode = JSON.stringify(obj);
81+
this.toCode = this.beautify ? JSON.stringify(obj, null, 2) : JSON.stringify(obj);
8182
break;
8283
case "xml":
83-
this.toCode = new xmlStringify().build(obj);
84+
this.toCode = this.beautify ? new xmlStringify({ format: true }).build(obj) : new xmlStringify().build(obj);
8485
break;
8586
case "yaml":
8687
this.toCode = YAML.stringify(obj);

0 commit comments

Comments
 (0)