Skip to content

Commit 8a96058

Browse files
jhonyeduardojhosefmarks
authored andcommitted
feat(dynamic-table): exibe o filtro mesmo que o campo esteja invisível
- Adiciona a propriedade PoPageDynamicField. AllowColumnsManager, que permite visualiza-lo no gerenciador de colunas mesmo estando visible: false; - Exibe o filtro mesmo que o campo esteja invisivel na tabela (visible=false); Fixes DTHFUI-4135
1 parent f69fb34 commit 8a96058

File tree

7 files changed

+137
-48
lines changed

7 files changed

+137
-48
lines changed

docs/guides/sync-get-started.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Para maiores detalhes sobre os serviços e métodos utilizados neste tutorial, c
1111
- [Node.js e NPM](https://nodejs.org/en/)
1212
- [Angular CLI](https://cli.angular.io/) (^10.0.2):
1313
- ```shell
14-
npm install -g @angular/cli@^10.0.2
14+
npm install -g @angular/cli@~10.0.2
1515
```
1616
- [Ionic](https://ionicframework.com/docs/cli/) (5.4.16):
1717
- ```shell

projects/templates/src/lib/components/po-page-dynamic-table/interfaces/po-page-dynamic-table-field.interface.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,12 @@ export interface PoPageDynamicTableField extends PoDynamicFormField {
1616

1717
/** Tamanho da coluna em pixels ou porcetagem. */
1818
width?: number | string;
19+
20+
/**
21+
* Permite o campo aparecer no gerenciador de colunas, mesmo que esteja utilizando `visible: false`,
22+
* possibilitando ativar a exibição na tabela.
23+
*
24+
* > Quando for `false`, será desconsiderado.
25+
*/
26+
allowColumnsManager?: boolean;
1927
}

projects/templates/src/lib/components/po-page-dynamic-table/po-page-dynamic-list-base.component.spec.ts

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,39 @@ describe('PoPageDynamicListBaseComponent:', () => {
4242
expect(component['setFieldsProperties']).toHaveBeenCalled();
4343
});
4444

45+
it('fields: should set `filters` with fields that have `filter` as true', () => {
46+
const newFields = [
47+
{ property: 'name', filter: true },
48+
{ property: 'birthdateTo', label: 'Birthdate', type: 'date', filter: true, visible: false },
49+
{ property: 'state', options: this.cityOptions, visible: false },
50+
{ property: 'address', visible: true, filter: false }
51+
];
52+
53+
component.fields = newFields;
54+
55+
expect(component.filters).toEqual([
56+
{ property: 'name', filter: true, visible: true },
57+
{ property: 'birthdateTo', label: 'Birthdate', type: 'date', filter: true, visible: true }
58+
]);
59+
});
60+
61+
it('fields: should set `columns` with fields that have `allowColumnsManager` and `visible` as true', () => {
62+
const newFields = [
63+
{ property: 'name', filter: true },
64+
{ property: 'birthdate', label: 'Birthdate', type: 'date', filter: true, visible: false },
65+
{ property: 'state', options: this.cityOptions, visible: false, allowColumnsManager: true },
66+
{ property: 'address', visible: true, filter: false }
67+
];
68+
69+
component.fields = newFields;
70+
71+
expect(component.columns).toEqual([
72+
{ property: 'name', filter: true },
73+
{ property: 'state', options: this.cityOptions, visible: false, allowColumnsManager: true },
74+
{ property: 'address', visible: true, filter: false }
75+
]);
76+
});
77+
4578
it('columns: should return a new reference', () => {
4679
const columns = [
4780
{ property: 'id', key: true },
@@ -69,19 +102,19 @@ describe('PoPageDynamicListBaseComponent:', () => {
69102
];
70103
});
71104

72-
it('should set `_filters` with items that have the `filter` property', () => {
105+
it('should set `filters` with items that have the `filter` property', () => {
73106
const filtersResult = [
74107
{ property: 'name', label: 'Name', filter: true, visible: true, gridColumns: 6 },
75-
{ property: 'genre', label: 'Genre', filter: true, gridColumns: 6, duplicate: true },
76-
{ property: 'city', label: 'City', filter: true, duplicate: true, gridColumns: 12 }
108+
{ property: 'genre', label: 'Genre', filter: true, gridColumns: 6, visible: true, duplicate: true },
109+
{ property: 'city', label: 'City', filter: true, duplicate: true, visible: true, gridColumns: 12 }
77110
];
78111

79112
component['setFieldsProperties'](fields);
80113

81114
expect(component.filters).toEqual(filtersResult);
82115
});
83116

84-
it('should set `_filters` with [] if no item has the `filter` property', () => {
117+
it('should set `filters` with [] if no item has the `filter` property', () => {
85118
const fieldsWithoutFilter = [
86119
{ property: 'id', key: true },
87120
{ property: 'birthdate', label: 'Birthdate', type: 'date', gridColumns: 6 }
@@ -107,15 +140,15 @@ describe('PoPageDynamicListBaseComponent:', () => {
107140
expect(component.filters).toEqual(fieldsEmpty);
108141
});
109142

110-
it('should set `_keys` with items that have the `key` property', () => {
143+
it('should set `keys` with items that have the `key` property', () => {
111144
const keysResult = ['id'];
112145

113146
component['setFieldsProperties'](fields);
114147

115148
expect(component.keys).toEqual(keysResult);
116149
});
117150

118-
it('should set `_keys` with [] if no item has the `key` property', () => {
151+
it('should set `keys` with [] if no item has the `key` property', () => {
119152
const fieldsWithoutKey = [
120153
{ property: 'birthdate', label: 'Birthdate', type: 'date', gridColumns: 6 },
121154
{ property: 'city', label: 'City', filter: true, duplicate: true, gridColumns: 12 }
@@ -127,15 +160,15 @@ describe('PoPageDynamicListBaseComponent:', () => {
127160
expect(component.keys).toEqual(keysResult);
128161
});
129162

130-
it('should set `_duplicates` with items that have the `duplicate` property', () => {
163+
it('should set `duplicates` with items that have the `duplicate` property', () => {
131164
const duplicatesResult = ['genre', 'city'];
132165

133166
component['setFieldsProperties'](fields);
134167

135168
expect(component.duplicates).toEqual(duplicatesResult);
136169
});
137170

138-
it('should set `_duplicates` with [] if no item has the `duplicate` property', () => {
171+
it('should set `duplicates` with [] if no item has the `duplicate` property', () => {
139172
const fieldsWithoutDuplicate = [
140173
{ property: 'birthdate', label: 'Birthdate', type: 'date', gridColumns: 6 },
141174
{ property: 'city', label: 'City', filter: true, gridColumns: 12 }

projects/templates/src/lib/components/po-page-dynamic-table/po-page-dynamic-list-base.component.ts

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ import { PoPageDynamicTableFilters } from './interfaces/po-page-dynamic-table-fi
1010
export class PoPageDynamicListBaseComponent {
1111
private _autoRouter: boolean = false;
1212
private _columns: Array<any> = [];
13-
private _duplicates: Array<any> = [];
13+
private _duplicates: Array<string> = [];
1414
private _fields: Array<any> = [];
1515
private _filters: Array<any> = [];
16-
private _keys: Array<any> = [];
16+
private _keys: Array<string> = [];
1717

1818
/**
1919
* @optional
@@ -148,22 +148,38 @@ export class PoPageDynamicListBaseComponent {
148148
return this._columns;
149149
}
150150

151+
set duplicates(value: Array<string>) {
152+
this._duplicates = [...value];
153+
}
154+
151155
get duplicates() {
152-
return [...this._duplicates];
156+
return this._duplicates;
157+
}
158+
159+
set filters(value: Array<PoPageDynamicTableFilters>) {
160+
this._filters = [...value];
153161
}
154162

155163
get filters() {
156-
return [...this._filters];
164+
return this._filters;
165+
}
166+
167+
set keys(value: Array<string>) {
168+
this._keys = [...value];
157169
}
158170

159171
get keys() {
160-
return [...this._keys];
172+
return this._keys;
161173
}
162174

163175
private setFieldsProperties(fields: Array<any>) {
164-
this._filters = fields.filter(field => field.filter === true);
165-
this.columns = fields.filter(field => field.visible === undefined || field.visible === true);
166-
this._keys = fields.filter(field => field.key === true).map(field => field.property);
167-
this._duplicates = fields.filter(field => field.duplicate === true).map(field => field.property);
176+
this.filters = fields
177+
.filter(field => field.filter === true)
178+
.map(filterField => ({ ...filterField, visible: true }));
179+
this.columns = fields.filter(
180+
field => field.visible === undefined || field.visible === true || field.allowColumnsManager === true
181+
);
182+
this.keys = fields.filter(field => field.key === true).map(field => field.property);
183+
this.duplicates = fields.filter(field => field.duplicate === true).map(field => field.property);
168184
}
169185
}

projects/templates/src/lib/components/po-page-dynamic-table/po-page-dynamic-table.component.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1662,7 +1662,7 @@ describe('PoPageDynamicTableComponent:', () => {
16621662
const pageAction = [
16631663
{
16641664
label: component.literals.pageAction,
1665-
action: jasmine.any(Function),
1665+
action: jasmine.any(Function)
16661666
}
16671667
];
16681668

@@ -1683,7 +1683,7 @@ describe('PoPageDynamicTableComponent:', () => {
16831683
const pageAction = [
16841684
{
16851685
label: component.literals.pageAction,
1686-
action: jasmine.any(Function),
1686+
action: jasmine.any(Function)
16871687
},
16881688
{
16891689
label: component.literals.pageActionRemoveAll,
@@ -1979,7 +1979,7 @@ describe('PoPageDynamicTableComponent:', () => {
19791979
{ id: '3', name: 'vue', $selected: false }
19801980
];
19811981

1982-
expect(component.pageActions[2].disabled()).toBe(true);
1982+
expect((<Function>component.pageActions[2].disabled)()).toBe(true);
19831983
});
19841984

19851985
it('should enable a custom action if selectable is true and the table has some item selected', () => {
@@ -1999,7 +1999,7 @@ describe('PoPageDynamicTableComponent:', () => {
19991999
{ id: '3', name: 'vue' }
20002000
];
20012001

2002-
expect(component.pageActions[2].disabled()).toBe(false);
2002+
expect((<Function>component.pageActions[2].disabled)()).toBe(false);
20032003
});
20042004

20052005
it('should navigate to `test/` if action of pageCustomAction is undefined and url is defined', () => {

projects/templates/src/lib/components/po-page-dynamic-table/po-page-dynamic-table.component.ts

Lines changed: 49 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -121,22 +121,46 @@ type UrlOrPoCustomizationFunction = string | (() => PoPageDynamicTableOptions);
121121
})
122122
export class PoPageDynamicTableComponent extends PoPageDynamicListBaseComponent implements OnInit, OnDestroy {
123123
private _actions: PoPageDynamicTableActions = {};
124-
private _pageActions: Array<PoPageAction> = [];
125-
private _tableActions: Array<PoTableAction> = [];
126124
private _pageCustomActions: Array<PoPageDynamicTableCustomAction> = [];
127125
private _tableCustomActions: Array<PoPageDynamicTableCustomTableAction> = [];
128126

127+
hasNext = false;
128+
items = [];
129+
literals;
130+
131+
pageActions: Array<PoPageAction> = [];
132+
tableActions: Array<PoTableAction> = [];
133+
129134
private page: number = 1;
130135
private params = {};
131136
private sortedColumn: PoTableColumnSort;
132137
private subscriptions = new Subscription();
133138
private hasCustomActionWithSelectable = false;
134-
private customPageListActions = [];
135-
private customTableActions = [];
136139

137-
hasNext = false;
138-
items = [];
139-
literals;
140+
private _customPageListActions: Array<PoPageAction> = [];
141+
private _customTableActions: Array<PoTableAction> = [];
142+
private _defaultPageActions: Array<PoPageAction> = [];
143+
private _defaultTableActions: Array<PoTableAction> = [];
144+
145+
private set defaultPageActions(value: Array<PoPageAction>) {
146+
this._defaultPageActions = value;
147+
this.updatePageActions();
148+
}
149+
150+
private set defaultTableActions(value: Array<PoTableAction>) {
151+
this._defaultTableActions = value;
152+
this.updateTableActions();
153+
}
154+
155+
private set customPageListActions(value: Array<PoPageAction>) {
156+
this._customPageListActions = value;
157+
this.updatePageActions();
158+
}
159+
160+
private set customTableActions(value: Array<PoTableAction>) {
161+
this._customTableActions = value;
162+
this.updateTableActions();
163+
}
140164

141165
/**
142166
* Função ou serviço que será executado na inicialização do componente.
@@ -352,14 +376,6 @@ export class PoPageDynamicTableComponent extends PoPageDynamicListBaseComponent
352376
return !!this.actions.removeAll;
353377
}
354378

355-
get pageActions() {
356-
return [...this._pageActions, ...this.customPageListActions];
357-
}
358-
359-
get tableActions() {
360-
return [...this._tableActions, ...this.customTableActions];
361-
}
362-
363379
private confirmRemove(
364380
actionRemove: PoPageDynamicTableActions['remove'],
365381
actionBeforeRemove: PoPageDynamicTableActions['beforeRemove'],
@@ -760,9 +776,7 @@ export class PoPageDynamicTableComponent extends PoPageDynamicListBaseComponent
760776

761777
private setPageActions(actions: PoPageDynamicTableActions) {
762778
if (actions?.new) {
763-
this._pageActions = [
764-
{ label: this.literals.pageAction, action: this.openNew.bind(this, actions.new) }
765-
];
779+
this.defaultPageActions = [{ label: this.literals.pageAction, action: this.openNew.bind(this, actions.new) }];
766780
}
767781
}
768782

@@ -824,11 +838,14 @@ export class PoPageDynamicTableComponent extends PoPageDynamicListBaseComponent
824838
private setRemoveAllAction() {
825839
const action = this._actions;
826840
if (this.showRemove(action.removeAll)) {
827-
this._pageActions.push({
828-
label: this.literals.pageActionRemoveAll,
829-
action: this.confirmRemoveAll.bind(this, action.removeAll, action.beforeRemoveAll),
830-
disabled: this.disableRemoveAll.bind(this)
831-
});
841+
this.defaultPageActions = [
842+
...this._defaultPageActions,
843+
{
844+
label: this.literals.pageActionRemoveAll,
845+
action: this.confirmRemoveAll.bind(this, action.removeAll, action.beforeRemoveAll),
846+
disabled: this.disableRemoveAll.bind(this)
847+
}
848+
];
832849
}
833850
}
834851

@@ -839,7 +856,7 @@ export class PoPageDynamicTableComponent extends PoPageDynamicListBaseComponent
839856
private setTableActions(actions: PoPageDynamicTableActions) {
840857
if (actions) {
841858
const visibleRemove = this.showRemove(actions.remove);
842-
this._tableActions = [
859+
this.defaultTableActions = [
843860
{
844861
action: this.openDetail.bind(this, actions.detail),
845862
label: this.literals.tableActionView,
@@ -979,4 +996,12 @@ export class PoPageDynamicTableComponent extends PoPageDynamicListBaseComponent
979996
}
980997
});
981998
}
999+
1000+
private updatePageActions() {
1001+
this.pageActions = [...this._defaultPageActions, ...this._customPageListActions];
1002+
}
1003+
1004+
private updateTableActions() {
1005+
this.tableActions = [...this._defaultTableActions, ...this._customTableActions];
1006+
}
9821007
}

projects/templates/src/lib/components/po-page-dynamic-table/samples/sample-po-page-dynamic-table-users/sample-po-page-dynamic-table-users.component.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,17 @@ export class SamplePoPageDynamicTableUsersComponent {
4040
];
4141

4242
readonly fields: Array<any> = [
43-
{ property: 'id', key: true },
43+
{ property: 'id', key: true, visible: false, filter: true },
4444
{ property: 'name', label: 'Name', filter: true, gridColumns: 6 },
4545
{ property: 'genre', label: 'Genre', filter: true, gridColumns: 6, duplicate: true },
46-
{ property: 'birthdate', label: 'Birthdate', type: 'date', gridColumns: 6 },
46+
{
47+
property: 'birthdate',
48+
label: 'Birthdate',
49+
type: 'date',
50+
gridColumns: 6,
51+
visible: false,
52+
allowColumnsManager: true
53+
},
4754
{ property: 'city', label: 'City', filter: true, duplicate: true, options: this.cityOptions, gridColumns: 12 }
4855
];
4956

0 commit comments

Comments
 (0)