In that component "output-console.component.html (1-90) @if (dataEntries() &&…
- User
In that component "output-console.component.html (1-90)
@if (dataEntries() && dataEntries().length > 0) { <button (click)="showRawData.set(!showRawData())" mat-flat-button color="primary"
@if (showRawData()) {Show Beautified Data } @else { Show Raw Data }output-console.component.ts (1-155)
import { CommonModule } from '@angular/common'; import { ChangeDetectionStrategy, Component, computed, input, signal, } from '@angular/core'; import { Highlight } from 'ngx-highlightjs'; import { HighlightLineNumbers } from 'ngx-highlightjs/line-numbers'; import { PrettyJsonPipe } from '../shared/pipes/pretty-json.pipe'; import { PrettyXmlPipe } from '../shared/pipes/pretty-xml.pipe'; import { NgxJsonViewerModule } from 'ngx-json-viewer'; import Papa from 'papaparse'; import { MatButtonModule } from '@angular/material/button';
@Component({ selector: 'app-output-console', standalone: true, imports: [ CommonModule, Highlight, PrettyJsonPipe, PrettyXmlPipe, NgxJsonViewerModule, MatButtonModule, HighlightLineNumbers, ], templateUrl: './output-console.component.html', styleUrls: ['./output-console.component.scss'], changeDetection: ChangeDetectionStrategy.OnPush, }) export class OutputConsoleComponent { public consoleData = input.required<string[]>();
public showRawData = signal(false);
public dataEntries = computed(() => { let entries: string[] = []; for (let dataString of this.consoleData()) { entries.push( ...dataString .split('\n') .map((line) => line.trim()) .filter((line) => line.length > 0), ); } return entries; });
public detectedLanguage = computed(() => { return this.detectLanguage(this.dataEntries()[0]); });
public parsedJson = computed(() => { if (this.detectedLanguage() !== 'json') { return []; }
return this.dataEntries().map((dataString) => { try { return JSON.parse(dataString); } catch (e) { console.error('JSON Parsing Error:', e); return null; } });});
public parsedCsv = computed(() => { if (this.detectedLanguage() !== 'csv') { return []; }
let allData = this.dataEntries().join('\n'); const result = Papa.parse<{ [key: string]: any }>(allData, { header: true, skipEmptyLines: true, }); return result.data.map((row) => { Object.keys(row).forEach((key) => { const value = row[key]; if (typeof value === 'string' && value.trim().startsWith('{')) { try { row[key] = JSON.parse(value); } catch (e) { console.warn(`Could not parse JSON in CSV field ${key}:`, e); } } }); return row; });});
public isObject(value: any): boolean { return value && typeof value === 'object' && !Array.isArray(value); }
public getCsvValues(row: any): any[] { return row ? Object.values(row) : []; }
- Assistant