ng-firebase-table-kxp 1.0.1 → 1.0.3
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/README.md +602 -594
- package/esm2020/lib/components/table/table.component.mjs +790 -0
- package/esm2020/lib/firebase-table-kxp-lib.component.mjs +19 -0
- package/esm2020/lib/firebase-table-kxp-lib.module.mjs +74 -0
- package/esm2020/lib/firebase-table-kxp-lib.service.mjs +14 -0
- package/esm2020/lib/services/table.service.mjs +905 -0
- package/esm2020/lib/types/Table.mjs +2 -0
- package/esm2020/ng-firebase-table-kxp.mjs +5 -0
- package/esm2020/public-api.mjs +15 -0
- package/fesm2015/ng-firebase-table-kxp.mjs +1823 -0
- package/fesm2015/ng-firebase-table-kxp.mjs.map +1 -0
- package/fesm2020/ng-firebase-table-kxp.mjs +1795 -0
- package/fesm2020/ng-firebase-table-kxp.mjs.map +1 -0
- package/index.d.ts +5 -0
- package/lib/components/table/table.component.d.ts +112 -0
- package/lib/firebase-table-kxp-lib.component.d.ts +5 -0
- package/lib/firebase-table-kxp-lib.module.d.ts +21 -0
- package/lib/firebase-table-kxp-lib.service.d.ts +6 -0
- package/lib/services/table.service.d.ts +74 -0
- package/{src/lib/types/Table.ts → lib/types/Table.d.ts} +139 -142
- package/package.json +22 -2
- package/{src/public-api.ts → public-api.d.ts} +6 -19
- package/CHANGELOG.md +0 -88
- package/ng-package.json +0 -7
- package/src/lib/components/table/table.component.html +0 -555
- package/src/lib/components/table/table.component.scss +0 -22
- package/src/lib/components/table/table.component.spec.ts +0 -24
- package/src/lib/components/table/table.component.ts +0 -917
- package/src/lib/firebase-table-kxp-lib.component.spec.ts +0 -23
- package/src/lib/firebase-table-kxp-lib.component.ts +0 -15
- package/src/lib/firebase-table-kxp-lib.module.ts +0 -45
- package/src/lib/firebase-table-kxp-lib.service.spec.ts +0 -16
- package/src/lib/firebase-table-kxp-lib.service.ts +0 -9
- package/src/lib/services/table.service.spec.ts +0 -16
- package/src/lib/services/table.service.ts +0 -1235
- package/tsconfig.lib.json +0 -14
- package/tsconfig.lib.prod.json +0 -10
- package/tsconfig.spec.json +0 -14
|
@@ -0,0 +1,1823 @@
|
|
|
1
|
+
import * as i0 from '@angular/core';
|
|
2
|
+
import { Component, Injectable, Optional, Input, ViewChild, NgModule } from '@angular/core';
|
|
3
|
+
import * as i4 from '@angular/common';
|
|
4
|
+
import { CommonModule } from '@angular/common';
|
|
5
|
+
import * as i5 from '@angular/forms';
|
|
6
|
+
import { FormControl, FormArray, FormGroup, ReactiveFormsModule, FormsModule } from '@angular/forms';
|
|
7
|
+
import * as i1$1 from '@angular/router';
|
|
8
|
+
import { RouterModule } from '@angular/router';
|
|
9
|
+
import * as i6 from '@angular/material/table';
|
|
10
|
+
import { MatTableDataSource, MatTableModule } from '@angular/material/table';
|
|
11
|
+
import * as i7 from '@angular/material/paginator';
|
|
12
|
+
import { MatPaginator, MatPaginatorModule } from '@angular/material/paginator';
|
|
13
|
+
import * as i8 from '@angular/material/sort';
|
|
14
|
+
import { MatSort, MatSortModule } from '@angular/material/sort';
|
|
15
|
+
import * as i9 from '@angular/material/form-field';
|
|
16
|
+
import { MatFormFieldModule } from '@angular/material/form-field';
|
|
17
|
+
import * as i10 from '@angular/material/input';
|
|
18
|
+
import { MatInputModule } from '@angular/material/input';
|
|
19
|
+
import * as i11 from '@angular/material/select';
|
|
20
|
+
import { MatSelectModule } from '@angular/material/select';
|
|
21
|
+
import * as i13 from '@angular/material/tooltip';
|
|
22
|
+
import { MatTooltipModule } from '@angular/material/tooltip';
|
|
23
|
+
import * as i14 from '@angular/material/progress-spinner';
|
|
24
|
+
import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
|
|
25
|
+
import * as i15 from '@angular/material/icon';
|
|
26
|
+
import { MatIconModule } from '@angular/material/icon';
|
|
27
|
+
import * as i2 from '@angular/material/dialog';
|
|
28
|
+
import { MatDialogModule } from '@angular/material/dialog';
|
|
29
|
+
import { __awaiter } from 'tslib';
|
|
30
|
+
import { firstValueFrom, Subject, debounceTime } from 'rxjs';
|
|
31
|
+
import firebase from 'firebase/compat/app';
|
|
32
|
+
import * as moment from 'moment';
|
|
33
|
+
import * as i1 from '@angular/fire/compat/firestore';
|
|
34
|
+
import * as i3 from 'ngx-toastr';
|
|
35
|
+
import * as i12 from '@angular/material/core';
|
|
36
|
+
|
|
37
|
+
class FirebaseTableKxpLibComponent {
|
|
38
|
+
}
|
|
39
|
+
FirebaseTableKxpLibComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: FirebaseTableKxpLibComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
40
|
+
FirebaseTableKxpLibComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.10", type: FirebaseTableKxpLibComponent, selector: "lib-firebase-table-kxp-lib", ngImport: i0, template: `
|
|
41
|
+
<p>
|
|
42
|
+
firebase-table-kxp-lib works!
|
|
43
|
+
</p>
|
|
44
|
+
`, isInline: true });
|
|
45
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: FirebaseTableKxpLibComponent, decorators: [{
|
|
46
|
+
type: Component,
|
|
47
|
+
args: [{ selector: 'lib-firebase-table-kxp-lib', template: `
|
|
48
|
+
<p>
|
|
49
|
+
firebase-table-kxp-lib works!
|
|
50
|
+
</p>
|
|
51
|
+
` }]
|
|
52
|
+
}] });
|
|
53
|
+
|
|
54
|
+
class TableService {
|
|
55
|
+
constructor(ngFire, dialog, toastr) {
|
|
56
|
+
this.ngFire = ngFire;
|
|
57
|
+
this.dialog = dialog;
|
|
58
|
+
this.toastr = toastr;
|
|
59
|
+
this.operators = {
|
|
60
|
+
'==': (a, b) => a === b,
|
|
61
|
+
'!=': (a, b) => a !== b,
|
|
62
|
+
'>': (a, b) => a > b,
|
|
63
|
+
'<': (a, b) => a < b,
|
|
64
|
+
'>=': (a, b) => a >= b,
|
|
65
|
+
'<=': (a, b) => a <= b,
|
|
66
|
+
in: (a, b) => Array.isArray(b) && b.includes(a),
|
|
67
|
+
'not-in': (a, b) => Array.isArray(b) && !b.includes(a),
|
|
68
|
+
'array-contains': (a, b) => Array.isArray(a) && a.includes(b),
|
|
69
|
+
'array-contains-any': (a, b) => Array.isArray(a) &&
|
|
70
|
+
Array.isArray(b) &&
|
|
71
|
+
b.some((item) => a.includes(item)),
|
|
72
|
+
includes: (a, b) => a.includes(b), // Para strings ou arrays
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
getItems(collection) {
|
|
76
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
77
|
+
try {
|
|
78
|
+
const querySnapshot = yield collection.get();
|
|
79
|
+
return querySnapshot.docs.map((doc) => {
|
|
80
|
+
return Object.assign(Object.assign({}, doc.data()), { id: doc.id });
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
console.warn('Collection não encontrada:', error);
|
|
85
|
+
return [];
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
executeQuery(params) {
|
|
90
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
91
|
+
if (params.filterFn) {
|
|
92
|
+
// Lógica com filtro no cliente (filterFn)
|
|
93
|
+
const BATCH_FETCH_SIZE = params.batchSize;
|
|
94
|
+
const GOAL_SIZE = params.batchSize + 1;
|
|
95
|
+
if (params.navigation === 'forward' || params.navigation === 'reload') {
|
|
96
|
+
if (params.navigation === 'reload' && params.doc) {
|
|
97
|
+
params.doc.lastDoc = null;
|
|
98
|
+
}
|
|
99
|
+
let lastDocCursor = params.doc ? params.doc.lastDoc : null;
|
|
100
|
+
let pageResults = [];
|
|
101
|
+
let allFetchedDocs = [];
|
|
102
|
+
let hasMoreDocsInDb = true;
|
|
103
|
+
while (pageResults.length < GOAL_SIZE && hasMoreDocsInDb) {
|
|
104
|
+
let query = this.ngFire.collection(params.collection).ref;
|
|
105
|
+
query = this.applyFilters(query, params.arrange, params.conditions);
|
|
106
|
+
if (lastDocCursor) {
|
|
107
|
+
query = query.startAfter(lastDocCursor);
|
|
108
|
+
}
|
|
109
|
+
query = query.limit(BATCH_FETCH_SIZE);
|
|
110
|
+
const snapshot = yield query.get();
|
|
111
|
+
if (snapshot.empty) {
|
|
112
|
+
hasMoreDocsInDb = false;
|
|
113
|
+
break;
|
|
114
|
+
}
|
|
115
|
+
lastDocCursor = snapshot.docs[snapshot.docs.length - 1];
|
|
116
|
+
allFetchedDocs.push(...snapshot.docs);
|
|
117
|
+
const batchUsers = snapshot.docs
|
|
118
|
+
.map((doc) => (Object.assign({ id: doc.id }, doc.data())))
|
|
119
|
+
.filter(params.filterFn);
|
|
120
|
+
pageResults.push(...batchUsers);
|
|
121
|
+
if (snapshot.size < BATCH_FETCH_SIZE) {
|
|
122
|
+
hasMoreDocsInDb = false;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
const hasNextPage = pageResults.length > params.batchSize;
|
|
126
|
+
const finalItems = pageResults.slice(0, params.batchSize);
|
|
127
|
+
const firstDocOfPage = allFetchedDocs.find((doc) => { var _a; return doc.id === ((_a = finalItems[0]) === null || _a === void 0 ? void 0 : _a.id); }) || null;
|
|
128
|
+
const lastDocOfPage = allFetchedDocs.find((doc) => { var _a; return doc.id === ((_a = finalItems[finalItems.length - 1]) === null || _a === void 0 ? void 0 : _a.id); }) || null;
|
|
129
|
+
return {
|
|
130
|
+
items: finalItems,
|
|
131
|
+
filterLength: null,
|
|
132
|
+
firstDoc: firstDocOfPage,
|
|
133
|
+
lastDoc: lastDocOfPage,
|
|
134
|
+
hasNextPage: hasNextPage,
|
|
135
|
+
hasPreviousPage: !!(params.doc && params.doc.lastDoc) &&
|
|
136
|
+
params.navigation !== 'reload',
|
|
137
|
+
currentClientPageIndex: undefined,
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
// Lógica para trás (backward)
|
|
141
|
+
else if (params.navigation === 'backward') {
|
|
142
|
+
if (!params.doc || !params.doc.firstDoc) {
|
|
143
|
+
return {
|
|
144
|
+
items: [],
|
|
145
|
+
filterLength: null,
|
|
146
|
+
firstDoc: null,
|
|
147
|
+
lastDoc: null,
|
|
148
|
+
hasNextPage: true,
|
|
149
|
+
hasPreviousPage: false,
|
|
150
|
+
currentClientPageIndex: undefined,
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
let pageResults = [];
|
|
154
|
+
let allFetchedDocs = [];
|
|
155
|
+
let hasMoreDocsInDb = true;
|
|
156
|
+
let boundaryDoc = params.doc.firstDoc;
|
|
157
|
+
while (pageResults.length < GOAL_SIZE && hasMoreDocsInDb) {
|
|
158
|
+
let query = this.ngFire.collection(params.collection).ref;
|
|
159
|
+
query = this.applyFilters(query, params.arrange, params.conditions);
|
|
160
|
+
query = query.endBefore(boundaryDoc);
|
|
161
|
+
query = query.limitToLast(BATCH_FETCH_SIZE);
|
|
162
|
+
const snapshot = yield query.get();
|
|
163
|
+
if (snapshot.empty) {
|
|
164
|
+
hasMoreDocsInDb = false;
|
|
165
|
+
break;
|
|
166
|
+
}
|
|
167
|
+
boundaryDoc = snapshot.docs[0];
|
|
168
|
+
allFetchedDocs = [...snapshot.docs, ...allFetchedDocs];
|
|
169
|
+
const batchUsers = snapshot.docs
|
|
170
|
+
.map((doc) => (Object.assign({ id: doc.id }, doc.data())))
|
|
171
|
+
.filter(params.filterFn);
|
|
172
|
+
pageResults = [...batchUsers, ...pageResults];
|
|
173
|
+
if (snapshot.size < BATCH_FETCH_SIZE) {
|
|
174
|
+
hasMoreDocsInDb = false;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
const finalItems = pageResults.slice(0, params.batchSize);
|
|
178
|
+
const firstDocOfPage = allFetchedDocs.find((doc) => { var _a; return doc.id === ((_a = finalItems[0]) === null || _a === void 0 ? void 0 : _a.id); }) || null;
|
|
179
|
+
const lastDocOfPage = allFetchedDocs.find((doc) => { var _a; return doc.id === ((_a = finalItems[finalItems.length - 1]) === null || _a === void 0 ? void 0 : _a.id); }) || null;
|
|
180
|
+
return {
|
|
181
|
+
items: finalItems,
|
|
182
|
+
filterLength: null,
|
|
183
|
+
firstDoc: firstDocOfPage,
|
|
184
|
+
lastDoc: lastDocOfPage,
|
|
185
|
+
hasNextPage: true,
|
|
186
|
+
currentClientPageIndex: undefined,
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
else {
|
|
191
|
+
let items = [];
|
|
192
|
+
let docs = [];
|
|
193
|
+
let hasNextPage = false;
|
|
194
|
+
let filterLength = null;
|
|
195
|
+
let query = this.ngFire.collection(params.collection).ref;
|
|
196
|
+
if (params.conditions) {
|
|
197
|
+
params.conditions.forEach((c) => {
|
|
198
|
+
if (c.operator === '!=') {
|
|
199
|
+
query = query.orderBy(c.firestoreProperty);
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
query = this.applyFilters(query, params.arrange, params.conditions);
|
|
204
|
+
if (params.navigation === 'reload') {
|
|
205
|
+
query = query.limit(params.batchSize + 1);
|
|
206
|
+
if (params.doc && params.doc.firstDoc) {
|
|
207
|
+
query = query.startAt(params.doc.firstDoc);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
else if (params.navigation === 'forward') {
|
|
211
|
+
query = query.limit(params.batchSize + 1);
|
|
212
|
+
if (params.doc && params.doc.lastDoc) {
|
|
213
|
+
query = query.startAfter(params.doc.lastDoc);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
else {
|
|
217
|
+
// backward
|
|
218
|
+
query = query.limitToLast(params.batchSize + 1);
|
|
219
|
+
if (params.doc && params.doc.firstDoc) {
|
|
220
|
+
query = query.endBefore(params.doc.firstDoc);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
const itemCol = yield query.get();
|
|
224
|
+
itemCol.docs.forEach((doc) => docs.push(doc));
|
|
225
|
+
const itemPromises = docs.map((item) => __awaiter(this, void 0, void 0, function* () {
|
|
226
|
+
const itemData = item.data();
|
|
227
|
+
items.push(Object.assign({ id: item.id }, itemData));
|
|
228
|
+
}));
|
|
229
|
+
let lastDoc = docs[docs.length - 1] || null;
|
|
230
|
+
let firstDoc = docs[0];
|
|
231
|
+
if ((items.length > params.batchSize && params.navigation === 'forward') ||
|
|
232
|
+
(params.navigation === 'reload' && items.length > params.batchSize)) {
|
|
233
|
+
lastDoc = docs[docs.length - 2] || null;
|
|
234
|
+
items.pop();
|
|
235
|
+
hasNextPage = true;
|
|
236
|
+
}
|
|
237
|
+
if (items.length > params.batchSize && params.navigation === 'backward') {
|
|
238
|
+
firstDoc = docs[1];
|
|
239
|
+
items.shift();
|
|
240
|
+
hasNextPage = true;
|
|
241
|
+
}
|
|
242
|
+
yield Promise.all(itemPromises);
|
|
243
|
+
return {
|
|
244
|
+
items,
|
|
245
|
+
filterLength,
|
|
246
|
+
lastDoc,
|
|
247
|
+
firstDoc,
|
|
248
|
+
hasNextPage,
|
|
249
|
+
currentClientPageIndex: undefined,
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
// Fallback para garantir que sempre retornamos algo
|
|
253
|
+
return {
|
|
254
|
+
items: [],
|
|
255
|
+
filterLength: null,
|
|
256
|
+
firstDoc: null,
|
|
257
|
+
lastDoc: null,
|
|
258
|
+
hasNextPage: false,
|
|
259
|
+
currentClientPageIndex: undefined,
|
|
260
|
+
};
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
applyFilters(query, arrange, conditions) {
|
|
264
|
+
if (conditions) {
|
|
265
|
+
conditions.map((cond) => {
|
|
266
|
+
query = query.where(cond.firestoreProperty, cond.operator, cond.dashProperty);
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
let hasFilterSpecificOrderBy = false;
|
|
270
|
+
let appliedOrderByField = null;
|
|
271
|
+
const equalsFilters = arrange.filters.filter((f) => f.arrange === 'equals' && f.filter);
|
|
272
|
+
const otherFilters = arrange.filters.filter((f) => f.arrange !== 'equals');
|
|
273
|
+
const equalsGroupedByProperty = equalsFilters.reduce((acc, current) => {
|
|
274
|
+
const prop = current.filter.property;
|
|
275
|
+
if (!acc[prop]) {
|
|
276
|
+
acc[prop] = [];
|
|
277
|
+
}
|
|
278
|
+
acc[prop].push(current.filter.filtering);
|
|
279
|
+
return acc;
|
|
280
|
+
}, {});
|
|
281
|
+
for (const prop in equalsGroupedByProperty) {
|
|
282
|
+
const values = equalsGroupedByProperty[prop];
|
|
283
|
+
if (values.length > 0) {
|
|
284
|
+
query = query.where(prop, 'in', values);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
otherFilters.forEach((filterItem) => {
|
|
288
|
+
var _a, _b;
|
|
289
|
+
// Aplicar filtragem por busca
|
|
290
|
+
if (((_a = filterItem.filter) === null || _a === void 0 ? void 0 : _a.filtering) &&
|
|
291
|
+
((_b = filterItem.filter) === null || _b === void 0 ? void 0 : _b.property) !== '' &&
|
|
292
|
+
filterItem.arrange === 'filter') {
|
|
293
|
+
query = query
|
|
294
|
+
.where(filterItem.filter.property, '>=', filterItem.filter.filtering.trim().toUpperCase())
|
|
295
|
+
.where(filterItem.filter.property, '<=', filterItem.filter.filtering.trim().toUpperCase() + '\uf8ff');
|
|
296
|
+
if (!hasFilterSpecificOrderBy) {
|
|
297
|
+
query = query.orderBy(filterItem.filter.property);
|
|
298
|
+
hasFilterSpecificOrderBy = true;
|
|
299
|
+
appliedOrderByField = filterItem.filter.property;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
// Aplicar filtro do tipo "filterByDate"
|
|
303
|
+
if (filterItem.dateFilter && filterItem.arrange === 'filterByDate') {
|
|
304
|
+
query = query
|
|
305
|
+
.where(arrange.sortBy.field, '>=', filterItem.dateFilter.initial)
|
|
306
|
+
.where(arrange.sortBy.field, '<=', filterItem.dateFilter.final);
|
|
307
|
+
if (!hasFilterSpecificOrderBy) {
|
|
308
|
+
query = query.orderBy(arrange.sortBy.field);
|
|
309
|
+
hasFilterSpecificOrderBy = true;
|
|
310
|
+
appliedOrderByField = arrange.sortBy.field;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
});
|
|
314
|
+
// Aplicar sortBy
|
|
315
|
+
if (arrange.sortBy && arrange.sortBy.field && arrange.sortBy.order) {
|
|
316
|
+
if (appliedOrderByField !== arrange.sortBy.field) {
|
|
317
|
+
query = query.orderBy(arrange.sortBy.field, arrange.sortBy.order);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
return query;
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* Detecta se a query vai precisar de index composto e deve usar fallback client-side
|
|
324
|
+
*/
|
|
325
|
+
shouldUseClientSideFallback(params) {
|
|
326
|
+
var _a, _b, _c;
|
|
327
|
+
const hasConditions = params.conditions && params.conditions.length > 0;
|
|
328
|
+
const hasArrangeFilters = ((_a = params.arrange) === null || _a === void 0 ? void 0 : _a.filters) && params.arrange.filters.length > 0;
|
|
329
|
+
const hasSortBy = (_c = (_b = params.arrange) === null || _b === void 0 ? void 0 : _b.sortBy) === null || _c === void 0 ? void 0 : _c.field;
|
|
330
|
+
if (params.filterFn) {
|
|
331
|
+
return false;
|
|
332
|
+
}
|
|
333
|
+
if (hasConditions && hasArrangeFilters && hasSortBy) {
|
|
334
|
+
return true;
|
|
335
|
+
}
|
|
336
|
+
if (hasConditions && hasArrangeFilters) {
|
|
337
|
+
return true;
|
|
338
|
+
}
|
|
339
|
+
if (hasArrangeFilters && params.arrange.filters.length > 1 && hasSortBy) {
|
|
340
|
+
return true;
|
|
341
|
+
}
|
|
342
|
+
return false;
|
|
343
|
+
}
|
|
344
|
+
getPaginated(params) {
|
|
345
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
346
|
+
// Detectar preventivamente se deve usar fallback
|
|
347
|
+
if (this.shouldUseClientSideFallback(params)) {
|
|
348
|
+
yield this.trackMissingIndexPreventive(params.collection, params.arrange, params.conditions);
|
|
349
|
+
const result = yield this.executeClientSideQuery(params);
|
|
350
|
+
console.log('📊 [TABLE] Resultados paginados via fallback client-side:', {
|
|
351
|
+
totalItems: result.filterLength,
|
|
352
|
+
returnedItems: result.items.length,
|
|
353
|
+
hasNextPage: result.hasNextPage,
|
|
354
|
+
currentPage: (result.currentClientPageIndex || 0) + 1,
|
|
355
|
+
});
|
|
356
|
+
return result;
|
|
357
|
+
}
|
|
358
|
+
try {
|
|
359
|
+
const result = yield this.executeQuery(params);
|
|
360
|
+
console.log('📊 [TABLE] Resultados paginados via Firestore:', {
|
|
361
|
+
totalItems: result.filterLength || 'N/A',
|
|
362
|
+
returnedItems: result.items.length,
|
|
363
|
+
hasNextPage: result.hasNextPage,
|
|
364
|
+
});
|
|
365
|
+
return result;
|
|
366
|
+
}
|
|
367
|
+
catch (error) {
|
|
368
|
+
if (error && error.code === 'failed-precondition') {
|
|
369
|
+
yield this.trackMissingIndex(error, params.collection, params.arrange, params.conditions);
|
|
370
|
+
const result = yield this.executeClientSideQuery(params);
|
|
371
|
+
console.log('📊 [TABLE] Resultados paginados via fallback (erro de index):', {
|
|
372
|
+
totalItems: result.filterLength,
|
|
373
|
+
returnedItems: result.items.length,
|
|
374
|
+
hasNextPage: result.hasNextPage,
|
|
375
|
+
currentPage: (result.currentClientPageIndex || 0) + 1,
|
|
376
|
+
});
|
|
377
|
+
return result;
|
|
378
|
+
}
|
|
379
|
+
else if (error && error.code === 'invalid-argument') {
|
|
380
|
+
yield this.trackMissingIndex(error, params.collection, params.arrange, params.conditions);
|
|
381
|
+
const result = yield this.executeClientSideQuery(params);
|
|
382
|
+
console.log('📊 [TABLE] Resultados paginados via fallback (argumento inválido):', {
|
|
383
|
+
totalItems: result.filterLength,
|
|
384
|
+
returnedItems: result.items.length,
|
|
385
|
+
hasNextPage: result.hasNextPage,
|
|
386
|
+
currentPage: (result.currentClientPageIndex || 0) + 1,
|
|
387
|
+
});
|
|
388
|
+
return result;
|
|
389
|
+
}
|
|
390
|
+
else {
|
|
391
|
+
throw error;
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
});
|
|
395
|
+
}
|
|
396
|
+
executeClientSideQuery(params) {
|
|
397
|
+
var _a, _b, _c;
|
|
398
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
399
|
+
// Otimizar usando pelo menos uma cláusula .where() quando possível
|
|
400
|
+
let query = this.ngFire.collection(params.collection).ref;
|
|
401
|
+
let appliedCondition = null;
|
|
402
|
+
let hasAppliedWhereClause = false;
|
|
403
|
+
// Primeiro, tenta aplicar condições simples
|
|
404
|
+
if (params.conditions && params.conditions.length > 0) {
|
|
405
|
+
const simpleCondition = params.conditions.find((cond) => ['==', '>', '<', '>=', '<=', 'in', 'array-contains'].includes(cond.operator));
|
|
406
|
+
if (simpleCondition) {
|
|
407
|
+
query = query.where(simpleCondition.firestoreProperty, simpleCondition.operator, simpleCondition.dashProperty);
|
|
408
|
+
appliedCondition = simpleCondition;
|
|
409
|
+
hasAppliedWhereClause = true;
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
// Se não há condições disponíveis, tenta aplicar filtros do arrange
|
|
413
|
+
let appliedFirestoreFilter = null;
|
|
414
|
+
if (!hasAppliedWhereClause && ((_a = params.arrange) === null || _a === void 0 ? void 0 : _a.filters)) {
|
|
415
|
+
const equalsFilter = params.arrange.filters.find((f) => { var _a; return f.arrange === 'equals' && ((_a = f.filter) === null || _a === void 0 ? void 0 : _a.filtering); });
|
|
416
|
+
if (equalsFilter && equalsFilter.filter) {
|
|
417
|
+
query = query.where(equalsFilter.filter.property, '==', equalsFilter.filter.filtering);
|
|
418
|
+
hasAppliedWhereClause = true;
|
|
419
|
+
appliedFirestoreFilter = equalsFilter;
|
|
420
|
+
}
|
|
421
|
+
else {
|
|
422
|
+
const otherFilter = params.arrange.filters.find((f) => {
|
|
423
|
+
var _a, _b, _c, _d;
|
|
424
|
+
return (f.arrange === 'filter' &&
|
|
425
|
+
((_a = f.filter) === null || _a === void 0 ? void 0 : _a.filtering) &&
|
|
426
|
+
((_b = f.filter) === null || _b === void 0 ? void 0 : _b.property)) ||
|
|
427
|
+
(f.arrange === 'filterByDate' &&
|
|
428
|
+
((_c = f.dateFilter) === null || _c === void 0 ? void 0 : _c.initial) &&
|
|
429
|
+
((_d = f.dateFilter) === null || _d === void 0 ? void 0 : _d.final));
|
|
430
|
+
});
|
|
431
|
+
if (otherFilter) {
|
|
432
|
+
if (otherFilter.arrange === 'filter' && otherFilter.filter) {
|
|
433
|
+
const filterValue = otherFilter.filter.filtering
|
|
434
|
+
.trim()
|
|
435
|
+
.toUpperCase();
|
|
436
|
+
query = query
|
|
437
|
+
.where(otherFilter.filter.property, '>=', filterValue)
|
|
438
|
+
.where(otherFilter.filter.property, '<=', filterValue + '\uf8ff');
|
|
439
|
+
hasAppliedWhereClause = true;
|
|
440
|
+
appliedFirestoreFilter = otherFilter;
|
|
441
|
+
}
|
|
442
|
+
else if (otherFilter.arrange === 'filterByDate' &&
|
|
443
|
+
otherFilter.dateFilter &&
|
|
444
|
+
((_b = params.arrange.sortBy) === null || _b === void 0 ? void 0 : _b.field)) {
|
|
445
|
+
query = query
|
|
446
|
+
.where(params.arrange.sortBy.field, '>=', otherFilter.dateFilter.initial)
|
|
447
|
+
.where(params.arrange.sortBy.field, '<=', otherFilter.dateFilter.final);
|
|
448
|
+
hasAppliedWhereClause = true;
|
|
449
|
+
appliedFirestoreFilter = otherFilter;
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
const allDocsSnapshot = yield query.get();
|
|
455
|
+
let items = allDocsSnapshot.docs.map((doc) => (Object.assign({ id: doc.id }, doc.data())));
|
|
456
|
+
// Aplicar condições restantes
|
|
457
|
+
if (params.conditions) {
|
|
458
|
+
const remainingConditions = params.conditions.filter((cond) => cond !== appliedCondition);
|
|
459
|
+
if (remainingConditions.length > 0) {
|
|
460
|
+
const operators = this.operators;
|
|
461
|
+
items = items.filter((item) => {
|
|
462
|
+
return remainingConditions.every((cond) => {
|
|
463
|
+
const operatorFn = operators[cond.operator];
|
|
464
|
+
return operatorFn
|
|
465
|
+
? operatorFn(item[cond.firestoreProperty], cond.dashProperty)
|
|
466
|
+
: false;
|
|
467
|
+
});
|
|
468
|
+
});
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
const { filters, sortBy } = params.arrange;
|
|
472
|
+
// Track which filter was already applied in Firestore to avoid double filtering
|
|
473
|
+
if (hasAppliedWhereClause && !appliedCondition && ((_c = params.arrange) === null || _c === void 0 ? void 0 : _c.filters)) {
|
|
474
|
+
const equalsFilter = params.arrange.filters.find((f) => { var _a; return f.arrange === 'equals' && ((_a = f.filter) === null || _a === void 0 ? void 0 : _a.filtering); });
|
|
475
|
+
if (equalsFilter) {
|
|
476
|
+
appliedFirestoreFilter = equalsFilter;
|
|
477
|
+
}
|
|
478
|
+
else {
|
|
479
|
+
appliedFirestoreFilter = params.arrange.filters.find((f) => {
|
|
480
|
+
var _a, _b, _c, _d;
|
|
481
|
+
return (f.arrange === 'filter' &&
|
|
482
|
+
((_a = f.filter) === null || _a === void 0 ? void 0 : _a.filtering) &&
|
|
483
|
+
((_b = f.filter) === null || _b === void 0 ? void 0 : _b.property)) ||
|
|
484
|
+
(f.arrange === 'filterByDate' &&
|
|
485
|
+
((_c = f.dateFilter) === null || _c === void 0 ? void 0 : _c.initial) &&
|
|
486
|
+
((_d = f.dateFilter) === null || _d === void 0 ? void 0 : _d.final));
|
|
487
|
+
});
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
const equalsFilters = filters.filter((f) => f.arrange === 'equals');
|
|
491
|
+
const otherFilters = filters.filter((f) => f.arrange !== 'equals');
|
|
492
|
+
const remainingEqualsFilters = equalsFilters.filter((f) => f !== appliedFirestoreFilter);
|
|
493
|
+
if (remainingEqualsFilters.length > 0) {
|
|
494
|
+
items = items.filter((item) => {
|
|
495
|
+
return remainingEqualsFilters.every((f) => item[f.filter.property] === f.filter.filtering);
|
|
496
|
+
});
|
|
497
|
+
}
|
|
498
|
+
otherFilters.forEach((filterItem) => {
|
|
499
|
+
var _a, _b, _c, _d;
|
|
500
|
+
if (appliedFirestoreFilter === filterItem) {
|
|
501
|
+
return;
|
|
502
|
+
}
|
|
503
|
+
if (filterItem.arrange === 'filter' &&
|
|
504
|
+
((_a = filterItem.filter) === null || _a === void 0 ? void 0 : _a.filtering) &&
|
|
505
|
+
((_b = filterItem.filter) === null || _b === void 0 ? void 0 : _b.property)) {
|
|
506
|
+
const filterValue = String(filterItem.filter.filtering)
|
|
507
|
+
.trim()
|
|
508
|
+
.toLowerCase();
|
|
509
|
+
items = items.filter((item) => {
|
|
510
|
+
const itemValue = String(item[filterItem.filter.property]).toLowerCase();
|
|
511
|
+
return itemValue.includes(filterValue);
|
|
512
|
+
});
|
|
513
|
+
}
|
|
514
|
+
if (filterItem.arrange === 'filterByDate' &&
|
|
515
|
+
((_c = filterItem.dateFilter) === null || _c === void 0 ? void 0 : _c.initial) &&
|
|
516
|
+
((_d = filterItem.dateFilter) === null || _d === void 0 ? void 0 : _d.final) &&
|
|
517
|
+
sortBy.field) {
|
|
518
|
+
items = items.filter((item) => {
|
|
519
|
+
try {
|
|
520
|
+
const fieldValue = item[sortBy.field];
|
|
521
|
+
if (!fieldValue) {
|
|
522
|
+
return false;
|
|
523
|
+
}
|
|
524
|
+
let itemDate;
|
|
525
|
+
if (typeof fieldValue.toDate === 'function') {
|
|
526
|
+
itemDate = fieldValue.toDate();
|
|
527
|
+
}
|
|
528
|
+
else if (fieldValue instanceof Date) {
|
|
529
|
+
itemDate = fieldValue;
|
|
530
|
+
}
|
|
531
|
+
else if (typeof fieldValue === 'string') {
|
|
532
|
+
itemDate = new Date(fieldValue);
|
|
533
|
+
if (isNaN(itemDate.getTime())) {
|
|
534
|
+
return false;
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
else if (typeof fieldValue === 'number') {
|
|
538
|
+
itemDate = new Date(fieldValue);
|
|
539
|
+
}
|
|
540
|
+
else {
|
|
541
|
+
return false;
|
|
542
|
+
}
|
|
543
|
+
return (itemDate >= filterItem.dateFilter.initial &&
|
|
544
|
+
itemDate <= filterItem.dateFilter.final);
|
|
545
|
+
}
|
|
546
|
+
catch (error) {
|
|
547
|
+
console.warn('Erro ao processar filtro de data para o item:', item.id, error);
|
|
548
|
+
return false;
|
|
549
|
+
}
|
|
550
|
+
});
|
|
551
|
+
}
|
|
552
|
+
});
|
|
553
|
+
// Aplicar filterFn se existir
|
|
554
|
+
if (params.filterFn) {
|
|
555
|
+
items = items.filter(params.filterFn);
|
|
556
|
+
}
|
|
557
|
+
if (sortBy && sortBy.field && sortBy.order) {
|
|
558
|
+
items.sort((a, b) => {
|
|
559
|
+
const valA = a[sortBy.field];
|
|
560
|
+
const valB = b[sortBy.field];
|
|
561
|
+
if (valA < valB) {
|
|
562
|
+
return sortBy.order === 'asc' ? -1 : 1;
|
|
563
|
+
}
|
|
564
|
+
if (valA > valB) {
|
|
565
|
+
return sortBy.order === 'asc' ? 1 : -1;
|
|
566
|
+
}
|
|
567
|
+
return 0;
|
|
568
|
+
});
|
|
569
|
+
}
|
|
570
|
+
// Implementação adequada da paginação
|
|
571
|
+
let currentClientPageIndex = 0;
|
|
572
|
+
// Determinar a página atual baseada na navegação
|
|
573
|
+
if (params.navigation === 'reload') {
|
|
574
|
+
currentClientPageIndex = 0;
|
|
575
|
+
}
|
|
576
|
+
else if (params.navigation === 'forward') {
|
|
577
|
+
currentClientPageIndex = (params.clientPageIndex || 0) + 1;
|
|
578
|
+
}
|
|
579
|
+
else if (params.navigation === 'backward') {
|
|
580
|
+
currentClientPageIndex = Math.max(0, (params.clientPageIndex || 0) - 1);
|
|
581
|
+
}
|
|
582
|
+
const pageSize = params.batchSize;
|
|
583
|
+
const startIndex = currentClientPageIndex * pageSize;
|
|
584
|
+
const endIndex = startIndex + pageSize;
|
|
585
|
+
const paginatedItems = items.slice(startIndex, endIndex);
|
|
586
|
+
const totalPages = Math.ceil(items.length / pageSize);
|
|
587
|
+
const hasNextPage = currentClientPageIndex < totalPages - 1;
|
|
588
|
+
const hasPreviousPage = currentClientPageIndex > 0;
|
|
589
|
+
return {
|
|
590
|
+
items: paginatedItems,
|
|
591
|
+
filterLength: items.length,
|
|
592
|
+
lastDoc: null,
|
|
593
|
+
firstDoc: null,
|
|
594
|
+
hasNextPage: hasNextPage,
|
|
595
|
+
hasPreviousPage: hasPreviousPage,
|
|
596
|
+
currentClientPageIndex: currentClientPageIndex,
|
|
597
|
+
totalPages: totalPages,
|
|
598
|
+
};
|
|
599
|
+
});
|
|
600
|
+
}
|
|
601
|
+
getItemsData(collection, arrange, conditions = undefined) {
|
|
602
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
603
|
+
try {
|
|
604
|
+
let query = this.ngFire.collection(collection).ref;
|
|
605
|
+
query = this.applyFilters(query, arrange, conditions);
|
|
606
|
+
const snapshot = yield query.get();
|
|
607
|
+
return yield Promise.all(snapshot.docs.map((doc) => __awaiter(this, void 0, void 0, function* () {
|
|
608
|
+
const data = doc.data();
|
|
609
|
+
const id = doc.id;
|
|
610
|
+
return Object.assign({ id }, data);
|
|
611
|
+
})));
|
|
612
|
+
}
|
|
613
|
+
catch (e) {
|
|
614
|
+
throw e;
|
|
615
|
+
}
|
|
616
|
+
});
|
|
617
|
+
}
|
|
618
|
+
deleteIndex(id, col) {
|
|
619
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
620
|
+
try {
|
|
621
|
+
const batch = this.ngFire.firestore.batch();
|
|
622
|
+
const docRef = this.ngFire.collection(col).doc(id);
|
|
623
|
+
const docSnapshot = (yield firstValueFrom(docRef.get()));
|
|
624
|
+
const doc = docSnapshot.data();
|
|
625
|
+
batch.delete(docRef.ref);
|
|
626
|
+
if (doc && typeof doc.index === 'number') {
|
|
627
|
+
yield this.reindex(doc.index, col, batch);
|
|
628
|
+
}
|
|
629
|
+
yield batch.commit();
|
|
630
|
+
this.toastr.success('Item excluído com sucesso!');
|
|
631
|
+
return true;
|
|
632
|
+
}
|
|
633
|
+
catch (e) {
|
|
634
|
+
const error = e;
|
|
635
|
+
console.error('Erro ao deletar item:', error);
|
|
636
|
+
this.toastr.error('Erro ao deletar item.');
|
|
637
|
+
return false;
|
|
638
|
+
}
|
|
639
|
+
});
|
|
640
|
+
}
|
|
641
|
+
reindex(index, col, batch) {
|
|
642
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
643
|
+
try {
|
|
644
|
+
const snapshot = (yield firstValueFrom(this.ngFire.collection(col).get()));
|
|
645
|
+
const docs = snapshot.docs;
|
|
646
|
+
for (let doc of docs) {
|
|
647
|
+
const data = doc.data();
|
|
648
|
+
if (data && typeof data.index === 'number' && data.index > index) {
|
|
649
|
+
data.index--;
|
|
650
|
+
const docRef = this.ngFire.collection(col).doc(doc.id).ref;
|
|
651
|
+
batch.update(docRef, data);
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
catch (error) {
|
|
656
|
+
console.error('Erro ao reindexar:', error);
|
|
657
|
+
}
|
|
658
|
+
return;
|
|
659
|
+
});
|
|
660
|
+
}
|
|
661
|
+
dateFormatValidator() {
|
|
662
|
+
return (control) => {
|
|
663
|
+
if (!control.value) {
|
|
664
|
+
return null;
|
|
665
|
+
}
|
|
666
|
+
const dateStr = control.value.trim();
|
|
667
|
+
const datePattern = /^(\d{1,2})\/(\d{1,2})\/(\d{4})$/;
|
|
668
|
+
if (!datePattern.test(dateStr)) {
|
|
669
|
+
return { invalidFormat: true };
|
|
670
|
+
}
|
|
671
|
+
const parts = dateStr.split('/');
|
|
672
|
+
const day = parts[0].padStart(2, '0');
|
|
673
|
+
const month = parts[1].padStart(2, '0');
|
|
674
|
+
const year = parts[2];
|
|
675
|
+
const normalizedDate = `${day}/${month}/${year}`;
|
|
676
|
+
const date = moment(normalizedDate, 'DD/MM/YYYY', true);
|
|
677
|
+
if (!date.isValid()) {
|
|
678
|
+
return { invalidDate: true };
|
|
679
|
+
}
|
|
680
|
+
return null;
|
|
681
|
+
};
|
|
682
|
+
}
|
|
683
|
+
updateIndex(index, id, col) {
|
|
684
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
685
|
+
yield this.ngFire.collection(col).doc(id).update({ index });
|
|
686
|
+
});
|
|
687
|
+
}
|
|
688
|
+
/**
|
|
689
|
+
* Extrai o link de criação de índice da mensagem de erro do Firestore
|
|
690
|
+
*/
|
|
691
|
+
extractIndexLink(error) {
|
|
692
|
+
if (!error || !error.message)
|
|
693
|
+
return null;
|
|
694
|
+
const linkMatch = error.message.match(/(https:\/\/console\.firebase\.google\.com\/[^\s]+)/);
|
|
695
|
+
return linkMatch ? linkMatch[1] : null;
|
|
696
|
+
}
|
|
697
|
+
/**
|
|
698
|
+
* Rastreia índices ausentes ao usar fallback preventivo
|
|
699
|
+
*/
|
|
700
|
+
trackMissingIndexPreventive(collection, arrange, conditions = undefined) {
|
|
701
|
+
var _a;
|
|
702
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
703
|
+
try {
|
|
704
|
+
const querySignature = this.generateQuerySignature(collection, arrange, conditions);
|
|
705
|
+
const docId = `${collection}_${querySignature}`;
|
|
706
|
+
const indexLink = this.generateIndexLink(collection, arrange, conditions);
|
|
707
|
+
const indexInstructions = this.generateIndexInstructions(collection, arrange, conditions);
|
|
708
|
+
const trackingData = {
|
|
709
|
+
collection,
|
|
710
|
+
indexLink,
|
|
711
|
+
indexInstructions,
|
|
712
|
+
arrange: {
|
|
713
|
+
sortBy: arrange.sortBy,
|
|
714
|
+
filters: ((_a = arrange.filters) === null || _a === void 0 ? void 0 : _a.map((f) => {
|
|
715
|
+
var _a, _b;
|
|
716
|
+
return ({
|
|
717
|
+
arrange: f.arrange,
|
|
718
|
+
property: ((_a = f.filter) === null || _a === void 0 ? void 0 : _a.property) || null,
|
|
719
|
+
dateField: f.arrange === 'filterByDate' ? (_b = arrange.sortBy) === null || _b === void 0 ? void 0 : _b.field : null,
|
|
720
|
+
});
|
|
721
|
+
})) || [],
|
|
722
|
+
},
|
|
723
|
+
conditions: (conditions === null || conditions === void 0 ? void 0 : conditions.map((c) => ({
|
|
724
|
+
property: c.firestoreProperty,
|
|
725
|
+
operator: c.operator,
|
|
726
|
+
}))) || [],
|
|
727
|
+
errorMessage: `Fallback preventivo usado para a collection ${collection}. A query exigiria índice composto.`,
|
|
728
|
+
updatedAt: firebase.firestore.FieldValue.serverTimestamp(),
|
|
729
|
+
};
|
|
730
|
+
console.log('📄 [INDEX LINK] Dados que serão salvos no documento:', {
|
|
731
|
+
docId,
|
|
732
|
+
collection: trackingData.collection,
|
|
733
|
+
indexLink: trackingData.indexLink,
|
|
734
|
+
arrange: trackingData.arrange,
|
|
735
|
+
conditions: trackingData.conditions,
|
|
736
|
+
errorMessage: trackingData.errorMessage,
|
|
737
|
+
});
|
|
738
|
+
const docRef = this.ngFire.collection('missingIndexes').doc(docId);
|
|
739
|
+
const doc = yield docRef.get().toPromise();
|
|
740
|
+
if (doc && doc.exists) {
|
|
741
|
+
yield docRef.update({
|
|
742
|
+
count: firebase.firestore.FieldValue.increment(1),
|
|
743
|
+
updatedAt: firebase.firestore.FieldValue.serverTimestamp(),
|
|
744
|
+
lastError: trackingData.errorMessage,
|
|
745
|
+
});
|
|
746
|
+
}
|
|
747
|
+
else {
|
|
748
|
+
yield docRef.set(Object.assign(Object.assign({}, trackingData), { count: 1, createdAt: firebase.firestore.FieldValue.serverTimestamp() }));
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
catch (trackingError) {
|
|
752
|
+
console.warn('Falha ao rastrear fallback preventivo:', trackingError);
|
|
753
|
+
}
|
|
754
|
+
});
|
|
755
|
+
}
|
|
756
|
+
/**
|
|
757
|
+
* Gera uma assinatura única para uma query
|
|
758
|
+
*/
|
|
759
|
+
generateQuerySignature(collection, arrange, conditions = undefined) {
|
|
760
|
+
var _a;
|
|
761
|
+
const signature = {
|
|
762
|
+
collection,
|
|
763
|
+
sortBy: arrange.sortBy,
|
|
764
|
+
filters: ((_a = arrange.filters) === null || _a === void 0 ? void 0 : _a.map((f) => {
|
|
765
|
+
var _a;
|
|
766
|
+
return ({
|
|
767
|
+
arrange: f.arrange,
|
|
768
|
+
property: ((_a = f.filter) === null || _a === void 0 ? void 0 : _a.property) || null,
|
|
769
|
+
});
|
|
770
|
+
})) || [],
|
|
771
|
+
conditions: (conditions === null || conditions === void 0 ? void 0 : conditions.map((c) => ({
|
|
772
|
+
property: c.firestoreProperty,
|
|
773
|
+
operator: c.operator,
|
|
774
|
+
}))) || [],
|
|
775
|
+
};
|
|
776
|
+
return btoa(JSON.stringify(signature))
|
|
777
|
+
.replace(/[^a-zA-Z0-9]/g, '')
|
|
778
|
+
.substring(0, 20);
|
|
779
|
+
}
|
|
780
|
+
/**
|
|
781
|
+
* Gera instruções claras para criar o índice manualmente
|
|
782
|
+
*/
|
|
783
|
+
generateIndexInstructions(collection, arrange, conditions = undefined) {
|
|
784
|
+
var _a;
|
|
785
|
+
const instructions = {
|
|
786
|
+
summary: '',
|
|
787
|
+
collection: collection,
|
|
788
|
+
fields: [],
|
|
789
|
+
queryExample: '',
|
|
790
|
+
stepByStep: [],
|
|
791
|
+
notes: [],
|
|
792
|
+
};
|
|
793
|
+
const fields = [];
|
|
794
|
+
if (conditions && conditions.length > 0) {
|
|
795
|
+
conditions.forEach((condition) => {
|
|
796
|
+
if (condition.firestoreProperty) {
|
|
797
|
+
fields.push({
|
|
798
|
+
field: condition.firestoreProperty,
|
|
799
|
+
order: 'Ascending',
|
|
800
|
+
type: 'WHERE clause',
|
|
801
|
+
operator: condition.operator,
|
|
802
|
+
description: `Filtrar por ${condition.firestoreProperty} usando operador ${condition.operator}`,
|
|
803
|
+
});
|
|
804
|
+
}
|
|
805
|
+
});
|
|
806
|
+
}
|
|
807
|
+
if (arrange.filters && arrange.filters.length > 0) {
|
|
808
|
+
arrange.filters.forEach((filter) => {
|
|
809
|
+
var _a;
|
|
810
|
+
if ((_a = filter.filter) === null || _a === void 0 ? void 0 : _a.property) {
|
|
811
|
+
fields.push({
|
|
812
|
+
field: filter.filter.property,
|
|
813
|
+
order: 'Ascending',
|
|
814
|
+
type: 'WHERE clause (filter)',
|
|
815
|
+
operator: filter.arrange === 'filter' ? 'CONTAINS' : 'RANGE',
|
|
816
|
+
description: `Filtrar por ${filter.filter.property} usando filtro ${filter.arrange}`,
|
|
817
|
+
});
|
|
818
|
+
}
|
|
819
|
+
});
|
|
820
|
+
}
|
|
821
|
+
if ((_a = arrange.sortBy) === null || _a === void 0 ? void 0 : _a.field) {
|
|
822
|
+
fields.push({
|
|
823
|
+
field: arrange.sortBy.field,
|
|
824
|
+
order: arrange.sortBy.order === 'desc' ? 'Descending' : 'Ascending',
|
|
825
|
+
type: 'ORDER BY clause',
|
|
826
|
+
operator: 'N/A',
|
|
827
|
+
description: `Ordenar resultados por ${arrange.sortBy.field} em ordem ${arrange.sortBy.order}`,
|
|
828
|
+
});
|
|
829
|
+
}
|
|
830
|
+
instructions.fields = fields;
|
|
831
|
+
const fieldNames = fields.map((f) => f.field).join(' + ');
|
|
832
|
+
instructions.summary = `Criar índice composto para ${collection}: ${fieldNames}`;
|
|
833
|
+
let queryExample = `db.collection('${collection}')`;
|
|
834
|
+
fields.forEach((field, index) => {
|
|
835
|
+
if (field.type.includes('WHERE')) {
|
|
836
|
+
if (field.operator === '==') {
|
|
837
|
+
queryExample += `\n .where('${field.field}', '==', 'value')`;
|
|
838
|
+
}
|
|
839
|
+
else if (field.operator === 'CONTAINS') {
|
|
840
|
+
queryExample += `\n .where('${field.field}', '>=', 'searchText')`;
|
|
841
|
+
}
|
|
842
|
+
else {
|
|
843
|
+
queryExample += `\n .where('${field.field}', '${field.operator}', 'value')`;
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
});
|
|
847
|
+
const orderByField = fields.find((f) => f.type.includes('ORDER BY'));
|
|
848
|
+
if (orderByField) {
|
|
849
|
+
queryExample += `\n .orderBy('${orderByField.field}', '${orderByField.order.toLowerCase()}')`;
|
|
850
|
+
}
|
|
851
|
+
instructions.queryExample = queryExample;
|
|
852
|
+
instructions.stepByStep = [
|
|
853
|
+
'1. Ir para Firebase Console → Firestore → Indexes',
|
|
854
|
+
'2. Clicar em "Create Index"',
|
|
855
|
+
`3. Definir Collection ID: ${collection}`,
|
|
856
|
+
'4. Configurar campos nesta ORDEM EXATA:',
|
|
857
|
+
...fields.map((field, index) => ` ${index + 1}. Campo: ${field.field}, Order: ${field.order}, Array: No`),
|
|
858
|
+
'5. Definir Query scopes: Collection',
|
|
859
|
+
'6. Clicar em "Create" e aguardar conclusão',
|
|
860
|
+
];
|
|
861
|
+
instructions.notes = [
|
|
862
|
+
'⚠️ A ordem dos campos é CRÍTICA - deve corresponder exatamente à ordem da query',
|
|
863
|
+
'⚠️ As cláusulas WHERE devem vir ANTES do campo ORDER BY',
|
|
864
|
+
'⚠️ Este índice só funcionará para queries com esta combinação EXATA de campos',
|
|
865
|
+
'⚠️ A criação do índice pode levar vários minutos',
|
|
866
|
+
];
|
|
867
|
+
return instructions;
|
|
868
|
+
}
|
|
869
|
+
/**
|
|
870
|
+
* Gera um link de índice baseado na estrutura da query
|
|
871
|
+
*/
|
|
872
|
+
generateIndexLink(collection, arrange, conditions = undefined) {
|
|
873
|
+
var _a;
|
|
874
|
+
try {
|
|
875
|
+
const indexFields = [];
|
|
876
|
+
if (conditions && conditions.length > 0) {
|
|
877
|
+
conditions.forEach((condition) => {
|
|
878
|
+
if (condition.firestoreProperty) {
|
|
879
|
+
indexFields.push(condition.firestoreProperty);
|
|
880
|
+
}
|
|
881
|
+
});
|
|
882
|
+
}
|
|
883
|
+
if (arrange.filters && arrange.filters.length > 0) {
|
|
884
|
+
arrange.filters.forEach((filter) => {
|
|
885
|
+
var _a;
|
|
886
|
+
if ((_a = filter.filter) === null || _a === void 0 ? void 0 : _a.property) {
|
|
887
|
+
indexFields.push(filter.filter.property);
|
|
888
|
+
}
|
|
889
|
+
});
|
|
890
|
+
}
|
|
891
|
+
if ((_a = arrange.sortBy) === null || _a === void 0 ? void 0 : _a.field) {
|
|
892
|
+
indexFields.push(arrange.sortBy.field);
|
|
893
|
+
}
|
|
894
|
+
if (indexFields.length > 1) {
|
|
895
|
+
const baseUrl = 'https://console.firebase.google.com/project/toppayy-dev/firestore/indexes';
|
|
896
|
+
const queryParams = new URLSearchParams({
|
|
897
|
+
create_composite: `collection=${collection}&fields=${indexFields.join(',')}`,
|
|
898
|
+
});
|
|
899
|
+
const finalLink = `${baseUrl}?${queryParams.toString()}`;
|
|
900
|
+
return finalLink;
|
|
901
|
+
}
|
|
902
|
+
return null;
|
|
903
|
+
}
|
|
904
|
+
catch (error) {
|
|
905
|
+
console.warn('Falha ao gerar link de índice:', error);
|
|
906
|
+
return null;
|
|
907
|
+
}
|
|
908
|
+
}
|
|
909
|
+
trackMissingIndex(error, collection, arrange, conditions = undefined) {
|
|
910
|
+
var _a;
|
|
911
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
912
|
+
try {
|
|
913
|
+
const indexLink = this.extractIndexLink(error);
|
|
914
|
+
if (!indexLink)
|
|
915
|
+
return;
|
|
916
|
+
const linkHash = btoa(indexLink)
|
|
917
|
+
.replace(/[^a-zA-Z0-9]/g, '')
|
|
918
|
+
.substring(0, 20);
|
|
919
|
+
const docId = `${collection}_${linkHash}`;
|
|
920
|
+
const indexInstructions = this.generateIndexInstructions(collection, arrange, conditions);
|
|
921
|
+
const trackingData = {
|
|
922
|
+
collection,
|
|
923
|
+
indexLink,
|
|
924
|
+
indexInstructions,
|
|
925
|
+
arrange: {
|
|
926
|
+
sortBy: arrange.sortBy,
|
|
927
|
+
filters: ((_a = arrange.filters) === null || _a === void 0 ? void 0 : _a.map((f) => {
|
|
928
|
+
var _a, _b;
|
|
929
|
+
return ({
|
|
930
|
+
arrange: f.arrange,
|
|
931
|
+
property: ((_a = f.filter) === null || _a === void 0 ? void 0 : _a.property) || null,
|
|
932
|
+
dateField: f.arrange === 'filterByDate' ? (_b = arrange.sortBy) === null || _b === void 0 ? void 0 : _b.field : null,
|
|
933
|
+
});
|
|
934
|
+
})) || [],
|
|
935
|
+
},
|
|
936
|
+
conditions: (conditions === null || conditions === void 0 ? void 0 : conditions.map((c) => ({
|
|
937
|
+
property: c.firestoreProperty,
|
|
938
|
+
operator: c.operator,
|
|
939
|
+
}))) || [],
|
|
940
|
+
errorMessage: error.message,
|
|
941
|
+
updatedAt: firebase.firestore.FieldValue.serverTimestamp(),
|
|
942
|
+
};
|
|
943
|
+
const docRef = this.ngFire.collection('missingIndexes').doc(docId);
|
|
944
|
+
const doc = yield docRef.get().toPromise();
|
|
945
|
+
if (doc && doc.exists) {
|
|
946
|
+
yield docRef.update({
|
|
947
|
+
count: firebase.firestore.FieldValue.increment(1),
|
|
948
|
+
updatedAt: firebase.firestore.FieldValue.serverTimestamp(),
|
|
949
|
+
lastError: error.message,
|
|
950
|
+
});
|
|
951
|
+
}
|
|
952
|
+
else {
|
|
953
|
+
yield docRef.set(Object.assign(Object.assign({}, trackingData), { count: 1, createdAt: firebase.firestore.FieldValue.serverTimestamp() }));
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
catch (trackingError) {
|
|
957
|
+
console.warn('Falha ao rastrear índice ausente:', trackingError);
|
|
958
|
+
}
|
|
959
|
+
});
|
|
960
|
+
}
|
|
961
|
+
}
|
|
962
|
+
TableService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: TableService, deps: [{ token: i1.AngularFirestore, optional: true }, { token: i2.MatDialog, optional: true }, { token: i3.ToastrService, optional: true }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
963
|
+
TableService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: TableService, providedIn: 'root' });
|
|
964
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: TableService, decorators: [{
|
|
965
|
+
type: Injectable,
|
|
966
|
+
args: [{
|
|
967
|
+
providedIn: 'root',
|
|
968
|
+
}]
|
|
969
|
+
}], ctorParameters: function () {
|
|
970
|
+
return [{ type: i1.AngularFirestore, decorators: [{
|
|
971
|
+
type: Optional
|
|
972
|
+
}] }, { type: i2.MatDialog, decorators: [{
|
|
973
|
+
type: Optional
|
|
974
|
+
}] }, { type: i3.ToastrService, decorators: [{
|
|
975
|
+
type: Optional
|
|
976
|
+
}] }];
|
|
977
|
+
} });
|
|
978
|
+
|
|
979
|
+
class TableComponent {
|
|
980
|
+
// CONSTRUCTOR
|
|
981
|
+
constructor(router, tableService, firestore) {
|
|
982
|
+
this.router = router;
|
|
983
|
+
this.tableService = tableService;
|
|
984
|
+
this.firestore = firestore;
|
|
985
|
+
this.arrange = null;
|
|
986
|
+
this.currentPageNumber = 1;
|
|
987
|
+
this.currentClientPageIndex = 0;
|
|
988
|
+
this.items = [];
|
|
989
|
+
this.isLoading = false;
|
|
990
|
+
this.lastDoc = null;
|
|
991
|
+
this.firstDoc = null;
|
|
992
|
+
this.sortBy = {
|
|
993
|
+
field: 'createdAt',
|
|
994
|
+
order: 'desc',
|
|
995
|
+
};
|
|
996
|
+
this.columnProperties = [];
|
|
997
|
+
this.selectSort = new FormControl('');
|
|
998
|
+
this.currentArrange = '';
|
|
999
|
+
this.hasNextPage = false;
|
|
1000
|
+
this.dropdownItems = [];
|
|
1001
|
+
this.sortableDropdownItems = [];
|
|
1002
|
+
this.pageSize = 25;
|
|
1003
|
+
this.totalItems = 0;
|
|
1004
|
+
this.filterValue = null;
|
|
1005
|
+
this.hasFilterableColumn = false;
|
|
1006
|
+
this.hasSortableColumn = false;
|
|
1007
|
+
this.filterSubject = new Subject();
|
|
1008
|
+
this.debounceTimeMs = 500;
|
|
1009
|
+
this.selectedTab = 0;
|
|
1010
|
+
// Propriedades para controle do tooltip
|
|
1011
|
+
this.hoveredCell = null;
|
|
1012
|
+
this.showTooltip = false;
|
|
1013
|
+
this.tooltipContent = '';
|
|
1014
|
+
this.tooltipPosition = { x: 0, y: 0 };
|
|
1015
|
+
this.filtersForm = new FormArray([this.createFilterGroup()]);
|
|
1016
|
+
}
|
|
1017
|
+
createFilterGroup() {
|
|
1018
|
+
return new FormGroup({
|
|
1019
|
+
selectFilter: new FormControl(''),
|
|
1020
|
+
typeFilter: new FormControl(''),
|
|
1021
|
+
selectItem: new FormControl(''),
|
|
1022
|
+
initialDate: new FormControl('', this.tableService.dateFormatValidator()),
|
|
1023
|
+
finalDate: new FormControl('', this.tableService.dateFormatValidator()),
|
|
1024
|
+
});
|
|
1025
|
+
}
|
|
1026
|
+
addFilter(filterData) {
|
|
1027
|
+
var _a, _b, _c, _d, _e;
|
|
1028
|
+
const newFilterGroup = this.createFilterGroup();
|
|
1029
|
+
if (filterData) {
|
|
1030
|
+
if (filterData.selectFilter) {
|
|
1031
|
+
(_a = newFilterGroup.get('selectFilter')) === null || _a === void 0 ? void 0 : _a.setValue(filterData.selectFilter);
|
|
1032
|
+
}
|
|
1033
|
+
if (filterData.typeFilter) {
|
|
1034
|
+
(_b = newFilterGroup.get('typeFilter')) === null || _b === void 0 ? void 0 : _b.setValue(filterData.typeFilter);
|
|
1035
|
+
}
|
|
1036
|
+
if (filterData.selectItem) {
|
|
1037
|
+
(_c = newFilterGroup.get('selectItem')) === null || _c === void 0 ? void 0 : _c.setValue(filterData.selectItem);
|
|
1038
|
+
}
|
|
1039
|
+
if (filterData.initialDate) {
|
|
1040
|
+
(_d = newFilterGroup.get('initialDate')) === null || _d === void 0 ? void 0 : _d.setValue(filterData.initialDate);
|
|
1041
|
+
}
|
|
1042
|
+
if (filterData.finalDate) {
|
|
1043
|
+
(_e = newFilterGroup.get('finalDate')) === null || _e === void 0 ? void 0 : _e.setValue(filterData.finalDate);
|
|
1044
|
+
}
|
|
1045
|
+
}
|
|
1046
|
+
this.filtersForm.push(newFilterGroup);
|
|
1047
|
+
}
|
|
1048
|
+
onSelectFilterChange() {
|
|
1049
|
+
var _a;
|
|
1050
|
+
const lastIndex = this.filtersForm.length - 1;
|
|
1051
|
+
const lastFilter = this.filtersForm.at(lastIndex);
|
|
1052
|
+
if ((_a = lastFilter.get('selectFilter')) === null || _a === void 0 ? void 0 : _a.value) {
|
|
1053
|
+
this.addFilter();
|
|
1054
|
+
}
|
|
1055
|
+
}
|
|
1056
|
+
removeFilter(index) {
|
|
1057
|
+
this.filtersForm.removeAt(index);
|
|
1058
|
+
if (this.filtersForm.length === 0) {
|
|
1059
|
+
this.addFilter();
|
|
1060
|
+
}
|
|
1061
|
+
}
|
|
1062
|
+
removeAllFilters() {
|
|
1063
|
+
this.filtersForm.clear();
|
|
1064
|
+
this.addFilter();
|
|
1065
|
+
this.resetFilter();
|
|
1066
|
+
}
|
|
1067
|
+
// METHODS
|
|
1068
|
+
ngOnInit() {
|
|
1069
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1070
|
+
if (!this.data.color)
|
|
1071
|
+
this.data.color = { bg: 'bg-primary', text: 'text-black' };
|
|
1072
|
+
this.columnProperties = this.data.displayedColumns.map((column) => {
|
|
1073
|
+
return column.property;
|
|
1074
|
+
});
|
|
1075
|
+
if (this.data.actionButton && !this.data.actionButton.condition) {
|
|
1076
|
+
this.data.actionButton.condition = (_row) => true;
|
|
1077
|
+
}
|
|
1078
|
+
if (this.data.pagination) {
|
|
1079
|
+
this.data.displayedColumns.forEach((col) => {
|
|
1080
|
+
if (col.isFilterable) {
|
|
1081
|
+
if (this.hasFilterableColumn === false)
|
|
1082
|
+
this.hasFilterableColumn = true;
|
|
1083
|
+
this.dropdownItems.push(Object.assign(Object.assign({}, col), { arrange: 'filter', title: col.title }));
|
|
1084
|
+
}
|
|
1085
|
+
if (col.isSortable) {
|
|
1086
|
+
if (this.hasSortableColumn === false)
|
|
1087
|
+
this.hasSortableColumn = true;
|
|
1088
|
+
this.sortableDropdownItems.push(Object.assign(Object.assign({}, col), { arrange: 'ascending', title: col.title + ': crescente' }));
|
|
1089
|
+
this.sortableDropdownItems.push(Object.assign(Object.assign({}, col), { arrange: 'descending', title: col.title + ': decrescente' }));
|
|
1090
|
+
}
|
|
1091
|
+
if (col.isFilterableByDate) {
|
|
1092
|
+
this.dropdownItems.push(Object.assign(Object.assign({}, col), { arrange: 'filterByDate', title: col.title + ': filtro por data' }));
|
|
1093
|
+
}
|
|
1094
|
+
});
|
|
1095
|
+
if (this.data.filterableOptions) {
|
|
1096
|
+
this.data.filterableOptions.forEach((option) => this.dropdownItems.push(Object.assign(Object.assign({}, option), { arrange: 'equals' })));
|
|
1097
|
+
}
|
|
1098
|
+
}
|
|
1099
|
+
// Sem paginação
|
|
1100
|
+
if (this.data.pagination === false) {
|
|
1101
|
+
yield this.loadItems();
|
|
1102
|
+
}
|
|
1103
|
+
// Com paginação
|
|
1104
|
+
if (this.data.pagination === true) {
|
|
1105
|
+
if (this.data.sortBy)
|
|
1106
|
+
this.sortBy = {
|
|
1107
|
+
field: this.data.sortBy.field,
|
|
1108
|
+
order: this.data.sortBy.order,
|
|
1109
|
+
};
|
|
1110
|
+
this.filterSubject
|
|
1111
|
+
.pipe(debounceTime(this.debounceTimeMs))
|
|
1112
|
+
.subscribe(() => {
|
|
1113
|
+
this.loadItemsPaginated('reload', true);
|
|
1114
|
+
});
|
|
1115
|
+
this.isLoading = true;
|
|
1116
|
+
yield this.loadItemsPaginated('reload', true);
|
|
1117
|
+
this.sort.active = 'createdAt';
|
|
1118
|
+
this.sort.direction = 'desc';
|
|
1119
|
+
this.dataSource.paginator = this.paginator;
|
|
1120
|
+
this.dataSource.sort = this.sort;
|
|
1121
|
+
this.totalItems = 0;
|
|
1122
|
+
if (this.data.totalRef) {
|
|
1123
|
+
for (const totalRef of this.data.totalRef) {
|
|
1124
|
+
const totalRefDoc = yield totalRef.ref.get();
|
|
1125
|
+
const docData = totalRefDoc.data();
|
|
1126
|
+
if (docData && docData[totalRef.field])
|
|
1127
|
+
this.totalItems = (this.totalItems +
|
|
1128
|
+
docData[totalRef.field]);
|
|
1129
|
+
}
|
|
1130
|
+
}
|
|
1131
|
+
this.isLoading = false;
|
|
1132
|
+
}
|
|
1133
|
+
});
|
|
1134
|
+
}
|
|
1135
|
+
getDisplayValue(col, row, withinLimit = false) {
|
|
1136
|
+
let value;
|
|
1137
|
+
if (row[col.property] === null || row[col.property] === undefined) {
|
|
1138
|
+
return '';
|
|
1139
|
+
}
|
|
1140
|
+
if (col.calculateValue) {
|
|
1141
|
+
value = String(col.calculateValue(row));
|
|
1142
|
+
}
|
|
1143
|
+
else {
|
|
1144
|
+
value = this.getNestedValue(row, col.property);
|
|
1145
|
+
}
|
|
1146
|
+
// Verifica se é um array e tem arrayField definido
|
|
1147
|
+
if (Array.isArray(value) && col.arrayField) {
|
|
1148
|
+
value = this.formatArrayValue(value, col.arrayField);
|
|
1149
|
+
}
|
|
1150
|
+
if (col.queryLength && row[col.property]) {
|
|
1151
|
+
value = row[col.property];
|
|
1152
|
+
}
|
|
1153
|
+
value = col.pipe ? col.pipe.transform(value) : value;
|
|
1154
|
+
return withinLimit ? value : value.substring(0, col.charLimit) + '...';
|
|
1155
|
+
}
|
|
1156
|
+
getNestedValue(obj, path) {
|
|
1157
|
+
if (!path)
|
|
1158
|
+
return undefined;
|
|
1159
|
+
const properties = path.split('.');
|
|
1160
|
+
return properties.reduce((acc, currentPart) => acc && acc[currentPart], obj);
|
|
1161
|
+
}
|
|
1162
|
+
formatArrayValue(array, field) {
|
|
1163
|
+
if (!Array.isArray(array) || array.length === 0) {
|
|
1164
|
+
return '';
|
|
1165
|
+
}
|
|
1166
|
+
const values = array
|
|
1167
|
+
.map((item) => {
|
|
1168
|
+
if (typeof item === 'object' && item !== null) {
|
|
1169
|
+
return item[field] || '';
|
|
1170
|
+
}
|
|
1171
|
+
return String(item);
|
|
1172
|
+
})
|
|
1173
|
+
.filter((value) => value !== '' && value !== null && value !== undefined);
|
|
1174
|
+
return values.join(', ');
|
|
1175
|
+
}
|
|
1176
|
+
// Métodos sem paginação
|
|
1177
|
+
loadItems() {
|
|
1178
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1179
|
+
this.items = yield this.tableService.getItems(this.data.collectionRef);
|
|
1180
|
+
if (this.data.conditions) {
|
|
1181
|
+
this.filterItems();
|
|
1182
|
+
}
|
|
1183
|
+
yield this.loadRelations();
|
|
1184
|
+
yield this.loadQueryLengths();
|
|
1185
|
+
this.totalItems = this.items.length;
|
|
1186
|
+
this.dataSource = new MatTableDataSource(this.items);
|
|
1187
|
+
this.dataSource.paginator = this.paginator;
|
|
1188
|
+
this.dataSource.sort = this.sort;
|
|
1189
|
+
if (this.data.sortBy) {
|
|
1190
|
+
this.dataSource.sort.active = this.data.sortBy.field;
|
|
1191
|
+
this.dataSource.sort.direction = this.data.sortBy.order;
|
|
1192
|
+
this.dataSource.sort.sortChange.emit();
|
|
1193
|
+
}
|
|
1194
|
+
this.dataSource.filterPredicate = (data, filter) => {
|
|
1195
|
+
return this.data.displayedColumns.some((col) => {
|
|
1196
|
+
if (col.filterPredicates) {
|
|
1197
|
+
return col.filterPredicates.some((predicate) => {
|
|
1198
|
+
const propertyValue = data[col.property];
|
|
1199
|
+
if (!propertyValue || typeof propertyValue !== 'object') {
|
|
1200
|
+
return false;
|
|
1201
|
+
}
|
|
1202
|
+
const predicateValue = propertyValue[predicate];
|
|
1203
|
+
if (predicateValue === null || predicateValue === undefined) {
|
|
1204
|
+
return false;
|
|
1205
|
+
}
|
|
1206
|
+
return String(predicateValue)
|
|
1207
|
+
.trim()
|
|
1208
|
+
.toLocaleLowerCase()
|
|
1209
|
+
.includes(filter);
|
|
1210
|
+
});
|
|
1211
|
+
}
|
|
1212
|
+
if (col.property && col.isFilterable) {
|
|
1213
|
+
const propertyValue = data[col.property];
|
|
1214
|
+
if (propertyValue === null || propertyValue === undefined) {
|
|
1215
|
+
return false;
|
|
1216
|
+
}
|
|
1217
|
+
return String(propertyValue)
|
|
1218
|
+
.trim()
|
|
1219
|
+
.toLocaleLowerCase()
|
|
1220
|
+
.includes(filter);
|
|
1221
|
+
}
|
|
1222
|
+
return false;
|
|
1223
|
+
});
|
|
1224
|
+
};
|
|
1225
|
+
this.filterPredicate = this.dataSource.filterPredicate;
|
|
1226
|
+
});
|
|
1227
|
+
}
|
|
1228
|
+
// Métodos com paginação
|
|
1229
|
+
loadItemsPaginated(navigation = 'reload', reset = false) {
|
|
1230
|
+
var _a;
|
|
1231
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1232
|
+
if (reset && ['forward', 'reload'].includes(navigation)) {
|
|
1233
|
+
this.lastDoc = null;
|
|
1234
|
+
}
|
|
1235
|
+
if (reset && ['backward', 'reload'].includes(navigation)) {
|
|
1236
|
+
this.firstDoc = null;
|
|
1237
|
+
}
|
|
1238
|
+
const activeFilters = this.filtersForm.controls
|
|
1239
|
+
.flatMap((control) => {
|
|
1240
|
+
var _a, _b, _c, _d, _e;
|
|
1241
|
+
const group = control;
|
|
1242
|
+
const selectedFilter = (_a = group.get('selectFilter')) === null || _a === void 0 ? void 0 : _a.value;
|
|
1243
|
+
if (!selectedFilter)
|
|
1244
|
+
return [];
|
|
1245
|
+
const arrange = selectedFilter.arrange;
|
|
1246
|
+
if (arrange === 'filter') {
|
|
1247
|
+
const filterValue = (_b = group.get('typeFilter')) === null || _b === void 0 ? void 0 : _b.value;
|
|
1248
|
+
if (!filterValue)
|
|
1249
|
+
return [];
|
|
1250
|
+
return {
|
|
1251
|
+
arrange,
|
|
1252
|
+
filter: {
|
|
1253
|
+
property: selectedFilter.property,
|
|
1254
|
+
filtering: filterValue,
|
|
1255
|
+
},
|
|
1256
|
+
dateFilter: undefined,
|
|
1257
|
+
};
|
|
1258
|
+
}
|
|
1259
|
+
if (arrange === 'filterByDate') {
|
|
1260
|
+
const initial = (_c = group.get('initialDate')) === null || _c === void 0 ? void 0 : _c.value;
|
|
1261
|
+
const final = (_d = group.get('finalDate')) === null || _d === void 0 ? void 0 : _d.value;
|
|
1262
|
+
if (initial && final) {
|
|
1263
|
+
const [dayI, monthI, yearI] = initial.split('/');
|
|
1264
|
+
const initialDate = new Date(`${monthI}/${dayI}/${yearI}`);
|
|
1265
|
+
const [dayF, monthF, yearF] = final.split('/');
|
|
1266
|
+
const finalDate = new Date(`${monthF}/${dayF}/${yearF}`);
|
|
1267
|
+
finalDate.setHours(23, 59, 59);
|
|
1268
|
+
return {
|
|
1269
|
+
arrange,
|
|
1270
|
+
filter: undefined,
|
|
1271
|
+
dateFilter: {
|
|
1272
|
+
initial: initialDate,
|
|
1273
|
+
final: finalDate,
|
|
1274
|
+
},
|
|
1275
|
+
};
|
|
1276
|
+
}
|
|
1277
|
+
return [];
|
|
1278
|
+
}
|
|
1279
|
+
if (selectedFilter.hasOwnProperty('items') && arrange === 'equals') {
|
|
1280
|
+
const selectedItems = (_e = group.get('selectItem')) === null || _e === void 0 ? void 0 : _e.value;
|
|
1281
|
+
if (Array.isArray(selectedItems) && selectedItems.length > 0) {
|
|
1282
|
+
return selectedItems.map((item) => ({
|
|
1283
|
+
arrange,
|
|
1284
|
+
filter: {
|
|
1285
|
+
property: item.property,
|
|
1286
|
+
filtering: item.value,
|
|
1287
|
+
},
|
|
1288
|
+
dateFilter: undefined,
|
|
1289
|
+
}));
|
|
1290
|
+
}
|
|
1291
|
+
}
|
|
1292
|
+
return [];
|
|
1293
|
+
})
|
|
1294
|
+
.filter((f) => { var _a; return f && (((_a = f.filter) === null || _a === void 0 ? void 0 : _a.filtering) !== undefined || f.dateFilter); });
|
|
1295
|
+
this.arrange = {
|
|
1296
|
+
filters: activeFilters,
|
|
1297
|
+
sortBy: this.sortBy,
|
|
1298
|
+
};
|
|
1299
|
+
const paginated = {
|
|
1300
|
+
batchSize: this.pageSize,
|
|
1301
|
+
collection: this.data.collection,
|
|
1302
|
+
doc: { lastDoc: this.lastDoc, firstDoc: this.firstDoc },
|
|
1303
|
+
navigation,
|
|
1304
|
+
arrange: this.arrange,
|
|
1305
|
+
conditions: this.data.conditions,
|
|
1306
|
+
size: this.totalItems,
|
|
1307
|
+
filterFn: this.data.filterFn,
|
|
1308
|
+
clientPageIndex: this.currentClientPageIndex,
|
|
1309
|
+
};
|
|
1310
|
+
const result = yield this.tableService.getPaginated(paginated);
|
|
1311
|
+
this.items = result.items;
|
|
1312
|
+
yield this.loadRelations();
|
|
1313
|
+
yield this.loadQueryLengths();
|
|
1314
|
+
this.lastDoc = result.lastDoc;
|
|
1315
|
+
this.firstDoc = result.firstDoc;
|
|
1316
|
+
// Atualizar currentClientPageIndex se retornado pelo fallback
|
|
1317
|
+
if (result.currentClientPageIndex !== undefined) {
|
|
1318
|
+
this.currentClientPageIndex = result.currentClientPageIndex;
|
|
1319
|
+
}
|
|
1320
|
+
let sum = 0;
|
|
1321
|
+
if (this.data.totalRef) {
|
|
1322
|
+
for (const totalRef of this.data.totalRef) {
|
|
1323
|
+
const totalRefDoc = yield totalRef.ref.get();
|
|
1324
|
+
const docData = totalRefDoc.data();
|
|
1325
|
+
if (docData || result.filterLength) {
|
|
1326
|
+
sum =
|
|
1327
|
+
(_a = result.filterLength) !== null && _a !== void 0 ? _a : (sum + (docData ? docData[totalRef.field] : 0));
|
|
1328
|
+
}
|
|
1329
|
+
}
|
|
1330
|
+
this.totalItems = sum;
|
|
1331
|
+
}
|
|
1332
|
+
this.hasNextPage = result.hasNextPage;
|
|
1333
|
+
this.dataSource = new MatTableDataSource(this.items);
|
|
1334
|
+
this.filterPredicate = this.dataSource.filterPredicate;
|
|
1335
|
+
});
|
|
1336
|
+
}
|
|
1337
|
+
onPageChange(event) {
|
|
1338
|
+
var _a;
|
|
1339
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1340
|
+
if (this.data.pagination === true && event) {
|
|
1341
|
+
this.isLoading = true;
|
|
1342
|
+
const previousPageIndex = (_a = event.previousPageIndex) !== null && _a !== void 0 ? _a : 0;
|
|
1343
|
+
const pageIndex = event.pageIndex;
|
|
1344
|
+
const currentComponentPageSize = this.pageSize;
|
|
1345
|
+
const eventPageSize = event.pageSize;
|
|
1346
|
+
const totalItems = this.totalItems;
|
|
1347
|
+
let navigationDirection;
|
|
1348
|
+
let resetDocs = false;
|
|
1349
|
+
let originalPageSize = null;
|
|
1350
|
+
const lastPageIndex = Math.max(0, Math.ceil(totalItems / eventPageSize) - 1);
|
|
1351
|
+
// Atualizar currentClientPageIndex sempre para o fallback
|
|
1352
|
+
this.currentClientPageIndex = pageIndex;
|
|
1353
|
+
if (previousPageIndex !== undefined && pageIndex > previousPageIndex) {
|
|
1354
|
+
this.currentPageNumber++;
|
|
1355
|
+
}
|
|
1356
|
+
else if (previousPageIndex !== undefined &&
|
|
1357
|
+
pageIndex < previousPageIndex) {
|
|
1358
|
+
this.currentPageNumber = Math.max(1, this.currentPageNumber - 1);
|
|
1359
|
+
}
|
|
1360
|
+
if (eventPageSize !== currentComponentPageSize) {
|
|
1361
|
+
console.log('Alterou a quantidade de elementos exibidos por página');
|
|
1362
|
+
this.pageSize = eventPageSize;
|
|
1363
|
+
navigationDirection = 'forward';
|
|
1364
|
+
resetDocs = true;
|
|
1365
|
+
this.currentClientPageIndex = 0;
|
|
1366
|
+
}
|
|
1367
|
+
else if (pageIndex === 0 &&
|
|
1368
|
+
previousPageIndex !== undefined &&
|
|
1369
|
+
pageIndex < previousPageIndex) {
|
|
1370
|
+
console.log('Pulou para a primeira página');
|
|
1371
|
+
navigationDirection = 'forward';
|
|
1372
|
+
this.currentPageNumber = 1;
|
|
1373
|
+
this.currentClientPageIndex = 0;
|
|
1374
|
+
resetDocs = true;
|
|
1375
|
+
}
|
|
1376
|
+
else if (pageIndex === lastPageIndex &&
|
|
1377
|
+
previousPageIndex !== undefined &&
|
|
1378
|
+
pageIndex > previousPageIndex &&
|
|
1379
|
+
pageIndex - previousPageIndex > 1) {
|
|
1380
|
+
console.log('Pulou para a ultima página');
|
|
1381
|
+
navigationDirection = 'backward';
|
|
1382
|
+
resetDocs = true;
|
|
1383
|
+
const itemsExpectedInLastPage = totalItems - lastPageIndex * eventPageSize;
|
|
1384
|
+
if (itemsExpectedInLastPage > 0 &&
|
|
1385
|
+
itemsExpectedInLastPage < eventPageSize) {
|
|
1386
|
+
originalPageSize = this.pageSize;
|
|
1387
|
+
this.pageSize = itemsExpectedInLastPage;
|
|
1388
|
+
}
|
|
1389
|
+
}
|
|
1390
|
+
else if (previousPageIndex !== undefined &&
|
|
1391
|
+
pageIndex > previousPageIndex) {
|
|
1392
|
+
console.log('Procedendo');
|
|
1393
|
+
navigationDirection = 'forward';
|
|
1394
|
+
resetDocs = false;
|
|
1395
|
+
}
|
|
1396
|
+
else if (previousPageIndex !== undefined &&
|
|
1397
|
+
pageIndex < previousPageIndex) {
|
|
1398
|
+
console.log('Retrocedendo.');
|
|
1399
|
+
navigationDirection = 'backward';
|
|
1400
|
+
resetDocs = false;
|
|
1401
|
+
}
|
|
1402
|
+
else if (previousPageIndex !== undefined &&
|
|
1403
|
+
pageIndex === previousPageIndex) {
|
|
1404
|
+
console.log('Recarregando.');
|
|
1405
|
+
navigationDirection = 'reload';
|
|
1406
|
+
resetDocs = false;
|
|
1407
|
+
}
|
|
1408
|
+
else if (previousPageIndex === undefined && pageIndex === 0) {
|
|
1409
|
+
console.log('Evento inicial do paginador para pág 0. ngOnInit carregou.');
|
|
1410
|
+
this.isLoading = false;
|
|
1411
|
+
if (event)
|
|
1412
|
+
this.pageEvent = event;
|
|
1413
|
+
return;
|
|
1414
|
+
}
|
|
1415
|
+
else {
|
|
1416
|
+
console.warn('INESPERADO! Condição de navegação não tratada:', event);
|
|
1417
|
+
this.isLoading = false;
|
|
1418
|
+
if (event)
|
|
1419
|
+
this.pageEvent = event;
|
|
1420
|
+
return;
|
|
1421
|
+
}
|
|
1422
|
+
if (navigationDirection) {
|
|
1423
|
+
try {
|
|
1424
|
+
yield this.loadItemsPaginated(navigationDirection, resetDocs);
|
|
1425
|
+
}
|
|
1426
|
+
catch (error) {
|
|
1427
|
+
console.error('Erro ao carregar itens paginados:', error);
|
|
1428
|
+
}
|
|
1429
|
+
finally {
|
|
1430
|
+
if (originalPageSize !== null) {
|
|
1431
|
+
this.pageSize = originalPageSize;
|
|
1432
|
+
}
|
|
1433
|
+
}
|
|
1434
|
+
}
|
|
1435
|
+
if (event)
|
|
1436
|
+
this.pageEvent = event;
|
|
1437
|
+
this.isLoading = false;
|
|
1438
|
+
}
|
|
1439
|
+
});
|
|
1440
|
+
}
|
|
1441
|
+
// Outros métodos
|
|
1442
|
+
applyFilter(value) {
|
|
1443
|
+
// Sem paginação
|
|
1444
|
+
if (this.data.pagination === false) {
|
|
1445
|
+
this.dataSource.filter = String(value).trim().toLowerCase();
|
|
1446
|
+
}
|
|
1447
|
+
// Com paginação
|
|
1448
|
+
if (this.data.pagination === true) {
|
|
1449
|
+
this.filterValue = value;
|
|
1450
|
+
this.filterSubject.next(this.filterValue);
|
|
1451
|
+
}
|
|
1452
|
+
}
|
|
1453
|
+
goToDetails(row) {
|
|
1454
|
+
if (this.data.isNotClickable) {
|
|
1455
|
+
return;
|
|
1456
|
+
}
|
|
1457
|
+
const urlPath = this.data.url || this.data.name;
|
|
1458
|
+
const url = this.router.serializeUrl(this.router.createUrlTree([`/${urlPath}`, row.id]));
|
|
1459
|
+
window.open(url, '_blank');
|
|
1460
|
+
}
|
|
1461
|
+
getRelation(params) {
|
|
1462
|
+
var _a;
|
|
1463
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1464
|
+
try {
|
|
1465
|
+
let snapshot;
|
|
1466
|
+
if (params.id !== '' &&
|
|
1467
|
+
params.id !== undefined &&
|
|
1468
|
+
params.collection !== undefined &&
|
|
1469
|
+
params.collection !== '') {
|
|
1470
|
+
snapshot = yield firstValueFrom(this.firestore.collection(params.collection).doc(params.id).get());
|
|
1471
|
+
}
|
|
1472
|
+
if (snapshot && snapshot.exists) {
|
|
1473
|
+
const data = snapshot.data();
|
|
1474
|
+
return (_a = data === null || data === void 0 ? void 0 : data[params.newProperty]) !== null && _a !== void 0 ? _a : '';
|
|
1475
|
+
}
|
|
1476
|
+
return '';
|
|
1477
|
+
}
|
|
1478
|
+
catch (e) {
|
|
1479
|
+
console.log(e);
|
|
1480
|
+
return '';
|
|
1481
|
+
}
|
|
1482
|
+
});
|
|
1483
|
+
}
|
|
1484
|
+
loadRelations() {
|
|
1485
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1486
|
+
const relationPromises = this.data.displayedColumns
|
|
1487
|
+
.filter((col) => col.relation)
|
|
1488
|
+
.flatMap((col) => this.items.map((item) => __awaiter(this, void 0, void 0, function* () {
|
|
1489
|
+
if (col.relation) {
|
|
1490
|
+
item[col.property] = yield this.getRelation({
|
|
1491
|
+
id: item[col.relation.property],
|
|
1492
|
+
collection: col.relation.collection,
|
|
1493
|
+
newProperty: col.relation.newProperty,
|
|
1494
|
+
});
|
|
1495
|
+
}
|
|
1496
|
+
})));
|
|
1497
|
+
yield Promise.all(relationPromises);
|
|
1498
|
+
});
|
|
1499
|
+
}
|
|
1500
|
+
getQueryLength(params) {
|
|
1501
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1502
|
+
const snapshot = yield this.firestore
|
|
1503
|
+
.collection(params.relation.collection)
|
|
1504
|
+
.ref.where(params.relation.property, params.relation.operator, params.item[params.relation.value])
|
|
1505
|
+
.get();
|
|
1506
|
+
return snapshot.size;
|
|
1507
|
+
});
|
|
1508
|
+
}
|
|
1509
|
+
loadQueryLengths() {
|
|
1510
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1511
|
+
const lengthPromises = this.data.displayedColumns
|
|
1512
|
+
.filter((col) => col.queryLength)
|
|
1513
|
+
.flatMap((col) => this.items.map((item) => __awaiter(this, void 0, void 0, function* () {
|
|
1514
|
+
if (col.queryLength) {
|
|
1515
|
+
item[col.property] = yield this.getQueryLength({
|
|
1516
|
+
item: item,
|
|
1517
|
+
relation: col.queryLength,
|
|
1518
|
+
});
|
|
1519
|
+
}
|
|
1520
|
+
})));
|
|
1521
|
+
yield Promise.all(lengthPromises);
|
|
1522
|
+
});
|
|
1523
|
+
}
|
|
1524
|
+
filterItems() {
|
|
1525
|
+
if (this.data.conditions) {
|
|
1526
|
+
this.data.conditions.forEach((cond) => {
|
|
1527
|
+
this.items = this.items.filter((item) => {
|
|
1528
|
+
const operatorFunction = this.tableService.operators[cond.operator];
|
|
1529
|
+
if (operatorFunction) {
|
|
1530
|
+
return operatorFunction(item[cond.firestoreProperty], cond.dashProperty);
|
|
1531
|
+
}
|
|
1532
|
+
return false;
|
|
1533
|
+
});
|
|
1534
|
+
});
|
|
1535
|
+
}
|
|
1536
|
+
}
|
|
1537
|
+
// Filtro de data
|
|
1538
|
+
search() {
|
|
1539
|
+
var _a, _b, _c;
|
|
1540
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1541
|
+
if (this.selectSort.value) {
|
|
1542
|
+
if (this.selectSort.value.arrange === 'ascending') {
|
|
1543
|
+
this.sortBy = {
|
|
1544
|
+
field: this.selectSort.value.property,
|
|
1545
|
+
order: 'asc',
|
|
1546
|
+
};
|
|
1547
|
+
}
|
|
1548
|
+
if (this.selectSort.value.arrange === 'descending') {
|
|
1549
|
+
this.sortBy = {
|
|
1550
|
+
field: this.selectSort.value.property,
|
|
1551
|
+
order: 'desc',
|
|
1552
|
+
};
|
|
1553
|
+
}
|
|
1554
|
+
}
|
|
1555
|
+
yield this.loadItemsPaginated('reload', true);
|
|
1556
|
+
this.currentArrange =
|
|
1557
|
+
this.filtersForm.length > 0
|
|
1558
|
+
? (_c = (_b = (_a = this.filtersForm.at(0).get('selectFilter')) === null || _a === void 0 ? void 0 : _a.value) === null || _b === void 0 ? void 0 : _b.arrange) !== null && _c !== void 0 ? _c : ''
|
|
1559
|
+
: '';
|
|
1560
|
+
this.paginator.firstPage();
|
|
1561
|
+
});
|
|
1562
|
+
}
|
|
1563
|
+
resetFilter() {
|
|
1564
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1565
|
+
if (!this.data.pagination) {
|
|
1566
|
+
this.dataSource.filter = '';
|
|
1567
|
+
if (this.filterPredicate) {
|
|
1568
|
+
this.dataSource.filterPredicate = this.filterPredicate;
|
|
1569
|
+
}
|
|
1570
|
+
}
|
|
1571
|
+
else {
|
|
1572
|
+
this.dataSource.filter = '';
|
|
1573
|
+
if (this.filterPredicate) {
|
|
1574
|
+
this.dataSource.filterPredicate = this.filterPredicate;
|
|
1575
|
+
}
|
|
1576
|
+
}
|
|
1577
|
+
this.filtersForm.clear();
|
|
1578
|
+
this.addFilter();
|
|
1579
|
+
this.selectSort.patchValue('');
|
|
1580
|
+
this.sortBy = {
|
|
1581
|
+
order: this.data.sortBy ? this.data.sortBy.order : 'desc',
|
|
1582
|
+
field: this.data.sortBy ? this.data.sortBy.field : 'createdAt',
|
|
1583
|
+
};
|
|
1584
|
+
yield this.loadItemsPaginated('reload', true);
|
|
1585
|
+
this.currentArrange = '';
|
|
1586
|
+
this.paginator.firstPage();
|
|
1587
|
+
});
|
|
1588
|
+
}
|
|
1589
|
+
// Método público para recarregar a tabela
|
|
1590
|
+
reloadTable() {
|
|
1591
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1592
|
+
if (this.data.pagination) {
|
|
1593
|
+
yield this.loadItemsPaginated('reload', true);
|
|
1594
|
+
this.paginator.firstPage();
|
|
1595
|
+
}
|
|
1596
|
+
else {
|
|
1597
|
+
yield this.loadItems();
|
|
1598
|
+
}
|
|
1599
|
+
});
|
|
1600
|
+
}
|
|
1601
|
+
updateDisplayedColumns() {
|
|
1602
|
+
if (this.dataSource) {
|
|
1603
|
+
this.dataSource = new MatTableDataSource([]);
|
|
1604
|
+
}
|
|
1605
|
+
this.columnProperties = this.data.displayedColumns.map((column) => {
|
|
1606
|
+
return column.property;
|
|
1607
|
+
});
|
|
1608
|
+
this.dropdownItems = [];
|
|
1609
|
+
this.sortableDropdownItems = [];
|
|
1610
|
+
this.data.displayedColumns.forEach((col) => {
|
|
1611
|
+
if (col.isFilterable) {
|
|
1612
|
+
this.dropdownItems.push(Object.assign(Object.assign({}, col), { arrange: 'filter', title: col.title }));
|
|
1613
|
+
}
|
|
1614
|
+
if (col.isSortable) {
|
|
1615
|
+
this.sortableDropdownItems.push(Object.assign(Object.assign({}, col), { arrange: 'ascending', title: col.title + ': crescente' }));
|
|
1616
|
+
this.sortableDropdownItems.push(Object.assign(Object.assign({}, col), { arrange: 'descending', title: col.title + ': decrescente' }));
|
|
1617
|
+
}
|
|
1618
|
+
if (col.isFilterableByDate) {
|
|
1619
|
+
this.dropdownItems.push(Object.assign(Object.assign({}, col), { arrange: 'filterByDate', title: col.title + ': filtro por data' }));
|
|
1620
|
+
}
|
|
1621
|
+
});
|
|
1622
|
+
if (this.data.filterableOptions) {
|
|
1623
|
+
this.data.filterableOptions.forEach((option) => this.dropdownItems.push(Object.assign(Object.assign({}, option), { arrange: 'equals' })));
|
|
1624
|
+
}
|
|
1625
|
+
}
|
|
1626
|
+
isString(value) {
|
|
1627
|
+
return typeof value === 'string';
|
|
1628
|
+
}
|
|
1629
|
+
// Métodos para controle do tooltip
|
|
1630
|
+
onCellMouseEnter(event, row, col) {
|
|
1631
|
+
// Só mostrar tooltip se a coluna tiver charLimit definido
|
|
1632
|
+
if (!col.charLimit) {
|
|
1633
|
+
return;
|
|
1634
|
+
}
|
|
1635
|
+
const fullValue = this.getDisplayValue(col, row, true);
|
|
1636
|
+
// Só mostrar tooltip se o valor completo for maior que o limite
|
|
1637
|
+
if (fullValue.length <= col.charLimit) {
|
|
1638
|
+
return;
|
|
1639
|
+
}
|
|
1640
|
+
this.hoveredCell = { row, col };
|
|
1641
|
+
this.tooltipContent = fullValue;
|
|
1642
|
+
// Definir posição do tooltip
|
|
1643
|
+
this.tooltipPosition = {
|
|
1644
|
+
x: event.clientX + 10,
|
|
1645
|
+
y: event.clientY - 10,
|
|
1646
|
+
};
|
|
1647
|
+
// Timeout para mostrar o tooltip
|
|
1648
|
+
this.tooltipTimeout = setTimeout(() => {
|
|
1649
|
+
if (this.hoveredCell &&
|
|
1650
|
+
this.hoveredCell.row === row &&
|
|
1651
|
+
this.hoveredCell.col === col) {
|
|
1652
|
+
this.showTooltip = true;
|
|
1653
|
+
}
|
|
1654
|
+
}, 500);
|
|
1655
|
+
}
|
|
1656
|
+
onCellMouseLeave() {
|
|
1657
|
+
if (this.tooltipTimeout) {
|
|
1658
|
+
clearTimeout(this.tooltipTimeout);
|
|
1659
|
+
this.tooltipTimeout = null;
|
|
1660
|
+
}
|
|
1661
|
+
this.showTooltip = false;
|
|
1662
|
+
this.hoveredCell = null;
|
|
1663
|
+
this.tooltipContent = '';
|
|
1664
|
+
}
|
|
1665
|
+
onCellMouseMove(event) {
|
|
1666
|
+
if (this.showTooltip) {
|
|
1667
|
+
this.tooltipPosition = {
|
|
1668
|
+
x: event.clientX + 10,
|
|
1669
|
+
y: event.clientY - 10,
|
|
1670
|
+
};
|
|
1671
|
+
}
|
|
1672
|
+
}
|
|
1673
|
+
// Métodos para inversão vertical dos tabs
|
|
1674
|
+
getTabGroups(tabs) {
|
|
1675
|
+
if (!tabs || tabs.length === 0)
|
|
1676
|
+
return [];
|
|
1677
|
+
const totalGroups = Math.ceil(tabs.length / 6);
|
|
1678
|
+
const groups = [];
|
|
1679
|
+
// Criar array de índices invertidos (último grupo primeiro)
|
|
1680
|
+
for (let i = totalGroups - 1; i >= 0; i--) {
|
|
1681
|
+
groups.push(i);
|
|
1682
|
+
}
|
|
1683
|
+
return groups;
|
|
1684
|
+
}
|
|
1685
|
+
getTabGroup(tabs, groupIndex) {
|
|
1686
|
+
if (!tabs || tabs.length === 0)
|
|
1687
|
+
return [];
|
|
1688
|
+
const startIndex = groupIndex * 6;
|
|
1689
|
+
const endIndex = Math.min(startIndex + 6, tabs.length);
|
|
1690
|
+
return tabs.slice(startIndex, endIndex);
|
|
1691
|
+
}
|
|
1692
|
+
getRealTabIndex(groupIndex, tabIndexInGroup) {
|
|
1693
|
+
var _a;
|
|
1694
|
+
if (!((_a = this.data.tabs) === null || _a === void 0 ? void 0 : _a.tabsData))
|
|
1695
|
+
return 0;
|
|
1696
|
+
const totalGroups = Math.ceil(this.data.tabs.tabsData.length / 6);
|
|
1697
|
+
const realGroupIndex = totalGroups - 1 - groupIndex;
|
|
1698
|
+
return realGroupIndex * 6 + tabIndexInGroup;
|
|
1699
|
+
}
|
|
1700
|
+
onTableSelected(i, j) {
|
|
1701
|
+
var _a;
|
|
1702
|
+
if (!((_a = this.data.tabs) === null || _a === void 0 ? void 0 : _a.tabsData) || !this.data.tabs.method)
|
|
1703
|
+
return;
|
|
1704
|
+
this.selectedTab = this.getRealTabIndex(i, j);
|
|
1705
|
+
const tab = this.data.tabs.tabsData[this.selectedTab];
|
|
1706
|
+
if (tab) {
|
|
1707
|
+
this.data.tabs.method(tab, this.selectedTab);
|
|
1708
|
+
}
|
|
1709
|
+
}
|
|
1710
|
+
isTabSelected(originalIndex) {
|
|
1711
|
+
return this.selectedTab === originalIndex;
|
|
1712
|
+
}
|
|
1713
|
+
shouldShowActionButton() {
|
|
1714
|
+
var _a, _b;
|
|
1715
|
+
if (!((_a = this.data) === null || _a === void 0 ? void 0 : _a.actionButton)) {
|
|
1716
|
+
return false;
|
|
1717
|
+
}
|
|
1718
|
+
if (!this.data.actionButton.condition) {
|
|
1719
|
+
return true;
|
|
1720
|
+
}
|
|
1721
|
+
try {
|
|
1722
|
+
return (_b = this.data.actionButton.condition(null)) !== null && _b !== void 0 ? _b : true;
|
|
1723
|
+
}
|
|
1724
|
+
catch (_c) {
|
|
1725
|
+
return true;
|
|
1726
|
+
}
|
|
1727
|
+
}
|
|
1728
|
+
}
|
|
1729
|
+
TableComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: TableComponent, deps: [{ token: i1$1.Router }, { token: TableService }, { token: i1.AngularFirestore }], target: i0.ɵɵFactoryTarget.Component });
|
|
1730
|
+
TableComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.10", type: TableComponent, selector: "lib-table", inputs: { data: "data", downloadTable: "downloadTable" }, viewQueries: [{ propertyName: "paginator", first: true, predicate: MatPaginator, descendants: true }, { propertyName: "sort", first: true, predicate: MatSort, descendants: true }], ngImport: i0, template: "<div *ngIf=\"data\" class=\"card-body\">\r\n <div class=\"flex flex-col justify-between gap-6\">\r\n <!-- UNIFIED CONTROL PANEL: FILTERS, SORT & ACTIONS -->\r\n <div\r\n class=\"rounded-xl border border-gray-200 bg-white p-4 shadow-lg\"\r\n *ngIf=\"\r\n data.pagination === true &&\r\n (dropdownItems.length > 0 ||\r\n sortableDropdownItems.length > 0 ||\r\n data.actionButton)\r\n \"\r\n >\r\n <!-- PANEL HEADER: Title, Custom Action, and Global Actions -->\r\n <div\r\n class=\"mb-4 flex flex-col items-start justify-between gap-4 border-b-2 border-gray-200 pb-4 md:flex-row md:items-center\"\r\n >\r\n <!-- Left Side: Title & Main Action Button -->\r\n <div class=\"flex flex-wrap items-center gap-4\">\r\n <div class=\"flex items-center gap-2\">\r\n <i class=\"fa fa-filter text-xl text-blue-500\"></i>\r\n <span class=\"text-lg font-semibold text-gray-700\"\r\n >Filtros e A\u00E7\u00F5es</span\r\n >\r\n </div>\r\n <button\r\n *ngIf=\"data.actionButton && data.actionButton.condition\"\r\n [ngClass]=\"\r\n (data.actionButton.colorClass || 'bg-blue-500') +\r\n ' flex items-center gap-2 rounded-lg px-4 py-2 text-sm font-medium text-white hover:opacity-70'\r\n \"\r\n [routerLink]=\"data.actionButton.routerLink\"\r\n (click)=\"\r\n data.actionButton.method ? data.actionButton.method($event) : null\r\n \"\r\n >\r\n <i\r\n *ngIf=\"data.actionButton.icon\"\r\n [class]=\"data.actionButton.icon\"\r\n ></i>\r\n {{ data.actionButton.label }}\r\n </button>\r\n </div>\r\n\r\n <!-- Right Side: Search, Reset, Export -->\r\n <div\r\n class=\"flex flex-wrap gap-3\"\r\n *ngIf=\"\r\n this.hasFilterableColumn === true || this.hasSortableColumn === true\r\n \"\r\n >\r\n <button\r\n (click)=\"search()\"\r\n type=\"button\"\r\n class=\"flex items-center gap-2 rounded-lg bg-green-600 px-5 py-2 text-sm font-medium text-white transition-colors hover:bg-green-700\"\r\n matTooltip=\"Aplicar filtros\"\r\n >\r\n <i class=\"fa fa-search\"></i>\r\n Pesquisar\r\n </button>\r\n\r\n <button\r\n (click)=\"resetFilter()\"\r\n class=\"flex items-center gap-2 rounded-lg bg-red-500 px-5 py-2 text-sm font-medium text-white transition-colors hover:bg-red-600\"\r\n matTooltip=\"Limpar filtros\"\r\n >\r\n <i class=\"fas fa-redo-alt\"></i>\r\n Resetar\r\n </button>\r\n\r\n <button\r\n *ngIf=\"data.download !== false && downloadTable\"\r\n class=\"flex items-center gap-2 rounded-lg bg-orange-500 px-5 py-2 text-sm font-medium text-white transition-colors hover:bg-orange-600\"\r\n matTooltipPosition=\"above\"\r\n matTooltip=\"Exportar Tabela\"\r\n [disabled]=\"\r\n this.dataSource && this.dataSource.filteredData.length <= 0\r\n \"\r\n (click)=\"\r\n $any(arrange) && downloadTable !== undefined\r\n ? downloadTable($any(arrange), data.conditions || [])\r\n : null\r\n \"\r\n >\r\n <i class=\"fa fa-download\"></i>\r\n Exportar\r\n </button>\r\n </div>\r\n </div>\r\n\r\n <!-- FILTERS CONTENT (WITH REFINEMENTS) -->\r\n <div class=\"mb-4 space-y-3\" *ngIf=\"filtersForm.controls.length > 0\">\r\n <div\r\n [formGroup]=\"$any(filterGroup)\"\r\n *ngFor=\"let filterGroup of filtersForm.controls; let i = index\"\r\n class=\"flex flex-wrap items-center gap-3 rounded-lg border border-gray-200 p-2\"\r\n >\r\n <!-- FILTER TYPE SELECTOR -->\r\n <div class=\"min-w-[200px] flex-1\" *ngIf=\"dropdownItems.length > 0\">\r\n <mat-form-field appearance=\"outline\" class=\"w-full\">\r\n <mat-label>Tipo de filtro</mat-label>\r\n <mat-select\r\n placeholder=\"Selecione o tipo...\"\r\n formControlName=\"selectFilter\"\r\n (selectionChange)=\"onSelectFilterChange()\"\r\n >\r\n <mat-option *ngFor=\"let item of dropdownItems\" [value]=\"item\">\r\n <div class=\"flex items-center gap-2\">\r\n <i\r\n [class]=\"item.icon || 'fa fa-filter'\"\r\n class=\"text-sm text-blue-500\"\r\n ></i>\r\n <span>{{ item.title }}</span>\r\n </div>\r\n </mat-option>\r\n </mat-select>\r\n </mat-form-field>\r\n </div>\r\n\r\n <!-- TEXT FILTER -->\r\n <div\r\n class=\"min-w-[200px] flex-1\"\r\n *ngIf=\"\r\n $any(filterGroup).get('selectFilter')?.value?.arrange === 'filter'\r\n \"\r\n >\r\n <mat-form-field appearance=\"outline\" class=\"w-full\">\r\n <mat-label class=\"flex items-center gap-2\">\r\n <i class=\"fa fa-search text-gray-400\"></i>\r\n <span>{{\r\n $any(filterGroup).get(\"selectFilter\")?.value?.title ||\r\n \"Filtrar\"\r\n }}</span>\r\n </mat-label>\r\n <input\r\n (keyup.enter)=\"search()\"\r\n formControlName=\"typeFilter\"\r\n matInput\r\n placeholder=\"Digite para filtrar...\"\r\n #input\r\n />\r\n </mat-form-field>\r\n </div>\r\n\r\n <!-- DROPDOWN FILTER -->\r\n <div\r\n class=\"min-w-[200px] flex-1\"\r\n *ngIf=\"\r\n $any(filterGroup).get('selectFilter')?.value &&\r\n $any(filterGroup)\r\n .get('selectFilter')\r\n ?.value.hasOwnProperty('items')\r\n \"\r\n >\r\n <mat-form-field appearance=\"outline\" class=\"w-full\">\r\n <mat-label>{{\r\n $any(filterGroup).get(\"selectFilter\")?.value?.title ||\r\n \"Selecione\"\r\n }}</mat-label>\r\n <mat-select\r\n placeholder=\"Selecione...\"\r\n formControlName=\"selectItem\"\r\n multiple\r\n >\r\n <mat-option\r\n *ngFor=\"\r\n let item of $any(filterGroup).get('selectFilter')?.value\r\n .items\r\n \"\r\n [value]=\"item\"\r\n >\r\n {{ item.label }}\r\n </mat-option>\r\n </mat-select>\r\n </mat-form-field>\r\n </div>\r\n\r\n <!-- DATE FILTER -->\r\n <div\r\n class=\"min-w-[340px] flex-auto\"\r\n *ngIf=\"\r\n $any(filterGroup).get('selectFilter')?.value?.arrange ===\r\n 'filterByDate'\r\n \"\r\n >\r\n <div\r\n class=\"flex flex-col items-stretch gap-3 sm:flex-row sm:items-center\"\r\n >\r\n <mat-form-field appearance=\"outline\" class=\"flex-1\">\r\n <mat-label class=\"flex items-center gap-2\">\r\n <i class=\"fa fa-calendar text-gray-400\"></i>\r\n <span>Data Inicial</span>\r\n </mat-label>\r\n <input\r\n matInput\r\n (keyup.enter)=\"search()\"\r\n formControlName=\"initialDate\"\r\n placeholder=\"DD/MM/AAAA\"\r\n maxlength=\"10\"\r\n />\r\n </mat-form-field>\r\n\r\n <mat-form-field appearance=\"outline\" class=\"flex-1\">\r\n <mat-label class=\"flex items-center gap-2\">\r\n <i class=\"fa fa-calendar text-gray-400\"></i>\r\n <span>Data Final</span>\r\n </mat-label>\r\n <input\r\n (keyup.enter)=\"search()\"\r\n matInput\r\n formControlName=\"finalDate\"\r\n placeholder=\"DD/MM/AAAA\"\r\n maxlength=\"10\"\r\n />\r\n </mat-form-field>\r\n </div>\r\n </div>\r\n\r\n <!-- REMOVE FILTER BUTTON -->\r\n <div *ngIf=\"filtersForm.length > 1\" class=\"ml-auto flex-shrink-0\">\r\n <button\r\n (click)=\"removeFilter(i)\"\r\n class=\"flex h-10 w-10 items-center justify-center rounded-full transition-colors duration-300 hover:bg-red-100\"\r\n matTooltip=\"Remover filtro\"\r\n >\r\n <i class=\"fa fa-trash text-red-500 hover:text-red-600\"></i>\r\n </button>\r\n </div>\r\n </div>\r\n </div>\r\n\r\n <!-- PANEL FOOTER: Add Filter & Sort -->\r\n <div\r\n class=\"-mb-2 flex flex-col items-center justify-between gap-4 border-t border-gray-200 pt-4 sm:flex-row\"\r\n >\r\n <!-- Add Filter Button -->\r\n <div *ngIf=\"dropdownItems.length > 0\">\r\n <button\r\n (click)=\"addFilter()\"\r\n class=\"transform rounded-full border-2 border-blue-300 bg-blue-50 px-6 py-2 text-sm font-medium text-blue-600 transition-all duration-300 hover:-translate-y-0.5 hover:border-blue-400 hover:bg-blue-100 hover:shadow-md\"\r\n matTooltip=\"Adicionar novo filtro\"\r\n >\r\n <i class=\"fa fa-plus mr-2\"></i>\r\n Adicionar Filtro\r\n </button>\r\n </div>\r\n\r\n <!-- Sort Dropdown -->\r\n <div\r\n class=\"w-full sm:w-auto sm:min-w-[250px]\"\r\n *ngIf=\"sortableDropdownItems.length > 0\"\r\n >\r\n <mat-form-field appearance=\"outline\" class=\"w-full\">\r\n <mat-label>Ordenar por</mat-label>\r\n <mat-select placeholder=\"Selecione...\" [formControl]=\"selectSort\">\r\n <mat-option\r\n *ngFor=\"let item of sortableDropdownItems\"\r\n [value]=\"item\"\r\n >\r\n <div class=\"flex items-center gap-2\">\r\n <i class=\"fa fa-sort-alpha-down text-cyan-600\"></i>\r\n <span>{{ item.title }}</span>\r\n </div>\r\n </mat-option>\r\n </mat-select>\r\n </mat-form-field>\r\n </div>\r\n </div>\r\n </div>\r\n\r\n <!-- SIMPLE SEARCH (for non-paginated tables) -->\r\n <div\r\n class=\"rounded-xl border border-gray-200 bg-white p-4 shadow-lg\"\r\n *ngIf=\"data.pagination === false\"\r\n >\r\n <mat-form-field appearance=\"outline\" class=\"w-full\">\r\n <mat-label class=\"flex items-center gap-2\">\r\n <i class=\"fa fa-search text-blue-500\"></i>\r\n Buscar\r\n </mat-label>\r\n <input\r\n matInput\r\n (keyup.enter)=\"search()\"\r\n (keyup)=\"applyFilter(filterInput.value)\"\r\n placeholder=\"Digite para filtrar...\"\r\n #filterInput\r\n />\r\n <mat-icon matSuffix class=\"text-gray-500\">search</mat-icon>\r\n </mat-form-field>\r\n <button\r\n *ngIf=\"data.actionButton\"\r\n [ngClass]=\"\r\n (data.actionButton.colorClass || 'bg-blue-500') +\r\n ' float-right flex items-center gap-2 rounded-lg px-4 py-2 text-sm font-medium text-white hover:opacity-70'\r\n \"\r\n [routerLink]=\"data.actionButton.routerLink\"\r\n (click)=\"\r\n data.actionButton.method ? data.actionButton.method($event) : null\r\n \"\r\n >\r\n <i *ngIf=\"data.actionButton.icon\" [class]=\"data.actionButton.icon\"></i>\r\n {{ data.actionButton.label }}\r\n </button>\r\n </div>\r\n\r\n <div class=\"flex flex-col\">\r\n <div\r\n class=\"mx-auto flex flex-col\"\r\n *ngIf=\"data.tabs && data.tabs.tabsData && data.tabs.tabsData.length > 0\"\r\n >\r\n <!-- Calcular quantos grupos de 6 tabs existem -->\r\n <ng-container\r\n *ngFor=\"\r\n let groupIndex of getTabGroups(data.tabs.tabsData);\r\n let i = index\r\n \"\r\n >\r\n <div class=\"mx-auto flex flex-row\">\r\n <ng-container\r\n *ngFor=\"\r\n let tab of getTabGroup(data.tabs.tabsData, groupIndex);\r\n let j = index\r\n \"\r\n >\r\n <button\r\n class=\"border-2 border-gray-300 bg-gray-200 px-4 py-2 font-medium transition hover:brightness-95\"\r\n [ngClass]=\"\r\n isTabSelected(getRealTabIndex(i, j))\r\n ? 'border-b-0 brightness-110'\r\n : ''\r\n \"\r\n (click)=\"onTableSelected(i, j)\"\r\n >\r\n {{ tab.label }}\r\n <span\r\n *ngIf=\"tab.counter !== undefined\"\r\n class=\"ml-2 text-xs font-bold\"\r\n [ngClass]=\"tab.counterClass\"\r\n >\r\n {{ tab.counter }}\r\n </span>\r\n </button>\r\n </ng-container>\r\n </div>\r\n </ng-container>\r\n </div>\r\n <div class=\"mat-elevation-z8 w-full overflow-x-auto rounded-xl\">\r\n <table\r\n mat-table\r\n [dataSource]=\"dataSource\"\r\n matSort\r\n #sort=\"matSort\"\r\n matSortActive=\"createdAt\"\r\n matSortDirection=\"desc\"\r\n >\r\n <ng-container\r\n *ngFor=\"let col of data.displayedColumns\"\r\n matColumnDef=\"{{ col.property }}\"\r\n >\r\n <ng-container *matHeaderCellDef>\r\n <!-- IF THE COLUMN IS NOT SORTABLE, THEN DON'T SHOW THE SORT BUTTONS -->\r\n <th\r\n *ngIf=\"!col.isSortable || data.pagination === true\"\r\n mat-header-cell\r\n [ngClass]=\"\r\n (data?.color?.bg ? ' ' + $any(data.color).bg : '') +\r\n (data?.color?.text ? ' ' + $any(data.color).text : '')\r\n \"\r\n >\r\n {{ col.title }}\r\n </th>\r\n <!-- IF THE COLUMN IS SORTABLE, THEN SHOW THE SORT BUTTONS -->\r\n <th\r\n *ngIf=\"col.isSortable && data.pagination === false\"\r\n mat-header-cell\r\n mat-sort-header\r\n [ngClass]=\"\r\n (data?.color?.bg ? ' ' + $any(data.color).bg : '') +\r\n (data?.color?.text ? ' ' + $any(data.color).text : '')\r\n \"\r\n >\r\n {{ col.title }}\r\n </th>\r\n <td\r\n mat-cell\r\n *matCellDef=\"let row\"\r\n (click)=\"col.method ? col.method(row) : null\"\r\n (mouseenter)=\"onCellMouseEnter($event, row, col)\"\r\n (mouseleave)=\"onCellMouseLeave()\"\r\n (mousemove)=\"onCellMouseMove($event)\"\r\n >\r\n <!-- CHECK IF THE COLUMN MUST BE DISPLAYED -->\r\n <span *ngIf=\"!col.image && !col.iconClass && !col.method\">\r\n <ng-container>\r\n <span\r\n *ngIf=\"\r\n col.charLimit &&\r\n row[col.property] &&\r\n row[col.property].length > col.charLimit;\r\n else withinLimit\r\n \"\r\n >\r\n <a\r\n *ngIf=\"col.hasLink === true\"\r\n [href]=\"row[col.property]\"\r\n target=\"_blank\"\r\n >\r\n {{ getDisplayValue(col, row) }}\r\n </a>\r\n <a\r\n *ngIf=\"col.hasLink && isString(col.hasLink)\"\r\n [href]=\"col.hasLink\"\r\n target=\"_blank\"\r\n >\r\n {{ getDisplayValue(col, row) }}\r\n </a>\r\n <span\r\n *ngIf=\"col.hasLink !== true && !isString(col.hasLink)\"\r\n >\r\n {{ getDisplayValue(col, row) }}\r\n </span>\r\n </span>\r\n </ng-container>\r\n <ng-template #withinLimit>\r\n <a\r\n *ngIf=\"col.hasLink === true\"\r\n [href]=\"row[col.property]\"\r\n target=\"_blank\"\r\n >\r\n {{ getDisplayValue(col, row, true) }}\r\n </a>\r\n <a\r\n *ngIf=\"col.hasLink && isString(col.hasLink)\"\r\n [href]=\"col.hasLink\"\r\n target=\"_blank\"\r\n >\r\n {{ getDisplayValue(col, row, true) }}\r\n </a>\r\n <span\r\n *ngIf=\"col.hasLink !== true && !isString(col.hasLink)\"\r\n >\r\n {{ getDisplayValue(col, row, true) }}\r\n </span>\r\n </ng-template>\r\n </span>\r\n <!------------------- IMAGE ------------------>\r\n <img\r\n *ngIf=\"\r\n col.image && col.image.path && !col.iconClass && !col.method\r\n \"\r\n [src]=\"col.image.path + '/' + row[col.property]\"\r\n [ngClass]=\"col.image.class\"\r\n alt=\"Imagem\"\r\n />\r\n <img\r\n *ngIf=\"\r\n col.image && col.image.url && !col.iconClass && !col.method\r\n \"\r\n [src]=\"row[col.property]\"\r\n [ngClass]=\"col.image.class\"\r\n alt=\"Imagem\"\r\n />\r\n <ng-container *ngIf=\"col.iconClass\">\r\n <button\r\n *ngFor=\"let iconClass of col.iconClass\"\r\n (click)=\"\r\n iconClass.buttonMethod\r\n ? iconClass.buttonMethod(row, $event)\r\n : $event.stopPropagation()\r\n \"\r\n >\r\n <span\r\n [ngClass]=\"iconClass.class\"\r\n *ngIf=\"\r\n iconClass.condition === undefined ||\r\n (iconClass.condition !== undefined &&\r\n $any(iconClass.condition)(row))\r\n \"\r\n >{{ iconClass.text }}</span\r\n >\r\n </button>\r\n </ng-container>\r\n </td>\r\n </ng-container>\r\n </ng-container>\r\n\r\n <tr mat-header-row *matHeaderRowDef=\"columnProperties\"></tr>\r\n <tr\r\n [ngClass]=\"{\r\n 'example-element-row': data.isNotClickable === true,\r\n 'example-element-row cursor-pointer': !data.isNotClickable\r\n }\"\r\n mat-row\r\n *matRowDef=\"let row; columns: columnProperties\"\r\n (click)=\"goToDetails(row)\"\r\n ></tr>\r\n\r\n <!-- ROW SHOWN WHEN THERE IS NO MATCHING DATA. -->\r\n <tr class=\"mat-row\" *matNoDataRow>\r\n <td *ngIf=\"!isLoading\" class=\"mat-cell p-4\" colspan=\"4\">\r\n Nenhum resultado encontrado para a busca\r\n </td>\r\n </tr>\r\n </table>\r\n\r\n <div class=\"flex justify-center\" *ngIf=\"isLoading\">\r\n <mat-spinner></mat-spinner>\r\n </div>\r\n\r\n <div class=\"paginator-container\">\r\n <mat-paginator\r\n #paginator\r\n [pageSizeOptions]=\"[25, 50, 100]\"\r\n [pageSize]=\"pageSize\"\r\n [length]=\"totalItems\"\r\n showFirstLastButtons\r\n aria-label=\"Select page of periodic elements\"\r\n (page)=\"onPageChange($event)\"\r\n [ngClass]=\"{\r\n 'hide-length':\r\n ['filter', 'filterByDate', 'equals'].includes(\r\n this.currentArrange\r\n ) || this.data.filterFn,\r\n 'hide-next-button': !hasNextPage && data.pagination === true,\r\n 'hide-last-button':\r\n (!hasNextPage && data.pagination === true) || this.data.filterFn\r\n }\"\r\n >\r\n </mat-paginator>\r\n <div\r\n *ngIf=\"\r\n !isLoading &&\r\n dataSource?.data &&\r\n dataSource.data.length > 0 &&\r\n data?.filterFn\r\n \"\r\n class=\"page-number-display\"\r\n >\r\n {{ currentPageNumber }}\r\n </div>\r\n </div>\r\n </div>\r\n </div>\r\n </div>\r\n\r\n <!-- TOOLTIP PERSONALIZADO -->\r\n <div\r\n *ngIf=\"showTooltip\"\r\n class=\"fixed z-50 max-w-md break-words rounded-lg bg-gray-800 px-3 py-2 text-sm text-white shadow-lg\"\r\n [style.left.px]=\"tooltipPosition.x\"\r\n [style.top.px]=\"tooltipPosition.y\"\r\n [style.pointer-events]=\"'none'\"\r\n >\r\n {{ tooltipContent }}\r\n </div>\r\n</div>\r\n", styles: ["::ng-deep .hide-length .mat-mdc-paginator-range-label{display:none}::ng-deep .hide-next-button .mat-mdc-tooltip-trigger.mat-mdc-paginator-navigation-next.mdc-icon-button.mat-mdc-icon-button.mat-unthemed.mat-mdc-button-base{visibility:hidden}::ng-deep .hide-next-button .mat-mdc-tooltip-trigger.mat-mdc-paginator-navigation-last.mdc-icon-button.mat-mdc-icon-button.mat-unthemed.mat-mdc-button-base.ng-star-inserted{visibility:hidden}::ng-deep .mat-mdc-text-field-wrapper.mdc-text-field.ng-tns-c162-1.mdc-text-field--filled{width:25dvw}::ng-deep .custom-filter .mat-mdc-text-field-wrapper{width:20dvw;max-width:300px}\n"], dependencies: [{ kind: "directive", type: i4.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i4.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "directive", type: i4.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i5.DefaultValueAccessor, selector: "input:not([type=checkbox])[formControlName],textarea[formControlName],input:not([type=checkbox])[formControl],textarea[formControl],input:not([type=checkbox])[ngModel],textarea[ngModel],[ngDefaultControl]" }, { kind: "directive", type: i5.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i5.NgControlStatusGroup, selector: "[formGroupName],[formArrayName],[ngModelGroup],[formGroup],form:not([ngNoForm]),[ngForm]" }, { kind: "directive", type: i5.MaxLengthValidator, selector: "[maxlength][formControlName],[maxlength][formControl],[maxlength][ngModel]", inputs: ["maxlength"] }, { kind: "directive", type: i5.FormControlDirective, selector: "[formControl]", inputs: ["formControl", "disabled", "ngModel"], outputs: ["ngModelChange"], exportAs: ["ngForm"] }, { kind: "directive", type: i5.FormGroupDirective, selector: "[formGroup]", inputs: ["formGroup"], outputs: ["ngSubmit"], exportAs: ["ngForm"] }, { kind: "directive", type: i5.FormControlName, selector: "[formControlName]", inputs: ["formControlName", "disabled", "ngModel"], outputs: ["ngModelChange"] }, { kind: "directive", type: i1$1.RouterLink, selector: "[routerLink]", inputs: ["target", "queryParams", "fragment", "queryParamsHandling", "state", "relativeTo", "preserveFragment", "skipLocationChange", "replaceUrl", "routerLink"] }, { kind: "component", type: i6.MatTable, selector: "mat-table, table[mat-table]", exportAs: ["matTable"] }, { kind: "directive", type: i6.MatHeaderCellDef, selector: "[matHeaderCellDef]" }, { kind: "directive", type: i6.MatHeaderRowDef, selector: "[matHeaderRowDef]", inputs: ["matHeaderRowDef", "matHeaderRowDefSticky"] }, { kind: "directive", type: i6.MatColumnDef, selector: "[matColumnDef]", inputs: ["sticky", "matColumnDef"] }, { kind: "directive", type: i6.MatCellDef, selector: "[matCellDef]" }, { kind: "directive", type: i6.MatRowDef, selector: "[matRowDef]", inputs: ["matRowDefColumns", "matRowDefWhen"] }, { kind: "directive", type: i6.MatHeaderCell, selector: "mat-header-cell, th[mat-header-cell]" }, { kind: "directive", type: i6.MatCell, selector: "mat-cell, td[mat-cell]" }, { kind: "component", type: i6.MatHeaderRow, selector: "mat-header-row, tr[mat-header-row]", exportAs: ["matHeaderRow"] }, { kind: "component", type: i6.MatRow, selector: "mat-row, tr[mat-row]", exportAs: ["matRow"] }, { kind: "directive", type: i6.MatNoDataRow, selector: "ng-template[matNoDataRow]" }, { kind: "component", type: i7.MatPaginator, selector: "mat-paginator", inputs: ["disabled"], exportAs: ["matPaginator"] }, { kind: "directive", type: i8.MatSort, selector: "[matSort]", inputs: ["matSortDisabled", "matSortActive", "matSortStart", "matSortDirection", "matSortDisableClear"], outputs: ["matSortChange"], exportAs: ["matSort"] }, { kind: "component", type: i8.MatSortHeader, selector: "[mat-sort-header]", inputs: ["disabled", "mat-sort-header", "arrowPosition", "start", "sortActionDescription", "disableClear"], exportAs: ["matSortHeader"] }, { kind: "component", type: i9.MatFormField, selector: "mat-form-field", inputs: ["hideRequiredMarker", "color", "floatLabel", "appearance", "subscriptSizing", "hintLabel"], exportAs: ["matFormField"] }, { kind: "directive", type: i9.MatLabel, selector: "mat-label" }, { kind: "directive", type: i9.MatSuffix, selector: "[matSuffix], [matIconSuffix], [matTextSuffix]", inputs: ["matTextSuffix"] }, { kind: "directive", type: i10.MatInput, selector: "input[matInput], textarea[matInput], select[matNativeControl], input[matNativeControl], textarea[matNativeControl]", inputs: ["disabled", "id", "placeholder", "name", "required", "type", "errorStateMatcher", "aria-describedby", "value", "readonly"], exportAs: ["matInput"] }, { kind: "component", type: i11.MatSelect, selector: "mat-select", inputs: ["disabled", "disableRipple", "tabIndex", "hideSingleSelectionIndicator"], exportAs: ["matSelect"] }, { kind: "component", type: i12.MatOption, selector: "mat-option", exportAs: ["matOption"] }, { kind: "directive", type: i13.MatTooltip, selector: "[matTooltip]", exportAs: ["matTooltip"] }, { kind: "component", type: i14.MatProgressSpinner, selector: "mat-progress-spinner, mat-spinner", inputs: ["color", "mode", "value", "diameter", "strokeWidth"], exportAs: ["matProgressSpinner"] }, { kind: "component", type: i15.MatIcon, selector: "mat-icon", inputs: ["color", "inline", "svgIcon", "fontSet", "fontIcon"], exportAs: ["matIcon"] }] });
|
|
1731
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: TableComponent, decorators: [{
|
|
1732
|
+
type: Component,
|
|
1733
|
+
args: [{ selector: 'lib-table', template: "<div *ngIf=\"data\" class=\"card-body\">\r\n <div class=\"flex flex-col justify-between gap-6\">\r\n <!-- UNIFIED CONTROL PANEL: FILTERS, SORT & ACTIONS -->\r\n <div\r\n class=\"rounded-xl border border-gray-200 bg-white p-4 shadow-lg\"\r\n *ngIf=\"\r\n data.pagination === true &&\r\n (dropdownItems.length > 0 ||\r\n sortableDropdownItems.length > 0 ||\r\n data.actionButton)\r\n \"\r\n >\r\n <!-- PANEL HEADER: Title, Custom Action, and Global Actions -->\r\n <div\r\n class=\"mb-4 flex flex-col items-start justify-between gap-4 border-b-2 border-gray-200 pb-4 md:flex-row md:items-center\"\r\n >\r\n <!-- Left Side: Title & Main Action Button -->\r\n <div class=\"flex flex-wrap items-center gap-4\">\r\n <div class=\"flex items-center gap-2\">\r\n <i class=\"fa fa-filter text-xl text-blue-500\"></i>\r\n <span class=\"text-lg font-semibold text-gray-700\"\r\n >Filtros e A\u00E7\u00F5es</span\r\n >\r\n </div>\r\n <button\r\n *ngIf=\"data.actionButton && data.actionButton.condition\"\r\n [ngClass]=\"\r\n (data.actionButton.colorClass || 'bg-blue-500') +\r\n ' flex items-center gap-2 rounded-lg px-4 py-2 text-sm font-medium text-white hover:opacity-70'\r\n \"\r\n [routerLink]=\"data.actionButton.routerLink\"\r\n (click)=\"\r\n data.actionButton.method ? data.actionButton.method($event) : null\r\n \"\r\n >\r\n <i\r\n *ngIf=\"data.actionButton.icon\"\r\n [class]=\"data.actionButton.icon\"\r\n ></i>\r\n {{ data.actionButton.label }}\r\n </button>\r\n </div>\r\n\r\n <!-- Right Side: Search, Reset, Export -->\r\n <div\r\n class=\"flex flex-wrap gap-3\"\r\n *ngIf=\"\r\n this.hasFilterableColumn === true || this.hasSortableColumn === true\r\n \"\r\n >\r\n <button\r\n (click)=\"search()\"\r\n type=\"button\"\r\n class=\"flex items-center gap-2 rounded-lg bg-green-600 px-5 py-2 text-sm font-medium text-white transition-colors hover:bg-green-700\"\r\n matTooltip=\"Aplicar filtros\"\r\n >\r\n <i class=\"fa fa-search\"></i>\r\n Pesquisar\r\n </button>\r\n\r\n <button\r\n (click)=\"resetFilter()\"\r\n class=\"flex items-center gap-2 rounded-lg bg-red-500 px-5 py-2 text-sm font-medium text-white transition-colors hover:bg-red-600\"\r\n matTooltip=\"Limpar filtros\"\r\n >\r\n <i class=\"fas fa-redo-alt\"></i>\r\n Resetar\r\n </button>\r\n\r\n <button\r\n *ngIf=\"data.download !== false && downloadTable\"\r\n class=\"flex items-center gap-2 rounded-lg bg-orange-500 px-5 py-2 text-sm font-medium text-white transition-colors hover:bg-orange-600\"\r\n matTooltipPosition=\"above\"\r\n matTooltip=\"Exportar Tabela\"\r\n [disabled]=\"\r\n this.dataSource && this.dataSource.filteredData.length <= 0\r\n \"\r\n (click)=\"\r\n $any(arrange) && downloadTable !== undefined\r\n ? downloadTable($any(arrange), data.conditions || [])\r\n : null\r\n \"\r\n >\r\n <i class=\"fa fa-download\"></i>\r\n Exportar\r\n </button>\r\n </div>\r\n </div>\r\n\r\n <!-- FILTERS CONTENT (WITH REFINEMENTS) -->\r\n <div class=\"mb-4 space-y-3\" *ngIf=\"filtersForm.controls.length > 0\">\r\n <div\r\n [formGroup]=\"$any(filterGroup)\"\r\n *ngFor=\"let filterGroup of filtersForm.controls; let i = index\"\r\n class=\"flex flex-wrap items-center gap-3 rounded-lg border border-gray-200 p-2\"\r\n >\r\n <!-- FILTER TYPE SELECTOR -->\r\n <div class=\"min-w-[200px] flex-1\" *ngIf=\"dropdownItems.length > 0\">\r\n <mat-form-field appearance=\"outline\" class=\"w-full\">\r\n <mat-label>Tipo de filtro</mat-label>\r\n <mat-select\r\n placeholder=\"Selecione o tipo...\"\r\n formControlName=\"selectFilter\"\r\n (selectionChange)=\"onSelectFilterChange()\"\r\n >\r\n <mat-option *ngFor=\"let item of dropdownItems\" [value]=\"item\">\r\n <div class=\"flex items-center gap-2\">\r\n <i\r\n [class]=\"item.icon || 'fa fa-filter'\"\r\n class=\"text-sm text-blue-500\"\r\n ></i>\r\n <span>{{ item.title }}</span>\r\n </div>\r\n </mat-option>\r\n </mat-select>\r\n </mat-form-field>\r\n </div>\r\n\r\n <!-- TEXT FILTER -->\r\n <div\r\n class=\"min-w-[200px] flex-1\"\r\n *ngIf=\"\r\n $any(filterGroup).get('selectFilter')?.value?.arrange === 'filter'\r\n \"\r\n >\r\n <mat-form-field appearance=\"outline\" class=\"w-full\">\r\n <mat-label class=\"flex items-center gap-2\">\r\n <i class=\"fa fa-search text-gray-400\"></i>\r\n <span>{{\r\n $any(filterGroup).get(\"selectFilter\")?.value?.title ||\r\n \"Filtrar\"\r\n }}</span>\r\n </mat-label>\r\n <input\r\n (keyup.enter)=\"search()\"\r\n formControlName=\"typeFilter\"\r\n matInput\r\n placeholder=\"Digite para filtrar...\"\r\n #input\r\n />\r\n </mat-form-field>\r\n </div>\r\n\r\n <!-- DROPDOWN FILTER -->\r\n <div\r\n class=\"min-w-[200px] flex-1\"\r\n *ngIf=\"\r\n $any(filterGroup).get('selectFilter')?.value &&\r\n $any(filterGroup)\r\n .get('selectFilter')\r\n ?.value.hasOwnProperty('items')\r\n \"\r\n >\r\n <mat-form-field appearance=\"outline\" class=\"w-full\">\r\n <mat-label>{{\r\n $any(filterGroup).get(\"selectFilter\")?.value?.title ||\r\n \"Selecione\"\r\n }}</mat-label>\r\n <mat-select\r\n placeholder=\"Selecione...\"\r\n formControlName=\"selectItem\"\r\n multiple\r\n >\r\n <mat-option\r\n *ngFor=\"\r\n let item of $any(filterGroup).get('selectFilter')?.value\r\n .items\r\n \"\r\n [value]=\"item\"\r\n >\r\n {{ item.label }}\r\n </mat-option>\r\n </mat-select>\r\n </mat-form-field>\r\n </div>\r\n\r\n <!-- DATE FILTER -->\r\n <div\r\n class=\"min-w-[340px] flex-auto\"\r\n *ngIf=\"\r\n $any(filterGroup).get('selectFilter')?.value?.arrange ===\r\n 'filterByDate'\r\n \"\r\n >\r\n <div\r\n class=\"flex flex-col items-stretch gap-3 sm:flex-row sm:items-center\"\r\n >\r\n <mat-form-field appearance=\"outline\" class=\"flex-1\">\r\n <mat-label class=\"flex items-center gap-2\">\r\n <i class=\"fa fa-calendar text-gray-400\"></i>\r\n <span>Data Inicial</span>\r\n </mat-label>\r\n <input\r\n matInput\r\n (keyup.enter)=\"search()\"\r\n formControlName=\"initialDate\"\r\n placeholder=\"DD/MM/AAAA\"\r\n maxlength=\"10\"\r\n />\r\n </mat-form-field>\r\n\r\n <mat-form-field appearance=\"outline\" class=\"flex-1\">\r\n <mat-label class=\"flex items-center gap-2\">\r\n <i class=\"fa fa-calendar text-gray-400\"></i>\r\n <span>Data Final</span>\r\n </mat-label>\r\n <input\r\n (keyup.enter)=\"search()\"\r\n matInput\r\n formControlName=\"finalDate\"\r\n placeholder=\"DD/MM/AAAA\"\r\n maxlength=\"10\"\r\n />\r\n </mat-form-field>\r\n </div>\r\n </div>\r\n\r\n <!-- REMOVE FILTER BUTTON -->\r\n <div *ngIf=\"filtersForm.length > 1\" class=\"ml-auto flex-shrink-0\">\r\n <button\r\n (click)=\"removeFilter(i)\"\r\n class=\"flex h-10 w-10 items-center justify-center rounded-full transition-colors duration-300 hover:bg-red-100\"\r\n matTooltip=\"Remover filtro\"\r\n >\r\n <i class=\"fa fa-trash text-red-500 hover:text-red-600\"></i>\r\n </button>\r\n </div>\r\n </div>\r\n </div>\r\n\r\n <!-- PANEL FOOTER: Add Filter & Sort -->\r\n <div\r\n class=\"-mb-2 flex flex-col items-center justify-between gap-4 border-t border-gray-200 pt-4 sm:flex-row\"\r\n >\r\n <!-- Add Filter Button -->\r\n <div *ngIf=\"dropdownItems.length > 0\">\r\n <button\r\n (click)=\"addFilter()\"\r\n class=\"transform rounded-full border-2 border-blue-300 bg-blue-50 px-6 py-2 text-sm font-medium text-blue-600 transition-all duration-300 hover:-translate-y-0.5 hover:border-blue-400 hover:bg-blue-100 hover:shadow-md\"\r\n matTooltip=\"Adicionar novo filtro\"\r\n >\r\n <i class=\"fa fa-plus mr-2\"></i>\r\n Adicionar Filtro\r\n </button>\r\n </div>\r\n\r\n <!-- Sort Dropdown -->\r\n <div\r\n class=\"w-full sm:w-auto sm:min-w-[250px]\"\r\n *ngIf=\"sortableDropdownItems.length > 0\"\r\n >\r\n <mat-form-field appearance=\"outline\" class=\"w-full\">\r\n <mat-label>Ordenar por</mat-label>\r\n <mat-select placeholder=\"Selecione...\" [formControl]=\"selectSort\">\r\n <mat-option\r\n *ngFor=\"let item of sortableDropdownItems\"\r\n [value]=\"item\"\r\n >\r\n <div class=\"flex items-center gap-2\">\r\n <i class=\"fa fa-sort-alpha-down text-cyan-600\"></i>\r\n <span>{{ item.title }}</span>\r\n </div>\r\n </mat-option>\r\n </mat-select>\r\n </mat-form-field>\r\n </div>\r\n </div>\r\n </div>\r\n\r\n <!-- SIMPLE SEARCH (for non-paginated tables) -->\r\n <div\r\n class=\"rounded-xl border border-gray-200 bg-white p-4 shadow-lg\"\r\n *ngIf=\"data.pagination === false\"\r\n >\r\n <mat-form-field appearance=\"outline\" class=\"w-full\">\r\n <mat-label class=\"flex items-center gap-2\">\r\n <i class=\"fa fa-search text-blue-500\"></i>\r\n Buscar\r\n </mat-label>\r\n <input\r\n matInput\r\n (keyup.enter)=\"search()\"\r\n (keyup)=\"applyFilter(filterInput.value)\"\r\n placeholder=\"Digite para filtrar...\"\r\n #filterInput\r\n />\r\n <mat-icon matSuffix class=\"text-gray-500\">search</mat-icon>\r\n </mat-form-field>\r\n <button\r\n *ngIf=\"data.actionButton\"\r\n [ngClass]=\"\r\n (data.actionButton.colorClass || 'bg-blue-500') +\r\n ' float-right flex items-center gap-2 rounded-lg px-4 py-2 text-sm font-medium text-white hover:opacity-70'\r\n \"\r\n [routerLink]=\"data.actionButton.routerLink\"\r\n (click)=\"\r\n data.actionButton.method ? data.actionButton.method($event) : null\r\n \"\r\n >\r\n <i *ngIf=\"data.actionButton.icon\" [class]=\"data.actionButton.icon\"></i>\r\n {{ data.actionButton.label }}\r\n </button>\r\n </div>\r\n\r\n <div class=\"flex flex-col\">\r\n <div\r\n class=\"mx-auto flex flex-col\"\r\n *ngIf=\"data.tabs && data.tabs.tabsData && data.tabs.tabsData.length > 0\"\r\n >\r\n <!-- Calcular quantos grupos de 6 tabs existem -->\r\n <ng-container\r\n *ngFor=\"\r\n let groupIndex of getTabGroups(data.tabs.tabsData);\r\n let i = index\r\n \"\r\n >\r\n <div class=\"mx-auto flex flex-row\">\r\n <ng-container\r\n *ngFor=\"\r\n let tab of getTabGroup(data.tabs.tabsData, groupIndex);\r\n let j = index\r\n \"\r\n >\r\n <button\r\n class=\"border-2 border-gray-300 bg-gray-200 px-4 py-2 font-medium transition hover:brightness-95\"\r\n [ngClass]=\"\r\n isTabSelected(getRealTabIndex(i, j))\r\n ? 'border-b-0 brightness-110'\r\n : ''\r\n \"\r\n (click)=\"onTableSelected(i, j)\"\r\n >\r\n {{ tab.label }}\r\n <span\r\n *ngIf=\"tab.counter !== undefined\"\r\n class=\"ml-2 text-xs font-bold\"\r\n [ngClass]=\"tab.counterClass\"\r\n >\r\n {{ tab.counter }}\r\n </span>\r\n </button>\r\n </ng-container>\r\n </div>\r\n </ng-container>\r\n </div>\r\n <div class=\"mat-elevation-z8 w-full overflow-x-auto rounded-xl\">\r\n <table\r\n mat-table\r\n [dataSource]=\"dataSource\"\r\n matSort\r\n #sort=\"matSort\"\r\n matSortActive=\"createdAt\"\r\n matSortDirection=\"desc\"\r\n >\r\n <ng-container\r\n *ngFor=\"let col of data.displayedColumns\"\r\n matColumnDef=\"{{ col.property }}\"\r\n >\r\n <ng-container *matHeaderCellDef>\r\n <!-- IF THE COLUMN IS NOT SORTABLE, THEN DON'T SHOW THE SORT BUTTONS -->\r\n <th\r\n *ngIf=\"!col.isSortable || data.pagination === true\"\r\n mat-header-cell\r\n [ngClass]=\"\r\n (data?.color?.bg ? ' ' + $any(data.color).bg : '') +\r\n (data?.color?.text ? ' ' + $any(data.color).text : '')\r\n \"\r\n >\r\n {{ col.title }}\r\n </th>\r\n <!-- IF THE COLUMN IS SORTABLE, THEN SHOW THE SORT BUTTONS -->\r\n <th\r\n *ngIf=\"col.isSortable && data.pagination === false\"\r\n mat-header-cell\r\n mat-sort-header\r\n [ngClass]=\"\r\n (data?.color?.bg ? ' ' + $any(data.color).bg : '') +\r\n (data?.color?.text ? ' ' + $any(data.color).text : '')\r\n \"\r\n >\r\n {{ col.title }}\r\n </th>\r\n <td\r\n mat-cell\r\n *matCellDef=\"let row\"\r\n (click)=\"col.method ? col.method(row) : null\"\r\n (mouseenter)=\"onCellMouseEnter($event, row, col)\"\r\n (mouseleave)=\"onCellMouseLeave()\"\r\n (mousemove)=\"onCellMouseMove($event)\"\r\n >\r\n <!-- CHECK IF THE COLUMN MUST BE DISPLAYED -->\r\n <span *ngIf=\"!col.image && !col.iconClass && !col.method\">\r\n <ng-container>\r\n <span\r\n *ngIf=\"\r\n col.charLimit &&\r\n row[col.property] &&\r\n row[col.property].length > col.charLimit;\r\n else withinLimit\r\n \"\r\n >\r\n <a\r\n *ngIf=\"col.hasLink === true\"\r\n [href]=\"row[col.property]\"\r\n target=\"_blank\"\r\n >\r\n {{ getDisplayValue(col, row) }}\r\n </a>\r\n <a\r\n *ngIf=\"col.hasLink && isString(col.hasLink)\"\r\n [href]=\"col.hasLink\"\r\n target=\"_blank\"\r\n >\r\n {{ getDisplayValue(col, row) }}\r\n </a>\r\n <span\r\n *ngIf=\"col.hasLink !== true && !isString(col.hasLink)\"\r\n >\r\n {{ getDisplayValue(col, row) }}\r\n </span>\r\n </span>\r\n </ng-container>\r\n <ng-template #withinLimit>\r\n <a\r\n *ngIf=\"col.hasLink === true\"\r\n [href]=\"row[col.property]\"\r\n target=\"_blank\"\r\n >\r\n {{ getDisplayValue(col, row, true) }}\r\n </a>\r\n <a\r\n *ngIf=\"col.hasLink && isString(col.hasLink)\"\r\n [href]=\"col.hasLink\"\r\n target=\"_blank\"\r\n >\r\n {{ getDisplayValue(col, row, true) }}\r\n </a>\r\n <span\r\n *ngIf=\"col.hasLink !== true && !isString(col.hasLink)\"\r\n >\r\n {{ getDisplayValue(col, row, true) }}\r\n </span>\r\n </ng-template>\r\n </span>\r\n <!------------------- IMAGE ------------------>\r\n <img\r\n *ngIf=\"\r\n col.image && col.image.path && !col.iconClass && !col.method\r\n \"\r\n [src]=\"col.image.path + '/' + row[col.property]\"\r\n [ngClass]=\"col.image.class\"\r\n alt=\"Imagem\"\r\n />\r\n <img\r\n *ngIf=\"\r\n col.image && col.image.url && !col.iconClass && !col.method\r\n \"\r\n [src]=\"row[col.property]\"\r\n [ngClass]=\"col.image.class\"\r\n alt=\"Imagem\"\r\n />\r\n <ng-container *ngIf=\"col.iconClass\">\r\n <button\r\n *ngFor=\"let iconClass of col.iconClass\"\r\n (click)=\"\r\n iconClass.buttonMethod\r\n ? iconClass.buttonMethod(row, $event)\r\n : $event.stopPropagation()\r\n \"\r\n >\r\n <span\r\n [ngClass]=\"iconClass.class\"\r\n *ngIf=\"\r\n iconClass.condition === undefined ||\r\n (iconClass.condition !== undefined &&\r\n $any(iconClass.condition)(row))\r\n \"\r\n >{{ iconClass.text }}</span\r\n >\r\n </button>\r\n </ng-container>\r\n </td>\r\n </ng-container>\r\n </ng-container>\r\n\r\n <tr mat-header-row *matHeaderRowDef=\"columnProperties\"></tr>\r\n <tr\r\n [ngClass]=\"{\r\n 'example-element-row': data.isNotClickable === true,\r\n 'example-element-row cursor-pointer': !data.isNotClickable\r\n }\"\r\n mat-row\r\n *matRowDef=\"let row; columns: columnProperties\"\r\n (click)=\"goToDetails(row)\"\r\n ></tr>\r\n\r\n <!-- ROW SHOWN WHEN THERE IS NO MATCHING DATA. -->\r\n <tr class=\"mat-row\" *matNoDataRow>\r\n <td *ngIf=\"!isLoading\" class=\"mat-cell p-4\" colspan=\"4\">\r\n Nenhum resultado encontrado para a busca\r\n </td>\r\n </tr>\r\n </table>\r\n\r\n <div class=\"flex justify-center\" *ngIf=\"isLoading\">\r\n <mat-spinner></mat-spinner>\r\n </div>\r\n\r\n <div class=\"paginator-container\">\r\n <mat-paginator\r\n #paginator\r\n [pageSizeOptions]=\"[25, 50, 100]\"\r\n [pageSize]=\"pageSize\"\r\n [length]=\"totalItems\"\r\n showFirstLastButtons\r\n aria-label=\"Select page of periodic elements\"\r\n (page)=\"onPageChange($event)\"\r\n [ngClass]=\"{\r\n 'hide-length':\r\n ['filter', 'filterByDate', 'equals'].includes(\r\n this.currentArrange\r\n ) || this.data.filterFn,\r\n 'hide-next-button': !hasNextPage && data.pagination === true,\r\n 'hide-last-button':\r\n (!hasNextPage && data.pagination === true) || this.data.filterFn\r\n }\"\r\n >\r\n </mat-paginator>\r\n <div\r\n *ngIf=\"\r\n !isLoading &&\r\n dataSource?.data &&\r\n dataSource.data.length > 0 &&\r\n data?.filterFn\r\n \"\r\n class=\"page-number-display\"\r\n >\r\n {{ currentPageNumber }}\r\n </div>\r\n </div>\r\n </div>\r\n </div>\r\n </div>\r\n\r\n <!-- TOOLTIP PERSONALIZADO -->\r\n <div\r\n *ngIf=\"showTooltip\"\r\n class=\"fixed z-50 max-w-md break-words rounded-lg bg-gray-800 px-3 py-2 text-sm text-white shadow-lg\"\r\n [style.left.px]=\"tooltipPosition.x\"\r\n [style.top.px]=\"tooltipPosition.y\"\r\n [style.pointer-events]=\"'none'\"\r\n >\r\n {{ tooltipContent }}\r\n </div>\r\n</div>\r\n", styles: ["::ng-deep .hide-length .mat-mdc-paginator-range-label{display:none}::ng-deep .hide-next-button .mat-mdc-tooltip-trigger.mat-mdc-paginator-navigation-next.mdc-icon-button.mat-mdc-icon-button.mat-unthemed.mat-mdc-button-base{visibility:hidden}::ng-deep .hide-next-button .mat-mdc-tooltip-trigger.mat-mdc-paginator-navigation-last.mdc-icon-button.mat-mdc-icon-button.mat-unthemed.mat-mdc-button-base.ng-star-inserted{visibility:hidden}::ng-deep .mat-mdc-text-field-wrapper.mdc-text-field.ng-tns-c162-1.mdc-text-field--filled{width:25dvw}::ng-deep .custom-filter .mat-mdc-text-field-wrapper{width:20dvw;max-width:300px}\n"] }]
|
|
1734
|
+
}], ctorParameters: function () { return [{ type: i1$1.Router }, { type: TableService }, { type: i1.AngularFirestore }]; }, propDecorators: { data: [{
|
|
1735
|
+
type: Input
|
|
1736
|
+
}], downloadTable: [{
|
|
1737
|
+
type: Input
|
|
1738
|
+
}], paginator: [{
|
|
1739
|
+
type: ViewChild,
|
|
1740
|
+
args: [MatPaginator]
|
|
1741
|
+
}], sort: [{
|
|
1742
|
+
type: ViewChild,
|
|
1743
|
+
args: [MatSort]
|
|
1744
|
+
}] } });
|
|
1745
|
+
|
|
1746
|
+
class FirebaseTableKxpLibModule {
|
|
1747
|
+
}
|
|
1748
|
+
FirebaseTableKxpLibModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: FirebaseTableKxpLibModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
|
1749
|
+
FirebaseTableKxpLibModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.2.10", ngImport: i0, type: FirebaseTableKxpLibModule, declarations: [FirebaseTableKxpLibComponent, TableComponent], imports: [CommonModule,
|
|
1750
|
+
ReactiveFormsModule,
|
|
1751
|
+
FormsModule,
|
|
1752
|
+
RouterModule,
|
|
1753
|
+
MatTableModule,
|
|
1754
|
+
MatPaginatorModule,
|
|
1755
|
+
MatSortModule,
|
|
1756
|
+
MatFormFieldModule,
|
|
1757
|
+
MatInputModule,
|
|
1758
|
+
MatSelectModule,
|
|
1759
|
+
MatTooltipModule,
|
|
1760
|
+
MatProgressSpinnerModule,
|
|
1761
|
+
MatIconModule,
|
|
1762
|
+
MatDialogModule], exports: [FirebaseTableKxpLibComponent, TableComponent] });
|
|
1763
|
+
FirebaseTableKxpLibModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: FirebaseTableKxpLibModule, imports: [CommonModule,
|
|
1764
|
+
ReactiveFormsModule,
|
|
1765
|
+
FormsModule,
|
|
1766
|
+
RouterModule,
|
|
1767
|
+
MatTableModule,
|
|
1768
|
+
MatPaginatorModule,
|
|
1769
|
+
MatSortModule,
|
|
1770
|
+
MatFormFieldModule,
|
|
1771
|
+
MatInputModule,
|
|
1772
|
+
MatSelectModule,
|
|
1773
|
+
MatTooltipModule,
|
|
1774
|
+
MatProgressSpinnerModule,
|
|
1775
|
+
MatIconModule,
|
|
1776
|
+
MatDialogModule] });
|
|
1777
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: FirebaseTableKxpLibModule, decorators: [{
|
|
1778
|
+
type: NgModule,
|
|
1779
|
+
args: [{
|
|
1780
|
+
declarations: [FirebaseTableKxpLibComponent, TableComponent],
|
|
1781
|
+
imports: [
|
|
1782
|
+
CommonModule,
|
|
1783
|
+
ReactiveFormsModule,
|
|
1784
|
+
FormsModule,
|
|
1785
|
+
RouterModule,
|
|
1786
|
+
MatTableModule,
|
|
1787
|
+
MatPaginatorModule,
|
|
1788
|
+
MatSortModule,
|
|
1789
|
+
MatFormFieldModule,
|
|
1790
|
+
MatInputModule,
|
|
1791
|
+
MatSelectModule,
|
|
1792
|
+
MatTooltipModule,
|
|
1793
|
+
MatProgressSpinnerModule,
|
|
1794
|
+
MatIconModule,
|
|
1795
|
+
MatDialogModule,
|
|
1796
|
+
],
|
|
1797
|
+
exports: [FirebaseTableKxpLibComponent, TableComponent],
|
|
1798
|
+
}]
|
|
1799
|
+
}] });
|
|
1800
|
+
|
|
1801
|
+
class FirebaseTableKxpLibService {
|
|
1802
|
+
constructor() { }
|
|
1803
|
+
}
|
|
1804
|
+
FirebaseTableKxpLibService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: FirebaseTableKxpLibService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
1805
|
+
FirebaseTableKxpLibService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: FirebaseTableKxpLibService, providedIn: 'root' });
|
|
1806
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: FirebaseTableKxpLibService, decorators: [{
|
|
1807
|
+
type: Injectable,
|
|
1808
|
+
args: [{
|
|
1809
|
+
providedIn: 'root'
|
|
1810
|
+
}]
|
|
1811
|
+
}], ctorParameters: function () { return []; } });
|
|
1812
|
+
|
|
1813
|
+
/*
|
|
1814
|
+
* Public API Surface of firebase-table-kxp-lib
|
|
1815
|
+
*/
|
|
1816
|
+
// Main module
|
|
1817
|
+
|
|
1818
|
+
/**
|
|
1819
|
+
* Generated bundle index. Do not edit.
|
|
1820
|
+
*/
|
|
1821
|
+
|
|
1822
|
+
export { FirebaseTableKxpLibComponent, FirebaseTableKxpLibModule, FirebaseTableKxpLibService, TableComponent, TableService };
|
|
1823
|
+
//# sourceMappingURL=ng-firebase-table-kxp.mjs.map
|