-
Notifications
You must be signed in to change notification settings - Fork 20
/
px-data-grid-filters-modal.html
185 lines (151 loc) · 5.26 KB
/
px-data-grid-filters-modal.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
<!--
Copyright (c) 2018, General Electric
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<link rel="import" href="../polymer/polymer-element.html">
<link rel="import" href="../px-modal/px-modal.html">
<link rel="import" href="../px-icon-set/px-icon.html">
<link rel="import" href="css/px-data-grid-filters-modal-styles.html">
<link rel="import" href="px-data-grid-filter.html">
<dom-module id="px-data-grid-filters-modal">
<template>
<style include="px-data-grid-filters-modal-styles"></style>
<px-modal
id="filtersModal"
header-text="[[localize('Filter Columns')]]"
open-trigger="[[filtersModalTrigger]]">
<div slot="body">
<px-data-grid-filter
id="filters"
columns="[[columns]]"
filters="{{filters}}"
temp-filters="{{_tempFilters}}"
compact-mode="[[compactMode]]"
disable-all-columns-filter="[[disableAllColumnsFilter]]"
string-comparators="[[stringComparators]]"
number-comparators="[[numberComparators]]"
localize="[[localize]]">
</px-data-grid-filter>
<template is="dom-if" if="[[_showSaveCheckbox(offerFilterSaving, _tempFilters, _tempFilters.*)]]" restamp>
<input id="saveFilterSet" type="checkbox">
<label class="label--inline" for="saveFilterSet">[[localize('Save this filter set')]]</label>
</template>
</div>
<div slot="actions" class="action-buttons">
<template is="dom-if" if="[[_hasAnyEntity(_tempFilters, _tempFilters.*)]]">
<button class="btn" on-click="_reset">[[localize('Reset')]]</button>
</template>
</div>
<button slot="reject-trigger" class="btn action-btn" on-click="_cancel">[[localize('Cancel')]]</button>
<button slot="accept-trigger" class="btn btn--call-to-action action-btn" on-click="_apply">[[localize('Apply')]]</button>
</px-modal>
<px-modal-trigger trigger="{{filtersModalTrigger}}">
<button class="btn table-filters">
<px-icon icon="px-utl:filter"></px-icon>
[[localize('Table Filters')]]
</button>
</px-modal-trigger>
</template>
<script>
{
/**
* @memberof Predix
* @extends Polymer.Element
*/
class DataGridFiltersModalElement extends Polymer.Element {
static get is() {
return 'px-data-grid-filters-modal';
}
static get properties() {
return {
columns: Array,
filters: {
type: Array,
notify: true
},
initialFilterState: {
type: Array,
},
offerFilterSaving: {
type: Boolean,
value: false
},
compactMode: {
type: Boolean,
value: false
},
disableAllColumnsFilter: {
type: Boolean,
value: false
},
stringComparators: {
type: Array
},
numberComparators: {
type: Array
},
_tempFilters: {
type: Array
},
localize: Function
};
}
ready() {
super.ready();
this.addEventListener('update-modal-focusable-elements', (event) => {
this.$.filtersModal.findFocusableElements();
});
}
open() {
this.$.filtersModal.opened = true;
}
_apply() {
this.$.filters.applyFilters();
const checkbox = this.shadowRoot.querySelector('#saveFilterSet');
if (checkbox && checkbox.checked) {
this.dispatchEvent(
new CustomEvent('save-filters',
{
bubbles: true,
composed: true,
detail: {
filters: this.filters
}
}
)
);
}
this.$.filtersModal.opened = false;
}
_cancel() {
this.$.filters.cancelChanges();
this.$.filtersModal.opened = false;
}
_reset() {
this.$.filters.resetFilters();
this.set('filters', this.initialFilterState);
}
_hasAnyEntity(filters) {
return filters.filter(filter => filter.entities && filter.entities.length > 0).length > 0;
}
_showSaveCheckbox(offerFilterSaving, filters) {
return offerFilterSaving && filters && this._hasAnyEntity(filters);
}
}
customElements.define(DataGridFiltersModalElement.is, DataGridFiltersModalElement);
/**
* @namespace Predix
*/
window.Predix = window.Predix || {};
Predix.DataGridFiltersModalElement = DataGridFiltersModalElement;
}
</script>
</dom-module>