Blame view

controllets/filters-controllet/filters-controllet.html 14.4 KB
0af843be   Renato De Donato   filters + alasql
1
2
  <link rel="import" href="../../bower_components/polymer/polymer.html" />
  
89558a41   Renato De Donato   datatype, provide...
3
4
  <link rel="import" href="../../bower_components/paper-material/paper-material.html" />
  
0af843be   Renato De Donato   filters + alasql
5
6
7
8
9
10
11
12
  <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...
13
14
  <link rel="import" href="../../bower_components/paper-button/paper-button.html">
  
0af843be   Renato De Donato   filters + alasql
15
16
17
18
19
20
  <dom-module id="filters-controllet">
  
      <template>
  
          <style is="custom-style">
  
0af843be   Renato De Donato   filters + alasql
21
              #filters_container {
89558a41   Renato De Donato   datatype, provide...
22
                  height: 48px;
0af843be   Renato De Donato   filters + alasql
23
                  width: 100%;
89558a41   Renato De Donato   datatype, provide...
24
              }
0af843be   Renato De Donato   filters + alasql
25
  
89558a41   Renato De Donato   datatype, provide...
26
              #filters_container * {
0af843be   Renato De Donato   filters + alasql
27
28
                  font-family: 'Roboto', 'Helvetica Neue', Helvetica, Arial, sans-serif;
                  font-size: 16px;
89558a41   Renato De Donato   datatype, provide...
29
                  line-height: 24px;
0af843be   Renato De Donato   filters + alasql
30
31
              }
  
89558a41   Renato De Donato   datatype, provide...
32
              #filters_container #header {
0af843be   Renato De Donato   filters + alasql
33
34
35
36
37
                  height: 32px;
                  padding-top: 16px;
                  text-align: center;
                  font-weight: 700;
  
89558a41   Renato De Donato   datatype, provide...
38
                  background: #FFFFFF;
0af843be   Renato De Donato   filters + alasql
39
40
41
42
                  color: #00BCD4;
                  cursor: pointer;
              }
  
89558a41   Renato De Donato   datatype, provide...
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
              #filters_container #header.hide{
                  color: #00BCD4;
                  background: #FFFFFF;
              }
  
              /*#filters_container #header.hide:hover{*/
              /*}*/
  
              #filters_container #header.show{
                  color: #000000;
                  background: #B6B6B6;
              }
  
              #filters_container #panel {
                  display: none;
                  position: relative;
                  height: calc(100% - 48px);
                  background: #FFFFFF;
              }
  
0af843be   Renato De Donato   filters + alasql
63
              paper-dropdown-menu {
89558a41   Renato De Donato   datatype, provide...
64
                  width: 100%;
0af843be   Renato De Donato   filters + alasql
65
66
67
                  --paper-input-container-focus-color: #2196F3;
              }
  
89558a41   Renato De Donato   datatype, provide...
68
69
70
71
72
73
74
75
              :host {
              --paper-dropdown-menu-icon: {
                   color: #2196F3;
               };
              }
  
              paper-item {
                  min-width: 128px;
f833bd4e   Renato De Donato   filter ln
76
                  white-space: nowrap;
89558a41   Renato De Donato   datatype, provide...
77
78
              }
  
0af843be   Renato De Donato   filters + alasql
79
80
81
82
83
              paper-item.iron-selected {
                  background-color: #2196F3;
                  color: #FFFFFF;
              }
  
89558a41   Renato De Donato   datatype, provide...
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
              paper-input {
                  width: 100%;
                  --paper-input-container-focus-color: #2196F3;
              }
  
              paper-button {
                  margin: 0px;
                  height: 44px;
                  color: #FFFFFF;
                  background: #2196F3;
                  font-weight: 700;
              }
  
              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
103
              paper-icon-button {
89558a41   Renato De Donato   datatype, provide...
104
105
106
107
                  padding: 4px;
              }
  
              paper-icon-button.add {
0af843be   Renato De Donato   filters + alasql
108
109
                  color: #2196F3;
                  --paper-icon-button-ink-color: #2196F3;
0af843be   Renato De Donato   filters + alasql
110
111
112
113
114
              }
  
              paper-icon-button.cancel {
                  color: #F44336;
                  --paper-icon-button-ink-color: #F44336;
0af843be   Renato De Donato   filters + alasql
115
              }
89558a41   Renato De Donato   datatype, provide...
116
117
118
119
120
  
              #filters_container .row {
                  display: flex;
                  height: 60px;
                  width: 100%;
0af843be   Renato De Donato   filters + alasql
121
122
              }
  
89558a41   Renato De Donato   datatype, provide...
123
124
125
126
127
128
129
130
131
132
133
134
135
136
              #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
137
                  display: inline-block;
89558a41   Renato De Donato   datatype, provide...
138
139
140
141
                  height: 44px;
                  width: calc(100% - 40px);
                  padding: 8px 0px;
                  text-align: right;
0af843be   Renato De Donato   filters + alasql
142
143
              }
  
89558a41   Renato De Donato   datatype, provide...
144
145
              #filters_container .row2 {
                  display: flex;
0af843be   Renato De Donato   filters + alasql
146
                  height: 48px;
89558a41   Renato De Donato   datatype, provide...
147
                  width: 100%;
0af843be   Renato De Donato   filters + alasql
148
149
              }
  
89558a41   Renato De Donato   datatype, provide...
150
151
152
153
154
155
156
157
158
              #filters_container .row2 .highlighted {
                  color: #2196F3;
                  font-weight: 700;
              }
  
              #filters_container .filter {
                  height: 24px;
                  width: calc(75% - 16px);
                  padding: 12px 8px;
0af843be   Renato De Donato   filters + alasql
159
160
              }
  
89558a41   Renato De Donato   datatype, provide...
161
162
163
164
165
              #filters_container .remove_container {
                  height: 40px;
                  width: 40px;
                  padding: 4px 8px;
  
0af843be   Renato De Donato   filters + alasql
166
167
168
169
              }
  
      </style>
  
89558a41   Renato De Donato   datatype, provide...
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
          <paper-material id="filters_container" elevation="5">
  
              <div id="header" class="hide" on-click="_showFiltersPanel"><span id="filters"><span id="addFilters"></span></span></div>
  
              <div id="panel">
  
                  <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
200
                              <paper-icon-button on-click="_addFilter" icon="add-circle" class="add"></paper-icon-button>
89558a41   Renato De Donato   datatype, provide...
201
202
203
204
205
206
207
208
209
210
211
                          </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">
f833bd4e   Renato De Donato   filter ln
212
                                  {{item.field}}&nbsp;&nbsp;&nbsp;<span class="highlighted">{{_getOperationlName(item.operation)}}</span>&nbsp;&nbsp;&nbsp;"{{item.value}}"&nbsp;&nbsp;&nbsp;<span class="highlighted">{{_getLogicalOperator(index)}}</span>
89558a41   Renato De Donato   datatype, provide...
213
214
215
216
217
                              </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
218
                      </template>
89558a41   Renato De Donato   datatype, provide...
219
                  </template>
0af843be   Renato De Donato   filters + alasql
220
221
222
  
              </div>
  
89558a41   Renato De Donato   datatype, provide...
223
          </paper-material>
0af843be   Renato De Donato   filters + alasql
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
  
      </template>
  
      <script>
  
          Polymer({
  
              is : 'filters-controllet',
  
              properties : {
  
                  fields : {
                      type : Array,
                      value : []
                  },
  
                  operations : {
                      type : Array,
f833bd4e   Renato De Donato   filter ln
242
                      value : ["=", "!=", ">", ">=", "<", "<=", "contains", "notContains", "start", "ends"]
0af843be   Renato De Donato   filters + alasql
243
244
245
246
                  },
  
                  filters : {
                      type : Array,
89558a41   Renato De Donato   datatype, provide...
247
                      value :  [{logicalOperator: "AND"}]
0af843be   Renato De Donato   filters + alasql
248
249
250
251
252
253
254
255
256
257
                  },
  
                  show : {
                      type  : Boolean,
                      value : false
                  }
  
              },
  
              ready : function() {
89558a41   Renato De Donato   datatype, provide...
258
                  $(this.$.panel).perfectScrollbar();
420ea6ab   Renato De Donato   workcicle...
259
260
  //                this._showFiltersPanel();gi
                  this.logicalOperator = "AND";
0af843be   Renato De Donato   filters + alasql
261
262
              },
  
e94f9513   Renato De Donato   filter ln
263
              attached : function() {
e94f9513   Renato De Donato   filter ln
264
265
266
                  this._translate();
              },
  
0af843be   Renato De Donato   filters + alasql
267
              setFields : function(fields) {
420ea6ab   Renato De Donato   workcicle...
268
                  this.fields = this._copy(fields);
89558a41   Renato De Donato   datatype, provide...
269
270
271
272
                  this.fields = fields;
              },
  
              setFilters : function(filters) {
c0d8052d   Renato De Donato   filters bug
273
274
275
276
277
                  if(filters && filters.length > 0) {
                      this.filters = this._copy(filters);
                      this.logicalOperator = this.filters[0].logicalOperator;
                      this._fire();
                  }
0af843be   Renato De Donato   filters + alasql
278
279
280
281
282
283
              },
  
              getFilters : function() {
                  return this.filters;
              },
  
89558a41   Renato De Donato   datatype, provide...
284
285
286
287
288
              reset : function() {
                  this.fields = [];
                  this.filters = [{logicalOperator: "AND"}];
              },
  
e94f9513   Renato De Donato   filter ln
289
              _translate : function() {
79627d7e   Renato De Donato   controllet ln
290
                  this.$.addFilters.innerHTML = ln["expertAddFilters_" + ln["localization"]];
e94f9513   Renato De Donato   filter ln
291
292
293
294
295
                  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"]]);
              },
  
0af843be   Renato De Donato   filters + alasql
296
297
298
299
300
              _fieldName : function(field) {
                  return field.substring(field.lastIndexOf(",")+1, field.length);
              },
  
              _showFiltersPanel : function() {
89558a41   Renato De Donato   datatype, provide...
301
302
  //                ? filter class hiddend & hover:
  
0af843be   Renato De Donato   filters + alasql
303
                  if(!this.show) {
89558a41   Renato De Donato   datatype, provide...
304
305
306
307
308
                      this.$.filters_container.style.height = "100%";
                      $(this.$.header).removeClass("hide");
                      $(this.$.header).addClass("show");
                      this.$.panel.style.display = "block";
  
0af843be   Renato De Donato   filters + alasql
309
310
                  }
                  else {
89558a41   Renato De Donato   datatype, provide...
311
312
313
314
                      this.$.filters_container.style.height = "48px";
                      $(this.$.header).removeClass("show");
                      $(this.$.header).addClass("hide");
                      this.$.panel.style.display = "none";
0af843be   Renato De Donato   filters + alasql
315
316
                  }
  
89558a41   Renato De Donato   datatype, provide...
317
318
                  this.fire('filters-controllet_show', {show: this.show});
  
0af843be   Renato De Donato   filters + alasql
319
320
321
                  this.show = !this.show;
              },
  
89558a41   Renato De Donato   datatype, provide...
322
323
324
325
326
327
328
              _fire : function() {
                  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
329
              _addFilter : function() {
e94f9513   Renato De Donato   filter ln
330
331
                  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
332
333
334
                      var id = this.$.filter_operation.selectedItem.id;
                      var operation = this.operations[id];
  //                    var operation = this.$.filter_operation.value;
e94f9513   Renato De Donato   filter ln
335
                      var value = this.$.filter_value.value;
0af843be   Renato De Donato   filters + alasql
336
  
89558a41   Renato De Donato   datatype, provide...
337
338
339
340
341
  //                    var filters = this.filters;
  //                    filters.push({"field": field, "operation": operation, "value": value});
  //                    this.filters = filters;
  
                      this.filters.push({"field": field, "operation": operation, "value": value});
98d9d8a5   Renato De Donato   filters+groupby
342
  
e94f9513   Renato De Donato   filter ln
343
344
345
                      this.$.filter_field_menu.select(-1);
                      this.$.filter_operation_menu.select(-1);
                      this.$.filter_value.value = "";
39d5ab70   Renato De Donato   update filters
346
  
89558a41   Renato De Donato   datatype, provide...
347
348
349
                      this._fire();
  
                      this._renderFilters();
e94f9513   Renato De Donato   filter ln
350
                  }
0af843be   Renato De Donato   filters + alasql
351
352
353
354
355
              },
  
              _deleteFilter : function(e) {
                  var index = e.model.index;
  
89558a41   Renato De Donato   datatype, provide...
356
357
358
359
360
361
362
  //                var filters = this.filters;
  //                filters.splice(index, 1);
  //                this.filters = this._copy(filters);
  
                  this.filters.splice(index, 1);
  
                  this._fire();
98d9d8a5   Renato De Donato   filters+groupby
363
  
89558a41   Renato De Donato   datatype, provide...
364
                  this._renderFilters();
0af843be   Renato De Donato   filters + alasql
365
366
              },
  
e94f9513   Renato De Donato   filter ln
367
              _getOperationlName: function(operation) {
f833bd4e   Renato De Donato   filter ln
368
369
370
371
372
373
374
375
376
377
                  return ln[operation + "_" + ln["localization"]];
  //                if(operation.indexOf("not") > -1)
  //                    return ln["notContains_" + ln["localization"]];
  //                if(operation.indexOf("contains") > -1)
  //                    return ln["contains_" + ln["localization"]];
  //                if(operation.indexOf("start") > -1)
  //                    return ln["start_" + ln["localization"]];
  //                if(operation.indexOf("ends") > -1)
  //                    return ln["ends_" + ln["localization"]];
  //                return operation;
e94f9513   Renato De Donato   filter ln
378
379
              },
  
89558a41   Renato De Donato   datatype, provide...
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
  //            _changeLogicalOperator : function() {
  //                if(this.logicalOperator == "AND")
  //                    this.logicalOperator = "OR";
  //                else
  //                    this.logicalOperator = "AND";
  //
  //                this._fire();
  //
  //                this._renderFilters();
  //            },
  
              _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;
              },
  
420ea6ab   Renato De Donato   workcicle...
419
420
421
422
423
424
425
426
427
              _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
428
429
430
431
432
433
  
          });
  
      </script>
  
  </dom-module>