Blame view

controllets/filters-controllet/filters-controllet.html 14.3 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) {
420ea6ab   Renato De Donato   workcicle...
273
                  this.filters = this._copy(filters);
89558a41   Renato De Donato   datatype, provide...
274
275
                  this.logicalOperator = this.filters[0].logicalOperator;
                  this._fire();
0af843be   Renato De Donato   filters + alasql
276
277
278
279
280
281
              },
  
              getFilters : function() {
                  return this.filters;
              },
  
89558a41   Renato De Donato   datatype, provide...
282
283
284
285
286
              reset : function() {
                  this.fields = [];
                  this.filters = [{logicalOperator: "AND"}];
              },
  
e94f9513   Renato De Donato   filter ln
287
              _translate : function() {
79627d7e   Renato De Donato   controllet ln
288
                  this.$.addFilters.innerHTML = ln["expertAddFilters_" + ln["localization"]];
e94f9513   Renato De Donato   filter ln
289
290
291
292
293
                  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
294
295
296
297
298
              _fieldName : function(field) {
                  return field.substring(field.lastIndexOf(",")+1, field.length);
              },
  
              _showFiltersPanel : function() {
89558a41   Renato De Donato   datatype, provide...
299
300
  //                ? filter class hiddend & hover:
  
0af843be   Renato De Donato   filters + alasql
301
                  if(!this.show) {
89558a41   Renato De Donato   datatype, provide...
302
303
304
305
306
                      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
307
308
                  }
                  else {
89558a41   Renato De Donato   datatype, provide...
309
310
311
312
                      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
313
314
                  }
  
89558a41   Renato De Donato   datatype, provide...
315
316
                  this.fire('filters-controllet_show', {show: this.show});
  
0af843be   Renato De Donato   filters + alasql
317
318
319
                  this.show = !this.show;
              },
  
89558a41   Renato De Donato   datatype, provide...
320
321
322
323
324
325
326
              _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
327
              _addFilter : function() {
e94f9513   Renato De Donato   filter ln
328
329
                  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
330
331
332
                      var id = this.$.filter_operation.selectedItem.id;
                      var operation = this.operations[id];
  //                    var operation = this.$.filter_operation.value;
e94f9513   Renato De Donato   filter ln
333
                      var value = this.$.filter_value.value;
0af843be   Renato De Donato   filters + alasql
334
  
89558a41   Renato De Donato   datatype, provide...
335
336
337
338
339
  //                    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
340
  
e94f9513   Renato De Donato   filter ln
341
342
343
                      this.$.filter_field_menu.select(-1);
                      this.$.filter_operation_menu.select(-1);
                      this.$.filter_value.value = "";
39d5ab70   Renato De Donato   update filters
344
  
89558a41   Renato De Donato   datatype, provide...
345
346
347
                      this._fire();
  
                      this._renderFilters();
e94f9513   Renato De Donato   filter ln
348
                  }
0af843be   Renato De Donato   filters + alasql
349
350
351
352
353
              },
  
              _deleteFilter : function(e) {
                  var index = e.model.index;
  
89558a41   Renato De Donato   datatype, provide...
354
355
356
357
358
359
360
  //                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
361
  
89558a41   Renato De Donato   datatype, provide...
362
                  this._renderFilters();
0af843be   Renato De Donato   filters + alasql
363
364
              },
  
e94f9513   Renato De Donato   filter ln
365
              _getOperationlName: function(operation) {
f833bd4e   Renato De Donato   filter ln
366
367
368
369
370
371
372
373
374
375
                  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
376
377
              },
  
89558a41   Renato De Donato   datatype, provide...
378
379
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
  //            _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...
417
418
419
420
421
422
423
424
425
              _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
426
427
428
429
430
431
  
          });
  
      </script>
  
  </dom-module>