integration layer; merge work on indicators from forks with existing ingestion pipeline
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
<h2 mat-dialog-title class="explorer__title">
|
||||
<mat-icon aria-hidden="true">travel_explore</mat-icon>Explorar la base de datos
|
||||
<button mat-icon-button type="button" (click)="refresh()" aria-label="Actualizar"><mat-icon aria-hidden="true">refresh</mat-icon></button>
|
||||
</h2>
|
||||
<mat-dialog-content class="explorer">
|
||||
<mat-nav-list class="explorer__tables" aria-label="Tablas">
|
||||
@for (target of data.targets; track target.key) {
|
||||
<a mat-list-item [activated]="selected() === target" (click)="open(target)" role="button">
|
||||
<mat-icon matListItemIcon aria-hidden="true">table_chart</mat-icon>
|
||||
<span matListItemTitle>{{ target.table }}</span>
|
||||
<span matListItemLine>
|
||||
@if (totals().get(target.key); as total) {
|
||||
{{ total | number }} filas
|
||||
} @else if (totals().has(target.key)) {
|
||||
{{ totals().get(target.key) === 0 ? 'vacía' : 'no disponible' }}
|
||||
} @else {
|
||||
…
|
||||
}
|
||||
</span>
|
||||
</a>
|
||||
}
|
||||
</mat-nav-list>
|
||||
|
||||
<section class="explorer__rows">
|
||||
@if (loading()) {
|
||||
<mat-progress-bar mode="indeterminate" aria-label="Cargando filas"></mat-progress-bar>
|
||||
}
|
||||
@if (error(); as message) {
|
||||
<p class="explorer__error" role="alert">{{ message }}</p>
|
||||
}
|
||||
@if (page(); as p) {
|
||||
@if (p.rows.length === 0) {
|
||||
<p class="explorer__empty">La tabla está vacía.</p>
|
||||
} @else {
|
||||
<div class="explorer__scroll">
|
||||
<table mat-table [dataSource]="p.rows" class="explorer__table">
|
||||
@for (column of allColumns(); track column) {
|
||||
<ng-container [matColumnDef]="column">
|
||||
<th mat-header-cell *matHeaderCellDef>{{ column }}</th>
|
||||
<td mat-cell *matCellDef="let row" [class.explorer__null]="row[column] === null">{{ display(row[column]) }}</td>
|
||||
</ng-container>
|
||||
}
|
||||
<tr mat-header-row *matHeaderRowDef="allColumns(); sticky: true"></tr>
|
||||
<tr mat-row *matRowDef="let row; columns: allColumns()"></tr>
|
||||
</table>
|
||||
</div>
|
||||
<mat-paginator
|
||||
[length]="p.total"
|
||||
[pageIndex]="pageIndex()"
|
||||
[pageSize]="pageSize()"
|
||||
[pageSizeOptions]="[25, 50, 100]"
|
||||
(page)="onPage($event)"
|
||||
aria-label="Paginación de filas"
|
||||
></mat-paginator>
|
||||
}
|
||||
}
|
||||
</section>
|
||||
</mat-dialog-content>
|
||||
<mat-dialog-actions align="end">
|
||||
<button mat-button mat-dialog-close type="button">Cerrar</button>
|
||||
</mat-dialog-actions>
|
||||
@@ -0,0 +1,76 @@
|
||||
.explorer__title {
|
||||
align-items: center;
|
||||
display: flex;
|
||||
gap: var(--space-2);
|
||||
|
||||
button {
|
||||
margin-left: auto;
|
||||
}
|
||||
}
|
||||
|
||||
.explorer {
|
||||
display: grid;
|
||||
gap: var(--space-4);
|
||||
grid-template-columns: 240px minmax(0, 1fr);
|
||||
height: 70vh;
|
||||
}
|
||||
|
||||
.explorer__tables {
|
||||
border-right: 1px solid var(--mat-sys-outline-variant);
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
.explorer__rows {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.explorer__scroll {
|
||||
border: 1px solid var(--mat-sys-outline-variant);
|
||||
border-radius: var(--mat-sys-corner-medium);
|
||||
flex: 1;
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
.explorer__table {
|
||||
--mat-table-row-item-container-height: 36px;
|
||||
width: max-content;
|
||||
min-width: 100%;
|
||||
|
||||
th,
|
||||
td {
|
||||
border-right: 1px solid var(--mat-sys-outline-variant);
|
||||
font-size: 12px;
|
||||
max-width: 260px;
|
||||
overflow: hidden;
|
||||
padding: 0 var(--space-3);
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
th {
|
||||
font-family: 'Roboto Mono', ui-monospace, monospace;
|
||||
}
|
||||
}
|
||||
|
||||
.explorer__null {
|
||||
color: var(--mat-sys-outline);
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
.explorer__empty,
|
||||
.explorer__error {
|
||||
color: var(--mat-sys-on-surface-variant);
|
||||
}
|
||||
|
||||
.explorer__error {
|
||||
color: var(--mat-sys-error);
|
||||
}
|
||||
|
||||
@media (max-width: 800px) {
|
||||
.explorer {
|
||||
grid-template-columns: 1fr;
|
||||
height: auto;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
import { DecimalPipe } from '@angular/common';
|
||||
import { Component, OnInit, computed, inject, signal } from '@angular/core';
|
||||
import { forkJoin, of } from 'rxjs';
|
||||
import { catchError, map } from 'rxjs/operators';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
import { MAT_DIALOG_DATA, MatDialogModule } from '@angular/material/dialog';
|
||||
import { MatIconModule } from '@angular/material/icon';
|
||||
import { MatListModule } from '@angular/material/list';
|
||||
import { MatPaginatorModule, PageEvent } from '@angular/material/paginator';
|
||||
import { MatProgressBarModule } from '@angular/material/progress-bar';
|
||||
import { MatTableModule } from '@angular/material/table';
|
||||
import { DataPage, TargetMeta, apiErrorMessage } from '../../api/api.types';
|
||||
import { DataApi } from '../../api/data.api';
|
||||
|
||||
export interface DatabaseExplorerData {
|
||||
targets: TargetMeta[];
|
||||
initial?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read-only view of what's stored in the destination database, table by
|
||||
* table, paged server-side through the backend's Repository. The "Vista de
|
||||
* datos" to confirm a load landed as expected.
|
||||
*/
|
||||
@Component({
|
||||
selector: 'app-database-explorer-dialog',
|
||||
imports: [DecimalPipe, MatButtonModule, MatDialogModule, MatIconModule, MatListModule, MatPaginatorModule, MatProgressBarModule, MatTableModule],
|
||||
templateUrl: './database-explorer-dialog.html',
|
||||
styleUrl: './database-explorer-dialog.scss',
|
||||
})
|
||||
export class DatabaseExplorerDialog implements OnInit {
|
||||
readonly data = inject<DatabaseExplorerData>(MAT_DIALOG_DATA);
|
||||
private readonly api = inject(DataApi);
|
||||
|
||||
readonly totals = signal<Map<string, number | null>>(new Map());
|
||||
readonly selected = signal<TargetMeta | null>(null);
|
||||
readonly page = signal<DataPage | null>(null);
|
||||
readonly pageIndex = signal(0);
|
||||
readonly pageSize = signal(25);
|
||||
readonly loading = signal(false);
|
||||
readonly error = signal<string | null>(null);
|
||||
|
||||
/** Table order from the backend (keys and FKs first), not the alphabetical order JSON objects arrive in. */
|
||||
readonly allColumns = computed(() => this.page()?.columns ?? []);
|
||||
|
||||
ngOnInit(): void {
|
||||
forkJoin(
|
||||
this.data.targets.map((target) =>
|
||||
this.api.page(target.key, 1, 0).pipe(
|
||||
map((page) => [target.key, page.total] as const),
|
||||
catchError(() => of([target.key, null] as const)),
|
||||
),
|
||||
),
|
||||
).subscribe((entries) => this.totals.set(new Map(entries)));
|
||||
const initial = this.data.targets.find((target) => target.key === this.data.initial) ?? this.data.targets[0];
|
||||
if (initial) this.open(initial);
|
||||
}
|
||||
|
||||
open(target: TargetMeta): void {
|
||||
this.selected.set(target);
|
||||
this.pageIndex.set(0);
|
||||
this.fetch();
|
||||
}
|
||||
|
||||
onPage(event: PageEvent): void {
|
||||
this.pageIndex.set(event.pageIndex);
|
||||
this.pageSize.set(event.pageSize);
|
||||
this.fetch();
|
||||
}
|
||||
|
||||
refresh(): void {
|
||||
this.ngOnInit();
|
||||
}
|
||||
|
||||
display(value: unknown): string {
|
||||
if (value === null || value === undefined) return 'null';
|
||||
return String(value);
|
||||
}
|
||||
|
||||
private fetch(): void {
|
||||
const target = this.selected();
|
||||
if (!target) return;
|
||||
this.loading.set(true);
|
||||
this.error.set(null);
|
||||
this.api.page(target.key, this.pageSize(), this.pageIndex() * this.pageSize()).subscribe({
|
||||
next: (page) => {
|
||||
this.loading.set(false);
|
||||
this.page.set(page);
|
||||
},
|
||||
error: (error) => {
|
||||
this.loading.set(false);
|
||||
this.error.set(apiErrorMessage(error, 'No se pudo leer la tabla.'));
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user