Blame view

controllets/data-table-controllet/data-table-controllet.html 18.8 KB
9fd4ca8a   Renato De Donato   new data table
1
2
3
4
5
6
  <link rel="import" href="../../bower_components/polymer/polymer.html" />
  
  <link rel="import" href="../../bower_components/paper-material/paper-material.html" />
  <link rel="import" href="../../bower_components/paper-input/paper-input.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">
706288a2   Renato De Donato   geojson incoming
7
  <link rel="import" href="../../bower_components/iron-icons/maps-icons.html">
9fd4ca8a   Renato De Donato   new data table
8
9
  <link rel="import" href="../../bower_components/paper-tooltip/paper-tooltip.html">
  
706288a2   Renato De Donato   geojson incoming
10
  <script type="text/javascript" src="../../bower_components/jsdatachecker/jsdatachecker.min.js"></script>
9fd4ca8a   Renato De Donato   new data table
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
  
  <dom-module id="data-table-controllet">
  
      <template>
  
          <style is="custom-style">
  
              paper-input {
                  max-width: 288px;
                  --paper-input-container-focus-color: #2196F3;
              }
  
              paper-icon-button{
                  height: 48px;
                  width: 48px;
                  padding: 0px;
                  --paper-icon-button-ink-color: #FFFFFF;
              }
  
              paper-icon-button:hover{
                  color: #2196F3;
              }
  
              paper-icon-button.clear {
                  width: 24px;
                  height: 24px;
                  padding: 0px 4px;
                  color: #F44336;
                  --paper-icon-button-ink-color: #FFFFFF;
              }
  
02e7d683   Renato De Donato   datatable
42
              paper-icon-button.order {
34789a0e   Renato De Donato   jsdatachecker ln,...
43
44
45
46
                  height: 40px;
                  width: 40px;
                  padding: 4px;
  
02e7d683   Renato De Donato   datatable
47
                  cursor: pointer;
0760b53c   Renato De Donato   warning ICONZ
48
49
50
              }
  
              paper-icon-button.warning {
34789a0e   Renato De Donato   jsdatachecker ln,...
51
52
53
                  height: 40px;
                  width: 40px;
                  padding: 4px;
0760b53c   Renato De Donato   warning ICONZ
54
                  color: #FFEB3B;
34789a0e   Renato De Donato   jsdatachecker ln,...
55
56
                  --paper-icon-button-ink-color: #FFEB3B;
  
0760b53c   Renato De Donato   warning ICONZ
57
                  cursor: help;
02e7d683   Renato De Donato   datatable
58
59
60
61
62
63
              }
  
              paper-icon-button.order:hover {
                 color: #FFFFFF;
              }
  
9fd4ca8a   Renato De Donato   new data table
64
65
66
67
              paper-tooltip {
                  --paper-tooltip-background: black;
              }
  
706288a2   Renato De Donato   geojson incoming
68
69
70
71
              iron-icon.icon {
                  color: #2196F3;
              }
  
9fd4ca8a   Renato De Donato   new data table
72
73
74
75
76
77
78
79
80
81
82
83
84
              #data_table_container {
                  height: 100%;
                  width: 100%;
              }
  
              #data_table_container * {
                  font-family: 'Roboto', 'Helvetica Neue', Helvetica, Arial, sans-serif;
                  font-size: 16px;
                  line-height: 24px;
              }
  
              #data_table_container #header {
                  background: #B6B6B6;
34789a0e   Renato De Donato   jsdatachecker ln,...
85
86
                  height: 40px;
                  padding: 4px;
9fd4ca8a   Renato De Donato   new data table
87
88
                  text-align: center;
                  font-weight: 700;
a1dedcfa   Renato De Donato   worning x gg
89
                  cursor: help;
9fd4ca8a   Renato De Donato   new data table
90
91
              }
  
34789a0e   Renato De Donato   jsdatachecker ln,...
92
93
94
95
              #data_table_container #header * {
                  line-height: 40px !important;
              }
  
9fd4ca8a   Renato De Donato   new data table
96
97
98
99
              #data_table_container table {
                  height: calc(100% - 96px);
                  width: 100%;
  
34789a0e   Renato De Donato   jsdatachecker ln,...
100
                  border-spacing: 0;
9fd4ca8a   Renato De Donato   new data table
101
102
103
104
105
106
107
108
109
110
111
112
113
114
              }
  
              #data_table_container tbody {
                  width: 100%;
                  display: block;
                  position: relative;
              }
  
              #data_table_container tr:nth-child(odd) {
                  background: #E0E0E0;
              }
  
              #data_table_container th,
              #data_table_container td{
34789a0e   Renato De Donato   jsdatachecker ln,...
115
116
                  height: 32px;
                  /*padding: 12px;*/
9fd4ca8a   Renato De Donato   new data table
117
                  text-align: center;
34789a0e   Renato De Donato   jsdatachecker ln,...
118
119
                  /*max-width: 256px;*/
                  /*min-width: 156px;*/
9fd4ca8a   Renato De Donato   new data table
120
121
122
123
124
125
                  overflow: hidden;
                  white-space: nowrap;
                  text-overflow: ellipsis;
                  width: 1%;
              }
  
34789a0e   Renato De Donato   jsdatachecker ln,...
126
127
128
129
130
131
              #data_table_container td {
                  font-size: 14px;
                  padding: 4px 12px;
                  max-width: calc(360px - 24px);
              }
  
9fd4ca8a   Renato De Donato   new data table
132
133
134
135
136
              #data_table_container th {
                  background: #2196F3;
                  color: #FFFFFF;
                  font-weight: 700;
                  cursor: help;
34789a0e   Renato De Donato   jsdatachecker ln,...
137
138
139
140
141
142
143
                  border-right: 2px solid #FFFFFF;
                  height: 40px;
                  padding: 4px 12px;
              }
  
              #data_table_container tr :nth-last-child(2) {
                  border-right: 0;
f833bd4e   Renato De Donato   filter ln
144
145
146
147
148
              }
  
              #data_table_container th,
              #data_table_container th * {
                  line-height: 22px;/**/
0760b53c   Renato De Donato   warning ICONZ
149
150
151
152
              }
  
              #data_table_container th .th_label {
                  display: inline-block;
34789a0e   Renato De Donato   jsdatachecker ln,...
153
                  /*max-width: calc(100% - 48px - 8px);*/
0760b53c   Renato De Donato   warning ICONZ
154
                  vertical-align: middle;
0760b53c   Renato De Donato   warning ICONZ
155
156
157
                  overflow: hidden;
                  white-space: nowrap;
                  text-overflow: ellipsis;
f833bd4e   Renato De Donato   filter ln
158
                  line-height: 24px;/**/
34789a0e   Renato De Donato   jsdatachecker ln,...
159
                  max-width: calc(360px - 114px);
9fd4ca8a   Renato De Donato   new data table
160
161
              }
  
9fd4ca8a   Renato De Donato   new data table
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
187
188
189
190
191
192
193
194
195
196
197
              #data_table_container #footer {
                  width: 100%;
                  height: 48px;
                  background: #B6B6B6;
  
                  display: flex;
                  flex-direction: row;
              }
  
              #data_table_container .footer_block {
                  height: 24px;
                  padding: 12px 8px;
                  text-align: right;
              }
  
              #data_table_container .footer_block:nth-child(1) {
                  width: 30%;
                  overflow: hidden;
                  white-space: nowrap;
                  text-overflow: ellipsis;
              }
  
              #data_table_container .footer_block:nth-child(2) {
                  width: 40%;
                  height: 48px;
                  padding: 0px 8px;
                  text-align: center;
              }
  
              #data_table_container .footer_block:nth-child(3) {
                  width: 30%;
                  height: 40px;
                  padding: 4px 8px;
                  text-align: left;
              }
  
02e7d683   Renato De Donato   datatable
198
              #data_table_container br {
9fd4ca8a   Renato De Donato   new data table
199
200
201
202
203
                  display: block;
                  margin-top: 8px;
                  content: " ";
              }
  
02e7d683   Renato De Donato   datatable
204
              #data_table_container p {
9fd4ca8a   Renato De Donato   new data table
205
206
207
208
                  margin: 0;
                  padding: 0;
              }
  
02e7d683   Renato De Donato   datatable
209
              #data_table_container p .type{
9fd4ca8a   Renato De Donato   new data table
210
211
212
                  font-weight: 700;
              }
  
02e7d683   Renato De Donato   datatable
213
              #data_table_container p .warning{
9fd4ca8a   Renato De Donato   new data table
214
215
216
217
218
219
220
221
                  font-weight: 700;
                  color: #F44336;
              }
  
          </style>
  
          <paper-material id="data_table_container" elevation="5">
  
0760b53c   Renato De Donato   warning ICONZ
222
              <div id="header">
0760b53c   Renato De Donato   warning ICONZ
223
224
225
                  <template is="dom-if" if={{hasWarnings}}>
                      <paper-icon-button class="warning" icon="warning"></paper-icon-button>
                  </template>
34789a0e   Renato De Donato   jsdatachecker ln,...
226
                  <span id="selected_data"></span>
0760b53c   Renato De Donato   warning ICONZ
227
              </div>
9fd4ca8a   Renato De Donato   new data table
228
  
a1dedcfa   Renato De Donato   worning x gg
229
230
231
232
233
234
235
236
237
238
              <paper-tooltip id="tooltip_wornings" for="header" offset="56">
                  <template is="dom-repeat" items="{{fields}}">
                      <template is="dom-if" if={{item.errorsDescription.length}}>
                          <p>
                              <span class="warning">{{_warning()}}:</span> {{item.errorsDescription}}
                          </p>
                      </template>
                  </template>
              </paper-tooltip>
  
9fd4ca8a   Renato De Donato   new data table
239
240
241
242
              <table>
                  <tbody id="tbody">
                      <tr>
                          <template is="dom-repeat" items="{{fields}}">
02e7d683   Renato De Donato   datatable
243
                              <th id="id_{{index}}">
34789a0e   Renato De Donato   jsdatachecker ln,...
244
  
0760b53c   Renato De Donato   warning ICONZ
245
246
247
                                  <template is="dom-if" if={{item.errorsDescription.length}}>
                                      <paper-icon-button class="warning" icon="warning"></paper-icon-button>
                                  </template>
34789a0e   Renato De Donato   jsdatachecker ln,...
248
                                  <div class="th_label">{{item.name}}</div>
02e7d683   Renato De Donato   datatable
249
250
                                  <paper-icon-button id="{{index}}" class="order" on-click="_order" icon="unfold-more"></paper-icon-button>
                              </th>
9fd4ca8a   Renato De Donato   new data table
251
252
                          </template>
                      </tr>
02e7d683   Renato De Donato   datatable
253
                      <template is="dom-repeat" items="{{shownData}}">
9fd4ca8a   Renato De Donato   new data table
254
255
                          <tr>
                              <template is="dom-repeat" items="{{_toArray(item)}}">
706288a2   Renato De Donato   geojson incoming
256
257
258
259
260
261
262
263
264
265
266
                                  <template is="dom-if" if={{!_isObject(item)}}>
                                      <td title="{{item.value}}">{{item.value}}</td>
                                  </template>
                                  <template is="dom-if" if={{_isObject(item)}}>
                                      <template is="dom-if" if={{_isGEOJSON(item)}}>
                                          <td title="GEOJSON"><iron-icon icon="maps:map" class="icon"></iron-icon></td>
                                      </template>
                                      <template is="dom-if" if={{!_isGEOJSON(item)}}>
                                          <td title="OBJECT"><iron-icon icon=":help-outline" class="icon"></iron-icon></td>
                                      </template>
                                  </template>
9fd4ca8a   Renato De Donato   new data table
267
268
269
270
271
272
273
                              </template>
                          </tr>
                      </template>
                  </tbody>
              </table>
  
              <template is="dom-repeat" items="{{fields}}">
02e7d683   Renato De Donato   datatable
274
                  <paper-tooltip for="{{_fieldId(index)}}" offset="8">
9fd4ca8a   Renato De Donato   new data table
275
276
                      <p>
                          <span class="type">{{_type()}}:</span> {{item.type}}
e136d5a6   Renato De Donato   filter bug fix
277
278
279
                          <template is="dom-if" if={{item.subtype}}>
                              ({{item.subtype}})
                          </template>
9fd4ca8a   Renato De Donato   new data table
280
281
282
283
284
285
286
287
288
289
                          <template is="dom-if" if={{item.errorsDescription.length}}>
                              <br/>
                              <span class="warning">{{_warning()}}:</span> {{item.errorsDescription}}
                          </template>
                      </p>
                  </paper-tooltip>
              </template>
  
              <div id="footer">
                  <div class="footer_block">
02e7d683   Renato De Donato   datatable
290
                      <span id="showing"></span> {{shownPrev}} <span id="to"></span> {{shownNext}} <span id="of"></span> {{length}} <span id="rows"></span>
9fd4ca8a   Renato De Donato   new data table
291
292
293
294
295
296
                  </div>
                  <div class="footer_block">
                      <paper-icon-button id="slider_chevron_left" class="chevron-left" on-click="_onPrevClick" icon="chevron-left"></paper-icon-button>
                      <paper-icon-button id="slider_chevron_right" class="chevron-right" on-click="_onNextClick" icon="chevron-right"></paper-icon-button>
                  </div>
                  <div class="footer_block">
02e7d683   Renato De Donato   datatable
297
                      <paper-input id="filter" value={{filter}} no-label-float>
9fd4ca8a   Renato De Donato   new data table
298
                          <iron-icon class="search" icon="search" prefix></iron-icon>
02e7d683   Renato De Donato   datatable
299
                          <paper-icon-button class="clear" suffix on-click="_clearInput" icon="clear"></paper-icon-button>
9fd4ca8a   Renato De Donato   new data table
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
                      </paper-input>
                  </div>
              </div>
  
          </paper-material>
  
      </template>
  
      <script>
  
          Polymer({
  
              is : 'data-table-controllet',
  
              properties : {
  
                  data : {
                      type  : Array,
                      value : []
                  },
  
02e7d683   Renato De Donato   datatable
321
322
323
324
                  filter : {
                      type  : String,
                      value : "",
                      observer : '_filter'
9fd4ca8a   Renato De Donato   new data table
325
326
327
328
329
                  }
  
              },
  
              ready : function() {
02e7d683   Renato De Donato   datatable
330
                  this.step = 100;
9fd4ca8a   Renato De Donato   new data table
331
332
333
              },
  
              attached : function(){
70b7a5e5   Renato De Donato   table for petta
334
335
                  $(this.$.tbody).perfectScrollbar();
  
9fd4ca8a   Renato De Donato   new data table
336
337
338
339
340
                  this._resize();
                  var that = this;
                  window.addEventListener("resize", function() { that._resize(); });
  
                  this._translate();
a1bb5753   Renato De Donato   table for petta
341
342
343
  
                  if(this.data.length > 0)
                      this.setData(this.data);
9fd4ca8a   Renato De Donato   new data table
344
345
346
347
348
349
350
351
352
353
              },
  
              _translate : function(){
                  this.$.selected_data.innerHTML = ln["selectedData_" + ln["localization"]];
  
                  this.$.showing.innerHTML = ln["showing_" + ln["localization"]];
                  this.$.to.innerHTML = ln["to_" + ln["localization"]];
                  this.$.of.innerHTML = ln["of_" + ln["localization"]];
                  this.$.rows.innerHTML = ln["rows_" + ln["localization"]];
  
02e7d683   Renato De Donato   datatable
354
                  this.$.filter.setAttribute("label", ln["search_" + ln["localization"]]);
9fd4ca8a   Renato De Donato   new data table
355
356
357
358
359
360
              },
  
              _type : function() {return ln["type_" + ln["localization"]];},
              _warning : function() {return ln["warning_" + ln["localization"]];},
  
              setData : function(data) {
9fd4ca8a   Renato De Donato   new data table
361
                  var converter = new DataTypeConverter();
34789a0e   Renato De Donato   jsdatachecker ln,...
362
                  var result = converter.inferJsonDataType(data, ["*"], { language: ln["localization"] } );
9fd4ca8a   Renato De Donato   new data table
363
364
                  result = converter.cast(result);
                  this.fields = ArrayUtils.toFieldsArray(result.types);
9fd4ca8a   Renato De Donato   new data table
365
                  this.data = result.dataset;
02e7d683   Renato De Donato   datatable
366
367
368
369
370
371
372
373
374
375
376
  
                  this.filter = "";
                  $(".order").attr("icon", "unfold-more");
  
                  this.prev = 1;
                  this.next = this.step;
                  this.length = this.data.length;
  
                  this.shownPrev = Math.min(this.prev, this.length);
                  this.shownNext = Math.min(this.next, this.length);
                  this.shownData = this.data.slice(this.prev-1, this.next);
4bd2f9c2   Renato De Donato   data-table
377
  
0760b53c   Renato De Donato   warning ICONZ
378
                  this.hasWarnings = this._hasWarnings();
a1dedcfa   Renato De Donato   worning x gg
379
  
899e9758   Renato De Donato   geojson <3
380
                  this.async(function() {
0760b53c   Renato De Donato   warning ICONZ
381
382
383
384
385
386
387
                      if(this.hasWarnings)
                          this.$.tooltip_wornings.show();
                      else
                          this.$.tooltip_wornings.hide();
                  }, 1);
  
                  this._resize();
4bd2f9c2   Renato De Donato   data-table
388
389
390
391
              },
  
              reset : function(){
                  this.setData([]);
a1bb5753   Renato De Donato   table for petta
392
                  $(this.$.tbody).animate({ scrollTop: 0}, 0);
02e7d683   Renato De Donato   datatable
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
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
              },
  
              _onPrevClick : function(){
                  if(this.prev != 1) {
                      this.prev -= this.step;
                      this.next -= this.step;
  
                      this.shownPrev = Math.min(this.prev, this.length);
                      this.shownNext = Math.min(this.next, this.length);
                      this.shownData = this.data.slice(this.prev - 1, this.next);
                  }
                  $(this.$.tbody).animate({ scrollTop: 0}, 0);
              },
  
              _onNextClick : function(){
                  if(this.next < this.length) {
                      this.prev += this.step;
                      this.next += this.step;
  
                      this.shownPrev = Math.min(this.prev, this.length);
                      this.shownNext = Math.min(this.next, this.length);
                      this.shownData = this.data.slice(this.prev - 1, this.next);
                  }
                  $(this.$.tbody).animate({ scrollTop: 0}, 0);
              },
  
              _filter : function() {
                  this.debounce('_filter', function () {
                      if(this.data.length) {
                          var filter = this.filter.toLowerCase();
  
                          if(filter == "")
                              this.shownData = this.data
                          else {
                              var keys = Object.keys(this.data[0]);
                              this.shownData = this.data.filter(function (el) {
                                  var values = keys.map(function (key) {
                                      return el[key];
                                  });
                                  for (var i in values)
                                      if (values[i] && String(values[i]).toLowerCase().indexOf(filter) > -1)
                                          return true;
                                  return false;
                              });
                          }
  
                          this.prev = 1;
                          this.next = this.step;
                          this.length = this.shownData.length;
  
                          this.shownPrev = Math.min(this.prev, this.length);
                          this.shownNext = Math.min(this.next, this.length);
                          this.shownData = this.shownData.slice(this.prev - 1, this.next);
  
                          $(this.$.tbody).animate({ scrollTop: 0}, 0);
                      }
                  }, 300);
              },
  
              _clearInput : function() {
                  this.$.filter.value = "";
              },
  
              _order : function(e) {
                  t = $(e.target).parents("paper-icon-button")[0];
  
                  var icon = t.getAttribute("icon");
                  var id = t.getAttribute("id");
                  var field = this.fields[id];
                  var reverse = false;
  
                  if(icon.indexOf("unfold-more") > -1){
                      t.setAttribute("icon", "arrow-drop-up");
                  }
                  else if(icon.indexOf("arrow-drop-up") > -1){
                      t.setAttribute("icon", "arrow-drop-down");
                      reverse = true;
                  }
                  else if(icon.indexOf("arrow-drop-down") > -1){
                      t.setAttribute("icon", "arrow-drop-up");
                  }
  
  
                  if(field.type == "NUMBER")
  //                    this.data = this.data.sort(this._sort_by(field.name, reverse, parseInt));
                      this.data = this.data.sort(this._sort_by(field.name, reverse, function(a){return (isNaN(a) ? -Number.MAX_VALUE : a)}));
                  else
                      this.data = this.data.sort(this._sort_by(field.name, reverse, function(a){return (a ? a.toLowerCase() : "")}));
                  this._filter();
              },
  
              _sort_by : function(field, reverse, primer){
02e7d683   Renato De Donato   datatable
485
486
487
488
489
490
491
492
493
                  var key = primer ?
                          function(x) {return primer(x[field])} :
                          function(x) {return x[field]};
  
                  reverse = !reverse ? 1 : -1;
  
                  return function (a, b) {
                      return a = key(a), b = key(b), reverse * ((a > b) - (b > a));
                  }
9fd4ca8a   Renato De Donato   new data table
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
              },
  
              _toArray: function(obj) {
                  return Object.keys(obj).map(function(key) {
                      return {
                          key: key,
                          value: obj[key]
                      };
                  });
              },
  
              _fieldId: function(index) {
                  return "id_" + index;
              },
  
0760b53c   Renato De Donato   warning ICONZ
509
510
511
512
513
514
515
              _hasWarnings: function() {
                  for (var i in this.fields)
                      if (this.fields[i].errorsDescription.length)
                          return true;
                  return false;
              },
  
706288a2   Renato De Donato   geojson incoming
516
517
518
519
520
521
522
523
524
525
526
527
528
              _isObject: function(item) {
                  if(item.value instanceof Array)
                      return false;
                  if(item.value instanceof Object)
                      return true;
                  return false;
              },
  
              _isGEOJSON: function(item) {
                  var dt = new DataTypeConverter();
                  return (dt.inferDataSubTypeOfValue(item.value) && dt.inferDataSubTypeOfValue(item.value).name == DataTypeConverter.SUBTYPES.GEOJSON.name);
              },
  
9fd4ca8a   Renato De Donato   new data table
529
530
531
532
533
534
              _resize : function(){
                  this.async(function() {
                      var h = $(this.$.data_table_container).height() - 96;
                      var w = $(this.$.data_table_container).width();
                      $(this.$.tbody).width(w).height(h);
                      $(this.$.tbody).perfectScrollbar('update');
899e9758   Renato De Donato   geojson <3
535
                  }, 0);
9fd4ca8a   Renato De Donato   new data table
536
537
538
539
540
541
542
              }
  
          });
  
      </script>
  
  </dom-module>