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.
Files changed (55) hide show
  1. package/EXAMPLES.md +255 -0
  2. package/INSTALLATION.md +226 -0
  3. package/README.md +310 -0
  4. package/STRUCTURE.md +123 -0
  5. package/dist/lib/catalog.module.d.ts +19 -0
  6. package/dist/lib/catalog.module.d.ts.map +1 -0
  7. package/dist/lib/catalog.module.js +49 -0
  8. package/dist/lib/catalog.module.js.map +1 -0
  9. package/dist/lib/components/catalog-items-select/catalog-items-select.component.d.ts +58 -0
  10. package/dist/lib/components/catalog-items-select/catalog-items-select.component.d.ts.map +1 -0
  11. package/dist/lib/components/catalog-items-select/catalog-items-select.component.js +147 -0
  12. package/dist/lib/components/catalog-items-select/catalog-items-select.component.js.map +1 -0
  13. package/dist/lib/components/index.d.ts +2 -0
  14. package/dist/lib/components/index.d.ts.map +1 -0
  15. package/dist/lib/components/index.js +2 -0
  16. package/dist/lib/components/index.js.map +1 -0
  17. package/dist/lib/config/catalog.config.d.ts +15 -0
  18. package/dist/lib/config/catalog.config.d.ts.map +1 -0
  19. package/dist/lib/config/catalog.config.js +5 -0
  20. package/dist/lib/config/catalog.config.js.map +1 -0
  21. package/dist/lib/models/catalog.model.d.ts +27 -0
  22. package/dist/lib/models/catalog.model.d.ts.map +1 -0
  23. package/dist/lib/models/catalog.model.js +2 -0
  24. package/dist/lib/models/catalog.model.js.map +1 -0
  25. package/dist/lib/models/index.d.ts +2 -0
  26. package/dist/lib/models/index.d.ts.map +1 -0
  27. package/dist/lib/models/index.js +2 -0
  28. package/dist/lib/models/index.js.map +1 -0
  29. package/dist/lib/services/catalog.service.d.ts +33 -0
  30. package/dist/lib/services/catalog.service.d.ts.map +1 -0
  31. package/dist/lib/services/catalog.service.js +74 -0
  32. package/dist/lib/services/catalog.service.js.map +1 -0
  33. package/dist/lib/services/index.d.ts +2 -0
  34. package/dist/lib/services/index.d.ts.map +1 -0
  35. package/dist/lib/services/index.js +2 -0
  36. package/dist/lib/services/index.js.map +1 -0
  37. package/dist/public-api.d.ts +9 -0
  38. package/dist/public-api.d.ts.map +1 -0
  39. package/dist/public-api.js +9 -0
  40. package/dist/public-api.js.map +1 -0
  41. package/index.ts +6 -0
  42. package/ng-package.json +6 -0
  43. package/package.json +44 -0
  44. package/src/lib/catalog.module.ts +40 -0
  45. package/src/lib/components/catalog-items-select/catalog-items-select.component.css +71 -0
  46. package/src/lib/components/catalog-items-select/catalog-items-select.component.html +43 -0
  47. package/src/lib/components/catalog-items-select/catalog-items-select.component.ts +125 -0
  48. package/src/lib/components/index.ts +1 -0
  49. package/src/lib/config/catalog.config.ts +15 -0
  50. package/src/lib/models/catalog.model.ts +28 -0
  51. package/src/lib/models/index.ts +1 -0
  52. package/src/lib/services/catalog.service.ts +71 -0
  53. package/src/lib/services/index.ts +1 -0
  54. package/src/public-api.ts +8 -0
  55. package/tsconfig.lib.json +28 -0
package/EXAMPLES.md ADDED
@@ -0,0 +1,255 @@
1
+ /**
2
+ * Ejemplo de uso de la librería Catalog Lib
3
+ *
4
+ * Este archivo muestra cómo usar el componente y servicio de catálogos
5
+ * en tu aplicación Angular.
6
+ */
7
+
8
+ import { Component, OnInit } from '@angular/core';
9
+ import { CatalogService, CatalogItem, Catalog } from '@catalogos/catalog-lib';
10
+
11
+ /**
12
+ * Ejemplo 1: Usando el componente CatalogItemsSelect
13
+ */
14
+ @Component({
15
+ selector: 'app-catalog-component-example',
16
+ template: `
17
+ <div class="container">
18
+ <h2>Ejemplo 1: Usando el Componente</h2>
19
+
20
+ <catalog-items-select
21
+ [catalogId]="selectedCatalogId"
22
+ [selectedItemId]="selectedItemId"
23
+ catalogLabel="Selecciona un Catálogo"
24
+ itemSelectPlaceholder="Elige un item..."
25
+ (itemSelected)="onItemSelected($event)"
26
+ (error)="onError($event)"
27
+ ></catalog-items-select>
28
+
29
+ <div *ngIf="errorMessage" class="alert alert-danger">
30
+ <strong>Error:</strong> {{ errorMessage }}
31
+ </div>
32
+
33
+ <div *ngIf="selectedItem" class="alert alert-success">
34
+ <h4>Item Seleccionado</h4>
35
+ <p><strong>ID:</strong> {{ selectedItem.id }}</p>
36
+ <p><strong>Nombre:</strong> {{ selectedItem.name }}</p>
37
+ <p><strong>Descripción:</strong> {{ selectedItem.description || 'N/A' }}</p>
38
+ </div>
39
+ </div>
40
+ `,
41
+ styles: [`
42
+ .container {
43
+ max-width: 500px;
44
+ margin: 20px auto;
45
+ padding: 20px;
46
+ border: 1px solid #ddd;
47
+ border-radius: 8px;
48
+ }
49
+ .alert {
50
+ padding: 15px;
51
+ margin-top: 15px;
52
+ border-radius: 4px;
53
+ }
54
+ .alert-danger {
55
+ background-color: #f8d7da;
56
+ border: 1px solid #f5c6cb;
57
+ color: #721c24;
58
+ }
59
+ .alert-success {
60
+ background-color: #d4edda;
61
+ border: 1px solid #c3e6cb;
62
+ color: #155724;
63
+ }
64
+ `]
65
+ })
66
+ export class CatalogComponentExampleComponent {
67
+ selectedCatalogId: number = 1;
68
+ selectedItemId?: number;
69
+ selectedItem: CatalogItem | null = null;
70
+ errorMessage: string = '';
71
+
72
+ onItemSelected(item: CatalogItem): void {
73
+ this.selectedItem = item;
74
+ this.selectedItemId = item.id;
75
+ this.errorMessage = '';
76
+ console.log('Item Seleccionado:', item);
77
+ }
78
+
79
+ onError(error: string): void {
80
+ this.errorMessage = error;
81
+ }
82
+ }
83
+
84
+ /**
85
+ * Ejemplo 2: Usando el servicio directamente
86
+ */
87
+ @Component({
88
+ selector: 'app-catalog-service-example',
89
+ template: `
90
+ <div class="container">
91
+ <h2>Ejemplo 2: Usando el Servicio Directamente</h2>
92
+
93
+ <div class="form-group">
94
+ <label>ID del Catálogo:</label>
95
+ <input
96
+ type="number"
97
+ [(ngModel)]="catalogId"
98
+ (change)="onCatalogIdChange()"
99
+ min="1"
100
+ />
101
+ </div>
102
+
103
+ <button (click)="loadCatalogs()" class="btn btn-primary">
104
+ Cargar Todos los Catálogos
105
+ </button>
106
+
107
+ <div *ngIf="catalogs.length > 0" class="catalogs-list">
108
+ <h3>Catálogos Disponibles:</h3>
109
+ <ul>
110
+ <li *ngFor="let catalog of catalogs">
111
+ {{ catalog.name }} (ID: {{ catalog.id }})
112
+ </li>
113
+ </ul>
114
+ </div>
115
+
116
+ <div *ngIf="items.length > 0" class="items-list">
117
+ <h3>Items del Catálogo {{ catalogId }}:</h3>
118
+ <select [(ngModel)]="selectedItemId" (change)="onItemSelected()">
119
+ <option value="">Selecciona un item</option>
120
+ <option *ngFor="let item of items" [value]="item.id">
121
+ {{ item.name }} (ID: {{ item.id }})
122
+ </option>
123
+ </select>
124
+ </div>
125
+
126
+ <div *ngIf="selectedItem" class="selected-item">
127
+ <h4>Detalles del Item:</h4>
128
+ <pre>{{ selectedItem | json }}</pre>
129
+ </div>
130
+
131
+ <div *ngIf="isLoading" class="loading">
132
+ Cargando...
133
+ </div>
134
+ </div>
135
+ `,
136
+ styles: [`
137
+ .container {
138
+ max-width: 600px;
139
+ margin: 20px auto;
140
+ padding: 20px;
141
+ border: 1px solid #ddd;
142
+ border-radius: 8px;
143
+ }
144
+ .form-group {
145
+ margin-bottom: 15px;
146
+ }
147
+ label {
148
+ display: block;
149
+ margin-bottom: 5px;
150
+ font-weight: 500;
151
+ }
152
+ input, select {
153
+ width: 100%;
154
+ padding: 8px;
155
+ border: 1px solid #ddd;
156
+ border-radius: 4px;
157
+ font-size: 14px;
158
+ }
159
+ .btn {
160
+ padding: 10px 20px;
161
+ border: none;
162
+ border-radius: 4px;
163
+ cursor: pointer;
164
+ font-size: 14px;
165
+ margin-top: 10px;
166
+ }
167
+ .btn-primary {
168
+ background-color: #007bff;
169
+ color: white;
170
+ }
171
+ .btn-primary:hover {
172
+ background-color: #0056b3;
173
+ }
174
+ .catalogs-list, .items-list, .selected-item {
175
+ margin-top: 20px;
176
+ padding: 15px;
177
+ background-color: #f5f5f5;
178
+ border-radius: 4px;
179
+ }
180
+ .loading {
181
+ text-align: center;
182
+ color: #666;
183
+ font-style: italic;
184
+ margin-top: 20px;
185
+ }
186
+ `]
187
+ })
188
+ export class CatalogServiceExampleComponent implements OnInit {
189
+ catalogId: number = 1;
190
+ selectedItemId?: number;
191
+ catalogs: Catalog[] = [];
192
+ items: CatalogItem[] = [];
193
+ selectedItem: CatalogItem | null = null;
194
+ isLoading: boolean = false;
195
+
196
+ constructor(private catalogService: CatalogService) {}
197
+
198
+ ngOnInit(): void {
199
+ this.loadCatalogs();
200
+ }
201
+
202
+ loadCatalogs(): void {
203
+ this.isLoading = true;
204
+ this.catalogService.getCatalogs().subscribe({
205
+ next: (catalogs) => {
206
+ this.catalogs = catalogs;
207
+ this.isLoading = false;
208
+ console.log('Catálogos cargados:', catalogs);
209
+ },
210
+ error: (error) => {
211
+ this.isLoading = false;
212
+ console.error('Error cargando catálogos:', error);
213
+ }
214
+ });
215
+ }
216
+
217
+ onCatalogIdChange(): void {
218
+ const catalogs = this.catalogs.filter(c => c.id === this.catalogId);
219
+ if (catalogs.length > 0) {
220
+ this.loadItems();
221
+ }
222
+ }
223
+
224
+ loadItems(): void {
225
+ this.isLoading = true;
226
+ this.items = [];
227
+ this.selectedItem = null;
228
+
229
+ this.catalogService.getItemsByCatalogId(this.catalogId).subscribe({
230
+ next: (items) => {
231
+ this.items = items;
232
+ this.isLoading = false;
233
+ console.log('Items cargados:', items);
234
+ },
235
+ error: (error) => {
236
+ this.isLoading = false;
237
+ console.error('Error cargando items:', error);
238
+ }
239
+ });
240
+ }
241
+
242
+ onItemSelected(): void {
243
+ if (this.selectedItemId) {
244
+ this.catalogService.getItemById(this.selectedItemId).subscribe({
245
+ next: (item) => {
246
+ this.selectedItem = item;
247
+ console.log('Detalles del item:', item);
248
+ },
249
+ error: (error) => {
250
+ console.error('Error cargando item:', error);
251
+ }
252
+ });
253
+ }
254
+ }
255
+ }
@@ -0,0 +1,226 @@
1
+ # Guía de Instalación - Catalog Lib
2
+
3
+ ## Requisitos Previos
4
+
5
+ - Node.js 14+ instalado
6
+ - Angular 15+
7
+ - npm o yarn
8
+
9
+ ## Pasos de Instalación
10
+
11
+ ### Paso 1: Preparar tu Proyecto Angular
12
+
13
+ Si aún no tienes un proyecto Angular, crea uno:
14
+
15
+ ```bash
16
+ ng new my-catalog-app
17
+ cd my-catalog-app
18
+ ```
19
+
20
+ ### Paso 2: Instalar las Dependencias Necesarias
21
+
22
+ La librería requiere que `@angular/common` y `HttpClientModule` estén disponibles.
23
+
24
+ ```bash
25
+ npm install
26
+ ```
27
+
28
+ ### Paso 3: Instalar la Librería Catalog Lib
29
+
30
+ Opción A - Si está publicada en npm:
31
+ ```bash
32
+ npm install @catalogos/catalog-lib
33
+ ```
34
+
35
+ Opción B - Si está en tu sistema de archivos local:
36
+ ```bash
37
+ npm install ../path/to/catalog-lib
38
+ ```
39
+
40
+ O si usas un monorepo con workspaces, simplemente asegúrate de que esté incluida.
41
+
42
+ ### Paso 4: Importar el Módulo en tu Aplicación
43
+
44
+ En tu archivo `src/app/app.module.ts`, añade:
45
+
46
+ ```typescript
47
+ import { NgModule } from '@angular/core';
48
+ import { BrowserModule } from '@angular/platform-browser';
49
+ import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
50
+ import { HttpClientModule } from '@angular/common/http';
51
+ import { FormsModule } from '@angular/forms';
52
+
53
+ // Importar el módulo de Catalog
54
+ import { CatalogModule } from '@catalogos/catalog-lib';
55
+
56
+ import { AppComponent } from './app.component';
57
+
58
+ @NgModule({
59
+ declarations: [AppComponent],
60
+ imports: [
61
+ BrowserModule,
62
+ BrowserAnimationsModule,
63
+ HttpClientModule, // ⚠️ REQUERIDO
64
+ FormsModule, // Recomendado si usas ngModel
65
+ CatalogModule.forRoot({
66
+ apiBaseUrl: 'http://localhost:3000/api' // Reemplaza con tu URL
67
+ })
68
+ ],
69
+ providers: [],
70
+ bootstrap: [AppComponent]
71
+ })
72
+ export class AppModule {}
73
+ ```
74
+
75
+ ### Importante ⚠️
76
+
77
+ - **HttpClientModule** es obligatorio. Si no lo importas, la librería no funcionará.
78
+ - Reemplaza `http://localhost:3000/api` con la URL correcta de tu backend.
79
+
80
+ ## Configuración de CORS
81
+
82
+ Si tu backend está en un servidor diferente, asegúrate de que CORS esté configurado correctamente.
83
+
84
+ En tu backend (Node.js/Express):
85
+
86
+ ```typescript
87
+ import cors from 'cors';
88
+ import express from 'express';
89
+
90
+ const app = express();
91
+
92
+ app.use(cors({
93
+ origin: ['http://localhost:4200'], // URL de tu aplicación Angular
94
+ credentials: true
95
+ }));
96
+
97
+ // ... resto de tu configuración
98
+ ```
99
+
100
+ ## Configuración por Ambiente
101
+
102
+ Para configurar diferentes URLs según el ambiente, usa `environment.ts`:
103
+
104
+ ```typescript
105
+ // src/environments/environment.ts
106
+ export const environment = {
107
+ production: false,
108
+ apiBaseUrl: 'http://localhost:3000/api'
109
+ };
110
+
111
+ // src/environments/environment.prod.ts
112
+ export const environment = {
113
+ production: true,
114
+ apiBaseUrl: 'https://api.example.com/api'
115
+ };
116
+ ```
117
+
118
+ Luego en `app.module.ts`:
119
+
120
+ ```typescript
121
+ import { environment } from '../environments/environment';
122
+ import { CatalogModule } from '@catalogos/catalog-lib';
123
+
124
+ @NgModule({
125
+ declarations: [AppComponent],
126
+ imports: [
127
+ // ... otros imports
128
+ CatalogModule.forRoot({
129
+ apiBaseUrl: environment.apiBaseUrl
130
+ })
131
+ ],
132
+ // ...
133
+ })
134
+ export class AppModule {}
135
+ ```
136
+
137
+ ## Uso en Componentes
138
+
139
+ Una vez instalada, puedes usar la librería en tus componentes:
140
+
141
+ ```typescript
142
+ import { Component } from '@angular/core';
143
+ import { CatalogItem } from '@catalogos/catalog-lib';
144
+
145
+ @Component({
146
+ selector: 'app-root',
147
+ template: `
148
+ <catalog-items-select
149
+ [catalogId]="1"
150
+ (itemSelected)="onItemSelected($event)"
151
+ (error)="onError($event)"
152
+ ></catalog-items-select>
153
+ `
154
+ })
155
+ export class AppComponent {
156
+ onItemSelected(item: CatalogItem): void {
157
+ console.log('Item seleccionado:', item);
158
+ }
159
+
160
+ onError(error: string): void {
161
+ console.error('Error:', error);
162
+ }
163
+ }
164
+ ```
165
+
166
+ ## Solución de Problemas
167
+
168
+ ### Error: "Cannot find module '@catalogos/catalog-lib'"
169
+
170
+ Asegúrate de que:
171
+ 1. Ejecutaste `npm install`
172
+ 2. La ruta a la librería es correcta
173
+ 3. Reconstruye tu proyecto: `ng serve` o `ng build`
174
+
175
+ ### Error: "HttpClientModule is not imported"
176
+
177
+ Asegúrate de importar `HttpClientModule` en tu `app.module.ts`:
178
+
179
+ ```typescript
180
+ import { HttpClientModule } from '@angular/common/http';
181
+
182
+ @NgModule({
183
+ imports: [HttpClientModule, CatalogModule.forRoot({...})]
184
+ })
185
+ export class AppModule {}
186
+ ```
187
+
188
+ ### Los items no cargan
189
+
190
+ 1. Verifica que la URL del API sea correcta
191
+ 2. Abre la consola del navegador (F12) y revisa los errores de red
192
+ 3. Asegúrate de que el backend está corriendo
193
+ 4. Verifica que CORS está configurado correctamente
194
+
195
+ ### Error de CORS
196
+
197
+ Si ves un error como `Access to XMLHttpRequest blocked by CORS policy`:
198
+
199
+ 1. Verifica que tu backend tiene CORS habilitado
200
+ 2. Asegúrate de que la URL de origen está permitida
201
+ 3. El header `Content-Type: application/json` debe estar permitido
202
+
203
+ ## Verificación de Instalación
204
+
205
+ Para verificar que todo está instalado correctamente:
206
+
207
+ ```bash
208
+ # Inicia el servidor de desarrollo
209
+ ng serve
210
+
211
+ # Abre tu navegador en http://localhost:4200
212
+ # La aplicación debe cargar sin errores
213
+ ```
214
+
215
+ ## Próximos Pasos
216
+
217
+ - Revisa [README.md](./README.md) para más información sobre la API
218
+ - Consulta [EXAMPLES.md](./EXAMPLES.md) para ver ejemplos de uso
219
+ - Integra el componente en tus páginas
220
+
221
+ ## Soporte
222
+
223
+ Si encuentras problemas, revisa:
224
+ 1. Los errores en la consola del navegador
225
+ 2. Los errores en la consola del servidor Node.js
226
+ 3. Las peticiones en Network tab del inspector