Refactor: Reorganización de archivos

This commit is contained in:
Angel Capetillo Zavala
2026-09-24 13:17:21 -06:00
parent 88ba59c669
commit 0795a971df
22 changed files with 523 additions and 464 deletions
+13
View File
@@ -0,0 +1,13 @@
@mixin base {
border-radius: 8px;
font: inherit;
font-weight: 600;
min-height: 44px;
padding: 10px 18px;
transition: background-color 0.18s ease;
}
@mixin focus {
outline: 3px solid rgb(168 194 67 / 65%);
outline-offset: 2px;
}
+3 -4
View File
@@ -115,10 +115,9 @@ describe('App', () => {
const jsonFile = new File(['{}'], 'nuevo.json', { type: 'application/json' });
const dialogComponent = TestBed.inject(MatDialog).openDialogs[0].componentRef!
.instance as import('./information-upload-dialog').InformationUploadDialog;
dialogComponent.onDrop({
preventDefault: () => undefined,
dataTransfer: { files: [jsonFile] },
} as unknown as DragEvent);
const drop = new Event('drop', { bubbles: true, cancelable: true });
Object.defineProperty(drop, 'dataTransfer', { value: { files: [jsonFile] } });
overlay.querySelector<HTMLElement>('.dropzone')!.dispatchEvent(drop);
detectDialogChanges();
fixture.detectChanges();
expect(overlay.querySelectorAll('.file-row')).toHaveLength(3);
+20
View File
@@ -0,0 +1,20 @@
<div class="dropzone" [class.dropzone--active]="isDragOver" (dragenter)="onDragEnter($event)" (dragover)="onDragOver($event)" (dragleave)="onDragLeave($event)" (drop)="onDrop($event)">
<mat-icon class="dropzone__icon" aria-hidden="true">cloud_upload</mat-icon>
<p class="dropzone__title">Arrastra tus archivos aquí</p>
<p class="dropzone__formats">Excel · CSV · JSON · PDF</p>
<input #fileInput class="visually-hidden" type="file" multiple accept=".xlsx,.csv,.json,.pdf,application/pdf,application/json,text/csv" aria-label="Seleccionar archivos" (change)="onFileSelection($event)" />
<button class="upload-action upload-action--outlined select-files-button" mat-stroked-button type="button" (click)="fileInput.click()">
<mat-icon aria-hidden="true">upload_file</mat-icon>
<span>Seleccionar archivos</span>
</button>
</div>
@if (messages.length > 0) {
<ul class="file-messages" aria-live="polite" aria-label="Mensajes sobre archivos">
@for (message of messages; track $index) { <li>{{ message }}</li> }
</ul>
}
@if (files.length > 0) {
<app-file-list [files]="files" (removeRequested)="removeRequested.emit($event)" />
}
+92
View File
@@ -0,0 +1,92 @@
@use 'upload-button' as button;
:host { display: block; }
.dropzone {
align-items: center;
background: #fcfdfb;
border: 1.5px dashed #cbd2c4;
border-radius: 10px;
display: flex;
flex-direction: column;
justify-content: center;
min-height: 244px;
padding: 24px;
text-align: center;
}
.dropzone--active {
background: #f5f8e9;
border-color: var(--color-primary);
border-style: solid;
}
.dropzone__icon {
color: #71882b;
font-size: 40px;
height: 40px;
width: 40px;
}
.dropzone__title {
font-size: 16px;
font-weight: 600;
margin: 14px 0 4px;
}
.dropzone__formats {
color: var(--color-text-secondary);
font-size: 13px;
margin: 0 0 16px;
}
.select-files-button {
--mat-button-outlined-label-text-color: var(--color-text);
--mat-button-outlined-outline-color: var(--color-border-subtle);
--mat-button-outlined-state-layer-color: transparent;
--mat-button-outlined-ripple-color: transparent;
background: #fff;
border: 1px solid var(--mat-button-outlined-outline-color);
transition: border-color 0.18s ease;
}
.select-files-button:hover {
background: var(--color-surface-hover);
border-color: var(--color-primary);
}
.select-files-button:active {
background: #e8eed5;
}
.select-files-button mat-icon {
color: #5f9ea0;
margin: 0;
}
.visually-hidden {
clip: rect(0, 0, 0, 0);
clip-path: inset(50%);
height: 1px;
overflow: hidden;
position: absolute;
white-space: nowrap;
width: 1px;
}
.file-messages {
background: #fffaf0;
border: 1px solid #ead8a7;
border-radius: 7px;
color: #634d13;
font-size: 13px;
line-height: 1.45;
list-style: none;
margin: 12px 0 0;
padding: 10px 14px;
}
.file-messages li + li {
margin-top: 4px;
}
.upload-action {
@include button.base;
}
.select-files-button:focus-visible {
@include button.focus;
}
@media (max-width: 600px) {
.dropzone {
min-height: 220px;
padding: 20px 12px;
}
}
+49
View File
@@ -0,0 +1,49 @@
import { Component, EventEmitter, Input, Output } from '@angular/core';
import { MatButtonModule } from '@angular/material/button';
import { MatIconModule } from '@angular/material/icon';
import { FileListComponent } from './file-list';
@Component({
imports: [MatButtonModule, MatIconModule, FileListComponent],
selector: 'app-file-configuration',
styleUrl: './file-configuration.scss',
templateUrl: './file-configuration.html',
})
export class FileConfigurationComponent {
@Input({ required: true }) files: File[] = [];
@Input() messages: string[] = [];
@Output() readonly filesAdded = new EventEmitter<File[]>();
@Output() readonly removeRequested = new EventEmitter<File>();
isDragOver = false;
private dragDepth = 0;
onFileSelection(event: Event): void {
const input = event.target as HTMLInputElement;
this.filesAdded.emit(input.files ? Array.from(input.files) : []);
input.value = '';
}
onDragEnter(event: DragEvent): void {
event.preventDefault();
this.dragDepth++;
this.isDragOver = true;
}
onDragOver(event: DragEvent): void {
event.preventDefault();
if (event.dataTransfer) event.dataTransfer.dropEffect = 'copy';
}
onDragLeave(event: DragEvent): void {
event.preventDefault();
this.dragDepth = Math.max(0, this.dragDepth - 1);
if (this.dragDepth === 0) this.isDragOver = false;
}
onDrop(event: DragEvent): void {
event.preventDefault();
this.dragDepth = 0;
this.isDragOver = false;
this.filesAdded.emit(event.dataTransfer?.files ? Array.from(event.dataTransfer.files) : []);
}
}
+6
View File
@@ -0,0 +1,6 @@
<dl class="confirmation-summary" aria-label="Resumen de la selección">
<div><dt>Fuente</dt><dd>Archivo</dd></div>
<div><dt>Archivos seleccionados</dt><dd>{{ files.length }}</dd></div>
<div><dt>Tamaño total</dt><dd>{{ formatFileSize(totalSize) }}</dd></div>
</dl>
<app-file-list [files]="files" [readonly]="true" />
+11
View File
@@ -0,0 +1,11 @@
:host { display: block; }
.confirmation-summary {
display: grid;
gap: 10px;
grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
margin: 0;
padding: 0;
}
.confirmation-summary div { background: #fcfdfb; border: 1px solid #e7eae3; border-radius: 8px; min-width: 0; padding: 10px 12px; }
.confirmation-summary dt { color: var(--color-text-secondary); font-size: 12px; }
.confirmation-summary dd { font-size: 15px; font-weight: 600; margin: 4px 0 0; overflow-wrap: anywhere; }
+15
View File
@@ -0,0 +1,15 @@
import { Component, Input } from '@angular/core';
import { FileListComponent } from './file-list';
import { formatFileSize } from './file-selection';
@Component({
imports: [FileListComponent],
selector: 'app-file-confirmation',
styleUrl: './file-confirmation.scss',
templateUrl: './file-confirmation.html',
})
export class FileConfirmationComponent {
@Input({ required: true }) files: File[] = [];
@Input({ required: true }) totalSize = 0;
readonly formatFileSize = formatFileSize;
}
+20
View File
@@ -0,0 +1,20 @@
<section class="selected-files" [class.confirmation-files]="readonly" [attr.aria-labelledby]="readonly ? 'confirmation-files-title' : 'selected-files-title'">
<header class="selected-files__header">
<h3 [id]="readonly ? 'confirmation-files-title' : 'selected-files-title'">{{ readonly ? 'Archivos a procesar' : 'Archivos seleccionados' }}</h3>
<span class="selected-files__count" aria-label="Cantidad de archivos">{{ files.length }}</span>
</header>
<ul class="selected-files__list">
@for (file of files; track file.name + ':' + file.size) {
<li class="file-row" [class.file-row--readonly]="readonly">
<mat-icon class="file-row__icon" aria-hidden="true">{{ fileIcon(file) }}</mat-icon>
<span class="file-row__name" [title]="file.name">{{ file.name }}</span>
<span class="file-row__size">{{ formatFileSize(file.size) }}</span>
@if (!readonly) {
<button class="file-row__remove" mat-icon-button type="button" [attr.aria-label]="'Eliminar ' + file.name" (click)="removeRequested.emit(file)">
<mat-icon aria-hidden="true">close</mat-icon>
</button>
}
</li>
}
</ul>
</section>
+87
View File
@@ -0,0 +1,87 @@
@use 'upload-button' as button;
:host { display: block; }
.selected-files {
margin-top: 20px;
}
.selected-files__header {
align-items: center;
display: flex;
gap: 10px;
justify-content: space-between;
margin-bottom: 8px;
}
.selected-files__header h3 {
font-size: 15px;
font-weight: 600;
margin: 0;
}
.selected-files__count {
align-items: center;
background: var(--color-step);
border-radius: 20px;
color: #52651d;
display: inline-flex;
font-size: 12px;
font-weight: 600;
height: 25px;
justify-content: center;
min-width: 25px;
padding: 0 7px;
}
.selected-files__list {
border: 1px solid #e7eae3;
border-radius: 8px;
list-style: none;
margin: 0;
max-height: 220px;
overflow-y: auto;
padding: 0;
}
.file-row--readonly { grid-template-columns: 22px minmax(0, 1fr) auto; padding-right: 12px; }
.file-row {
align-items: center;
display: grid;
gap: 10px;
grid-template-columns: 22px minmax(0, 1fr) auto 40px;
min-height: 54px;
padding: 6px 8px 6px 12px;
}
.file-row + .file-row {
border-top: 1px solid #eef0eb;
}
.file-row__icon {
color: #71882b;
font-size: 20px;
height: 20px;
width: 20px;
}
.file-row__name {
font-size: 13px;
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.file-row__size {
color: #737b6b;
font-size: 12px;
white-space: nowrap;
}
.file-row__remove {
color: #596273;
}
.file-row__remove:focus-visible {
@include button.focus;
}
@media (max-width: 600px) {
.file-row {
gap: 6px;
grid-template-columns: 20px minmax(0, 1fr) auto 36px;
padding-left: 8px;
}
.file-row--readonly { grid-template-columns: 20px minmax(0, 1fr) auto; }
.file-row__name { font-size: 12px; }
.file-row__size { font-size: 11px; }
}
+18
View File
@@ -0,0 +1,18 @@
import { Component, EventEmitter, Input, Output } from '@angular/core';
import { MatButtonModule } from '@angular/material/button';
import { MatIconModule } from '@angular/material/icon';
import { fileIcon, formatFileSize } from './file-selection';
@Component({
imports: [MatButtonModule, MatIconModule],
selector: 'app-file-list',
styleUrl: './file-list.scss',
templateUrl: './file-list.html',
})
export class FileListComponent {
@Input({ required: true }) files: File[] = [];
@Input() readonly = false;
@Output() readonly removeRequested = new EventEmitter<File>();
readonly fileIcon = fileIcon;
readonly formatFileSize = formatFileSize;
}
+42
View File
@@ -0,0 +1,42 @@
const allowedExtensions = new Set(['xlsx', 'csv', 'json', 'pdf']);
function extensionOf(fileName: string): string {
const finalDot = fileName.lastIndexOf('.');
return finalDot >= 0 ? fileName.slice(finalDot + 1).toLowerCase() : '';
}
export function selectFiles(selected: File[], incomingFiles: File[]): { files: File[]; messages: string[] } {
const messages: string[] = [];
const files = [...selected];
for (const file of incomingFiles) {
if (!allowedExtensions.has(extensionOf(file.name))) {
messages.push(`${file.name} no fue agregado. Formato no compatible.`);
} else if (file.size === 0) {
messages.push(`${file.name} no fue agregado. El archivo está vacío.`);
} else if (files.some((existing) => existing.name === file.name && existing.size === file.size)) {
messages.push(`${file.name} ya se encuentra seleccionado.`);
} else {
files.push(file);
}
}
return { files, messages };
}
export function formatFileSize(size: number): string {
if (size < 1024) return `${size} bytes`;
const units = ['KB', 'MB', 'GB'];
let value = size / 1024;
let unit = 0;
while (value >= 1024 && unit < units.length - 1) {
value /= 1024;
unit++;
}
return `${new Intl.NumberFormat('es-MX', { maximumFractionDigits: 1 }).format(value)} ${units[unit]}`;
}
export function fileIcon(file: File): string {
const extension = extensionOf(file.name);
if (extension === 'pdf') return 'picture_as_pdf';
if (extension === 'csv' || extension === 'xlsx') return 'table_chart';
return 'data_object';
}
+3 -69
View File
@@ -24,59 +24,12 @@
@if (step() === 'source') {
<p class="upload-dialog__description">Selecciona cómo deseas proporcionar los datos.</p>
<div class="upload-dialog__content">
<div class="source-options" role="group" aria-label="Selecciona una fuente de información">
<button class="source-card" [class.source-card--selected]="source() === 'file'" [attr.aria-pressed]="source() === 'file'" type="button" (click)="selectSource('file')">
<span class="source-card__icon"><mat-icon aria-hidden="true">upload_file</mat-icon></span>
<span class="source-card__copy"><span class="source-card__title">Archivo</span><span class="source-card__description">Excel, CSV, JSON o PDF</span></span>
@if (source() === 'file') { <mat-icon class="source-card__check" aria-hidden="true">check_circle</mat-icon> }
</button>
<button class="source-card" [class.source-card--selected]="source() === 'sql'" [attr.aria-pressed]="source() === 'sql'" type="button" (click)="selectSource('sql')">
<span class="source-card__icon"><mat-icon aria-hidden="true">storage</mat-icon></span>
<span class="source-card__copy"><span class="source-card__title">Conexión SQL</span><span class="source-card__description">Conecta una base de datos para utilizar su información.</span></span>
@if (source() === 'sql') { <mat-icon class="source-card__check" aria-hidden="true">check_circle</mat-icon> }
</button>
</div>
<app-source-selection [source]="source()" (sourceChange)="selectSource($event)" />
</div>
} @else if (step() === 'configuration' && source() === 'file') {
<p class="upload-dialog__description">Selecciona los archivos que deseas procesar.</p>
<div class="upload-dialog__content file-configuration">
<div class="dropzone" [class.dropzone--active]="isDragOver()" (dragenter)="onDragEnter($event)" (dragover)="onDragOver($event)" (dragleave)="onDragLeave($event)" (drop)="onDrop($event)">
<mat-icon class="dropzone__icon" aria-hidden="true">cloud_upload</mat-icon>
<p class="dropzone__title">Arrastra tus archivos aquí</p>
<p class="dropzone__formats">Excel · CSV · JSON · PDF</p>
<input #fileInput class="visually-hidden" type="file" multiple accept=".xlsx,.csv,.json,.pdf,application/pdf,application/json,text/csv" aria-label="Seleccionar archivos" (change)="onFileSelection($event)" />
<button class="upload-action upload-action--outlined select-files-button" mat-stroked-button type="button" (click)="fileInput.click()">
<mat-icon aria-hidden="true">upload_file</mat-icon>
<span>Seleccionar archivos</span>
</button>
</div>
@if (fileMessages().length > 0) {
<ul class="file-messages" aria-live="polite" aria-label="Mensajes sobre archivos">
@for (message of fileMessages(); track $index) { <li>{{ message }}</li> }
</ul>
}
@if (files().length > 0) {
<section class="selected-files" aria-labelledby="selected-files-title">
<header class="selected-files__header">
<h3 id="selected-files-title">Archivos seleccionados</h3>
<span class="selected-files__count" aria-label="Cantidad de archivos">{{ files().length }}</span>
</header>
<ul class="selected-files__list">
@for (file of files(); track file.name + ':' + file.size) {
<li class="file-row">
<mat-icon class="file-row__icon" aria-hidden="true">{{ fileIcon(file) }}</mat-icon>
<span class="file-row__name" [title]="file.name">{{ file.name }}</span>
<span class="file-row__size">{{ formatFileSize(file.size) }}</span>
<button class="file-row__remove" mat-icon-button type="button" [attr.aria-label]="'Eliminar ' + file.name" (click)="removeFile(file)">
<mat-icon aria-hidden="true">close</mat-icon>
</button>
</li>
}
</ul>
</section>
}
<app-file-configuration [files]="files()" [messages]="fileMessages()" (filesAdded)="addFiles($event)" (removeRequested)="removeFile($event)" />
</div>
} @else if (step() === 'configuration') {
<p class="upload-dialog__description">Configura la fuente seleccionada.</p>
@@ -91,26 +44,7 @@
} @else {
<p class="upload-dialog__description">Revisa la información antes de iniciar el procesamiento.</p>
<div class="upload-dialog__content" aria-live="polite">
<dl class="confirmation-summary" aria-label="Resumen de la selección">
<div><dt>Fuente</dt><dd>Archivo</dd></div>
<div><dt>Archivos seleccionados</dt><dd>{{ files().length }}</dd></div>
<div><dt>Tamaño total</dt><dd>{{ formatFileSize(totalFileSize()) }}</dd></div>
</dl>
<section class="selected-files confirmation-files" aria-labelledby="confirmation-files-title">
<header class="selected-files__header">
<h3 id="confirmation-files-title">Archivos a procesar</h3>
<span class="selected-files__count" aria-label="Cantidad de archivos">{{ files().length }}</span>
</header>
<ul class="selected-files__list">
@for (file of files(); track file.name + ':' + file.size) {
<li class="file-row file-row--readonly">
<mat-icon class="file-row__icon" aria-hidden="true">{{ fileIcon(file) }}</mat-icon>
<span class="file-row__name" [title]="file.name">{{ file.name }}</span>
<span class="file-row__size">{{ formatFileSize(file.size) }}</span>
</li>
}
</ul>
</section>
<app-file-confirmation [files]="files()" [totalSize]="totalFileSize()" />
</div>
}
+22 -291
View File
@@ -1,10 +1,12 @@
@use 'upload-button' as button;
:host {
display: block;
}
.upload-dialog {
background: #fff;
color: #081839;
color: var(--color-text);
max-height: 100dvh;
overflow: auto;
padding: 28px 32px 24px;
@@ -22,7 +24,7 @@
margin: 0;
}
.upload-dialog__description {
color: #7a7a7a;
color: var(--color-text-secondary);
font-size: 15px;
line-height: 1.5;
margin: 14px 0 0;
@@ -33,8 +35,8 @@
}
.upload-steps {
align-items: center;
border-bottom: 1px solid #e3e7df;
color: #7a7a7a;
border-bottom: 1px solid var(--color-border);
color: var(--color-text-secondary);
display: flex;
justify-content: center;
list-style: none;
@@ -70,274 +72,26 @@
width: 16px;
}
.upload-steps__item--active {
color: #081839;
color: var(--color-text);
font-weight: 600;
}
.upload-steps__item--active .upload-steps__number {
background: #a8c243;
color: #081839;
background: var(--color-primary);
color: var(--color-text);
}
.upload-steps__item--complete {
color: #71882b;
}
.upload-steps__item--complete .upload-steps__number {
background: #f0f3e8;
background: var(--color-step);
color: #71882b;
}
.upload-dialog__content {
padding: 18px 0 28px;
}
.source-options {
display: grid;
gap: 16px;
grid-template-columns: repeat(2, minmax(0, 1fr));
}
.source-card {
align-items: center;
background: #fff;
border: 1px solid #e3e7df;
border-radius: 9px;
color: #081839;
cursor: pointer;
display: flex;
gap: 16px;
min-height: 126px;
padding: 20px;
position: relative;
text-align: left;
}
.source-card:focus-visible,
.upload-dialog__close:focus-visible,
.file-row__remove:focus-visible,
.upload-action:focus-visible {
outline: 3px solid rgb(168 194 67 / 65%);
outline-offset: 2px;
}
.source-card--selected {
background: #fbfcf6;
border: 2px solid #a8c243;
padding: 19px;
}
.source-card__icon {
align-items: center;
background: #f0f3e8;
border-radius: 8px;
color: #71882b;
display: inline-flex;
flex: 0 0 46px;
height: 46px;
justify-content: center;
}
.source-card__copy {
display: grid;
gap: 6px;
min-width: 0;
}
.source-card__title {
font-size: 16px;
font-weight: 600;
}
.source-card__description {
color: #7a7a7a;
font-size: 13px;
line-height: 1.45;
}
.source-card__check {
color: #71882b;
margin-left: auto;
}
.configuration-placeholder {
align-items: center;
display: flex;
flex-direction: column;
justify-content: center;
min-height: 164px;
text-align: center;
}
.configuration-placeholder__icon {
align-items: center;
background: #f0f3e8;
border-radius: 50%;
color: #71882b;
display: inline-flex;
height: 48px;
justify-content: center;
width: 48px;
}
.configuration-placeholder h3 {
font-family: var(--font-heading);
font-size: 22px;
margin: 14px 0 6px;
}
.configuration-placeholder p {
color: #7a7a7a;
font-size: 14px;
line-height: 1.55;
margin: 0;
max-width: 460px;
}
.file-configuration {
padding-top: 18px;
}
.dropzone {
align-items: center;
background: #fcfdfb;
border: 1.5px dashed #cbd2c4;
border-radius: 10px;
display: flex;
flex-direction: column;
justify-content: center;
min-height: 244px;
padding: 24px;
text-align: center;
}
.dropzone--active {
background: #f5f8e9;
border-color: #a8c243;
border-style: solid;
}
.dropzone__icon {
color: #71882b;
font-size: 40px;
height: 40px;
width: 40px;
}
.dropzone__title {
font-size: 16px;
font-weight: 600;
margin: 14px 0 4px;
}
.dropzone__formats {
color: #7a7a7a;
font-size: 13px;
margin: 0 0 16px;
}
.select-files-button {
--mat-button-outlined-label-text-color: #081839;
--mat-button-outlined-outline-color: #d7dccf;
--mat-button-outlined-state-layer-color: transparent;
--mat-button-outlined-ripple-color: transparent;
background: #fff;
border: 1px solid var(--mat-button-outlined-outline-color);
transition: border-color 0.18s ease;
}
.upload-action--outlined:hover {
background: #f3f6e9;
border-color: #a8c243;
}
.upload-action--outlined:active {
background: #e8eed5;
}
.select-files-button mat-icon {
color: #5f9ea0;
margin: 0;
}
.visually-hidden {
clip: rect(0, 0, 0, 0);
clip-path: inset(50%);
height: 1px;
overflow: hidden;
position: absolute;
white-space: nowrap;
width: 1px;
}
.file-messages {
background: #fffaf0;
border: 1px solid #ead8a7;
border-radius: 7px;
color: #634d13;
font-size: 13px;
line-height: 1.45;
list-style: none;
margin: 12px 0 0;
padding: 10px 14px;
}
.file-messages li + li {
margin-top: 4px;
}
.selected-files {
margin-top: 20px;
}
.selected-files__header {
align-items: center;
display: flex;
gap: 10px;
justify-content: space-between;
margin-bottom: 8px;
}
.selected-files__header h3 {
font-size: 15px;
font-weight: 600;
margin: 0;
}
.selected-files__count {
align-items: center;
background: #f0f3e8;
border-radius: 20px;
color: #52651d;
display: inline-flex;
font-size: 12px;
font-weight: 600;
height: 25px;
justify-content: center;
min-width: 25px;
padding: 0 7px;
}
.selected-files__list {
border: 1px solid #e7eae3;
border-radius: 8px;
list-style: none;
margin: 0;
max-height: 220px;
overflow-y: auto;
padding: 0;
}
.confirmation-summary {
display: grid;
gap: 10px;
grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
margin: 0;
padding: 0;
}
.confirmation-summary div { background: #fcfdfb; border: 1px solid #e7eae3; border-radius: 8px; min-width: 0; padding: 10px 12px; }
.confirmation-summary dt { color: #7a7a7a; font-size: 12px; }
.confirmation-summary dd { font-size: 15px; font-weight: 600; margin: 4px 0 0; overflow-wrap: anywhere; }
.file-row--readonly { grid-template-columns: 22px minmax(0, 1fr) auto; padding-right: 12px; }
.file-row {
align-items: center;
display: grid;
gap: 10px;
grid-template-columns: 22px minmax(0, 1fr) auto 40px;
min-height: 54px;
padding: 6px 8px 6px 12px;
}
.file-row + .file-row {
border-top: 1px solid #eef0eb;
}
.file-row__icon {
color: #71882b;
font-size: 20px;
height: 20px;
width: 20px;
}
.file-row__name {
font-size: 13px;
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.file-row__size {
color: #737b6b;
font-size: 12px;
white-space: nowrap;
}
.file-row__remove {
color: #596273;
}
.upload-dialog__footer {
align-items: center;
border-top: 1px solid #e3e7df;
border-top: 1px solid var(--color-border);
display: grid;
gap: 10px;
grid-template-columns: minmax(0, 1fr) auto;
@@ -353,12 +107,7 @@
justify-self: end;
}
.upload-action {
border-radius: 8px;
font: inherit;
font-weight: 600;
min-height: 44px;
padding: 10px 18px;
transition: background-color 0.18s ease;
@include button.base;
}
.action-cancel,
.action-back {
@@ -367,22 +116,22 @@
}
.action-cancel {
--mat-button-text-label-text-color: #fff;
background: #7a7a7a;
background: var(--color-text-secondary);
}
.action-cancel:hover {
background: #696969;
}
.action-back {
--mat-button-text-label-text-color: #081839;
--mat-button-text-label-text-color: var(--color-text);
background: #fff;
border: 1px solid #d7dccf;
border: 1px solid var(--color-border-subtle);
}
.action-back:hover {
background: #f3f6e9;
border-color: #a8c243;
background: var(--color-surface-hover);
border-color: var(--color-primary);
}
.action-continue {
--mat-button-filled-container-color: #6f821c;
--mat-button-filled-container-color: var(--color-primary-action);
--mat-button-filled-label-text-color: #f7f9ef;
--mat-button-filled-state-layer-color: transparent;
--mat-button-filled-ripple-color: transparent;
@@ -424,31 +173,9 @@
height: 22px;
width: 22px;
}
.source-options {
grid-template-columns: 1fr;
}
.source-card {
min-height: 94px;
padding: 16px;
}
.source-card--selected {
padding: 15px;
}
.upload-dialog__content {
padding: 20px 0;
}
.dropzone {
min-height: 220px;
padding: 20px 12px;
}
.file-row {
gap: 6px;
grid-template-columns: 20px minmax(0, 1fr) auto 36px;
padding-left: 8px;
}
.file-row--readonly { grid-template-columns: 20px minmax(0, 1fr) auto; }
.file-row__name { font-size: 12px; }
.file-row__size { font-size: 11px; }
}
@media (max-width: 360px) {
@@ -461,3 +188,7 @@
}
.action-continue { min-width: 92px; padding-inline: 10px; }
}
.upload-dialog__close:focus-visible, .upload-action:focus-visible {
@include button.focus;
}
+10 -81
View File
@@ -5,13 +5,16 @@ import { MatIconModule } from '@angular/material/icon';
import { SqlConnectionConfig, SqlConnectionConfigComponent } from './sql-connection-config';
import { SqlConnectionConfirmationComponent, SqlConnectionVerificationState } from './sql-connection-confirmation';
import { ProcessingStatusComponent } from './processing-status';
import { SourceSelectionComponent, UploadSource } from './source-selection';
import { FileConfigurationComponent } from './file-configuration';
import { FileConfirmationComponent } from './file-confirmation';
import { formatFileSize, selectFiles } from './file-selection';
type UploadSource = 'file' | 'sql';
type UploadStep = 'source' | 'configuration' | 'confirmation';
export type ProcessingState = 'processing' | 'success' | 'error';
@Component({
imports: [MatButtonModule, MatDialogModule, MatIconModule, SqlConnectionConfigComponent, SqlConnectionConfirmationComponent, ProcessingStatusComponent],
imports: [MatButtonModule, MatDialogModule, MatIconModule, SqlConnectionConfigComponent, SqlConnectionConfirmationComponent, ProcessingStatusComponent, SourceSelectionComponent, FileConfigurationComponent, FileConfirmationComponent],
selector: 'app-information-upload-dialog',
styleUrl: './information-upload-dialog.scss',
templateUrl: './information-upload-dialog.html',
@@ -22,15 +25,12 @@ export class InformationUploadDialog implements OnDestroy {
readonly files = signal<File[]>([]);
readonly totalFileSize = computed(() => this.files().reduce((total, file) => total + file.size, 0));
readonly fileMessages = signal<string[]>([]);
readonly isDragOver = signal(false);
readonly sqlConfig = signal<SqlConnectionConfig>({ host: '', port: '', database: '', username: '', password: '' });
readonly sqlConfigValid = signal(false);
readonly sqlVerificationState = signal<SqlConnectionVerificationState>('idle');
readonly processingState = signal<ProcessingState | null>(null);
readonly processingProgress = signal(0);
private dragDepth = 0;
private readonly allowedExtensions = new Set(['xlsx', 'csv', 'json', 'pdf']);
private verifiedSqlConfig: SqlConnectionConfig | null = null;
private verificationTimer: ReturnType<typeof setTimeout> | null = null;
private processingTimer: ReturnType<typeof setInterval> | null = null;
@@ -142,86 +142,15 @@ export class InformationUploadDialog implements OnDestroy {
this.processingTimer = null;
}
onFileSelection(event: Event): void {
const input = event.target as HTMLInputElement;
this.addFiles(input.files ? Array.from(input.files) : []);
input.value = '';
}
onDragEnter(event: DragEvent): void {
event.preventDefault();
this.dragDepth++;
this.isDragOver.set(true);
}
onDragOver(event: DragEvent): void {
event.preventDefault();
if (event.dataTransfer) event.dataTransfer.dropEffect = 'copy';
}
onDragLeave(event: DragEvent): void {
event.preventDefault();
this.dragDepth = Math.max(0, this.dragDepth - 1);
if (this.dragDepth === 0) this.isDragOver.set(false);
}
onDrop(event: DragEvent): void {
event.preventDefault();
this.dragDepth = 0;
this.isDragOver.set(false);
this.addFiles(event.dataTransfer?.files ? Array.from(event.dataTransfer.files) : []);
}
removeFile(fileToRemove: File): void {
this.files.update((files) => files.filter((file) => file !== fileToRemove));
}
formatFileSize(size: number): string {
if (size < 1024) return `${size} bytes`;
const units = ['KB', 'MB', 'GB'];
let value = size / 1024;
let unit = 0;
while (value >= 1024 && unit < units.length - 1) {
value /= 1024;
unit++;
}
return `${new Intl.NumberFormat('es-MX', { maximumFractionDigits: 1 }).format(value)} ${units[unit]}`;
}
readonly formatFileSize = formatFileSize;
fileIcon(file: File): string {
const extension = this.extensionOf(file.name);
if (extension === 'pdf') return 'picture_as_pdf';
if (extension === 'csv' || extension === 'xlsx') return 'table_chart';
return 'data_object';
}
private addFiles(incomingFiles: File[]): void {
const messages: string[] = [];
const accepted = [...this.files()];
for (const file of incomingFiles) {
const extension = this.extensionOf(file.name);
if (!this.allowedExtensions.has(extension)) {
messages.push(`${file.name} no fue agregado. Formato no compatible.`);
continue;
}
if (file.size === 0) {
messages.push(`${file.name} no fue agregado. El archivo está vacío.`);
continue;
}
if (accepted.some((existing) => existing.name === file.name && existing.size === file.size)) {
messages.push(`${file.name} ya se encuentra seleccionado.`);
continue;
}
accepted.push(file);
}
if (accepted.length !== this.files().length) this.files.set(accepted);
this.fileMessages.set(messages);
}
private extensionOf(fileName: string): string {
const finalDot = fileName.lastIndexOf('.');
return finalDot >= 0 ? fileName.slice(finalDot + 1).toLowerCase() : '';
addFiles(incomingFiles: File[]): void {
const selection = selectFiles(this.files(), incomingFiles);
if (selection.files.length !== this.files().length) this.files.set(selection.files);
this.fileMessages.set(selection.messages);
}
}
+6 -6
View File
@@ -2,7 +2,7 @@
.processing {
align-items: center;
background: #fff;
color: #081839;
color: var(--color-text);
display: flex;
justify-content: center;
min-height: min(500px, 100dvh);
@@ -11,23 +11,23 @@
}
.processing__active, .processing__success { margin: auto; max-width: 520px; width: 100%; }
.processing h2 { font-family: var(--font-heading); font-size: clamp(24px, 4vw, 30px); line-height: 1.2; margin: 0; }
.processing__intro, .processing__success p { color: #7a7a7a; font-size: 15px; line-height: 1.55; margin: 14px 0 30px; }
.processing__intro, .processing__success p { color: var(--color-text-secondary); font-size: 15px; line-height: 1.55; margin: 14px 0 30px; }
.processing__meter { align-items: center; display: flex; gap: 14px; }
.processing__meter mat-progress-bar { --mat-progress-bar-active-indicator-color: #71882b; --mat-progress-bar-track-color: #e9eddf; flex: 1; }
.processing__percentage { color: #081839; font-size: 14px; font-variant-numeric: tabular-nums; font-weight: 600; min-width: 42px; text-align: right; }
.processing__percentage { color: var(--color-text); font-size: 14px; font-variant-numeric: tabular-nums; font-weight: 600; min-width: 42px; text-align: right; }
.processing__current { color: #52651d; font-size: 15px; font-weight: 600; margin: 18px 0 26px; }
.processing__stages { display: grid; gap: 14px; list-style: none; margin: 0 auto; max-width: 320px; padding: 0; text-align: left; }
.processing__stages li { align-items: center; display: flex; gap: 10px; font-size: 14px; }
.processing__stages mat-icon { flex: 0 0 20px; font-size: 20px; height: 20px; width: 20px; }
.processing__stage--complete { color: #71882b; }
.processing__stage--active { color: #081839; font-weight: 600; }
.processing__stage--active { color: var(--color-text); font-weight: 600; }
.processing__stage--pending { color: #858585; }
.processing__note { color: #858585; font-size: 13px; line-height: 1.5; margin: 30px auto 0; max-width: 300px; }
.processing__success { padding: 28px 0; }
.processing__success-icon { align-items: center; background: #f0f3e8; border-radius: 50%; color: #71882b; display: inline-flex; height: 64px; justify-content: center; margin-bottom: 22px; width: 64px; }
.processing__success-icon { align-items: center; background: var(--color-step); border-radius: 50%; color: #71882b; display: inline-flex; height: 64px; justify-content: center; margin-bottom: 22px; width: 64px; }
.processing__success-icon mat-icon { font-size: 34px; height: 34px; width: 34px; }
.processing__success p { margin-bottom: 28px; }
.processing__finish { --mat-button-filled-container-color: #6f821c; --mat-button-filled-label-text-color: #f7f9ef; --mat-button-filled-state-layer-color: transparent; border-radius: 8px; font-weight: 600; min-height: 46px; min-width: 150px; }
.processing__finish { --mat-button-filled-container-color: var(--color-primary-action); --mat-button-filled-label-text-color: #f7f9ef; --mat-button-filled-state-layer-color: transparent; border-radius: 8px; font-weight: 600; min-height: 46px; min-width: 150px; }
.processing__finish:hover { --mat-button-filled-container-color: #809625; }
.visually-hidden { clip: rect(0, 0, 0, 0); clip-path: inset(50%); height: 1px; overflow: hidden; position: absolute; white-space: nowrap; width: 1px; }
@media (max-width: 480px) { .processing { min-height: min(440px, 100dvh); padding: 28px 4px; } .processing__intro { font-size: 14px; } .processing__stages { gap: 12px; } }
+12
View File
@@ -0,0 +1,12 @@
<div class="source-options" role="group" aria-label="Selecciona una fuente de información">
<button class="source-card" [class.source-card--selected]="source === 'file'" [attr.aria-pressed]="source === 'file'" type="button" (click)="sourceChange.emit('file')">
<span class="source-card__icon"><mat-icon aria-hidden="true">upload_file</mat-icon></span>
<span class="source-card__copy"><span class="source-card__title">Archivo</span><span class="source-card__description">Excel, CSV, JSON o PDF</span></span>
@if (source === 'file') { <mat-icon class="source-card__check" aria-hidden="true">check_circle</mat-icon> }
</button>
<button class="source-card" [class.source-card--selected]="source === 'sql'" [attr.aria-pressed]="source === 'sql'" type="button" (click)="sourceChange.emit('sql')">
<span class="source-card__icon"><mat-icon aria-hidden="true">storage</mat-icon></span>
<span class="source-card__copy"><span class="source-card__title">Conexión SQL</span><span class="source-card__description">Conecta una base de datos para utilizar su información.</span></span>
@if (source === 'sql') { <mat-icon class="source-card__check" aria-hidden="true">check_circle</mat-icon> }
</button>
</div>
+63
View File
@@ -0,0 +1,63 @@
@use 'upload-button' as button;
:host { display: block; }
.source-options {
display: grid;
gap: 16px;
grid-template-columns: repeat(2, minmax(0, 1fr));
}
.source-card {
align-items: center;
background: #fff;
border: 1px solid var(--color-border);
border-radius: 9px;
color: var(--color-text);
cursor: pointer;
display: flex;
gap: 16px;
min-height: 126px;
padding: 20px;
position: relative;
text-align: left;
}
.source-card:focus-visible {
@include button.focus;
}
.source-card--selected {
background: #fbfcf6;
border: 2px solid var(--color-primary);
padding: 19px;
}
.source-card__icon {
align-items: center;
background: var(--color-step);
border-radius: 8px;
color: #71882b;
display: inline-flex;
flex: 0 0 46px;
height: 46px;
justify-content: center;
}
.source-card__copy {
display: grid;
gap: 6px;
min-width: 0;
}
.source-card__title {
font-size: 16px;
font-weight: 600;
}
.source-card__description {
color: var(--color-text-secondary);
font-size: 13px;
line-height: 1.45;
}
.source-card__check {
color: #71882b;
margin-left: auto;
}
@media (max-width: 600px) {
.source-options { grid-template-columns: 1fr; }
.source-card { min-height: 94px; padding: 16px; }
.source-card--selected { padding: 15px; }
}
+15
View File
@@ -0,0 +1,15 @@
import { Component, EventEmitter, Input, Output } from '@angular/core';
import { MatIconModule } from '@angular/material/icon';
export type UploadSource = 'file' | 'sql';
@Component({
imports: [MatIconModule],
selector: 'app-source-selection',
styleUrl: './source-selection.scss',
templateUrl: './source-selection.html',
})
export class SourceSelectionComponent {
@Input() source: UploadSource | null = null;
@Output() readonly sourceChange = new EventEmitter<UploadSource>();
}
+6 -6
View File
@@ -1,28 +1,28 @@
:host { display: block; min-width: 0; }
.sql-config { display: grid; gap: 2px; min-width: 0; }
.sql-config__hint { color: #7a7a7a; font-size: 14px; margin: 0 0 10px; }
.sql-config__hint { color: var(--color-text-secondary); font-size: 14px; margin: 0 0 10px; }
.sql-config__host-row { display: grid; gap: 12px; grid-template-columns: minmax(0, 2.5fr) minmax(130px, 1fr); }
mat-form-field {
--mat-form-field-outlined-focus-outline-color: #a8c243;
--mat-form-field-outlined-focus-outline-color: var(--color-primary);
--mat-form-field-outlined-focus-label-text-color: #71882b;
--mat-form-field-outlined-label-text-color: #596273;
min-width: 0;
width: 100%;
}
mat-form-field input { color: #081839; }
mat-form-field input { color: var(--color-text); }
.password-toggle {
--mat-icon-button-icon-color: #7a7a7a;
--mat-icon-button-icon-color: var(--color-text-secondary);
--mat-icon-button-state-layer-color: transparent;
--mat-icon-button-ripple-color: transparent;
background: transparent;
border: 0;
border-radius: 50%;
box-shadow: none;
color: #7a7a7a;
color: var(--color-text-secondary);
opacity: 0.82;
transition: color 120ms ease, opacity 120ms ease;
}
.password-toggle:hover { background: transparent; color: #596273; opacity: 1; }
.password-toggle:active { background: transparent; color: #4d586a; }
.password-toggle:focus-visible { outline: 2px solid #a8c243; outline-offset: -3px; }
.password-toggle:focus-visible { outline: 2px solid var(--color-primary); outline-offset: -3px; }
@media (max-width: 560px) { .sql-config__host-row { grid-template-columns: minmax(0, 1fr); gap: 2px; } }
+7 -7
View File
@@ -12,8 +12,8 @@
min-width: 0;
padding: 10px 12px;
}
.sql-summary dt { color: #7a7a7a; font-size: 12px; }
.sql-summary dd { color: #081839; font-size: 15px; font-weight: 600; margin: 4px 0 0; overflow-wrap: anywhere; }
.sql-summary dt { color: var(--color-text-secondary); font-size: 12px; }
.sql-summary dd { color: var(--color-text); font-size: 15px; font-weight: 600; margin: 4px 0 0; overflow-wrap: anywhere; }
.connection-check {
align-items: center;
background: #fcfdfb;
@@ -25,16 +25,16 @@
margin-top: 14px;
padding: 12px 14px;
}
.connection-check h3 { color: #081839; font-size: 14px; font-weight: 600; margin: 0; }
.connection-check p { color: #7a7a7a; font-size: 13px; margin: 4px 0 0; }
.connection-check h3 { color: var(--color-text); font-size: 14px; font-weight: 600; margin: 0; }
.connection-check p { color: var(--color-text-secondary); font-size: 13px; margin: 4px 0 0; }
.connection-check__status { align-items: center; display: flex; gap: 7px; min-height: 20px; }
.connection-check__status p { margin: 4px 0 0; }
.connection-check__spinner { --mat-progress-spinner-active-indicator-color: #71882b; flex: 0 0 auto; }
.connection-check__success { color: #71882b; }
.connection-check__error { color: #7a7a7a; }
.connection-check__error { color: var(--color-text-secondary); }
.connection-check__action { align-items: flex-end; display: flex; flex-direction: column; gap: 3px; }
.connection-check__action button { --mat-button-outlined-label-text-color: #596273; --mat-button-outlined-outline-color: #d7dccf; white-space: nowrap; }
.connection-check__action span { color: #7a7a7a; font-size: 11px; }
.connection-check__action button { --mat-button-outlined-label-text-color: #596273; --mat-button-outlined-outline-color: var(--color-border-subtle); white-space: nowrap; }
.connection-check__action span { color: var(--color-text-secondary); font-size: 11px; }
@media (max-width: 760px) { .sql-summary { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 480px) {
.sql-summary { grid-template-columns: minmax(0, 1fr); }
+3
View File
@@ -8,6 +8,9 @@
--color-surface: #ffffff;
--color-border: #e3e7df;
--color-step: #f0f3e8;
--color-border-subtle: #d7dccf;
--color-surface-hover: #f3f6e9;
--color-primary-action: #6f821c;
--font-body: 'Roboto', sans-serif;
--font-heading: 'Rajdhani', 'Roboto Condensed', 'Arial Narrow', sans-serif;
}