chaqui-catalog-frontend-lib 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/EXAMPLES.md +255 -0
- package/INSTALLATION.md +226 -0
- package/README.md +310 -0
- package/STRUCTURE.md +123 -0
- package/dist/lib/catalog.module.d.ts +19 -0
- package/dist/lib/catalog.module.d.ts.map +1 -0
- package/dist/lib/catalog.module.js +49 -0
- package/dist/lib/catalog.module.js.map +1 -0
- package/dist/lib/components/catalog-items-select/catalog-items-select.component.d.ts +58 -0
- package/dist/lib/components/catalog-items-select/catalog-items-select.component.d.ts.map +1 -0
- package/dist/lib/components/catalog-items-select/catalog-items-select.component.js +147 -0
- package/dist/lib/components/catalog-items-select/catalog-items-select.component.js.map +1 -0
- package/dist/lib/components/index.d.ts +2 -0
- package/dist/lib/components/index.d.ts.map +1 -0
- package/dist/lib/components/index.js +2 -0
- package/dist/lib/components/index.js.map +1 -0
- package/dist/lib/config/catalog.config.d.ts +15 -0
- package/dist/lib/config/catalog.config.d.ts.map +1 -0
- package/dist/lib/config/catalog.config.js +5 -0
- package/dist/lib/config/catalog.config.js.map +1 -0
- package/dist/lib/models/catalog.model.d.ts +27 -0
- package/dist/lib/models/catalog.model.d.ts.map +1 -0
- package/dist/lib/models/catalog.model.js +2 -0
- package/dist/lib/models/catalog.model.js.map +1 -0
- package/dist/lib/models/index.d.ts +2 -0
- package/dist/lib/models/index.d.ts.map +1 -0
- package/dist/lib/models/index.js +2 -0
- package/dist/lib/models/index.js.map +1 -0
- package/dist/lib/services/catalog.service.d.ts +33 -0
- package/dist/lib/services/catalog.service.d.ts.map +1 -0
- package/dist/lib/services/catalog.service.js +74 -0
- package/dist/lib/services/catalog.service.js.map +1 -0
- package/dist/lib/services/index.d.ts +2 -0
- package/dist/lib/services/index.d.ts.map +1 -0
- package/dist/lib/services/index.js +2 -0
- package/dist/lib/services/index.js.map +1 -0
- package/dist/public-api.d.ts +9 -0
- package/dist/public-api.d.ts.map +1 -0
- package/dist/public-api.js +9 -0
- package/dist/public-api.js.map +1 -0
- package/index.ts +6 -0
- package/ng-package.json +6 -0
- package/package.json +44 -0
- package/src/lib/catalog.module.ts +40 -0
- package/src/lib/components/catalog-items-select/catalog-items-select.component.css +71 -0
- package/src/lib/components/catalog-items-select/catalog-items-select.component.html +43 -0
- package/src/lib/components/catalog-items-select/catalog-items-select.component.ts +125 -0
- package/src/lib/components/index.ts +1 -0
- package/src/lib/config/catalog.config.ts +15 -0
- package/src/lib/models/catalog.model.ts +28 -0
- package/src/lib/models/index.ts +1 -0
- package/src/lib/services/catalog.service.ts +71 -0
- package/src/lib/services/index.ts +1 -0
- package/src/public-api.ts +8 -0
- package/tsconfig.lib.json +28 -0
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { Component, Input, Output, EventEmitter, OnInit, OnDestroy } from '@angular/core';
|
|
2
|
+
import { CatalogService } from '../../services/catalog.service.js';
|
|
3
|
+
import { CatalogItem } from '../../models/catalog.model.js';
|
|
4
|
+
import { Subject } from 'rxjs';
|
|
5
|
+
import { takeUntil } from 'rxjs/operators';
|
|
6
|
+
|
|
7
|
+
@Component({
|
|
8
|
+
selector: 'catalog-items-select',
|
|
9
|
+
templateUrl: './catalog-items-select.component.html',
|
|
10
|
+
styleUrls: ['./catalog-items-select.component.css']
|
|
11
|
+
})
|
|
12
|
+
export class CatalogItemsSelectComponent implements OnInit, OnDestroy {
|
|
13
|
+
/**
|
|
14
|
+
* ID del catálogo del cual cargar los items
|
|
15
|
+
*/
|
|
16
|
+
@Input() catalogId!: number;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* ID del item actualmente seleccionado (opcional)
|
|
20
|
+
*/
|
|
21
|
+
@Input() selectedItemId?: number;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Label del input del catálogo
|
|
25
|
+
*/
|
|
26
|
+
@Input() catalogLabel: string = 'ID del Catálogo';
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Placeholder del select de items
|
|
30
|
+
*/
|
|
31
|
+
@Input() itemSelectPlaceholder: string = 'Selecciona un item';
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Emite cuando se selecciona un item
|
|
35
|
+
*/
|
|
36
|
+
@Output() itemSelected = new EventEmitter<CatalogItem>();
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Emite cuando hay un error al cargar los items
|
|
40
|
+
*/
|
|
41
|
+
@Output() error = new EventEmitter<string>();
|
|
42
|
+
|
|
43
|
+
items: CatalogItem[] = [];
|
|
44
|
+
isLoading: boolean = false;
|
|
45
|
+
errorMessage: string = '';
|
|
46
|
+
|
|
47
|
+
private destroy$ = new Subject<void>();
|
|
48
|
+
|
|
49
|
+
constructor(private catalogService: CatalogService) {}
|
|
50
|
+
|
|
51
|
+
ngOnInit(): void {
|
|
52
|
+
if (this.catalogId) {
|
|
53
|
+
this.loadItems();
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
ngOnDestroy(): void {
|
|
58
|
+
this.destroy$.next();
|
|
59
|
+
this.destroy$.complete();
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Carga los items del catálogo especificado
|
|
64
|
+
*/
|
|
65
|
+
loadItems(): void {
|
|
66
|
+
if (!this.catalogId) {
|
|
67
|
+
this.errorMessage = 'Por favor ingresa un ID de catálogo válido';
|
|
68
|
+
this.error.emit(this.errorMessage);
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
this.isLoading = true;
|
|
73
|
+
this.errorMessage = '';
|
|
74
|
+
this.items = [];
|
|
75
|
+
|
|
76
|
+
this.catalogService.getItemsByCatalogId(this.catalogId)
|
|
77
|
+
.pipe(takeUntil(this.destroy$))
|
|
78
|
+
.subscribe({
|
|
79
|
+
next: (items: CatalogItem[]) => {
|
|
80
|
+
this.items = items;
|
|
81
|
+
this.isLoading = false;
|
|
82
|
+
},
|
|
83
|
+
error: (err: any) => {
|
|
84
|
+
this.isLoading = false;
|
|
85
|
+
this.errorMessage = err?.message || 'Error al cargar los items del catálogo';
|
|
86
|
+
this.error.emit(this.errorMessage);
|
|
87
|
+
console.error('Error cargando items:', err);
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Maneja el cambio de catálogo
|
|
94
|
+
* @param event Evento del input
|
|
95
|
+
*/
|
|
96
|
+
onCatalogIdChange(event: any): void {
|
|
97
|
+
const value = event.target.value;
|
|
98
|
+
this.catalogId = value ? Number(value) : null as any;
|
|
99
|
+
if (this.catalogId) {
|
|
100
|
+
this.loadItems();
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Maneja la selección de un item
|
|
106
|
+
* @param event Evento del select
|
|
107
|
+
*/
|
|
108
|
+
onItemSelected(event: any): void {
|
|
109
|
+
const itemId = Number(event.target.value);
|
|
110
|
+
const selectedItem = this.items.find(item => item.id === itemId);
|
|
111
|
+
|
|
112
|
+
if (selectedItem) {
|
|
113
|
+
this.itemSelected.emit(selectedItem);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Obtiene el nombre del item para mostrar en el select
|
|
119
|
+
* @param item Item del catálogo
|
|
120
|
+
* @returns Nombre del item o ID si no hay nombre
|
|
121
|
+
*/
|
|
122
|
+
getItemDisplayName(item: CatalogItem): string {
|
|
123
|
+
return item.name || `Item ${item.id}`;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './catalog-items-select/catalog-items-select.component.js';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuración de la librería de Catálogos
|
|
3
|
+
*/
|
|
4
|
+
export interface CatalogConfig {
|
|
5
|
+
/**
|
|
6
|
+
* URL base del servicio de catálogos
|
|
7
|
+
* Ejemplo: 'http://localhost:3000/api'
|
|
8
|
+
*/
|
|
9
|
+
apiBaseUrl: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Token de inyección para la configuración
|
|
14
|
+
*/
|
|
15
|
+
export const CATALOG_CONFIG_TOKEN = 'CATALOG_CONFIG';
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Interfaz para representar un Catálogo
|
|
3
|
+
*/
|
|
4
|
+
export interface Catalog {
|
|
5
|
+
id: number;
|
|
6
|
+
name: string;
|
|
7
|
+
description?: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Interfaz para representar un Item de Catálogo
|
|
12
|
+
*/
|
|
13
|
+
export interface CatalogItem {
|
|
14
|
+
id: number;
|
|
15
|
+
catalogId: number;
|
|
16
|
+
name: string;
|
|
17
|
+
description?: string;
|
|
18
|
+
[key: string]: any;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Interfaz para la respuesta de error de la API
|
|
23
|
+
*/
|
|
24
|
+
export interface ApiErrorResponse {
|
|
25
|
+
message: string;
|
|
26
|
+
status?: number;
|
|
27
|
+
error?: any;
|
|
28
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './catalog.model.js';
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { Injectable, Inject } from '@angular/core';
|
|
2
|
+
import { HttpClient } from '@angular/common/http';
|
|
3
|
+
import { Observable, throwError } from 'rxjs';
|
|
4
|
+
import { catchError } from 'rxjs/operators';
|
|
5
|
+
import { Catalog, CatalogItem, ApiErrorResponse } from '../models/catalog.model.js';
|
|
6
|
+
import { CATALOG_CONFIG_TOKEN } from '../config/catalog.config.js';
|
|
7
|
+
import type { CatalogConfig } from '../config/catalog.config.js';
|
|
8
|
+
|
|
9
|
+
@Injectable({
|
|
10
|
+
providedIn: 'root'
|
|
11
|
+
})
|
|
12
|
+
export class CatalogService {
|
|
13
|
+
private apiBaseUrl: string;
|
|
14
|
+
|
|
15
|
+
constructor(
|
|
16
|
+
private http: HttpClient,
|
|
17
|
+
@Inject(CATALOG_CONFIG_TOKEN) config: CatalogConfig
|
|
18
|
+
) {
|
|
19
|
+
this.apiBaseUrl = config.apiBaseUrl;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Obtiene todos los catálogos disponibles
|
|
24
|
+
* @returns Observable con la lista de catálogos
|
|
25
|
+
*/
|
|
26
|
+
getCatalogs(): Observable<Catalog[]> {
|
|
27
|
+
return this.http.get<Catalog[]>(`${this.apiBaseUrl}/catalogs`)
|
|
28
|
+
.pipe(
|
|
29
|
+
catchError(this.handleError)
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Obtiene todos los items de un catálogo específico
|
|
35
|
+
* @param catalogId ID del catálogo
|
|
36
|
+
* @returns Observable con la lista de items
|
|
37
|
+
*/
|
|
38
|
+
getItemsByCatalogId(catalogId: number): Observable<CatalogItem[]> {
|
|
39
|
+
return this.http.get<CatalogItem[]>(`${this.apiBaseUrl}/catalogs/${catalogId}/items`)
|
|
40
|
+
.pipe(
|
|
41
|
+
catchError(this.handleError)
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Obtiene un item específico por su ID
|
|
47
|
+
* @param itemId ID del item
|
|
48
|
+
* @returns Observable con los datos del item
|
|
49
|
+
*/
|
|
50
|
+
getItemById(itemId: number): Observable<CatalogItem> {
|
|
51
|
+
return this.http.get<CatalogItem>(`${this.apiBaseUrl}/items/${itemId}`)
|
|
52
|
+
.pipe(
|
|
53
|
+
catchError(this.handleError)
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Maneja los errores de las peticiones HTTP
|
|
59
|
+
* @param error Error de la petición
|
|
60
|
+
* @returns Observable con el error
|
|
61
|
+
*/
|
|
62
|
+
private handleError(error: any) {
|
|
63
|
+
const errorResponse: ApiErrorResponse = {
|
|
64
|
+
message: error.message || 'Error en la petición',
|
|
65
|
+
status: error.status,
|
|
66
|
+
error: error.error
|
|
67
|
+
};
|
|
68
|
+
console.error('Error en CatalogService:', errorResponse);
|
|
69
|
+
return throwError(() => errorResponse);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './catalog.service.js';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Exporta todos los módulos, servicios y componentes públicos de la librería
|
|
3
|
+
*/
|
|
4
|
+
export * from './lib/catalog.module.js';
|
|
5
|
+
export * from './lib/services/index.js';
|
|
6
|
+
export * from './lib/models/index.js';
|
|
7
|
+
export * from './lib/components/index.js';
|
|
8
|
+
export * from './lib/config/catalog.config.js';
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"module": "ES2022",
|
|
5
|
+
"moduleResolution": "node",
|
|
6
|
+
"lib": ["ES2022", "dom"],
|
|
7
|
+
"outDir": "./dist",
|
|
8
|
+
"declaration": true,
|
|
9
|
+
"declarationMap": true,
|
|
10
|
+
"inlineSources": true,
|
|
11
|
+
"skipLibCheck": true,
|
|
12
|
+
"removeComments": false,
|
|
13
|
+
"strict": true,
|
|
14
|
+
"esModuleInterop": true,
|
|
15
|
+
"experimentalDecorators": true,
|
|
16
|
+
"emitDecoratorMetadata": true,
|
|
17
|
+
"sourceMap": true,
|
|
18
|
+
"types": ["node"]
|
|
19
|
+
},
|
|
20
|
+
"angularCompilerOptions": {
|
|
21
|
+
"enableI18nLegacyMessageIdFormat": false,
|
|
22
|
+
"strictInjectionParameters": true,
|
|
23
|
+
"strictInputAccessModifiers": true,
|
|
24
|
+
"strictTemplates": true
|
|
25
|
+
},
|
|
26
|
+
"include": ["src/**/*.ts"],
|
|
27
|
+
"exclude": ["src/**/*.spec.ts", "node_modules"]
|
|
28
|
+
}
|