Blame view

controllets/filters-controllet/filters-controllet.html 12.9 KB
0af843be   Renato De Donato   filters + alasql
1
2
  <link rel="import" href="../../bower_components/polymer/polymer.html" />
  
0af843be   Renato De Donato   filters + alasql
3
4
5
6
7
8
9
10
  <link rel="import" href="../../bower_components/paper-dropdown-menu/paper-dropdown-menu.html">
  <link rel="import" href="../../bower_components/paper-menu/paper-menu.html">
  <link rel="import" href="../../bower_components/paper-item/paper-item.html">
  
  <link rel="import" href="../../bower_components/paper-icon-button/paper-icon-button.html">
  <link rel="import" href="../../bower_components/iron-icons/iron-icons.html">
  <link rel="import" href="../../bower_components/iron-icon/iron-icon.html">
  
89558a41   Renato De Donato   datatype, provide...
11
12
  <link rel="import" href="../../bower_components/paper-button/paper-button.html">
  
0af843be   Renato De Donato   filters + alasql
13
14
15
16
17
18
  <dom-module id="filters-controllet">
  
      <template>
  
          <style is="custom-style">
  
0af843be   Renato De Donato   filters + alasql
19
              #filters_container {
256ece27   Renato De Donato   new controllet
20
                  height: 100%;
0af843be   Renato De Donato   filters + alasql
21
                  width: 100%;
256ece27   Renato De Donato   new controllet
22
                  position: relative;
89558a41   Renato De Donato   datatype, provide...
23
              }
0af843be   Renato De Donato   filters + alasql
24
  
89558a41   Renato De Donato   datatype, provide...
25
              #filters_container * {
0af843be   Renato De Donato   filters + alasql
26
27
                  font-family: 'Roboto', 'Helvetica Neue', Helvetica, Arial, sans-serif;
                  font-size: 16px;
89558a41   Renato De Donato   datatype, provide...
28
                  line-height: 24px;
0af843be   Renato De Donato   filters + alasql
29
30
              }
  
0af843be   Renato De Donato   filters + alasql
31
              paper-dropdown-menu {
89558a41   Renato De Donato   datatype, provide...
32
                  width: 100%;
0af843be   Renato De Donato   filters + alasql
33
34
35
                  --paper-input-container-focus-color: #2196F3;
              }
  
89558a41   Renato De Donato   datatype, provide...
36
37
38
39
40
41
42
43
              :host {
              --paper-dropdown-menu-icon: {
                   color: #2196F3;
               };
              }
  
              paper-item {
                  min-width: 128px;
f833bd4e   Renato De Donato   filter ln
44
                  white-space: nowrap;
89558a41   Renato De Donato   datatype, provide...
45
46
              }
  
0af843be   Renato De Donato   filters + alasql
47
48
49
50
51
              paper-item.iron-selected {
                  background-color: #2196F3;
                  color: #FFFFFF;
              }
  
89558a41   Renato De Donato   datatype, provide...
52
53
54
55
56
57
              paper-input {
                  width: 100%;
                  --paper-input-container-focus-color: #2196F3;
              }
  
              paper-button {
256ece27   Renato De Donato   new controllet
58
59
60
                  margin: 0;
                  height: 48px;
                  padding: 12px;
89558a41   Renato De Donato   datatype, provide...
61
62
63
                  color: #FFFFFF;
                  background: #2196F3;
                  font-weight: 700;
256ece27   Renato De Donato   new controllet
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
  
                  min-width: 96px;
              }
  
              paper-button#disable_filters {
                  position: absolute;
                  bottom: 0;
                  right: 0;
                  margin: 0 8px 8px 0;
  
                  min-width: 192px;
              }
  
              paper-button#disable_filters.disabled {
                  background-color: #B6B6B6;
              }
  
              iron-icon[icon=filter-list] {
                  height: 32px;
                  width: 32px;
                  color: #FFFFFF;
                  margin-top: -4px;
89558a41   Renato De Donato   datatype, provide...
86
87
88
89
90
91
92
93
              }
  
              paper-button:hover {
                  box-shadow: 0px 8px 12px #888;
                  -webkit-box-shadow: 0px 8px 12px #888;
                  -moz-box-shadow: 0px 8px 12px #888;
              }
  
0af843be   Renato De Donato   filters + alasql
94
              paper-icon-button {
89558a41   Renato De Donato   datatype, provide...
95
96
97
98
                  padding: 4px;
              }
  
              paper-icon-button.add {
0af843be   Renato De Donato   filters + alasql
99
100
                  color: #2196F3;
                  --paper-icon-button-ink-color: #2196F3;
0af843be   Renato De Donato   filters + alasql
101
102
103
104
105
              }
  
              paper-icon-button.cancel {
                  color: #F44336;
                  --paper-icon-button-ink-color: #F44336;
0af843be   Renato De Donato   filters + alasql
106
              }
89558a41   Renato De Donato   datatype, provide...
107
108
109
110
111
  
              #filters_container .row {
                  display: flex;
                  height: 60px;
                  width: 100%;
0af843be   Renato De Donato   filters + alasql
112
113
              }
  
89558a41   Renato De Donato   datatype, provide...
114
115
116
117
118
119
120
121
122
123
124
125
126
127
              #filters_container .ddl_container {
                  display: flex;
                  height: 60px;
                  width: 25%;
                  padding: 0px 8px;
              }
  
              #filters_container .add_container {
                  height: 40px;
                  width: 40px;
                  padding: 10px 0px;
              }
  
              #filters_container .andOr_container {
0af843be   Renato De Donato   filters + alasql
128
                  display: inline-block;
89558a41   Renato De Donato   datatype, provide...
129
130
131
                  height: 44px;
                  width: calc(100% - 40px);
                  padding: 8px 0px;
256ece27   Renato De Donato   new controllet
132
133
                  /*text-align: right;*/
                  text-align: center;
0af843be   Renato De Donato   filters + alasql
134
135
              }
  
89558a41   Renato De Donato   datatype, provide...
136
137
              #filters_container .row2 {
                  display: flex;
0af843be   Renato De Donato   filters + alasql
138
                  height: 48px;
89558a41   Renato De Donato   datatype, provide...
139
                  width: 100%;
0af843be   Renato De Donato   filters + alasql
140
141
              }
  
256ece27   Renato De Donato   new controllet
142
               .highlighted {
89558a41   Renato De Donato   datatype, provide...
143
144
145
146
147
148
149
150
                  color: #2196F3;
                  font-weight: 700;
              }
  
              #filters_container .filter {
                  height: 24px;
                  width: calc(75% - 16px);
                  padding: 12px 8px;
0af843be   Renato De Donato   filters + alasql
151
152
              }
  
89558a41   Renato De Donato   datatype, provide...
153
154
155
156
              #filters_container .remove_container {
                  height: 40px;
                  width: 40px;
                  padding: 4px 8px;
0af843be   Renato De Donato   filters + alasql
157
158
159
160
              }
  
      </style>
  
256ece27   Renato De Donato   new controllet
161
          <div id="filters_container">
89558a41   Renato De Donato   datatype, provide...
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
  
                  <div class="row">
                      <div class="ddl_container">
                          <paper-dropdown-menu id="filter_field" label="Field">
                              <paper-menu id="filter_field_menu" class="dropdown-content">
                                  <template is="dom-repeat" items={{fields}}>
                                      <paper-item id={{index}}>{{_fieldName(item)}}</paper-item>
                                  </template>
                              </paper-menu>
                          </paper-dropdown-menu>
                      </div>
                      <div class="ddl_container">
                          <paper-dropdown-menu id="filter_operation" label="Operation">
                              <paper-menu id="filter_operation_menu" class="dropdown-content">
                                  <template is="dom-repeat" items={{operations}}>
                                      <paper-item id={{index}}>{{_getOperationlName(item)}}</paper-item>
                                  </template>
                              </paper-menu>
                          </paper-dropdown-menu>
                      </div>
                      <div class="ddl_container">
                          <paper-input id="filter_value" label="Value" class="base_input" maxlength="32" auto-validate pattern="^[.:,;+-_ a-zA-Z0-9]*" error-message="Invalid value!"></paper-input>
                      </div>
                      <div class="ddl_container">
                          <div class="add_container">
0af843be   Renato De Donato   filters + alasql
187
                              <paper-icon-button on-click="_addFilter" icon="add-circle" class="add"></paper-icon-button>
89558a41   Renato De Donato   datatype, provide...
188
189
190
191
192
193
194
195
196
197
198
                          </div>
                          <div class="andOr_container">
                              <paper-button raised on-click="_changeLogicalOperator"><span id="andOr">{{logicalOperator}}</span></paper-button>
                          </div>
                      </div>
                  </div>
  
                  <template is="dom-repeat" items={{filters}}>
                      <template is="dom-if" if="{{index}}"><!--excludes logicalOperator-->
                          <div class="row2">
                              <div class="filter">
256ece27   Renato De Donato   new controllet
199
                                  {{item.field}} <span class="highlighted">{{_getOperationlName(item.operation)}}</span> "{{item.value}}" <span class="highlighted">{{_getLogicalOperator(index)}}</span>
89558a41   Renato De Donato   datatype, provide...
200
201
202
203
204
                              </div>
                              <div class="remove_container">
                                  <paper-icon-button on-click="_deleteFilter" icon="cancel" class="cancel"></paper-icon-button>
                              </div>
                          </div>
0af843be   Renato De Donato   filters + alasql
205
                      </template>
89558a41   Renato De Donato   datatype, provide...
206
                  </template>
0af843be   Renato De Donato   filters + alasql
207
  
256ece27   Renato De Donato   new controllet
208
              <paper-button id="disable_filters" raised on-click="_disableFilters"><iron-icon icon="filter-list"></iron-icon>&nbsp; <span id="disable_enable"></span></paper-button>
0af843be   Renato De Donato   filters + alasql
209
  
256ece27   Renato De Donato   new controllet
210
          </div>
0af843be   Renato De Donato   filters + alasql
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
  
      </template>
  
      <script>
  
          Polymer({
  
              is : 'filters-controllet',
  
              properties : {
  
                  fields : {
                      type : Array,
                      value : []
                  },
  
                  operations : {
                      type : Array,
f833bd4e   Renato De Donato   filter ln
229
                      value : ["=", "!=", ">", ">=", "<", "<=", "contains", "notContains", "start", "ends"]
0af843be   Renato De Donato   filters + alasql
230
231
232
233
                  },
  
                  filters : {
                      type : Array,
89558a41   Renato De Donato   datatype, provide...
234
                      value :  [{logicalOperator: "AND"}]
0af843be   Renato De Donato   filters + alasql
235
236
237
238
239
                  }
  
              },
  
              ready : function() {
256ece27   Renato De Donato   new controllet
240
                  $(this.$.filters_container).perfectScrollbar();
420ea6ab   Renato De Donato   workcicle...
241
                  this.logicalOperator = "AND";
0af843be   Renato De Donato   filters + alasql
242
243
              },
  
e94f9513   Renato De Donato   filter ln
244
              attached : function() {
e94f9513   Renato De Donato   filter ln
245
246
247
                  this._translate();
              },
  
0af843be   Renato De Donato   filters + alasql
248
              setFields : function(fields) {
420ea6ab   Renato De Donato   workcicle...
249
                  this.fields = this._copy(fields);
256ece27   Renato De Donato   new controllet
250
251
252
253
              },
  
              setSelectedFields : function(selectedFields) {
                  this.selectedFields = this._copy(selectedFields);
89558a41   Renato De Donato   datatype, provide...
254
255
256
              },
  
              setFilters : function(filters) {
c0d8052d   Renato De Donato   filters bug
257
258
259
260
261
                  if(filters && filters.length > 0) {
                      this.filters = this._copy(filters);
                      this.logicalOperator = this.filters[0].logicalOperator;
                      this._fire();
                  }
0af843be   Renato De Donato   filters + alasql
262
263
264
265
266
267
              },
  
              getFilters : function() {
                  return this.filters;
              },
  
89558a41   Renato De Donato   datatype, provide...
268
269
              reset : function() {
                  this.fields = [];
256ece27   Renato De Donato   new controllet
270
                  this.selectedFields = [];
89558a41   Renato De Donato   datatype, provide...
271
272
273
                  this.filters = [{logicalOperator: "AND"}];
              },
  
e94f9513   Renato De Donato   filter ln
274
              _translate : function() {
e94f9513   Renato De Donato   filter ln
275
276
277
                  this.$.filter_field.setAttribute("label", ln["filterField_" + ln["localization"]]);
                  this.$.filter_operation.setAttribute("label", ln["filterOperation_" + ln["localization"]]);
                  this.$.filter_value.setAttribute("label", ln["filterValue_" + ln["localization"]]);
256ece27   Renato De Donato   new controllet
278
279
  
                  this.$.disable_enable.innerHTML = ln["disableFilters_" + ln["localization"]];
e94f9513   Renato De Donato   filter ln
280
281
              },
  
0af843be   Renato De Donato   filters + alasql
282
283
284
285
              _fieldName : function(field) {
                  return field.substring(field.lastIndexOf(",")+1, field.length);
              },
  
89558a41   Renato De Donato   datatype, provide...
286
              _fire : function() {
256ece27   Renato De Donato   new controllet
287
288
289
                  this.$.disable_enable.innerHTML = ln["disableFilters_" + ln["localization"]];
                  this.$.disable_filters.className = this.$.disable_filters.className.replace(" disabled", "");
  
89558a41   Renato De Donato   datatype, provide...
290
291
292
293
294
295
                  if (this.filters.length > 1)
                      this.fire('filters-controllet_filters', {filters: this.filters});
                  else
                      this.fire('filters-controllet_filters', {filters: []});
              },
  
0af843be   Renato De Donato   filters + alasql
296
              _addFilter : function() {
e94f9513   Renato De Donato   filter ln
297
298
                  if (this.$.filter_field.selectedItem && this.$.filter_operation_menu.selectedItem && this.$.filter_value.value != "" && !this.$.filter_value.invalid) {
                      var field = this.$.filter_field.value;
93ba7167   Renato De Donato   filters bug fix + ln
299
300
                      var id = this.$.filter_operation.selectedItem.id;
                      var operation = this.operations[id];
e94f9513   Renato De Donato   filter ln
301
                      var value = this.$.filter_value.value;
0af843be   Renato De Donato   filters + alasql
302
  
89558a41   Renato De Donato   datatype, provide...
303
                      this.filters.push({"field": field, "operation": operation, "value": value});
98d9d8a5   Renato De Donato   filters+groupby
304
  
e94f9513   Renato De Donato   filter ln
305
306
307
                      this.$.filter_field_menu.select(-1);
                      this.$.filter_operation_menu.select(-1);
                      this.$.filter_value.value = "";
39d5ab70   Renato De Donato   update filters
308
  
89558a41   Renato De Donato   datatype, provide...
309
310
311
                      this._fire();
  
                      this._renderFilters();
e94f9513   Renato De Donato   filter ln
312
                  }
0af843be   Renato De Donato   filters + alasql
313
314
315
316
317
              },
  
              _deleteFilter : function(e) {
                  var index = e.model.index;
  
89558a41   Renato De Donato   datatype, provide...
318
319
320
                  this.filters.splice(index, 1);
  
                  this._fire();
98d9d8a5   Renato De Donato   filters+groupby
321
  
89558a41   Renato De Donato   datatype, provide...
322
                  this._renderFilters();
0af843be   Renato De Donato   filters + alasql
323
324
              },
  
e94f9513   Renato De Donato   filter ln
325
              _getOperationlName: function(operation) {
f833bd4e   Renato De Donato   filter ln
326
                  return ln[operation + "_" + ln["localization"]];
e94f9513   Renato De Donato   filter ln
327
328
              },
  
89558a41   Renato De Donato   datatype, provide...
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
              _changeLogicalOperator : function() {
                  if(this.logicalOperator == "AND")
                      this.logicalOperator = "OR";
                  else
                      this.logicalOperator = "AND";
  
                  this.filters[0] = {logicalOperator: this.logicalOperator}
  
                  this._fire();
  
                  this._renderFilters();
              },
  
              _renderFilters : function() {
                  var filters = this.filters.slice();
                  this.filters = [];
                  this.async(function() {
                      this.filters = filters;
                  }, 0);
              },
  
              _getLogicalOperator : function(index) {
                  if(index == this.filters.length -1)
                      return "";
                  else
                      return this.filters[0].logicalOperator;
              },
  
256ece27   Renato De Donato   new controllet
357
358
359
360
361
362
363
364
365
366
367
368
369
370
              _disableFilters : function() {
                  var classes = this.$.disable_filters.className;
                  if (classes.indexOf("disabled") > -1) {
  //                    this.$.disable_enable.innerHTML = ln["disableFilters_" + ln["localization"]];
  //                    this.$.disable_filters.className = classes.replace(" disabled", "");
                      this._fire();
                  }
                  else {
                      this.$.disable_enable.innerHTML = ln["enableFilters_" + ln["localization"]];
                      this.$.disable_filters.className = classes + " disabled";
                      this.fire('filters-controllet_filters', {filters: []});
                  }
              },
  
420ea6ab   Renato De Donato   workcicle...
371
372
373
374
375
376
377
378
379
              _copy : function(o) {
                  var out, v, key;
                  out = Array.isArray(o) ? [] : {};
                  for (key in o) {
                      v = o[key];
                      out[key] = (typeof v === "object") ? this._copy(v) : v;
                  }
                  return out;
              }
0af843be   Renato De Donato   filters + alasql
380
381
382
383
384
385
  
          });
  
      </script>
  
  </dom-module>