Blame view

controllets/datalet-selection-controllet/datalet-selection-controllet.html 34.8 KB
a31f0660   root   sevc-controllet i...
1
2
3
4
5
6
7
8
9
10
11
12
13
  <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-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">
  
  <link rel="import" href="../../bower_components/paper-input/paper-textarea.html">
3c812cc9   Renato De Donato   title-desciption ...
14
  <link rel="import" href="../../bower_components/paper-input/paper-input.html">
a31f0660   root   sevc-controllet i...
15
16
17
  
  <link rel="import" href="../../bower_components/paper-button/paper-button.html">
  
57ef9bf4   Renato De Donato   labels + info
18
19
  <link rel="import" href="../../bower_components/paper-dialog/paper-dialog.html">
  
a31f0660   root   sevc-controllet i...
20
21
  <link rel="import" href="../items-vslider-controllet/items-vslider-controllet.html" />
  
0f6424fe   root   update new data-s...
22
  <script src="../../../DEEPCLIENT/js/deepClient.js"></script>
a31f0660   root   sevc-controllet i...
23
24
25
26
27
28
  
  <dom-module id="datalet-selection-controllet">
  
      <template>
  
          <style is="custom-style">
e0e4a976   Renato De Donato   data-sevc-control...
29
30
31
32
33
              :host {
              --paper-dropdown-menu-icon: {
                   color: #2196F3;
               };
              }
a31f0660   root   sevc-controllet i...
34
35
36
37
38
  
              #datalet_selection_container {
                  display: flex;
                  font-family: 'Roboto', 'Helvetica Neue', Helvetica, Arial, sans-serif;
                  font-size: 16px;
0f6424fe   root   update new data-s...
39
                  margin-top: 8px;
a31f0660   root   sevc-controllet i...
40
41
              }
  
3d8cde48   Renato De Donato   safari bug fix
42
43
              #items_vslider_controllet {
                  position: relative;
58a818e7   Renato De Donato   safari bug fix
44
                  min-width: 172px;
3d8cde48   Renato De Donato   safari bug fix
45
46
              }
  
a31f0660   root   sevc-controllet i...
47
48
49
50
              #datalet_selection_inputs {
                  position: relative;
                  height: 100vh;
                  margin-left: 32px;
e0e4a976   Renato De Donato   data-sevc-control...
51
                  min-width: 258px;
a31f0660   root   sevc-controllet i...
52
53
54
55
56
57
              }
  
              #datalet_selection_labels {
                  position: relative;
                  height: 100vh;
                  margin-left: 32px;
e0e4a976   Renato De Donato   data-sevc-control...
58
                  min-width: 258px;
a31f0660   root   sevc-controllet i...
59
60
61
62
63
64
65
66
67
68
69
70
              }
  
              #datalet_selection_column {
                  position: relative;
                  width: 100%;
                  margin-left: 32px;
              }
  
              #datalet_selection_datalet {
                  position: relative;
                  height: 100vh;
                  width: 100%;
a31f0660   root   sevc-controllet i...
71
72
73
74
75
76
77
78
              }
  
              #datalet_selection_datalet_placeholder {
                  padding: 16px;
              }
  
              .inputs{
                  position: relative;
a31f0660   root   sevc-controllet i...
79
80
              }
  
98d9d8a5   Renato De Donato   filters+groupby
81
82
83
84
85
86
87
88
89
90
91
              .input_header {
                  height: 32px;
                  padding-top: 16px;
                  text-align: center;
                  font-weight: 700;
                  background-color: #B6B6B6;
              }
  
              #expert_container {
                  display: none;
              }
a31f0660   root   sevc-controllet i...
92
  
98d9d8a5   Renato De Donato   filters+groupby
93
94
              #expert_header {
                  display: none;
a31f0660   root   sevc-controllet i...
95
  
e0e4a976   Renato De Donato   data-sevc-control...
96
97
                  height: 32px;
                  padding-top: 16px;
98d9d8a5   Renato De Donato   filters+groupby
98
                  margin-top: 8px;
a31f0660   root   sevc-controllet i...
99
100
                  text-align: center;
                  font-weight: 700;
98d9d8a5   Renato De Donato   filters+groupby
101
102
103
104
105
106
107
108
109
110
111
112
113
                  color: #00BCD4;
                  cursor: pointer;
              }
  
              .field_nema {
                  height: 40px;
                  padding-top: 8px;
  
                  margin-top: 8px;
                  padding-left: 16px;
                  font-weight: 700;
                  color: #2196F3;
                  background-color: #E0E0E0;
a31f0660   root   sevc-controllet i...
114
115
116
              }
  
              .info_button {
a31f0660   root   sevc-controllet i...
117
                  position: absolute;
e0e4a976   Renato De Donato   data-sevc-control...
118
                  top: 18px;
a31f0660   root   sevc-controllet i...
119
120
121
                  right: 0px;
              }
  
3c812cc9   Renato De Donato   title-desciption ...
122
              paper-input {
e0e4a976   Renato De Donato   data-sevc-control...
123
                  display: inline-block;
a31f0660   root   sevc-controllet i...
124
                  height: 48px;
e0e4a976   Renato De Donato   data-sevc-control...
125
126
127
128
                  /*padding: 0px 8px;*/
                  width: 210px;
                  padding-left: 8px;
                  padding-bottom: 8px;
a31f0660   root   sevc-controllet i...
129
130
131
                  --paper-input-container-focus-color: #2196F3;
              }
  
3c812cc9   Renato De Donato   title-desciption ...
132
133
134
135
136
              paper-input.base_input {
                  width: 242px;
              }
  
              paper-textarea {
3c812cc9   Renato De Donato   title-desciption ...
137
138
139
140
141
142
                  width: 242px;
                  padding-left: 8px;
                  padding-bottom: 4px;
                  --paper-input-container-focus-color: #2196F3;
              }
  
a31f0660   root   sevc-controllet i...
143
              paper-dropdown-menu {
a31f0660   root   sevc-controllet i...
144
                  height: 48px;
e0e4a976   Renato De Donato   data-sevc-control...
145
                  width: 210px;;
e0e4a976   Renato De Donato   data-sevc-control...
146
147
                  padding-left: 8px;
                  padding-bottom: 8px;
a31f0660   root   sevc-controllet i...
148
149
150
151
152
153
154
155
156
                  --paper-input-container-focus-color: #2196F3;
              }
  
              paper-item.iron-selected {
                  background-color: #2196F3;
                  color: #FFFFFF;
              }
  
              paper-icon-button {
e0e4a976   Renato De Donato   data-sevc-control...
157
                  color: #2196F3;
a31f0660   root   sevc-controllet i...
158
                  --paper-icon-button-ink-color: #2196F3;
e0e4a976   Renato De Donato   data-sevc-control...
159
                  margin: 0px;
a31f0660   root   sevc-controllet i...
160
161
162
              }
  
              paper-button {
a31f0660   root   sevc-controllet i...
163
164
165
166
                  position: absolute;
                  bottom: 16px;
                  right: 11px;
  
a31f0660   root   sevc-controllet i...
167
168
169
170
171
172
173
174
175
176
                  height: 48px;
                  width: 172px;
                  background-color: #00BCD4;
                  color: white;
                  font-weight: 700;
                  padding: 16px;
              }
  
              paper-button:hover {
                  background-color: #00AABF;
3c812cc9   Renato De Donato   title-desciption ...
177
178
179
180
  
                  box-shadow: 0px 8px 12px #888;
                  -webkit-box-shadow: 0px 8px 12px #888;
                  -moz-box-shadow: 0px 8px 12px #888;
a31f0660   root   sevc-controllet i...
181
              }
0f6424fe   root   update new data-s...
182
183
184
185
  
              paper-button[disabled] {
                  background-color: #B6B6B6;
              }
57ef9bf4   Renato De Donato   labels + info
186
  
79ec939f   Renato De Donato   info position + a...
187
              #dialog_info_input {
57ef9bf4   Renato De Donato   labels + info
188
189
                  border: 2px solid #2196F3;
                  background-color: #E0E0E0;
3c812cc9   Renato De Donato   title-desciption ...
190
                  min-width: 248px;
57ef9bf4   Renato De Donato   labels + info
191
              }
a31f0660   root   sevc-controllet i...
192
193
          </style>
  
0f6424fe   root   update new data-s...
194
          <iron-ajax id="selectedDatalet_request" on-response="_handleSelectedDatalet"></iron-ajax>
a31f0660   root   sevc-controllet i...
195
196
  
          <div id="datalet_selection_container">
3d8cde48   Renato De Donato   safari bug fix
197
198
199
200
  
              <div id="items_vslider_controllet">
                  <items-vslider-controllet id="vslider" datalets-list-url={{dataletsListUrl}} preselected-datalet={{preselectedDatalet}}></items-vslider-controllet>
              </div>
a31f0660   root   sevc-controllet i...
201
  
a31f0660   root   sevc-controllet i...
202
              <paper-material id="datalet_selection_inputs" elevation="5">
6d2a2a1e   Andrea Petta   language handling
203
                  <div class="input_header"><span id="inputs"></span></div>
e0e4a976   Renato De Donato   data-sevc-control...
204
                  <template is="dom-repeat" items="{{inputs}}" index-as="ddl_index">
a31f0660   root   sevc-controllet i...
205
                      <div class="inputs">
ac237fdd   Renato De Donato   controllet ln
206
                          <paper-dropdown-menu id={{ddl_index}} label={{_getLabelName(item.name)}}>
a31f0660   root   sevc-controllet i...
207
                              <paper-menu class="dropdown-content">
e0e4a976   Renato De Donato   data-sevc-control...
208
                                  <template is="dom-repeat" items={{fields}}>
0b7cbd33   Renato De Donato   title-desciption
209
                                      <paper-item id={{index}} on-tap="_addInput">{{_fieldName(item)}}</paper-item>
59100bec   Renato De Donato   localization + ba...
210
                                      <!--{{_fieldName(item)}}-->
a31f0660   root   sevc-controllet i...
211
212
213
                                  </template>
                              </paper-menu>
                          </paper-dropdown-menu>
e0e4a976   Renato De Donato   data-sevc-control...
214
                          <div class="info_button">
ac237fdd   Renato De Donato   controllet ln
215
                              <paper-icon-button id={{item.name}} on-click="_showInfo" icon="info-outline" title="{{_getLabelName(item.name)}} info"></paper-icon-button>
e0e4a976   Renato De Donato   data-sevc-control...
216
                          </div>
a31f0660   root   sevc-controllet i...
217
218
                      </div>
                  </template>
98d9d8a5   Renato De Donato   filters+groupby
219
220
221
  
                  <!-- EXPERT MODE EXPERT MODE EXPERT MODE EXPERT MODE EXPERT MODE EXPERT MODE EXPERT MODE EXPERT MODE -->
  
39d5ab70   Renato De Donato   update filters
222
                  <div id="expert_header" on-click="_showExpertMode"><span id="expert">GROUP BY</span></div>
98d9d8a5   Renato De Donato   filters+groupby
223
224
225
226
227
228
229
230
231
232
233
234
  
                  <div id="expert_container">
  
                      <div class="inputs">
                          <paper-dropdown-menu id="group_by" label="GROUP BY">
                              <paper-menu class="dropdown-content">
                                  <template is="dom-repeat" items={{selectedFields}}>
                                      <paper-item id={{index}} on-tap="_showGroupedFields">{{_fieldName(item)}}</paper-item>
                                  </template>
                              </paper-menu>
                          </paper-dropdown-menu>
                          <div class="info_button">
e31934c0   Renato De Donato   group by bug fix
235
                              <paper-icon-button id="gb" on-click="_addOrder" icon="unfold-more" title=""></paper-icon-button>
98d9d8a5   Renato De Donato   filters+groupby
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
                          </div>
                      </div>
  
                      <template is="dom-repeat" items="{{groupedFields}}">
                          <div class="inputs">
                              <paper-dropdown-menu id="calculate_{{index}}" label="CALCULATE">
                                  <paper-menu class="dropdown-content">
                                      <paper-item on-tap="_addGroupByInput">COUNT of {{_fieldName(item)}}</paper-item>
                                      <paper-item on-tap="_addGroupByInput">SUM of {{_fieldName(item)}}</paper-item>
                                      <paper-item on-tap="_addGroupByInput">MIN of {{_fieldName(item)}}</paper-item>
                                      <paper-item on-tap="_addGroupByInput">MAX of {{_fieldName(item)}}</paper-item>
                                      <paper-item on-tap="_addGroupByInput">AVG of {{_fieldName(item)}}</paper-item>
                                      <paper-item on-tap="_addGroupByInput">FIRST of {{_fieldName(item)}}</paper-item>
                                      <paper-item on-tap="_addGroupByInput">LAST of {{_fieldName(item)}}</paper-item>
                                  </paper-menu>
                              </paper-dropdown-menu>
                              <div class="info_button">
e31934c0   Renato De Donato   group by bug fix
253
                                  <paper-icon-button id={{_fieldName(item)}} on-click="_addOrder" icon="unfold-more" title=""></paper-icon-button>
98d9d8a5   Renato De Donato   filters+groupby
254
255
256
257
258
259
260
261
                              </div>
                          </div>
                      </template>
  
                  </div>
  
                  <!-- EXPERT MODE EXPERT MODE EXPERT MODE EXPERT MODE EXPERT MODE EXPERT MODE EXPERT MODE EXPERT MODE -->
  
a31f0660   root   sevc-controllet i...
262
263
264
              </paper-material>
  
              <paper-material id="datalet_selection_labels" elevation="5">
6d2a2a1e   Andrea Petta   language handling
265
                  <div class="input_header"><span id="baseInfo"></span></div>
3c812cc9   Renato De Donato   title-desciption ...
266
267
  
                  <div class="inputs">
ac237fdd   Renato De Donato   controllet ln
268
                      <paper-input id="base_title" maxlength="32" class="base_input"></paper-input>
3c812cc9   Renato De Donato   title-desciption ...
269
270
271
                  </div>
  
                  <div class="inputs">
ac237fdd   Renato De Donato   controllet ln
272
                      <paper-textarea id="base_description" maxlength="100" class="base_input"></paper-textarea>
3c812cc9   Renato De Donato   title-desciption ...
273
274
                  </div>
  
6d2a2a1e   Andrea Petta   language handling
275
                  <div class="input_header"><span id="layouts"></span></div>
3c812cc9   Renato De Donato   title-desciption ...
276
  
a31f0660   root   sevc-controllet i...
277
278
                  <template is="dom-repeat" items="{{labels}}" index-as="index">
                      <div class="inputs">
ac237fdd   Renato De Donato   controllet ln
279
                          <paper-input label={{_getLabelName(item.name)}}></paper-input>
e0e4a976   Renato De Donato   data-sevc-control...
280
                          <div class="info_button">
ac237fdd   Renato De Donato   controllet ln
281
                              <paper-icon-button id={{item.name}} on-click="_showInfo" icon="info-outline" title="{{_getLabelName(item.name)}} info"></paper-icon-button>
a31f0660   root   sevc-controllet i...
282
                          </div>
a31f0660   root   sevc-controllet i...
283
284
285
286
287
288
                      </div>
                  </template>
              </paper-material>
  
  
              <div id="datalet_selection_column">
e0e4a976   Renato De Donato   data-sevc-control...
289
  
a31f0660   root   sevc-controllet i...
290
                  <paper-material id="datalet_selection_datalet" elevation="5">
6d2a2a1e   Andrea Petta   language handling
291
                      <div class="input_header"><span id="dataletPreview"></span></div>
a31f0660   root   sevc-controllet i...
292
293
294
295
                      <div id="datalet_selection_datalet_placeholder"></div>
  
                  </paper-material>
  
6d2a2a1e   Andrea Petta   language handling
296
                  <paper-button id="add_button" disabled raised on-click="_addDatalet"></paper-button>
a31f0660   root   sevc-controllet i...
297
298
299
  
              </div>
  
79ec939f   Renato De Donato   info position + a...
300
              <paper-dialog id="dialog_info_input">
57ef9bf4   Renato De Donato   labels + info
301
302
303
304
                  <h2 id="dialog_name"></h2>
                  <p id="dialog_description"></p>
              </paper-dialog>
  
a31f0660   root   sevc-controllet i...
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
          </div>
  
      </template>
  
      <script>
  
          Polymer({
  
              is : 'datalet-selection-controllet',
  
              properties : {
  
                  deepUrl : {
                      type : String,
                      value : undefined
                  },
  
                  dataletsListUrl : {
                      type : String,
                      value : undefined
                  },
  
                  selectedDatalet : {
                      type  : String,
                      value : undefined
                  },
  
e0e4a976   Renato De Donato   data-sevc-control...
332
333
334
335
336
                  preselectedDatalet : {
                      type  : String,
                      value : undefined
                  },
  
d2da5141   Renato De Donato   async 0
337
338
339
340
341
342
343
344
345
346
                  loadPreview : {
                      type :  Boolean,
                      value : false
                  },
  
                  type : {
                      type : String,
                      value : undefined
                  },
  
a31f0660   root   sevc-controllet i...
347
348
349
350
351
352
353
354
355
356
                  inputs : {
                      type : Array,
                      value : []
                  },
  
                  labels : {
                      type : Array,
                      value : []
                  },
  
98d9d8a5   Renato De Donato   filters+groupby
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
                  filters : {
                      type : Array,
                      value : []
                  },
  
                  aggregators : {
                      type : Array,
                      value : []
                  },
  
                  orders : {
                      type : Array,
                      value : []
                  },
  
a31f0660   root   sevc-controllet i...
372
373
                  fields : {
                      type : Array,
0f6424fe   root   update new data-s...
374
375
376
377
378
379
380
381
                      value : []
                  },
  
                  selectedFields : {
                      type : Array,
                      value : []
                  },
  
98d9d8a5   Renato De Donato   filters+groupby
382
383
384
385
386
                  groupedFields : {
                      type : Array,
                      value : []
                  },
  
e8219f9a   Renato De Donato   datalet-mod
387
388
389
390
391
                  dataletPreset : {
                      type  : Object,
                      value : []
                  },
  
e0e4a976   Renato De Donato   data-sevc-control...
392
393
394
395
  //                selectableFields : {
  //                    type : Array,
  //                    value : []
  //                },
a31f0660   root   sevc-controllet i...
396
397
398
  
                  dataUrl : {
                      type  : String,
0f6424fe   root   update new data-s...
399
                      value : undefined
e0e4a976   Renato De Donato   data-sevc-control...
400
401
                  },
  
57ef9bf4   Renato De Donato   labels + info
402
403
404
405
406
                  params:{
                      type: Object,
                      value: undefined
                  },
  
98d9d8a5   Renato De Donato   filters+groupby
407
408
409
410
411
                  expert : {
                      type  : Boolean,
                      value : false
                  },
  
e0e4a976   Renato De Donato   data-sevc-control...
412
413
414
                  modify : {
                      type  : Boolean,
                      value : false
a31f0660   root   sevc-controllet i...
415
416
417
418
419
                  }
  
              },
  
              listeners: {
4b79b3c8   Renato De Donato   datalet-selection...
420
                  'items-vslider-controllet_selected-datalet': '_selectDatalet',
0f6424fe   root   update new data-s...
421
  //                'tree-view-controllet_selected-fields': '_updateSelectedFields'
b4accc86   Renato De Donato   datalet improved
422
                  'change': '_paramsChanged'
a31f0660   root   sevc-controllet i...
423
424
              },
  
98d9d8a5   Renato De Donato   filters+groupby
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
              _showExpertMode : function() {
                  if(!this.expert) {
                      this.$.expert_header.style.color = "#000000";
                      this.$.expert_header.style.background = "#B6B6B6";
                      this.$.expert_container.style.display = "block";
                  }
                  else {
                      this.$.expert_header.style.color = "#00BCD4";
                      this.$.expert_header.style.background = "#FFFFFF";
                      this.$.expert_container.style.display = "none";
                  }
  
                  this.expert = !this.expert;
              },
  
              _showGroupedFields : function(e) {
                  var index = e.target.id;
98d9d8a5   Renato De Donato   filters+groupby
442
443
                  var temp = [];
  
e31934c0   Renato De Donato   group by bug fix
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
  //                var isSelected = false;
  //                for (var i = 0; i < this.selectedFields.length; i++) {
  //                    if (this.selectedFields[i]) {
  //                        if (this.selectedFields[i].indexOf(this.fields[index]) > -1) {
  //                            isSelected = true;
  //                        }
  //                        else {
  //                            temp.push(this.selectedFields[i]);
  //                        }
  //                    }
  //                }
  //
  //                if (isSelected)
  //                    this.groupedFields = this._copy(temp);
  //                else
  //                    this.groupedFields =[];
  
98d9d8a5   Renato De Donato   filters+groupby
461
462
                  for (var i = 0; i < this.selectedFields.length; i++) {
                      if (this.selectedFields[i]) {
e31934c0   Renato De Donato   group by bug fix
463
464
                          if (i != index) {
                              temp.push(this.selectedFields[i]);
98d9d8a5   Renato De Donato   filters+groupby
465
466
467
468
                          }
                      }
                  }
  
e31934c0   Renato De Donato   group by bug fix
469
                  this.groupedFields = this._copy(temp);
98d9d8a5   Renato De Donato   filters+groupby
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
  
                  this.async(function() {
                      var ddls = document.getElementsByTagName("paper-dropdown-menu");
                      for (var i = 0; i < ddls.length; i++){
                          var id = ddls[i].id;
                          if(id.indexOf("calculate") > -1) {
                              $(ddls[i]).find("paper-menu")[0].select(-1);
                              $(ddls[i]).find("paper-menu")[0].select(0);
                          }
                      }
                  }, 0);
  
                  this._addGroupByInput();
              },
  
              ready : function() {
a31f0660   root   sevc-controllet i...
486
487
488
489
                  this._resize();
                  $(this.$.datalet_selection_inputs).perfectScrollbar();
                  $(this.$.datalet_selection_labels).perfectScrollbar();
                  $(this.$.datalet_selection_datalet).perfectScrollbar();
0f6424fe   root   update new data-s...
490
  
ed1bed76   Renato De Donato   fix bug-modify in...
491
492
493
                  this.params = {'data-url' : this.dataUrl};
  
                  //this.modify = true;//da eliminare in futuro
e0e4a976   Renato De Donato   data-sevc-control...
494
                  if(this.preselectedDatalet){
0b7cbd33   Renato De Donato   title-desciption
495
496
497
                      if(this.modify)
                          this._preselectDatalet();
  
e0e4a976   Renato De Donato   data-sevc-control...
498
                      this.modify = true;
e0e4a976   Renato De Donato   data-sevc-control...
499
500
                      this.preselectedDatalet = undefined;
                  }
a31f0660   root   sevc-controllet i...
501
502
503
504
505
506
              },
  
              attached : function() {
                  this._resize();
                  var that = this;
                  window.addEventListener("resize", function() { that._resize(); });
e0e4a976   Renato De Donato   data-sevc-control...
507
  
97e0b0f8   Renato De Donato   google chart & lo...
508
                  this._translate();
97e0b0f8   Renato De Donato   google chart & lo...
509
510
              },
  
98d9d8a5   Renato De Donato   filters+groupby
511
512
513
514
              setFilters : function(filters) {
                  this.filters = filters;
              },
  
0f6424fe   root   update new data-s...
515
516
517
518
              setFields : function(fields) {
                  this.fields = fields;
              },
  
e0e4a976   Renato De Donato   data-sevc-control...
519
              reset : function() {
98d9d8a5   Renato De Donato   filters+groupby
520
521
522
                  this.selectedDatalet = undefined;//non va!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
                  this.preselectedDatalet = undefined;
                  this.type = undefined;
e0e4a976   Renato De Donato   data-sevc-control...
523
524
                  this.inputs = [];
                  this.labels = [];
98d9d8a5   Renato De Donato   filters+groupby
525
526
527
528
                  this.$.expert_header.style.display = "none";
                  this.expert = true;
                  this._showExpertMode();
                  this.loadPreview = false;
e0e4a976   Renato De Donato   data-sevc-control...
529
                  this.$.datalet_selection_datalet_placeholder.innerHTML = "";
98d9d8a5   Renato De Donato   filters+groupby
530
                  this._resetGroupBy();
e0e4a976   Renato De Donato   data-sevc-control...
531
532
              },
  
3c812cc9   Renato De Donato   title-desciption ...
533
              _translate : function(){
6d2a2a1e   Andrea Petta   language handling
534
535
536
537
538
539
540
  
                  this.$.add_button.innerHTML     = ln["addDatalet_" + ln["localization"]];
                  this.$.inputs.innerHTML         = ln["inputs_" + ln["localization"]];
                  this.$.baseInfo.innerHTML       = ln["baseInfo_" + ln["localization"]];
                  this.$.layouts.innerHTML        = ln["layouts_" + ln["localization"]];
                  this.$.dataletPreview.innerHTML = ln["dataletPreview_" + ln["localization"]];
  
ac237fdd   Renato De Donato   controllet ln
541
542
543
                  this.$.base_title.label = ln["title_" + ln["localization"]];
                  this.$.base_description.label = ln["description_" + ln["localization"]];
  
6d2a2a1e   Andrea Petta   language handling
544
545
                  if(this.modify)
                      this.$.add_button.innerHTML = ln["modifyDatalet_" + ln["localization"]];
3c812cc9   Renato De Donato   title-desciption ...
546
547
              },
  
e0e4a976   Renato De Donato   data-sevc-control...
548
              _selectDatalet : function(e){
0f6424fe   root   update new data-s...
549
550
                  this.$.add_button.setAttribute("disabled", "true");
  
a31f0660   root   sevc-controllet i...
551
                  this.selectedDatalet = e.detail.datalet;
0f6424fe   root   update new data-s...
552
  
d2da5141   Renato De Donato   async 0
553
554
555
556
557
558
                  this.$.datalet_selection_datalet_placeholder.innerHTML = "";
  
                  if(!this.selectedDatalet){
                      this.type = undefined;
                      this.inputs = [];
                      this.labels = [];
98d9d8a5   Renato De Donato   filters+groupby
559
560
561
                      this.$.expert_header.style.display = "none";
                      this.expert = true;
                      this._showExpertMode();
d2da5141   Renato De Donato   async 0
562
563
564
                      this.loadPreview = false;
                  }
                  else{
a31f0660   root   sevc-controllet i...
565
566
                      this.$.selectedDatalet_request.url = this.deepUrl + e.detail.datalet + "-datalet";
                      this.$.selectedDatalet_request.generateRequest();
98d9d8a5   Renato De Donato   filters+groupby
567
                      this.$.expert_header.style.display = "block";
a31f0660   root   sevc-controllet i...
568
                  }
e0e4a976   Renato De Donato   data-sevc-control...
569
              },
0f6424fe   root   update new data-s...
570
  
e0e4a976   Renato De Donato   data-sevc-control...
571
              _preselectDatalet : function() {
0b7cbd33   Renato De Donato   title-desciption
572
573
574
575
                  this.type = "undefined";
                  this.$.selectedDatalet_request.url = this.deepUrl + this.preselectedDatalet + "-datalet";
                  this.$.selectedDatalet_request.generateRequest();
  
e0e4a976   Renato De Donato   data-sevc-control...
576
577
578
                  this.selectedDatalet = this.preselectedDatalet;
                  this.selectedFields = this._copy(this.fields);
  
e31934c0   Renato De Donato   group by bug fix
579
  //                this.filters = JSON.parse(this.dataletPreset["filters"]);
efb059b1   Renato De Donato   preload filter in...
580
581
582
  //                this.aggregators = JSON.parse(this.dataletPreset["aggregators"]);
  //                this.orders = JSON.parse(this.dataletPreset["orders"]);
  
0b7cbd33   Renato De Donato   title-desciption
583
584
                  this.async(function() {
                      this.selectedFields = this._copy(this.fields);
e0e4a976   Renato De Donato   data-sevc-control...
585
  
0b7cbd33   Renato De Donato   title-desciption
586
                      //set info labels options
efb059b1   Renato De Donato   preload filter in...
587
588
589
590
591
592
593
594
                      var textarea = this.$.datalet_selection_labels.querySelectorAll("paper-textarea");
                      textarea[0].value = this.dataletPreset["description"];
  
                      var inputs = this.$.datalet_selection_labels.querySelectorAll("paper-input");
                      inputs[0].value = this.dataletPreset["title"];
  
                      for (var i = 1; i < inputs.length; i++)
                          inputs[i].value = this.dataletPreset[this.labels[i-1].name];
e8219f9a   Renato De Donato   datalet-mod
595
  
efb059b1   Renato De Donato   preload filter in...
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
                      //set inputs --> prima apri GB e riempi CALCULATE e poi gli ORDERBY???
                      var ddls = document.getElementsByTagName("paper-dropdown-menu");
                      for (var i = 0; i < ddls.length; i++) {
                          var id = ddls[i].id;
                          if (!isNaN(id)) {
  //                            id = parseInt(id);
                              $(ddls[i]).find("paper-menu")[0].select(id);
                          }
                          else if (id.indexOf("group_by") > -1) {
                              ;
                          }
                          else if (id.indexOf("calculate") > -1) {
                              ;
                          }
                      }
3c812cc9   Renato De Donato   title-desciption ...
611
  
55dade56   Renato De Donato   modify a datalet
612
613
614
                      this.loadPreview = true;
                      this._loadDatalet(this.selectedFields);
                  }, 300);
a31f0660   root   sevc-controllet i...
615
616
              },
  
0f6424fe   root   update new data-s...
617
              _handleSelectedDatalet : function(e){
0f6424fe   root   update new data-s...
618
  
d2da5141   Renato De Donato   async 0
619
                  if(this.type != e.detail.response.type) {
a31f0660   root   sevc-controllet i...
620
  
d2da5141   Renato De Donato   async 0
621
622
623
624
625
626
627
628
629
630
631
                      this.inputs = [];
                      this.labels = [];
  
                      var inputs = e.detail.response.idm.inputs.input;
  
                      if (inputs.constructor == Object) {//not Array && inputs.input.selection == "*"
                          var name = inputs.name;
                          var description = inputs.description;
                          var selection = inputs.selection;
                          inputs = [];
                          for (var i in this.fields)
d2da5141   Renato De Donato   async 0
632
633
                              inputs.push({name: name + " " + i, description: description, selection: selection});
                      }
a31f0660   root   sevc-controllet i...
634
  
d2da5141   Renato De Donato   async 0
635
636
637
638
                      this.async(function(){
                          this.type = e.detail.response.type;
                          this.inputs = inputs;
                          this.labels = e.detail.response.idm.inputs.layouts.input;
a31f0660   root   sevc-controllet i...
639
  
d2da5141   Renato De Donato   async 0
640
641
642
                          this.selectedFields = new Array(inputs.length);
                      },0);
  
98d9d8a5   Renato De Donato   filters+groupby
643
644
                      this._resetGroupBy();
  
d2da5141   Renato De Donato   async 0
645
646
647
648
649
                      this.loadPreview = false;
                  }
  
                  else if (this.loadPreview)
                      this._loadDatalet(this.selectedFields);
0f6424fe   root   update new data-s...
650
651
              },
  
98d9d8a5   Renato De Donato   filters+groupby
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
              _resetGroupBy : function(){
                  $(this.$.group_by).find("paper-menu")[0].select(-1);
                  this.groupedFields = [];
                  this.aggregators = [];
              },
  
              _addGroupByInput : function(){
                  this.async(function() {//codice reprlicato!
                      var selectedFields = this.selectedFields;
  
                      var load = true;
  
                      if(this.inputs[0].selection == "*"){
                          var temp = [];
                          for (var i = 0; i < selectedFields.length; i++)
                              if(selectedFields[i])
                                  temp.push(selectedFields[i]);
                          selectedFields = temp;
                      }
                      else {
                          for (var i = 0; i < selectedFields.length; i++)
                              if (!selectedFields[i]) {
                                  load = false;
                                  break;
                              }
                      }
  
                      if(load){
                          this.loadPreview = true;
                          this._loadDatalet(selectedFields);
                      }
                  }, 0);
              },
  
              _addOrder : function(e){
                  var t = e.target;
                  if(t.tagName.indexOf("IRON-ICON") > -1)
                      t = $(e.target).parents("paper-icon-button")[0];
  
                  var icon = t.getAttribute("icon");
                  var name = t.getAttribute("id");
  
                  if(name.indexOf("gb") > -1){
                      var selectedItem = $(this.$.group_by).find("paper-menu")[0].selectedItem;
                      if(selectedItem)
                          name = selectedItem.textContent.trim();
  //                        name = "[" + selectedItem.textContent.trim() + "]";
                      else
                          return;
                  }// else {
  //                    var i = name;
  //                    var ddl = $("#calculate_"+i);
  //
  //                    var label = $(ddl).find("paper-menu")[0].selectedItem.textContent.trim();
  //                    var index = label.split(" ", 2).join(" ").length;
  //                    var field = label.substring(index+1, label.length);
  //                    var operation = label.substring(0, label.indexOf(" "));
  //                    name = operation + "([" + field + "])";
  //                }
  
                  if(icon.indexOf("unfold-more") > -1){
                      t.setAttribute("icon", "expand-less");
e31934c0   Renato De Donato   group by bug fix
714
                      t.setAttribute("title", ln["sortAscending_" + ln["localization"]]);
98d9d8a5   Renato De Donato   filters+groupby
715
716
717
718
719
720
                      var orders = this.orders.filter(function (el) { return el.field !== name; });
                      orders.push({"field": name, "operation": "ASC"});
                      this.orders = this._copy(orders);
                  }
                  else if(icon.indexOf("expand-less") > -1){
                      t.setAttribute("icon", "expand-more");
e31934c0   Renato De Donato   group by bug fix
721
                      t.setAttribute("title", ln["sortDescending_" + ln["localization"]]);
98d9d8a5   Renato De Donato   filters+groupby
722
723
724
725
726
727
                      var orders = this.orders.filter(function (el) { return el.field !== name; });
                      orders.push({"field": name, "operation": "DESC"});
                      this.orders = this._copy(orders);
                  }
                  else if(icon.indexOf("expand-more") > -1){
                      t.setAttribute("icon", "unfold-more");
e31934c0   Renato De Donato   group by bug fix
728
                      t.setAttribute("title", ln["unsort_" + ln["localization"]]);
98d9d8a5   Renato De Donato   filters+groupby
729
730
731
732
733
734
735
736
737
738
739
                      var orders = this.orders.filter(function (el) { return el.field !== name; });
                      this.orders = this._copy(orders);
                  }
  
                  this._addGroupByInput();//no buoono
  //                if(load){
  //                    this.loadPreview = true;
  //                    this._loadDatalet(selectedFields);
  //                }
              },
  
e0e4a976   Renato De Donato   data-sevc-control...
740
              _addInput : function(e){
0f6424fe   root   update new data-s...
741
                  var selectedFields = this._copy(this.selectedFields);
0f6424fe   root   update new data-s...
742
  
0b7cbd33   Renato De Donato   title-desciption
743
744
745
746
747
748
  //                var index = $(e.target).parents("paper-dropdown-menu")[0].id;
  //                selectedFields[index] = e.target.innerHTML.trim();
  
                  var ddl_index = $(e.target).parents("paper-dropdown-menu")[0].id;
                  var index = e.target.id;
                  selectedFields[ddl_index] = this.fields[index];
0f6424fe   root   update new data-s...
749
  
e0e4a976   Renato De Donato   data-sevc-control...
750
                  this.selectedFields = this._copy(selectedFields);
0f6424fe   root   update new data-s...
751
  
e0e4a976   Renato De Donato   data-sevc-control...
752
                  var load = true;
0f6424fe   root   update new data-s...
753
  
e0e4a976   Renato De Donato   data-sevc-control...
754
755
756
757
                  if(this.inputs[0].selection == "*"){
                      var temp = [];
                      for (var i = 0; i < selectedFields.length; i++)
                          if(selectedFields[i])
98d9d8a5   Renato De Donato   filters+groupby
758
                              temp.push(selectedFields[i]);
e0e4a976   Renato De Donato   data-sevc-control...
759
760
761
762
763
764
765
766
767
                      selectedFields = temp;
                  }
                  else {
                      for (var i = 0; i < selectedFields.length; i++)
                          if (!selectedFields[i]) {
                              load = false;
                              break;
                          }
                  }
0f6424fe   root   update new data-s...
768
  
98d9d8a5   Renato De Donato   filters+groupby
769
770
                  this._resetGroupBy();//--> conflitto, in _updateparams valorizza this.aggregators
  
0f6424fe   root   update new data-s...
771
                  if(load){
98d9d8a5   Renato De Donato   filters+groupby
772
                      this.loadPreview = true;
e0e4a976   Renato De Donato   data-sevc-control...
773
774
                      this._loadDatalet(selectedFields);
                  }
e0e4a976   Renato De Donato   data-sevc-control...
775
              },
0f6424fe   root   update new data-s...
776
  
e31934c0   Renato De Donato   group by bug fix
777
              _updateParams : function(){
84242065   Andrea Petta   params fix
778
779
                  var textarea = this.$.datalet_selection_labels.querySelectorAll("paper-textarea");
                  this.params["description"] = textarea[0].value;
e8219f9a   Renato De Donato   datalet-mod
780
  
84242065   Andrea Petta   params fix
781
782
                  if(!textarea[0].value)
                      this.params[textarea[0].label] = "";
b4accc86   Renato De Donato   datalet improved
783
  
84242065   Andrea Petta   params fix
784
785
                  var inputs = this.$.datalet_selection_labels.querySelectorAll("paper-input");
                  this.params["title"] = inputs[0].value;
0f6424fe   root   update new data-s...
786
  
84242065   Andrea Petta   params fix
787
788
                  for (var i = 1; i < inputs.length; i++)
                      this.params[this.labels[i-1].name] = inputs[i].value;
98d9d8a5   Renato De Donato   filters+groupby
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
  
                  this.aggregators = [];
  
                  var ddls = document.getElementsByTagName("paper-dropdown-menu");
                  for (var i = 0; i < ddls.length; i++){
                      var id = ddls[i].id;
                      if(id.indexOf("group_by") > -1 && $(ddls[i]).find("paper-menu")[0].selectedItem) {
                          var label = $(ddls[i]).find("paper-menu")[0].selectedItem.textContent.trim();
                          this.aggregators.push({"field": label, "operation": "GROUP BY"});
                      }
                      if(id.indexOf("calculate") > -1) {
                          var label = $(ddls[i]).find("paper-menu")[0].selectedItem.textContent.trim();
  //                        var field = label.substring(label.lastIndexOf(" ")+1, label.length);
                          var index = label.split(" ", 2).join(" ").length;
                          var field = label.substring(index+1, label.length);
                          var operation = label.substring(0, label.indexOf(" "));
                          this.aggregators.push({"field": field, "operation": operation});
                      }
                  }
b4accc86   Renato De Donato   datalet improved
808
809
810
811
812
              },
  
              _paramsChanged : function(){
  
                  this._updateParams();
e8219f9a   Renato De Donato   datalet-mod
813
  
4b79b3c8   Renato De Donato   datalet-selection...
814
815
                  if(this.$.datalet_selection_datalet_placeholder.children[1])
                      this.$.datalet_selection_datalet_placeholder.children[1].behavior.setParameters(this.params);
e8219f9a   Renato De Donato   datalet-mod
816
817
818
819
              },
  
              _loadDatalet : function(selectedFields){
  
b4accc86   Renato De Donato   datalet improved
820
                  this._updateParams();
e8219f9a   Renato De Donato   datalet-mod
821
  
98d9d8a5   Renato De Donato   filters+groupby
822
823
824
825
826
827
828
829
830
831
832
                  this.params["filters"] = JSON.stringify(this.filters);
                  this.params["aggregators"] = JSON.stringify(this.aggregators);
                  this.params["orders"] = JSON.stringify(this.orders);
  
  //                this.params["filters"] = '[{"field": "Lat", "operation": ">=", "value": "53.298164"}, {"field": "Lat", "operation": "<", "value": "54"}]';
  //                this.params["aggregators"] = '[{"field": "Lat", "operation": "GROUP BY"}, {"field": "Lng", "operation": "COUNT"}]';
  //                this.params["orders"] = '[{"field": "Lat", "operation": "DESC"}, {"field": "Lat", "operation": "ASC"}]';
  
                  //this.params["aggregators"] = '[{"field": "Value", "operation": "GROUP BY"}, {"field": "LOCATION", "operation": "COUNT"}]';
                  //this.params["orders"] = '[{"field": "Value", "operation": "ASC"}, {"field": "Value", "operation": "ASC"}]';
  
e0e4a976   Renato De Donato   data-sevc-control...
833
834
                  var dataletParams ={
                      component   : this.selectedDatalet+"-datalet",
57ef9bf4   Renato De Donato   labels + info
835
                      params      : this.params,
e0e4a976   Renato De Donato   data-sevc-control...
836
837
838
                      fields      : selectedFields,
                      placeHolder : this.$.datalet_selection_datalet_placeholder
                  };
0f6424fe   root   update new data-s...
839
  
e0e4a976   Renato De Donato   data-sevc-control...
840
841
                  ComponentService.deep_url = this.deepUrl;
                  ComponentService.getComponent(dataletParams);
a31f0660   root   sevc-controllet i...
842
  
8afca675   Renato De Donato   title-description
843
                  this.$.add_button.removeAttribute("disabled");
0f6424fe   root   update new data-s...
844
845
              },
  
e0e4a976   Renato De Donato   data-sevc-control...
846
              _addDatalet : function(){
0f6424fe   root   update new data-s...
847
  
346a4475   Andrea Petta   private room bug fix
848
849
                  this._updateParams();
  
9579b866   Renato De Donato   firefox bug fix
850
851
852
853
854
                  var selectedFields = [];
                  for (var i = 0; i < this.selectedFields.length; i++)
                      if(this.selectedFields[i])
                          selectedFields.push(this.selectedFields[i]);
  
0f6424fe   root   update new data-s...
855
856
                  var data = {
                      dataUrl : this.dataUrl,
57ef9bf4   Renato De Donato   labels + info
857
                      params :  this.params,
9579b866   Renato De Donato   firefox bug fix
858
                      fields :  selectedFields,
0f6424fe   root   update new data-s...
859
                      datalet : this.selectedDatalet+"-datalet",
3c812cc9   Renato De Donato   title-desciption ...
860
  //                    comment : "",//DEPRECATED!!!
0f6424fe   root   update new data-s...
861
862
863
                      staticData : JSON.stringify(this.$.datalet_selection_datalet_placeholder.children[1].behavior.data)
                  }
  
0f6424fe   root   update new data-s...
864
                  this.fire('data-sevc-controllet.dataletCreated', {data : data});
a31f0660   root   sevc-controllet i...
865
866
867
  
              },
  
57ef9bf4   Renato De Donato   labels + info
868
              _showInfo : function(e){
98d9d8a5   Renato De Donato   filters+groupby
869
  //                var that = this;
57ef9bf4   Renato De Donato   labels + info
870
871
872
873
                  var t = e.target;
                  if(t.tagName.indexOf("IRON-ICON") != -1)
                      t = $(e.target).parents("paper-icon-button")[0];
  
ac237fdd   Renato De Donato   controllet ln
874
875
  //                var name = t.getAttribute("title").replace(" info", "");
                  var name = t.getAttribute("id");
57ef9bf4   Renato De Donato   labels + info
876
877
878
879
880
  
                  var dataset = $.grep(this.inputs, function(e){ return e.name == name; })[0];
                  if(!dataset)
                      dataset = $.grep(this.labels, function(e){ return e.name == name; })[0];
  
98d9d8a5   Renato De Donato   filters+groupby
881
                  this.$.dialog_name.innerHTML = this._getLabelName(dataset.name);
6d2a2a1e   Andrea Petta   language handling
882
                  this.$.dialog_description.innerHTML = ln[dataset.description + "_" +  ln["localization"]];
79ec939f   Renato De Donato   info position + a...
883
                  this.$.dialog_info_input.open();
57ef9bf4   Renato De Donato   labels + info
884
885
  
                  var pos = t.getBoundingClientRect();
79ec939f   Renato De Donato   info position + a...
886
887
                  $("#dialog_info_input").css("top", pos.top - 4);
                  $("#dialog_info_input").css("left", pos.left - 4);
57ef9bf4   Renato De Donato   labels + info
888
889
              },
  
59100bec   Renato De Donato   localization + ba...
890
              _fieldName : function(field) {
98d9d8a5   Renato De Donato   filters+groupby
891
892
893
                  if(!field)//when?
                      return "";
                  return field.substring(field.lastIndexOf(",")+1, field.length);
59100bec   Renato De Donato   localization + ba...
894
895
              },
  
e0e4a976   Renato De Donato   data-sevc-control...
896
897
898
899
900
901
902
903
904
905
              _copy : function(o) {
                  var out, v, key;
                  out = Array.isArray(o) ? new Array(o.length) : {};
                  for (key in o) {
                      v = o[key];
                      out[key] = (typeof v === "object") ? this._copy(v) : v;
                  }
                  return out;
              },
  
ac237fdd   Renato De Donato   controllet ln
906
              _getLabelName: function(key) {
98d9d8a5   Renato De Donato   filters+groupby
907
908
909
910
911
912
913
914
                  //* exceptions
                  if(key.indexOf("Cell") > -1) {
                      return ln["Cell" + "_" +ln["localization"]] + key.slice(-2);
                  }
                  if(key.indexOf("Level") > -1) {
                      return ln["Level" + "_" +ln["localization"]] + key.slice(-2);
                  }
  
ac237fdd   Renato De Donato   controllet ln
915
916
917
                  return ln[key + "_" +ln["localization"]];
              },
  
a31f0660   root   sevc-controllet i...
918
919
920
921
922
923
924
925
              _resize : function(){
                  var h = Math.max(document.documentElement.clientHeight, window.innerHeight || 0) - 16;
                  h = h - 64 - 8; //height with page scroller
  
                  $("#items_vslider_container").height(h);//vslider controllet
  
                  $("#datalet_selection_inputs").height(h);
                  $("#datalet_selection_labels").height(h);
98d9d8a5   Renato De Donato   filters+groupby
926
                  $("#datalet_selection_datalet").height(h);
a31f0660   root   sevc-controllet i...
927
928
929
930
931
932
933
              }
  
          });
  
      </script>
  
  </dom-module>