7f17681409
Session login against /auth/*, with a guard on every route and an interceptor that returns to the login on 401. The header, the import workspace and both governance panels only offer the account's own domains (auth/dominios.ts), and a batch opens on the account's database. The sign-in screen follows the app's palette: logo above the title, the action button in the shared tokens, and no register or password-recovery rows.
124 lines
4.9 KiB
TypeScript
124 lines
4.9 KiB
TypeScript
import { DatePipe } from '@angular/common';
|
|
import { Component, DestroyRef, OnInit, computed, inject, signal } from '@angular/core';
|
|
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
|
|
import { MatButtonModule } from '@angular/material/button';
|
|
import { MatButtonToggleModule } from '@angular/material/button-toggle';
|
|
import { MatDialog } from '@angular/material/dialog';
|
|
import { MatIconModule } from '@angular/material/icon';
|
|
import { MatProgressBarModule } from '@angular/material/progress-bar';
|
|
import { MatTableModule } from '@angular/material/table';
|
|
import { MatTooltipModule } from '@angular/material/tooltip';
|
|
import { Subscription, timer } from 'rxjs';
|
|
import { apiErrorMessage } from '../../../connect/api/api.types';
|
|
import { AuthService } from '../../../auth/auth.service';
|
|
import { alcanzaTodos, dominioInicial, dominiosPermitidos } from '../../../auth/dominios';
|
|
import { DOMAINS } from '../../../connect/state/connect-workspace.store';
|
|
import { GovernanceApi } from '../../api/governance.api';
|
|
import { Experiment, ExperimentDetail, ExperimentStatus } from '../../api/governance.types';
|
|
import { NotebookRunDefaults, NotebookRunDialog } from '../notebook-run-dialog/notebook-run-dialog';
|
|
|
|
const STATUS: Record<ExperimentStatus, { label: string; icon: string }> = {
|
|
en_curso: { label: 'En curso', icon: 'hourglass_top' },
|
|
terminado: { label: 'Terminado', icon: 'check_circle' },
|
|
fallido: { label: 'Falló', icon: 'error' },
|
|
interrumpido: { label: 'Interrumpido', icon: 'block' },
|
|
};
|
|
const POLL_MS = 5000;
|
|
|
|
/**
|
|
* Notebooks run on cohort builds: upload one, follow it while it runs, and
|
|
* open its page or download its files. The list refreshes on its own while
|
|
* a run is in progress.
|
|
*/
|
|
@Component({
|
|
selector: 'app-experiments-panel',
|
|
imports: [DatePipe, MatButtonModule, MatButtonToggleModule, MatIconModule, MatProgressBarModule, MatTableModule, MatTooltipModule],
|
|
templateUrl: './experiments-panel.html',
|
|
styleUrl: './experiments-panel.scss',
|
|
})
|
|
export class ExperimentsPanel implements OnInit {
|
|
readonly api = inject(GovernanceApi);
|
|
private readonly auth = inject(AuthService);
|
|
private readonly dialog = inject(MatDialog);
|
|
private readonly destroyRef = inject(DestroyRef);
|
|
|
|
/** Only the account's domains; «Todos» only when it reaches all of them. */
|
|
readonly domains = computed<{ id: string | null; label: string }[]>(() => [
|
|
...(alcanzaTodos(this.auth, DOMAINS) ? [{ id: null, label: 'Todos' }] : []),
|
|
...dominiosPermitidos(this.auth, DOMAINS).map((d) => ({ id: d.id as string | null, label: d.label })),
|
|
]);
|
|
readonly domain = signal<string | null>(dominioInicial(this.auth, DOMAINS));
|
|
readonly experiments = signal<Experiment[]>([]);
|
|
readonly details = signal<Record<string, ExperimentDetail>>({});
|
|
readonly loading = signal(false);
|
|
readonly loadError = signal<string | null>(null);
|
|
readonly displayedColumns = ['notebook', 'scenario', 'cohort', 'status', 'started_at', 'acciones'];
|
|
private poll?: Subscription;
|
|
|
|
ngOnInit(): void {
|
|
this.reload();
|
|
}
|
|
|
|
status(status: ExperimentStatus): { label: string; icon: string } {
|
|
return STATUS[status] ?? { label: status, icon: 'help' };
|
|
}
|
|
|
|
setDomain(domain: string | null): void {
|
|
if (domain !== null && !this.auth.puedeVer(domain)) return;
|
|
this.domain.set(domain);
|
|
this.reload();
|
|
}
|
|
|
|
start(defaults: NotebookRunDefaults = {}): void {
|
|
this.dialog
|
|
.open<NotebookRunDialog, NotebookRunDefaults, ExperimentDetail>(NotebookRunDialog, {
|
|
data: defaults,
|
|
width: '640px',
|
|
maxWidth: '96vw',
|
|
autoFocus: false,
|
|
})
|
|
.afterClosed()
|
|
.subscribe((run) => {
|
|
if (run) this.reload();
|
|
});
|
|
}
|
|
|
|
/** Loads a run's files and error the first time it's expanded. */
|
|
toggle(run: Experiment): void {
|
|
const current = { ...this.details() };
|
|
if (current[run.run_id]) {
|
|
delete current[run.run_id];
|
|
this.details.set(current);
|
|
return;
|
|
}
|
|
this.api.getExperiment(run.run_id).subscribe((detail) => this.details.set({ ...this.details(), [run.run_id]: detail }));
|
|
}
|
|
|
|
reload(quiet = false): void {
|
|
if (!quiet) this.loading.set(true);
|
|
this.loadError.set(null);
|
|
this.api
|
|
.listExperiments(this.domain() ? { domain: this.domain()! } : {})
|
|
.pipe(takeUntilDestroyed(this.destroyRef))
|
|
.subscribe({
|
|
next: ({ experiments }) => {
|
|
this.loading.set(false);
|
|
this.experiments.set(experiments);
|
|
this.schedule(experiments.some((run) => run.status === 'en_curso'));
|
|
},
|
|
error: (error) => {
|
|
this.loading.set(false);
|
|
this.loadError.set(apiErrorMessage(error, 'No se pudieron cargar los notebooks.'));
|
|
},
|
|
});
|
|
}
|
|
|
|
private schedule(running: boolean): void {
|
|
this.poll?.unsubscribe();
|
|
if (!running) return;
|
|
this.poll = timer(POLL_MS)
|
|
.pipe(takeUntilDestroyed(this.destroyRef))
|
|
.subscribe(() => this.reload(true));
|
|
}
|
|
}
|