appproject-components 1.0.47 → 1.0.49
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 +24 -24
- package/karma.conf.js +44 -44
- package/ng-package.json +6 -6
- package/package.json +1 -1
- package/src/lib/appproject-components.component.spec.ts +23 -23
- package/src/lib/appproject-components.component.ts +20 -20
- package/src/lib/appproject-components.service.spec.ts +16 -16
- package/src/lib/appproject-components.service.ts +9 -9
- package/src/lib/entity-edit/entity-edit.component.html +142 -142
- package/src/lib/entity-edit/entity-edit.component.spec.ts +23 -23
- package/src/lib/entity-edit/entity-edit.component.ts +43 -43
- package/src/lib/grid-view/grid-view.component.html +115 -115
- package/src/lib/grid-view/grid-view.component.spec.ts +23 -23
- package/src/lib/grid-view/grid-view.component.ts +292 -292
- package/src/lib/input-area/input-area.component.spec.ts +23 -23
- package/src/lib/input-area/input-area.component.ts +69 -69
- package/src/lib/input-cep/input-cep.component.spec.ts +23 -23
- package/src/lib/input-cep/input-cep.component.ts +186 -186
- package/src/lib/input-checkbox/input-checkbox.component.html +11 -11
- package/src/lib/input-checkbox/input-checkbox.component.spec.ts +23 -23
- package/src/lib/input-checkbox/input-checkbox.component.ts +48 -48
- package/src/lib/input-format/input-format.component.spec.ts +23 -23
- package/src/lib/input-pesquisa/input-pesquisa.component.spec.ts +23 -23
- package/src/lib/input-pesquisa/input-pesquisa.component.ts +2 -2
- package/src/lib/input-radio/input-radio.component.html +20 -20
- package/src/lib/input-radio/input-radio.component.spec.ts +23 -23
- package/src/lib/input-radio/input-radio.component.ts +49 -49
- package/src/lib/input-select/input-select.component.spec.ts +23 -23
- package/src/lib/input-text/input-text.component.spec.ts +23 -23
- package/src/lib/input-valor/input-valor.component.spec.ts +23 -23
- package/src/lib/model-treeview/model-treeview.component.html +19 -19
- package/src/lib/model-treeview/model-treeview.component.spec.ts +23 -23
- package/src/lib/model-treeview/model-treeview.component.ts +152 -152
- package/src/lib/tree-view/tree-view.component.html +95 -95
- package/src/lib/tree-view/tree-view.component.spec.ts +23 -23
- package/src/lib/tree-view/tree-view.component.ts +92 -92
- package/src/lib/tree-view-nivel/tree-view-nivel.component.html +17 -17
- package/src/lib/tree-view-nivel/tree-view-nivel.component.spec.ts +23 -23
- package/src/lib/tree-view-nivel/tree-view-nivel.component.ts +43 -43
- package/tsconfig.lib.json +15 -15
- package/tsconfig.lib.prod.json +10 -10
- package/tsconfig.spec.json +17 -17
|
@@ -1,292 +1,292 @@
|
|
|
1
|
-
import { Component, EventEmitter, Input, OnChanges, OnInit, Output, SimpleChanges } from '@angular/core';
|
|
2
|
-
import { GridColuna, GridTabela, LibService } from 'appproject-lib';
|
|
3
|
-
|
|
4
|
-
@Component({
|
|
5
|
-
selector: 'kb-grid-view',
|
|
6
|
-
templateUrl: './grid-view.component.html',
|
|
7
|
-
styleUrl: './grid-view.component.scss'
|
|
8
|
-
})
|
|
9
|
-
export class GridViewComponent implements OnInit, OnChanges {
|
|
10
|
-
@Input() empresaId: number;
|
|
11
|
-
@Input() tabelaCampos: GridTabela;
|
|
12
|
-
@Input() dataSet: Array<any>;
|
|
13
|
-
@Input() minHeight: string = '400px';
|
|
14
|
-
@Input() inMemoryPagination: boolean = false;
|
|
15
|
-
|
|
16
|
-
@Output() selecionarItem = new EventEmitter();
|
|
17
|
-
@Output() excluirItem = new EventEmitter();
|
|
18
|
-
@Output() selecionarChecked = new EventEmitter();
|
|
19
|
-
|
|
20
|
-
selectedItem: any;
|
|
21
|
-
//inputs = inject(new InjectionToken<any>('title inputs'));
|
|
22
|
-
grupos: any[] = [{ Coluna: '', Tabela: null, Dados: null, Nivel: 0 }];
|
|
23
|
-
|
|
24
|
-
// tabelaCampos = {
|
|
25
|
-
// Selecionar: false,
|
|
26
|
-
// Exportar: true,
|
|
27
|
-
// Colunas: [
|
|
28
|
-
// { Campo: 'Id', Titulo: 'Id', Tamanho: '10%', Ordem: true, Grupo: false, Filtrar: true, OrdemStatus: 0, Tipo: 'number', Valores: [], FiltroOperador: '=', FiltroValor: '', FiltroVisivel: false },
|
|
29
|
-
// { Campo: 'Marca', Titulo: 'Marca', Tamanho: '25%', Ordem: true, Grupo: true, Filtrar: true, OrdemStatus: 0, Tipo: 'string', Valores: [], FiltroOperador: '=', FiltroValor: '', FiltroVisivel: false },
|
|
30
|
-
// { Campo: 'Descricao', Titulo: 'Descrição', Tamanho: '25%', Ordem: true, Grupo: true, Filtrar: true, OrdemStatus: 0, Tipo: 'string', Valores: [], FiltroOperador: '=', FiltroValor: '', FiltroVisivel: false },
|
|
31
|
-
// { Campo: 'Data', Titulo: 'Data', Tamanho: '20%', Ordem: true, Grupo: true, Filtrar: true, OrdemStatus: 0, Tipo: 'date', Valores: [], FiltroOperador: '=', FiltroValor: '', FiltroVisivel: false },
|
|
32
|
-
// { Campo: 'Valor', Titulo: 'Valor', Tamanho: '20%', Ordem: true, Grupo: false, Filtrar: true, OrdemStatus: 0, Tipo: 'number', Valores: [], FiltroOperador: '=', FiltroValor: '', FiltroVisivel: false },
|
|
33
|
-
// ]
|
|
34
|
-
// }
|
|
35
|
-
|
|
36
|
-
// dataSet: Array<any> = [
|
|
37
|
-
// { Id: 1, Marca: 'Apple', Descricao: 'IPhone 14', Data: '2023-05-01', Valor: 7899.99 },
|
|
38
|
-
// { Id: 2, Marca: 'Apple', Descricao: 'MacBook Pro', Data: '2023-06-01', Valor: 17999.99 },
|
|
39
|
-
// { Id: 3, Marca: 'Samsung', Descricao: 'Galaxy S23', Data: '2023-05-01', Valor: 6899.99 },
|
|
40
|
-
// { Id: 4, Marca: 'Sony', Descricao: 'PS 5', Data: '2023-06-01', Valor: 4899.99 },
|
|
41
|
-
// { Id: 5, Marca: 'Samsung', Descricao: 'Watch 23', Data: '2023-05-01', Valor: 1899.99 },
|
|
42
|
-
// ]
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
groups = []
|
|
47
|
-
@Input() filteredDataSet = [];
|
|
48
|
-
pageDataSet = [];
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
//array com os campos filtrados para display
|
|
52
|
-
camposDisplay = [];
|
|
53
|
-
|
|
54
|
-
//filtro
|
|
55
|
-
isFiltroOpen: boolean = false;
|
|
56
|
-
selectedColuna: any;
|
|
57
|
-
todosSelecionados: boolean = false;
|
|
58
|
-
|
|
59
|
-
//pagination
|
|
60
|
-
//página atual
|
|
61
|
-
page: number = 1;
|
|
62
|
-
//registros por página
|
|
63
|
-
@Input() pageOffset: number = 20;
|
|
64
|
-
//total de registros
|
|
65
|
-
totalRec: number;
|
|
66
|
-
//total de páginas
|
|
67
|
-
totalPages: number;
|
|
68
|
-
//indexador de paginas
|
|
69
|
-
pages: number[];
|
|
70
|
-
start: number;
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
constructor() { }
|
|
74
|
-
|
|
75
|
-
valoresFiltro() {
|
|
76
|
-
this.tabelaCampos.Colunas.forEach(c => {
|
|
77
|
-
if (c.Filtrar) {
|
|
78
|
-
//projetar a coluna
|
|
79
|
-
let initial = [];
|
|
80
|
-
let valores = this.dataSet.map(d => d[c.Campo]);
|
|
81
|
-
c.Valores = valores.filter((value, index, self) => {
|
|
82
|
-
return self.indexOf(value) === index;
|
|
83
|
-
}).map(v => { return { Selecionado: false, Valor: v } });
|
|
84
|
-
// console.log(c.Campo, valores);
|
|
85
|
-
// console.log(c.Valores)
|
|
86
|
-
}
|
|
87
|
-
})
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
ngOnInit() {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
//this.inicializaGrupo();
|
|
94
|
-
//this.agrupar('Marca');
|
|
95
|
-
//console.log('inputs', this.inputs);
|
|
96
|
-
//console.log('Input empresa', this.empresaId);
|
|
97
|
-
GridTabela.init(this.tabelaCampos);
|
|
98
|
-
this.valoresFiltro();
|
|
99
|
-
this.filteredDataSet = this.dataSet;
|
|
100
|
-
console.log('Init Tabela campos', this.tabelaCampos);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
ngOnChanges(changes: SimpleChanges) {
|
|
104
|
-
console.log('On changes Tabela campos', this.tabelaCampos);
|
|
105
|
-
//evento chamado quando o dataset for atualizado
|
|
106
|
-
//inicializar vars de paginação
|
|
107
|
-
this.initPage();
|
|
108
|
-
this.todosSelecionados = false;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
initPage() {
|
|
112
|
-
this.page = 1;
|
|
113
|
-
this.totalRec = this.filteredDataSet.length;
|
|
114
|
-
this.totalPages = Math.ceil(this.totalRec / this.pageOffset);
|
|
115
|
-
|
|
116
|
-
if (this.inMemoryPagination === true) {
|
|
117
|
-
this.getRegistrosPage();
|
|
118
|
-
} else {
|
|
119
|
-
this.pageDataSet = this.filteredDataSet;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
getRegistrosPage() {
|
|
124
|
-
this.start = (this.page - 1) * this.pageOffset;
|
|
125
|
-
console.log('dataset', this.filteredDataSet);
|
|
126
|
-
console.log('start', this.start);
|
|
127
|
-
console.log('offset', this.pageOffset);
|
|
128
|
-
this.pageDataSet = this.filteredDataSet.slice(this.start, (this.start + this.pageOffset));
|
|
129
|
-
console.log('page dataset', this.pageDataSet);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
proximo() {
|
|
133
|
-
if (this.page < this.totalPages) {
|
|
134
|
-
this.page++;
|
|
135
|
-
this.getRegistrosPage();
|
|
136
|
-
this.gerarArrayPags();
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
anterior() {
|
|
141
|
-
if (this.page > 1) {
|
|
142
|
-
this.page--;
|
|
143
|
-
this.getRegistrosPage();
|
|
144
|
-
this.gerarArrayPags();
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
gerarArrayPags() {
|
|
149
|
-
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
inicializaGrupo() {
|
|
153
|
-
//inicializar o primeiro grupo 'default'
|
|
154
|
-
this.camposDisplay = this.tabelaCampos.Colunas;
|
|
155
|
-
this.grupos[0].Tabela = this.camposDisplay;
|
|
156
|
-
this.grupos[0].Dados = this.dataSet;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
agrupar(campo: string) {
|
|
160
|
-
this.groups.push(campo);
|
|
161
|
-
let level = 0;
|
|
162
|
-
for (let g in this.groups) {
|
|
163
|
-
console.log(g);
|
|
164
|
-
//filtrar os dados
|
|
165
|
-
let result = this.dataSet.reduce((group, data) => {
|
|
166
|
-
const { g } = data;
|
|
167
|
-
group[g] = group[campo] ?? [];
|
|
168
|
-
group[g].push(data);
|
|
169
|
-
return group;
|
|
170
|
-
}, {});
|
|
171
|
-
console.log(result);
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
filtrarCampos(coluna = '') {
|
|
177
|
-
if (coluna != '') {
|
|
178
|
-
|
|
179
|
-
} else {
|
|
180
|
-
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
filtrar(col: GridColuna) {
|
|
185
|
-
//console.log('filtrar', col);
|
|
186
|
-
if (col.Valores && col.Valores.find(v => v.Selecionado) != null) {
|
|
187
|
-
const valores = col.Valores.filter(v => v.Selecionado).map(v => v.Valor);
|
|
188
|
-
|
|
189
|
-
//filtrar por valores selecionados
|
|
190
|
-
this.filteredDataSet = this.dataSet.filter(d => valores.indexOf(d[col.Campo]) > -1);
|
|
191
|
-
} else if (col.FiltroOperador && col.FiltroValor) {
|
|
192
|
-
//console.log(col.FiltroOperador, col.FiltroValor)
|
|
193
|
-
try {
|
|
194
|
-
this.filteredDataSet = this.dataSet.filter(d => {
|
|
195
|
-
switch (col.FiltroOperador) {
|
|
196
|
-
case "=":
|
|
197
|
-
return d[col.Campo] == col.FiltroValor;
|
|
198
|
-
case ">=":
|
|
199
|
-
if (col.Tipo == 'number') {
|
|
200
|
-
return LibService.stringToDecimal(d[col.Campo], true) >= LibService.stringToDecimal(col.FiltroValor, true);
|
|
201
|
-
} else if (col.Tipo == 'data') {
|
|
202
|
-
return new Date(this.dataToString(d[col.Campo])) >= new Date(this.dataToString(col.FiltroValor));
|
|
203
|
-
} else
|
|
204
|
-
return d[col.Campo] >= col.FiltroValor;
|
|
205
|
-
case "<=":
|
|
206
|
-
if (col.Tipo == 'number') {
|
|
207
|
-
return LibService.stringToDecimal(d[col.Campo], true) <= LibService.stringToDecimal(col.FiltroValor, true);
|
|
208
|
-
} else
|
|
209
|
-
return d[col.Campo] <= col.FiltroValor;
|
|
210
|
-
case "tem":
|
|
211
|
-
return d[col.Campo].toString().toLowerCase().indexOf(col.FiltroValor.toLowerCase()) > -1;
|
|
212
|
-
default:
|
|
213
|
-
return true;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
});
|
|
217
|
-
} catch(ex) {
|
|
218
|
-
console.log(ex);
|
|
219
|
-
this.filteredDataSet = this.dataSet;
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
col.FiltroVisivel = false;
|
|
223
|
-
|
|
224
|
-
this.initPage();
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
getPage() {
|
|
228
|
-
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
limpar() {
|
|
232
|
-
this.filteredDataSet = this.dataSet;
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
dataToString(data: string): string {
|
|
236
|
-
if (data) {
|
|
237
|
-
return data.split('/').reverse().join('-');
|
|
238
|
-
} else {
|
|
239
|
-
return "";
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
ordenar(col: GridColuna) {
|
|
244
|
-
if (col.OrdemStatus == 0 || col.OrdemStatus == -1) {
|
|
245
|
-
if (col.Tipo == 'data') {
|
|
246
|
-
this.filteredDataSet.sort((a, b) => this.dataToString(a[col.Campo]) > this.dataToString(b[col.Campo]) ? 1 : (this.dataToString(a[col.Campo]) < this.dataToString(b[col.Campo]) ? -1 : 0));
|
|
247
|
-
} else if (col.Tipo == 'number') {
|
|
248
|
-
this.filteredDataSet.sort((a, b) => LibService.stringToDecimal(a[col.Campo]) > LibService.stringToDecimal(b[col.Campo]) ? 1 : (LibService.stringToDecimal(a[col.Campo]) < LibService.stringToDecimal(b[col.Campo]) ? -1 : 0));
|
|
249
|
-
} else
|
|
250
|
-
this.filteredDataSet.sort((a, b) => a[col.Campo] > b[col.Campo] ? 1 : (a[col.Campo] < b[col.Campo] ? -1 : 0));
|
|
251
|
-
col.OrdemStatus = 1; //asc
|
|
252
|
-
} else {
|
|
253
|
-
if (col.Tipo == 'data') {
|
|
254
|
-
this.filteredDataSet.sort((a, b) => this.dataToString(a[col.Campo]) < this.dataToString(b[col.Campo]) ? 1 : (this.dataToString(a[col.Campo]) > this.dataToString(b[col.Campo]) ? -1 : 0));
|
|
255
|
-
} else if (col.Tipo == 'number') {
|
|
256
|
-
this.filteredDataSet.sort((a, b) => LibService.stringToDecimal(a[col.Campo], true) < LibService.stringToDecimal(b[col.Campo], true) ? 1 : (LibService.stringToDecimal(a[col.Campo], true) > LibService.stringToDecimal(b[col.Campo], true) ? -1 : 0));
|
|
257
|
-
} else
|
|
258
|
-
this.filteredDataSet.sort((a, b) => a[col.Campo] < b[col.Campo] ? 1 : (a[col.Campo] > b[col.Campo] ? -1 : 0));
|
|
259
|
-
col.OrdemStatus = -1; //desc
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
setFiltroOpen(col: any) {
|
|
264
|
-
col.FiltroVisivel = !col.FiltroVisivel
|
|
265
|
-
if (col.FiltroVisivel) {
|
|
266
|
-
this.selectedColuna = col;
|
|
267
|
-
//console.log(this.selectedColuna);
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
selecionarTodos() {
|
|
272
|
-
//this.todosSelecionados = !this.todosSelecionados;
|
|
273
|
-
this.filteredDataSet.forEach(item => {
|
|
274
|
-
item[this.tabelaCampos.CampoSelecionar] = this.todosSelecionados;
|
|
275
|
-
});
|
|
276
|
-
this.selecionarChecked.emit();
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
selecionarLinha(item: any) {
|
|
280
|
-
this.selecionarItem.emit(item);
|
|
281
|
-
this.selectedItem = item;
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
excluirLinha(item: any) {
|
|
285
|
-
this.excluirItem.emit(item);
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
//check
|
|
289
|
-
selecionadoChecked() {
|
|
290
|
-
this.selecionarChecked.emit();
|
|
291
|
-
}
|
|
292
|
-
}
|
|
1
|
+
import { Component, EventEmitter, Input, OnChanges, OnInit, Output, SimpleChanges } from '@angular/core';
|
|
2
|
+
import { GridColuna, GridTabela, LibService } from 'appproject-lib';
|
|
3
|
+
|
|
4
|
+
@Component({
|
|
5
|
+
selector: 'kb-grid-view',
|
|
6
|
+
templateUrl: './grid-view.component.html',
|
|
7
|
+
styleUrl: './grid-view.component.scss'
|
|
8
|
+
})
|
|
9
|
+
export class GridViewComponent implements OnInit, OnChanges {
|
|
10
|
+
@Input() empresaId: number;
|
|
11
|
+
@Input() tabelaCampos: GridTabela;
|
|
12
|
+
@Input() dataSet: Array<any>;
|
|
13
|
+
@Input() minHeight: string = '400px';
|
|
14
|
+
@Input() inMemoryPagination: boolean = false;
|
|
15
|
+
|
|
16
|
+
@Output() selecionarItem = new EventEmitter();
|
|
17
|
+
@Output() excluirItem = new EventEmitter();
|
|
18
|
+
@Output() selecionarChecked = new EventEmitter();
|
|
19
|
+
|
|
20
|
+
selectedItem: any;
|
|
21
|
+
//inputs = inject(new InjectionToken<any>('title inputs'));
|
|
22
|
+
grupos: any[] = [{ Coluna: '', Tabela: null, Dados: null, Nivel: 0 }];
|
|
23
|
+
|
|
24
|
+
// tabelaCampos = {
|
|
25
|
+
// Selecionar: false,
|
|
26
|
+
// Exportar: true,
|
|
27
|
+
// Colunas: [
|
|
28
|
+
// { Campo: 'Id', Titulo: 'Id', Tamanho: '10%', Ordem: true, Grupo: false, Filtrar: true, OrdemStatus: 0, Tipo: 'number', Valores: [], FiltroOperador: '=', FiltroValor: '', FiltroVisivel: false },
|
|
29
|
+
// { Campo: 'Marca', Titulo: 'Marca', Tamanho: '25%', Ordem: true, Grupo: true, Filtrar: true, OrdemStatus: 0, Tipo: 'string', Valores: [], FiltroOperador: '=', FiltroValor: '', FiltroVisivel: false },
|
|
30
|
+
// { Campo: 'Descricao', Titulo: 'Descrição', Tamanho: '25%', Ordem: true, Grupo: true, Filtrar: true, OrdemStatus: 0, Tipo: 'string', Valores: [], FiltroOperador: '=', FiltroValor: '', FiltroVisivel: false },
|
|
31
|
+
// { Campo: 'Data', Titulo: 'Data', Tamanho: '20%', Ordem: true, Grupo: true, Filtrar: true, OrdemStatus: 0, Tipo: 'date', Valores: [], FiltroOperador: '=', FiltroValor: '', FiltroVisivel: false },
|
|
32
|
+
// { Campo: 'Valor', Titulo: 'Valor', Tamanho: '20%', Ordem: true, Grupo: false, Filtrar: true, OrdemStatus: 0, Tipo: 'number', Valores: [], FiltroOperador: '=', FiltroValor: '', FiltroVisivel: false },
|
|
33
|
+
// ]
|
|
34
|
+
// }
|
|
35
|
+
|
|
36
|
+
// dataSet: Array<any> = [
|
|
37
|
+
// { Id: 1, Marca: 'Apple', Descricao: 'IPhone 14', Data: '2023-05-01', Valor: 7899.99 },
|
|
38
|
+
// { Id: 2, Marca: 'Apple', Descricao: 'MacBook Pro', Data: '2023-06-01', Valor: 17999.99 },
|
|
39
|
+
// { Id: 3, Marca: 'Samsung', Descricao: 'Galaxy S23', Data: '2023-05-01', Valor: 6899.99 },
|
|
40
|
+
// { Id: 4, Marca: 'Sony', Descricao: 'PS 5', Data: '2023-06-01', Valor: 4899.99 },
|
|
41
|
+
// { Id: 5, Marca: 'Samsung', Descricao: 'Watch 23', Data: '2023-05-01', Valor: 1899.99 },
|
|
42
|
+
// ]
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
groups = []
|
|
47
|
+
@Input() filteredDataSet = [];
|
|
48
|
+
pageDataSet = [];
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
//array com os campos filtrados para display
|
|
52
|
+
camposDisplay = [];
|
|
53
|
+
|
|
54
|
+
//filtro
|
|
55
|
+
isFiltroOpen: boolean = false;
|
|
56
|
+
selectedColuna: any;
|
|
57
|
+
todosSelecionados: boolean = false;
|
|
58
|
+
|
|
59
|
+
//pagination
|
|
60
|
+
//página atual
|
|
61
|
+
page: number = 1;
|
|
62
|
+
//registros por página
|
|
63
|
+
@Input() pageOffset: number = 20;
|
|
64
|
+
//total de registros
|
|
65
|
+
totalRec: number;
|
|
66
|
+
//total de páginas
|
|
67
|
+
totalPages: number;
|
|
68
|
+
//indexador de paginas
|
|
69
|
+
pages: number[];
|
|
70
|
+
start: number;
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
constructor() { }
|
|
74
|
+
|
|
75
|
+
valoresFiltro() {
|
|
76
|
+
this.tabelaCampos.Colunas.forEach(c => {
|
|
77
|
+
if (c.Filtrar) {
|
|
78
|
+
//projetar a coluna
|
|
79
|
+
let initial = [];
|
|
80
|
+
let valores = this.dataSet.map(d => d[c.Campo]);
|
|
81
|
+
c.Valores = valores.filter((value, index, self) => {
|
|
82
|
+
return self.indexOf(value) === index;
|
|
83
|
+
}).map(v => { return { Selecionado: false, Valor: v } });
|
|
84
|
+
// console.log(c.Campo, valores);
|
|
85
|
+
// console.log(c.Valores)
|
|
86
|
+
}
|
|
87
|
+
})
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
ngOnInit() {
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
//this.inicializaGrupo();
|
|
94
|
+
//this.agrupar('Marca');
|
|
95
|
+
//console.log('inputs', this.inputs);
|
|
96
|
+
//console.log('Input empresa', this.empresaId);
|
|
97
|
+
GridTabela.init(this.tabelaCampos);
|
|
98
|
+
this.valoresFiltro();
|
|
99
|
+
this.filteredDataSet = this.dataSet;
|
|
100
|
+
console.log('Init Tabela campos', this.tabelaCampos);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
ngOnChanges(changes: SimpleChanges) {
|
|
104
|
+
console.log('On changes Tabela campos', this.tabelaCampos);
|
|
105
|
+
//evento chamado quando o dataset for atualizado
|
|
106
|
+
//inicializar vars de paginação
|
|
107
|
+
this.initPage();
|
|
108
|
+
this.todosSelecionados = false;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
initPage() {
|
|
112
|
+
this.page = 1;
|
|
113
|
+
this.totalRec = this.filteredDataSet.length;
|
|
114
|
+
this.totalPages = Math.ceil(this.totalRec / this.pageOffset);
|
|
115
|
+
|
|
116
|
+
if (this.inMemoryPagination === true) {
|
|
117
|
+
this.getRegistrosPage();
|
|
118
|
+
} else {
|
|
119
|
+
this.pageDataSet = this.filteredDataSet;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
getRegistrosPage() {
|
|
124
|
+
this.start = (this.page - 1) * this.pageOffset;
|
|
125
|
+
console.log('dataset', this.filteredDataSet);
|
|
126
|
+
console.log('start', this.start);
|
|
127
|
+
console.log('offset', this.pageOffset);
|
|
128
|
+
this.pageDataSet = this.filteredDataSet.slice(this.start, (this.start + this.pageOffset));
|
|
129
|
+
console.log('page dataset', this.pageDataSet);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
proximo() {
|
|
133
|
+
if (this.page < this.totalPages) {
|
|
134
|
+
this.page++;
|
|
135
|
+
this.getRegistrosPage();
|
|
136
|
+
this.gerarArrayPags();
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
anterior() {
|
|
141
|
+
if (this.page > 1) {
|
|
142
|
+
this.page--;
|
|
143
|
+
this.getRegistrosPage();
|
|
144
|
+
this.gerarArrayPags();
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
gerarArrayPags() {
|
|
149
|
+
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
inicializaGrupo() {
|
|
153
|
+
//inicializar o primeiro grupo 'default'
|
|
154
|
+
this.camposDisplay = this.tabelaCampos.Colunas;
|
|
155
|
+
this.grupos[0].Tabela = this.camposDisplay;
|
|
156
|
+
this.grupos[0].Dados = this.dataSet;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
agrupar(campo: string) {
|
|
160
|
+
this.groups.push(campo);
|
|
161
|
+
let level = 0;
|
|
162
|
+
for (let g in this.groups) {
|
|
163
|
+
console.log(g);
|
|
164
|
+
//filtrar os dados
|
|
165
|
+
let result = this.dataSet.reduce((group, data) => {
|
|
166
|
+
const { g } = data;
|
|
167
|
+
group[g] = group[campo] ?? [];
|
|
168
|
+
group[g].push(data);
|
|
169
|
+
return group;
|
|
170
|
+
}, {});
|
|
171
|
+
console.log(result);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
filtrarCampos(coluna = '') {
|
|
177
|
+
if (coluna != '') {
|
|
178
|
+
|
|
179
|
+
} else {
|
|
180
|
+
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
filtrar(col: GridColuna) {
|
|
185
|
+
//console.log('filtrar', col);
|
|
186
|
+
if (col.Valores && col.Valores.find(v => v.Selecionado) != null) {
|
|
187
|
+
const valores = col.Valores.filter(v => v.Selecionado).map(v => v.Valor);
|
|
188
|
+
|
|
189
|
+
//filtrar por valores selecionados
|
|
190
|
+
this.filteredDataSet = this.dataSet.filter(d => valores.indexOf(d[col.Campo]) > -1);
|
|
191
|
+
} else if (col.FiltroOperador && col.FiltroValor) {
|
|
192
|
+
//console.log(col.FiltroOperador, col.FiltroValor)
|
|
193
|
+
try {
|
|
194
|
+
this.filteredDataSet = this.dataSet.filter(d => {
|
|
195
|
+
switch (col.FiltroOperador) {
|
|
196
|
+
case "=":
|
|
197
|
+
return d[col.Campo] == col.FiltroValor;
|
|
198
|
+
case ">=":
|
|
199
|
+
if (col.Tipo == 'number') {
|
|
200
|
+
return LibService.stringToDecimal(d[col.Campo], true) >= LibService.stringToDecimal(col.FiltroValor, true);
|
|
201
|
+
} else if (col.Tipo == 'data') {
|
|
202
|
+
return new Date(this.dataToString(d[col.Campo])) >= new Date(this.dataToString(col.FiltroValor));
|
|
203
|
+
} else
|
|
204
|
+
return d[col.Campo] >= col.FiltroValor;
|
|
205
|
+
case "<=":
|
|
206
|
+
if (col.Tipo == 'number') {
|
|
207
|
+
return LibService.stringToDecimal(d[col.Campo], true) <= LibService.stringToDecimal(col.FiltroValor, true);
|
|
208
|
+
} else
|
|
209
|
+
return d[col.Campo] <= col.FiltroValor;
|
|
210
|
+
case "tem":
|
|
211
|
+
return d[col.Campo].toString().toLowerCase().indexOf(col.FiltroValor.toLowerCase()) > -1;
|
|
212
|
+
default:
|
|
213
|
+
return true;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
});
|
|
217
|
+
} catch(ex) {
|
|
218
|
+
console.log(ex);
|
|
219
|
+
this.filteredDataSet = this.dataSet;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
col.FiltroVisivel = false;
|
|
223
|
+
|
|
224
|
+
this.initPage();
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
getPage() {
|
|
228
|
+
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
limpar() {
|
|
232
|
+
this.filteredDataSet = this.dataSet;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
dataToString(data: string): string {
|
|
236
|
+
if (data) {
|
|
237
|
+
return data.split('/').reverse().join('-');
|
|
238
|
+
} else {
|
|
239
|
+
return "";
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
ordenar(col: GridColuna) {
|
|
244
|
+
if (col.OrdemStatus == 0 || col.OrdemStatus == -1) {
|
|
245
|
+
if (col.Tipo == 'data') {
|
|
246
|
+
this.filteredDataSet.sort((a, b) => this.dataToString(a[col.Campo]) > this.dataToString(b[col.Campo]) ? 1 : (this.dataToString(a[col.Campo]) < this.dataToString(b[col.Campo]) ? -1 : 0));
|
|
247
|
+
} else if (col.Tipo == 'number') {
|
|
248
|
+
this.filteredDataSet.sort((a, b) => LibService.stringToDecimal(a[col.Campo]) > LibService.stringToDecimal(b[col.Campo]) ? 1 : (LibService.stringToDecimal(a[col.Campo]) < LibService.stringToDecimal(b[col.Campo]) ? -1 : 0));
|
|
249
|
+
} else
|
|
250
|
+
this.filteredDataSet.sort((a, b) => a[col.Campo] > b[col.Campo] ? 1 : (a[col.Campo] < b[col.Campo] ? -1 : 0));
|
|
251
|
+
col.OrdemStatus = 1; //asc
|
|
252
|
+
} else {
|
|
253
|
+
if (col.Tipo == 'data') {
|
|
254
|
+
this.filteredDataSet.sort((a, b) => this.dataToString(a[col.Campo]) < this.dataToString(b[col.Campo]) ? 1 : (this.dataToString(a[col.Campo]) > this.dataToString(b[col.Campo]) ? -1 : 0));
|
|
255
|
+
} else if (col.Tipo == 'number') {
|
|
256
|
+
this.filteredDataSet.sort((a, b) => LibService.stringToDecimal(a[col.Campo], true) < LibService.stringToDecimal(b[col.Campo], true) ? 1 : (LibService.stringToDecimal(a[col.Campo], true) > LibService.stringToDecimal(b[col.Campo], true) ? -1 : 0));
|
|
257
|
+
} else
|
|
258
|
+
this.filteredDataSet.sort((a, b) => a[col.Campo] < b[col.Campo] ? 1 : (a[col.Campo] > b[col.Campo] ? -1 : 0));
|
|
259
|
+
col.OrdemStatus = -1; //desc
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
setFiltroOpen(col: any) {
|
|
264
|
+
col.FiltroVisivel = !col.FiltroVisivel
|
|
265
|
+
if (col.FiltroVisivel) {
|
|
266
|
+
this.selectedColuna = col;
|
|
267
|
+
//console.log(this.selectedColuna);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
selecionarTodos() {
|
|
272
|
+
//this.todosSelecionados = !this.todosSelecionados;
|
|
273
|
+
this.filteredDataSet.forEach(item => {
|
|
274
|
+
item[this.tabelaCampos.CampoSelecionar] = this.todosSelecionados;
|
|
275
|
+
});
|
|
276
|
+
this.selecionarChecked.emit();
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
selecionarLinha(item: any) {
|
|
280
|
+
this.selecionarItem.emit(item);
|
|
281
|
+
this.selectedItem = item;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
excluirLinha(item: any) {
|
|
285
|
+
this.excluirItem.emit(item);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
//check
|
|
289
|
+
selecionadoChecked() {
|
|
290
|
+
this.selecionarChecked.emit();
|
|
291
|
+
}
|
|
292
|
+
}
|
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
|
2
|
-
|
|
3
|
-
import { InputAreaComponent } from './input-area.component';
|
|
4
|
-
|
|
5
|
-
describe('InputAreaComponent', () => {
|
|
6
|
-
let component: InputAreaComponent;
|
|
7
|
-
let fixture: ComponentFixture<InputAreaComponent>;
|
|
8
|
-
|
|
9
|
-
beforeEach(async () => {
|
|
10
|
-
await TestBed.configureTestingModule({
|
|
11
|
-
declarations: [ InputAreaComponent ]
|
|
12
|
-
})
|
|
13
|
-
.compileComponents();
|
|
14
|
-
|
|
15
|
-
fixture = TestBed.createComponent(InputAreaComponent);
|
|
16
|
-
component = fixture.componentInstance;
|
|
17
|
-
fixture.detectChanges();
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
it('should create', () => {
|
|
21
|
-
expect(component).toBeTruthy();
|
|
22
|
-
});
|
|
23
|
-
});
|
|
1
|
+
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
|
2
|
+
|
|
3
|
+
import { InputAreaComponent } from './input-area.component';
|
|
4
|
+
|
|
5
|
+
describe('InputAreaComponent', () => {
|
|
6
|
+
let component: InputAreaComponent;
|
|
7
|
+
let fixture: ComponentFixture<InputAreaComponent>;
|
|
8
|
+
|
|
9
|
+
beforeEach(async () => {
|
|
10
|
+
await TestBed.configureTestingModule({
|
|
11
|
+
declarations: [ InputAreaComponent ]
|
|
12
|
+
})
|
|
13
|
+
.compileComponents();
|
|
14
|
+
|
|
15
|
+
fixture = TestBed.createComponent(InputAreaComponent);
|
|
16
|
+
component = fixture.componentInstance;
|
|
17
|
+
fixture.detectChanges();
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it('should create', () => {
|
|
21
|
+
expect(component).toBeTruthy();
|
|
22
|
+
});
|
|
23
|
+
});
|