ng-firebase-table-kxp 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/CHANGELOG.md ADDED
@@ -0,0 +1,88 @@
1
+ # Changelog
2
+
3
+ Todas as mudanças notáveis neste projeto serão documentadas neste arquivo.
4
+
5
+ O formato é baseado em [Keep a Changelog](https://keepachangelog.com/pt-BR/1.0.0/),
6
+ e este projeto adere ao [Versionamento Semântico](https://semver.org/lang/pt-BR/).
7
+
8
+ ## [Unreleased]
9
+
10
+ ## [0.0.1] - 2024-11-03
11
+
12
+ ### Adicionado
13
+ - ✨ Componente principal de tabela (`TableComponent`)
14
+ - 🔥 Integração completa com Firebase Firestore
15
+ - 📊 Sistema de paginação avançado (client-side e server-side)
16
+ - 🔍 Sistema de filtros:
17
+ - Filtro por texto
18
+ - Filtro por data
19
+ - Filtro por igualdade (equals)
20
+ - Filtros personalizados com dropdown
21
+ - Função de filtro customizada (filterFn)
22
+ - ⚡ Fallback automático client-side quando índices compostos não existem
23
+ - 📈 Rastreamento automático de índices ausentes
24
+ - 🔗 Suporte a relações entre collections
25
+ - 🖼️ Suporte a exibição de imagens
26
+ - 🎯 Botões de ação customizáveis
27
+ - 📥 Sistema de exportação de dados
28
+ - 🎨 Interface Material Design responsiva
29
+ - 📝 Suporte a valores calculados
30
+ - 🔢 Suporte a arrays e propriedades aninhadas
31
+ - 💬 Tooltips para valores longos com charLimit
32
+ - 🎨 Customização de cores e estilos
33
+ - 📑 Sistema de tabs
34
+ - 🔄 Método público `reloadTable()` para atualização manual
35
+ - 📊 Query lengths para contar documentos relacionados
36
+
37
+ ### Serviços
38
+ - `TableService` com métodos:
39
+ - `getPaginated()` - Paginação otimizada
40
+ - `getItems()` - Buscar todos os itens
41
+ - `getItemsData()` - Buscar itens com filtros
42
+ - `executeClientSideQuery()` - Fallback client-side
43
+ - `deleteIndex()` - Deletar com reindexação
44
+ - `dateFormatValidator()` - Validador de data
45
+ - `operators` - Operadores de comparação
46
+
47
+ ### Tipos
48
+ - `TableData` - Interface principal de configuração
49
+ - `Column` - Interface de configuração de colunas
50
+ - `Arrange` - Interface de arranjo (filtros e ordenação)
51
+ - `Condition` - Interface de condições where
52
+ - `Pagination` - Interface de paginação
53
+ - `FilterableOption` - Interface de opções filtráveis
54
+ - `Tab` e `TabData` - Interfaces para tabs
55
+ - `Image` - Interface para imagens
56
+
57
+ ### Documentação
58
+ - README.md completo com exemplos
59
+ - USAGE_EXAMPLE.md com casos de uso detalhados
60
+ - BUILD.md com guia de publicação
61
+ - CHANGELOG.md
62
+
63
+ ### Dependências Peer
64
+ - @angular/common ^15.0.0
65
+ - @angular/core ^15.0.0
66
+ - @angular/forms ^15.0.0
67
+ - @angular/router ^15.0.0
68
+ - @angular/material ^15.0.0
69
+ - @angular/cdk ^15.0.0
70
+ - @angular/fire ^7.0.0
71
+ - firebase ^9.0.0
72
+ - ngx-toastr ^16.0.0
73
+ - moment ^2.29.0
74
+ - ngx-mask ^15.0.0
75
+
76
+ ## Tipos de Mudanças
77
+
78
+ - `Added` - para novas funcionalidades
79
+ - `Changed` - para mudanças em funcionalidades existentes
80
+ - `Deprecated` - para funcionalidades que serão removidas
81
+ - `Removed` - para funcionalidades removidas
82
+ - `Fixed` - para correção de bugs
83
+ - `Security` - para vulnerabilidades de segurança
84
+
85
+ [Unreleased]: https://github.com/adryanmmm/firebase-table-kxp-lib/compare/v0.0.1...HEAD
86
+ [0.0.1]: https://github.com/adryanmmm/firebase-table-kxp-lib/releases/tag/v0.0.1
87
+
88
+
package/README.md ADDED
@@ -0,0 +1,476 @@
1
+ # Firebase Table KXP Lib
2
+
3
+ Uma biblioteca Angular poderosa para criar tabelas dinâmicas com integração completa ao Firebase Firestore. Inclui paginação avançada, filtros personalizáveis, ordenação e fallback client-side para queries sem índices.
4
+
5
+ ## ✨ Características
6
+
7
+ - 🔥 **Integração completa com Firebase/Firestore**
8
+ - 📊 **Paginação otimizada** (client-side e server-side)
9
+ - 🔍 **Sistema de filtros avançado** (texto, data, equals)
10
+ - ⚡ **Fallback automático** quando índices compostos não existem
11
+ - 🎨 **Interface Material Design** com Angular Material
12
+ - 📱 **Responsivo** e adaptável
13
+ - 🔗 **Suporte a relações** entre collections
14
+ - 📥 **Exportação de dados**
15
+ - 🎯 **Altamente configurável**
16
+
17
+ ## 📦 Instalação
18
+
19
+ ### Instalação Simples (npm 7+ / Node 15+)
20
+
21
+ ```bash
22
+ npm install ng-firebase-table-kxp
23
+ ```
24
+
25
+ ✅ **Pronto!** Todas as dependências necessárias serão instaladas automaticamente pelo npm 7+.
26
+
27
+ ### Se você usa npm 6 ou anterior
28
+
29
+ Caso esteja usando npm 6 ou anterior (raro hoje em dia), você precisará instalar as peer dependencies manualmente:
30
+
31
+ ```bash
32
+ npm install ng-firebase-table-kxp
33
+ npm install @angular/fire@^15.0.0 firebase@^9.0.0 @angular/material@^15.0.0 @angular/cdk@^15.0.0 ngx-toastr@^16.0.0 moment@^2.29.0 ngx-mask@^15.0.0
34
+ ```
35
+
36
+ **Como verificar sua versão do npm:**
37
+ ```bash
38
+ npm --version
39
+ # Se retornar 7.x ou superior, está tudo certo!
40
+ ```
41
+
42
+ ## 🔧 Dependências
43
+
44
+ A biblioteca usa as seguintes peer dependencies (instaladas automaticamente):
45
+
46
+ - `@angular/fire` ^15.0.0 - Integração com Firebase
47
+ - `firebase` ^9.0.0 - SDK do Firebase
48
+ - `@angular/material` ^15.0.0 - Componentes Material
49
+ - `@angular/cdk` ^15.0.0 - Component Dev Kit
50
+ - `ngx-toastr` ^16.0.0 - Notificações toast
51
+ - `moment` ^2.29.0 - Manipulação de datas
52
+ - `ngx-mask` ^15.0.0 - Máscaras de input
53
+
54
+ ## 🚀 Configuração
55
+
56
+ ### 1. Importe o módulo no seu `app.module.ts`:
57
+
58
+ ```typescript
59
+ import { NgModule } from '@angular/core';
60
+ import { BrowserModule } from '@angular/platform-browser';
61
+ import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
62
+
63
+ // Firebase
64
+ import { AngularFireModule } from '@angular/fire/compat';
65
+ import { AngularFirestoreModule } from '@angular/fire/compat/firestore';
66
+
67
+ // Toastr
68
+ import { ToastrModule } from 'ngx-toastr';
69
+
70
+ // Firebase Table KXP Lib
71
+ import { FirebaseTableKxpLibModule } from 'ng-firebase-table-kxp';
72
+
73
+ // Mask
74
+ import { NgxMaskModule } from 'ngx-mask';
75
+
76
+ import { environment } from '../environments/environment';
77
+
78
+ @NgModule({
79
+ declarations: [
80
+ AppComponent
81
+ ],
82
+ imports: [
83
+ BrowserModule,
84
+ BrowserAnimationsModule,
85
+ AngularFireModule.initializeApp(environment.firebase),
86
+ AngularFirestoreModule,
87
+ ToastrModule.forRoot(),
88
+ NgxMaskModule.forRoot(),
89
+ FirebaseTableKxpLibModule
90
+ ],
91
+ providers: [],
92
+ bootstrap: [AppComponent]
93
+ })
94
+ export class AppModule { }
95
+ ```
96
+
97
+ ### 2. Configure o Firebase no `environment.ts`:
98
+
99
+ ```typescript
100
+ export const environment = {
101
+ production: false,
102
+ firebase: {
103
+ apiKey: "sua-api-key",
104
+ authDomain: "seu-projeto.firebaseapp.com",
105
+ projectId: "seu-projeto-id",
106
+ storageBucket: "seu-projeto.appspot.com",
107
+ messagingSenderId: "123456789",
108
+ appId: "seu-app-id"
109
+ }
110
+ };
111
+ ```
112
+
113
+ ### 3. Importe os estilos do Angular Material no `styles.scss`:
114
+
115
+ ```scss
116
+ @import '@angular/material/prebuilt-themes/indigo-pink.css';
117
+ @import 'ngx-toastr/toastr';
118
+
119
+ // Se estiver usando Tailwind CSS, adicione também:
120
+ @tailwind base;
121
+ @tailwind components;
122
+ @tailwind utilities;
123
+ ```
124
+
125
+ ## 💻 Uso Básico
126
+
127
+ ### No seu componente TypeScript:
128
+
129
+ ```typescript
130
+ import { Component, OnInit } from '@angular/core';
131
+ import { AngularFirestore } from '@angular/fire/compat/firestore';
132
+ import { TableData, Column } from 'ng-firebase-table-kxp';
133
+
134
+ @Component({
135
+ selector: 'app-users',
136
+ template: `
137
+ <lib-table
138
+ [data]="tableData"
139
+ [downloadTable]="downloadTable">
140
+ </lib-table>
141
+ `
142
+ })
143
+ export class UsersComponent implements OnInit {
144
+ tableData: TableData;
145
+
146
+ constructor(private firestore: AngularFirestore) {}
147
+
148
+ ngOnInit() {
149
+ this.tableData = {
150
+ name: 'users',
151
+ collection: 'users',
152
+ collectionRef: this.firestore.collection('users').ref,
153
+ pagination: true,
154
+ download: true,
155
+ sortBy: {
156
+ field: 'createdAt',
157
+ order: 'desc'
158
+ },
159
+ displayedColumns: [
160
+ {
161
+ property: 'name',
162
+ title: 'Nome',
163
+ isFilterable: true,
164
+ isSortable: true
165
+ },
166
+ {
167
+ property: 'email',
168
+ title: 'E-mail',
169
+ isFilterable: true
170
+ },
171
+ {
172
+ property: 'createdAt',
173
+ title: 'Data de Criação',
174
+ isFilterableByDate: true,
175
+ isSortable: true,
176
+ pipe: new DatePipe('pt-BR')
177
+ }
178
+ ]
179
+ };
180
+ }
181
+
182
+ downloadTable = (arrange, conditions) => {
183
+ // Lógica para exportar a tabela
184
+ console.log('Exportando tabela...', arrange, conditions);
185
+ }
186
+ }
187
+ ```
188
+
189
+ ## 📖 API Completa
190
+
191
+ ### TableData Interface
192
+
193
+ ```typescript
194
+ interface TableData {
195
+ // Configurações básicas
196
+ name: string; // Nome da tabela
197
+ collection: string; // Nome da collection no Firestore
198
+ collectionRef: CollectionReference; // Referência da collection
199
+ pagination: boolean; // Habilitar paginação
200
+ download: boolean; // Habilitar exportação
201
+
202
+ // Colunas
203
+ displayedColumns: Column[]; // Array de colunas a exibir
204
+
205
+ // Ordenação
206
+ sortBy?: {
207
+ field: string;
208
+ order: 'asc' | 'desc';
209
+ };
210
+
211
+ // Filtros e condições
212
+ conditions?: Condition[]; // Condições where do Firestore
213
+ filterFn?: (item: any) => boolean; // Função de filtro customizada
214
+ filterableOptions?: FilterableOption[]; // Opções de filtro personalizadas
215
+
216
+ // Aparência
217
+ color?: {
218
+ bg: string; // Classe CSS para fundo
219
+ text: string; // Classe CSS para texto
220
+ };
221
+
222
+ // Navegação
223
+ isNotClickable?: boolean; // Desabilitar clique nas linhas
224
+ url?: string; // URL base para navegação
225
+
226
+ // Totalizadores
227
+ totalRef?: {
228
+ ref: DocumentReference;
229
+ field: string;
230
+ }[];
231
+
232
+ // Botão de ação
233
+ actionButton?: {
234
+ label: string;
235
+ routerLink: string;
236
+ icon?: string;
237
+ colorClass?: string;
238
+ method?: (row: any, event?: any) => any;
239
+ condition?: (row: any) => boolean;
240
+ };
241
+
242
+ // Tabs
243
+ tabs?: {
244
+ method: (tab: any, event?: any) => any;
245
+ tabsData: TabData[];
246
+ };
247
+ }
248
+ ```
249
+
250
+ ### Column Interface
251
+
252
+ ```typescript
253
+ interface Column {
254
+ property: string; // Propriedade do objeto
255
+ title?: string; // Título da coluna
256
+ charLimit?: number; // Limite de caracteres (com tooltip)
257
+
258
+ // Formatação
259
+ pipe?: PipeTransform; // Pipe do Angular para formatação
260
+ calculateValue?: (row: any) => any; // Função para calcular valor
261
+
262
+ // Filtros e ordenação
263
+ isFilterable?: boolean; // Permite filtrar por texto
264
+ isSortable?: boolean; // Permite ordenação
265
+ isFilterableByDate?: boolean; // Permite filtro por data
266
+ filterPredicates?: string[]; // Predicados customizados
267
+
268
+ // Links e downloads
269
+ hasLink?: boolean | string; // Tornar valor um link
270
+ hasDownload?: boolean | string; // Habilitar download
271
+
272
+ // Imagens
273
+ image?: {
274
+ class: string;
275
+ path?: string;
276
+ url?: boolean;
277
+ default?: string;
278
+ };
279
+
280
+ // Ícones e botões
281
+ iconClass?: {
282
+ text?: string;
283
+ class?: string;
284
+ condition?: (row: any) => any;
285
+ buttonMethod?: (row: any, event?: any) => any;
286
+ }[];
287
+
288
+ // Relações com outras collections
289
+ relation?: {
290
+ collection: string;
291
+ property: string;
292
+ newProperty: string;
293
+ };
294
+
295
+ // Query lengths
296
+ queryLength?: {
297
+ collection: string;
298
+ property: string;
299
+ operator: WhereFilterOp;
300
+ value: string;
301
+ };
302
+
303
+ // Arrays
304
+ arrayField?: string; // Campo para exibir de arrays de objetos
305
+
306
+ // Métodos customizados
307
+ method?: (row: any, event?: any) => any;
308
+ }
309
+ ```
310
+
311
+ ## 🎯 Exemplos Avançados
312
+
313
+ ### Exemplo com Filtros Personalizados
314
+
315
+ ```typescript
316
+ this.tableData = {
317
+ name: 'products',
318
+ collection: 'products',
319
+ collectionRef: this.firestore.collection('products').ref,
320
+ pagination: true,
321
+ download: true,
322
+ displayedColumns: [
323
+ {
324
+ property: 'name',
325
+ title: 'Produto',
326
+ isFilterable: true
327
+ },
328
+ {
329
+ property: 'price',
330
+ title: 'Preço',
331
+ pipe: new CurrencyPipe('pt-BR'),
332
+ isSortable: true
333
+ },
334
+ {
335
+ property: 'category',
336
+ title: 'Categoria',
337
+ isFilterable: true
338
+ }
339
+ ],
340
+ filterableOptions: [
341
+ {
342
+ title: 'Status',
343
+ items: [
344
+ { property: 'status', value: 'active', label: 'Ativo' },
345
+ { property: 'status', value: 'inactive', label: 'Inativo' }
346
+ ]
347
+ }
348
+ ]
349
+ };
350
+ ```
351
+
352
+ ### Exemplo com Relações
353
+
354
+ ```typescript
355
+ displayedColumns: [
356
+ {
357
+ property: 'userName',
358
+ title: 'Usuário',
359
+ relation: {
360
+ collection: 'users',
361
+ property: 'userId', // Campo na collection atual
362
+ newProperty: 'name' // Campo a buscar na collection relacionada
363
+ }
364
+ }
365
+ ]
366
+ ```
367
+
368
+ ### Exemplo com Botões Customizados
369
+
370
+ ```typescript
371
+ displayedColumns: [
372
+ {
373
+ property: 'actions',
374
+ title: 'Ações',
375
+ iconClass: [
376
+ {
377
+ class: 'fa fa-edit text-blue-500 cursor-pointer',
378
+ buttonMethod: (row, event) => {
379
+ event.stopPropagation();
380
+ this.editItem(row);
381
+ },
382
+ condition: (row) => row.canEdit === true
383
+ },
384
+ {
385
+ class: 'fa fa-trash text-red-500 cursor-pointer ml-2',
386
+ buttonMethod: (row, event) => {
387
+ event.stopPropagation();
388
+ this.deleteItem(row);
389
+ }
390
+ }
391
+ ]
392
+ }
393
+ ]
394
+ ```
395
+
396
+ ### Exemplo com Condições (Where Clauses)
397
+
398
+ ```typescript
399
+ this.tableData = {
400
+ // ... outras configurações
401
+ conditions: [
402
+ {
403
+ operator: '==',
404
+ firestoreProperty: 'status',
405
+ dashProperty: 'active'
406
+ },
407
+ {
408
+ operator: '>=',
409
+ firestoreProperty: 'createdAt',
410
+ dashProperty: new Date('2024-01-01')
411
+ }
412
+ ]
413
+ };
414
+ ```
415
+
416
+ ### Exemplo com Filtro Customizado (filterFn)
417
+
418
+ ```typescript
419
+ this.tableData = {
420
+ // ... outras configurações
421
+ filterFn: (item) => {
422
+ // Filtro customizado no lado do cliente
423
+ return item.age >= 18 && item.status === 'active';
424
+ }
425
+ };
426
+ ```
427
+
428
+ ## 🎨 Customização de Estilos
429
+
430
+ A biblioteca usa Tailwind CSS e Angular Material. Você pode customizar os estilos no seu `styles.scss`:
431
+
432
+ ```scss
433
+ // Customizar cores da tabela
434
+ .mat-elevation-z8 {
435
+ box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1) !important;
436
+ }
437
+
438
+ // Customizar header da tabela
439
+ .bg-primary {
440
+ background-color: #your-color !important;
441
+ }
442
+
443
+ // Customizar paginador
444
+ .mat-mdc-paginator {
445
+ background-color: #f9fafb;
446
+ }
447
+ ```
448
+
449
+ ## ⚡ Performance e Otimização
450
+
451
+ ### Fallback Client-Side
452
+
453
+ A biblioteca detecta automaticamente quando uma query necessita de índices compostos no Firestore e usa um fallback client-side para evitar erros. Isso significa que sua aplicação continuará funcionando mesmo sem todos os índices criados.
454
+
455
+ ### Rastreamento de Índices Ausentes
456
+
457
+ O serviço `TableService` rastreia automaticamente queries que precisam de índices e salva as informações na collection `missingIndexes` do Firestore, incluindo:
458
+ - Link direto para criar o índice no Firebase Console
459
+ - Instruções passo a passo
460
+ - Estrutura da query
461
+
462
+ ## 🤝 Contribuindo
463
+
464
+ Contribuições são bem-vindas! Por favor, sinta-se à vontade para submeter pull requests.
465
+
466
+ ## 📝 Licença
467
+
468
+ MIT
469
+
470
+ ## 👨‍💻 Autor
471
+
472
+ Adryan - [@adryanmmm](https://github.com/adryanmmm)
473
+
474
+ ## 🐛 Reportar Bugs
475
+
476
+ Se encontrar algum bug, por favor abra uma issue no GitHub.
@@ -0,0 +1,7 @@
1
+ {
2
+ "$schema": "../../../node_modules/ng-packagr/ng-package.schema.json",
3
+ "dest": "../../dist/ng-firebase-table-kxp",
4
+ "lib": {
5
+ "entryFile": "src/public-api.ts"
6
+ }
7
+ }
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "ng-firebase-table-kxp",
3
+ "version": "1.0.0",
4
+ "description": "Uma biblioteca Angular poderosa para criar tabelas dinâmicas com integração completa ao Firebase Firestore",
5
+ "keywords": [
6
+ "angular",
7
+ "firebase",
8
+ "firestore",
9
+ "table",
10
+ "pagination",
11
+ "material",
12
+ "data-table"
13
+ ],
14
+ "author": "Adryan",
15
+ "license": "MIT",
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "https://github.com/adryanmbs/firebase-table-kxp-lib"
19
+ },
20
+ "peerDependencies": {
21
+ "@angular/common": "^15.0.0",
22
+ "@angular/core": "^15.0.0",
23
+ "@angular/forms": "^15.0.0",
24
+ "@angular/router": "^15.0.0",
25
+ "@angular/material": "^15.0.0",
26
+ "@angular/cdk": "^15.0.0",
27
+ "@angular/fire": "^7.0.0",
28
+ "firebase": "^9.0.0",
29
+ "ngx-toastr": "^16.0.0",
30
+ "moment": "^2.29.0",
31
+ "ngx-mask": "^15.0.0"
32
+ },
33
+ "dependencies": {
34
+ "tslib": "^2.3.0"
35
+ }
36
+ }