Blame view

controllets/select-visualization-controllet/select-datalet-inputs.html 21.9 KB
fb05b400   Renato De Donato   controllet 2.0, n...
1
2
3
4
5
6
7
8
9
10
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
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
  <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">
  
  <dom-module id="select-datalet-inputs">
  
      <template>
  
          <style is="custom-style">
              :host {
              --paper-dropdown-menu-icon: {
                   color: #2196F3;
               };
              }
  
              #inputs_container {
                  font-family: 'Roboto', 'Helvetica Neue', Helvetica, Arial, sans-serif;
                  font-size: 16px;
  
                  height: 100%;
                  width: 258px;
              }
  
              .inputs{
                  position: relative;
              }
  
              .input_header {
                  height: 32px;
                  padding-top: 16px;
                  text-align: center;
                  font-weight: 700;
                  background-color: #B6B6B6;
              }
  
              #expert_container {
                  display: none;
              }
  
              #expert_header {
                  height: 32px;
                  padding-top: 16px;
                  margin-top: 8px;
                  text-align: center;
                  font-weight: 700;
                  color: #00BCD4;
                  cursor: pointer;
  
                  display: none;
              }
  
              .info_button {
                  position: absolute;
                  top: 18px;
                  right: 0px;
              }
  
              paper-dropdown-menu {
                  height: 48px;
                  width: 210px;;
                  padding-left: 8px;
                  padding-bottom: 8px;
                  --paper-input-container-focus-color: #2196F3;
              }
  
              paper-item.iron-selected {
                  background-color: #2196F3;
                  color: #FFFFFF;
              }
  
              paper-icon-button {
                  color: #2196F3;
                  --paper-icon-button-ink-color: #2196F3;
                  margin: 0px;
              }
          </style>
  
          <paper-material id="inputs_container" elevation="5">
  
              <div class="input_header"><span id="inputs"></span></div>
  
              <template is="dom-repeat" items="{{inputs}}" index-as="ddl_index">
                  <div class="inputs">
                      <paper-dropdown-menu id={{ddl_index}} label={{_getLabelName(item.name)}}>
                          <paper-menu class="dropdown-content">
                              <template is="dom-repeat" items={{fields}}>
                                  <paper-item id={{index}} on-tap="_addInput">{{_fieldName(item)}}</paper-item>
                              </template>
                          </paper-menu>
                      </paper-dropdown-menu>
                      <div class="info_button">
                          <paper-icon-button id="{{ddl_index}}" on-click="_setOrders" icon="unfold-more" title=""></paper-icon-button>
                      </div>
                  </div>
              </template>
  
              <div id="expert_header" on-click="_showExpertMode"><span id="groupBy"></span></div>
  
              <div id="expert_container">
  
                  <div class="inputs">
                      <paper-dropdown-menu id="group_by" disabled>
                          <paper-menu class="dropdown-content">
                              <template is="dom-repeat" items={{groupableFields}}>
                                  <paper-item id={{index}} on-tap="_setAggregatorsFields">{{_fieldName(item)}}</paper-item>
                              </template>
                          </paper-menu>
                      </paper-dropdown-menu>
                  </div>
  
                  <template is="dom-repeat" items="{{aggregateFields}}" as="field">
                      <div class="inputs">
                          <paper-dropdown-menu id="calculate_{{index}}" label="{{_calculateLabel()}}">
                              <paper-menu class="dropdown-content">
                                  <template is="dom-repeat" items="{{functions}}">
                                      <paper-item id={{index}} on-tap="_setAggregators">{{_operationName(index)}} : {{_fieldName(field)}}</paper-item>
                                  </template>
                              </paper-menu>
                          </paper-dropdown-menu>
                      </div>
                  </template>
  
              </div>
  
          </paper-material>
  
  
      </template>
  
      <script>
  
          Polymer({
  
              is : 'select-datalet-inputs',
  
              properties : {
  
                  //INPUT
                  fields : {type : Array, value : []},
  
                  //OUTPUT
                  selectedFields : {type : Array, value : []},
                  aggregators : {type : Array, value : []},
                  orders : {type : Array, value : []},
  
                  expert : {
                      type  : Boolean,
                      value : false
                  },
  
                  functions : {
                      type  : Array,
                      value : ["COUNT", "SUM", "MIN", "MAX", "AVG", "FIRST", "LAST"]
                  },
  
                  inputs : {
                      type : Array,
                      value : []
                  },
  
                  groupableFields : {
                      type : Array,
                      value : []
                  },
  
                  aggregateFields : {
                      type : Array,
                      value : []
                  }
  
              },
  
              ready : function() {
                  $(this.$.inputs_container).perfectScrollbar();
              },
  
              attached : function() {
                  this._translate();
              },
  
a53fbbed   Renato De Donato   select-dataset ne...
189
              _preselectInputs : function(fields, aggregators, orders) {
20f33314   Renato De Donato   preselect strikes...
190
191
192
193
194
                  aggregators = JSON.parse(aggregators);
                  orders = JSON.parse(orders);
  
                  this.selectedFields = this._copy(fields);
  
a53fbbed   Renato De Donato   select-dataset ne...
195
196
                  var ddls = this.$.inputs_container.querySelectorAll("paper-dropdown-menu");
  
20f33314   Renato De Donato   preselect strikes...
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
                  for (var i = 0; i < fields.length; i++)
                     $(ddls[i]).find("paper-menu")[0].select(i+1);
  
                  if(orders.length > 0) {
                      this.orders = this._copy(orders);//wrong
                  }
  
                  if(aggregators.length > 0) {
  
                      this.$.group_by.removeAttribute("disabled");
                      this._showExpertMode();
  
                      var groupableFields = [];
                      for (var i = 0; i < this.selectedFields.length; i++) {
                          if(this.selectedFields[i])
                              groupableFields.push(this.selectedFields[i]);
                      }
                      this.groupableFields = this._copy(groupableFields);
                      this.aggregateFields = [];
  
                      var index = this.groupableFields.indexOf(aggregators[0].field);
  
                      this.async(function () {
                          var menu = $(this.$.group_by).find("paper-menu")[0];
                          menu.select(index);
                      }, 0);
  
                      var aggregateFields = [];
                      for (var i = 0; i < this.groupableFields.length; i++) {
                          if (i != index && this.groupableFields[i])
                              aggregateFields.push(this.groupableFields[i]);
                      }
                      this.aggregateFields = this._copy(aggregateFields);
  
                      this.async(function() {
                          var ddls = document.getElementsByTagName("paper-dropdown-menu");
                          var j = 1;
                          for (var i = 0; i < ddls.length; i++){
                              var id = ddls[i].id;
                              if(id.indexOf("calculate") > -1) {
                                  var ii = this.functions.indexOf(aggregators[j].operation);
                                  j++;
                                  $(ddls[i]).find("paper-menu")[0].select(-1);
                                  $(ddls[i]).find("paper-menu")[0].select(ii);
                              }
                          }
  
  //                        this._setAggregators();
                          this.aggregators = this._copy(aggregators);
  
                          this.fireReady();
                      }, 0);
a53fbbed   Renato De Donato   select-dataset ne...
249
                  }
576713c8   Renato De Donato   preselect
250
251
                  else
                      this.fireReady();
a53fbbed   Renato De Donato   select-dataset ne...
252
253
              },
  
fb05b400   Renato De Donato   controllet 2.0, n...
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
              getSelectedFields : function () {
                  return this.selectedFields.filter(function(field){ return field != "" });
              },
  
              getAggregators : function () {
                  return this.aggregators;
              },
  
              getOrders : function () {
                  return this.orders;
              },
  
              setFields : function(fields) {
                  var temp = this._copy(fields);
                  temp.unshift("");
fb05b400   Renato De Donato   controllet 2.0, n...
269
  
a53fbbed   Renato De Donato   select-dataset ne...
270
271
272
273
274
                  if (JSON.stringify(this.fields) != JSON.stringify(temp)) {
                      this.fields = this._copy(temp);
                      this.$.expert_header.style.display = "block";
                      this._reset();
                  }
fb05b400   Renato De Donato   controllet 2.0, n...
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
              },
  
              setInputs : function(inputs) {
                  var temp =  this._copy(inputs);
                  if (inputs.constructor != Array) {//table --> 1 input
                      var name = inputs.name;
                      var description = inputs.description;
                      var selection = inputs.selection;
                      temp = [];
                      for (var i = 1; i < this.fields.length; i++)
                          temp.push({name: name + " " + i, description: description, selection: selection});
                  }
                  else if (inputs.length > 2 && inputs[2].selection == "*") {//map --> multiple baloon content
                      name = inputs[2].name;
                      description = inputs[2].description;
                      selection = inputs[2].selection;
                      temp = [inputs[0], inputs[1]];
9819a403   Renato De Donato   bubble scatter tr...
292
293
294
                      temp.push({name: name + " 1", description: description, selection: selection});
                      for (var i = 4; i < this.fields.length; i++)
                          temp.push({name: name + " " +(i-2), description: description, selection: selection});
fb05b400   Renato De Donato   controllet 2.0, n...
295
                  }
9819a403   Renato De Donato   bubble scatter tr...
296
297
298
299
300
301
302
303
304
  //                else if (inputs.length > 4 && inputs[4].selection == "+") {//bubble --> multiple bubble content
  //                    name = inputs[4].name;
  //                    description = inputs[4].description;
  //                    selection = inputs[4].selection;
  //                    temp = [inputs[0], inputs[1], inputs[2], inputs[3]];
  //                    temp.push({name: name + " 1", description: description, selection: selection});
  //                    for (var i = 6; i < this.fields.length; i++)
  //                        temp.push({name: name + " " + (i-4), description: description, selection: selection});
  //                }
fb05b400   Renato De Donato   controllet 2.0, n...
305
  
0f4f5f1b   Renato De Donato   new datalets mult...
306
307
308
309
310
311
312
313
314
315
                  else if (inputs.length == 2 && inputs[1].selection == "*") {//
                      name = inputs[1].name;
                      description = inputs[1].description;
                      selection = inputs[1].selection;
                      temp = [inputs[0]];
                      temp.push({name: name + " 1", description: description, selection: selection});
                      for (var i = 3; i < this.fields.length; i++)
                          temp.push({name: name + " " +(i-1), description: description, selection: selection});
                  }
  
fb05b400   Renato De Donato   controllet 2.0, n...
316
317
318
                  this.inputs = this._copy(temp);
  
                  this.selectedFields = new Array(temp.length);
0f4f5f1b   Renato De Donato   new datalets mult...
319
320
  
                  this.selectedFields2 = new Array(temp.length);
fb05b400   Renato De Donato   controllet 2.0, n...
321
322
323
324
              },
  
              fireReady : function() {
                  if(this._isReady())
9819a403   Renato De Donato   bubble scatter tr...
325
326
327
                      this.fire('select_visualization_inputs_ready', {isReady: true});
                  else
                      this.fire('select_visualization_inputs_ready', {isReady: false});
fb05b400   Renato De Donato   controllet 2.0, n...
328
329
330
331
332
              },
  
              _isReady : function() {
                  var fire = true;
                  for (var i = 0; i < this.selectedFields.length; i++) {
9819a403   Renato De Donato   bubble scatter tr...
333
                      if (!this.selectedFields[i] && this.inputs[i].selection != "+" && this.inputs[i].selection != "*" && this.inputs[i].selection != "?")
fb05b400   Renato De Donato   controllet 2.0, n...
334
                          return false;
9819a403   Renato De Donato   bubble scatter tr...
335
                      if(this.inputs[i].selection == "+")
fb05b400   Renato De Donato   controllet 2.0, n...
336
337
338
339
340
                          fire = false;
                  }
  
                  if(!fire) {
                      for (var i = 0; i < this.selectedFields.length; i++) {
9819a403   Renato De Donato   bubble scatter tr...
341
                          if (this.selectedFields[i] && this.inputs[i].selection == "+") {
fb05b400   Renato De Donato   controllet 2.0, n...
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
                              fire = true;
                              break;
                          }
                      }
                  }
  
                  return fire;
              },
  
              _reset : function() {
                  //this.fields = []; --> setFields
                  //this.inputs = []; --> setInputs
                  this.selectedFields = [];
                  this.aggregators = [];
                  //this.orders = []; --> _resetOrders
                  this._resetOrders();
                  this.expert = true;
                  this._showExpertMode();//expert --> false
                  this.groupableFields = [];
                  this.aggregateFields = [];
  
                  this.async(function () {
                      //reset ddl
cc0a0122   Renato De Donato   new scatter + dat...
365
                      var ddls = this.$.inputs_container.getElementsByTagName("paper-dropdown-menu");
fb05b400   Renato De Donato   controllet 2.0, n...
366
367
368
369
370
371
372
373
374
375
                      for (var i = 0; i < ddls.length; i++)
                          $(ddls[i]).find("paper-menu")[0].select(-1);
                      this.$.group_by.setAttribute("disabled", "");
                      //reset orders
                      this._resetOrders();
                  }, 1);
              },
  
              _translate : function(){
                  this.$.inputs.innerHTML = ln["inputs_" + ln["localization"]];
79627d7e   Renato De Donato   controllet ln
376
377
                  this.$.groupBy.innerHTML = ln["expertGroupBy_" + ln["localization"]];
  
fb05b400   Renato De Donato   controllet 2.0, n...
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
                  this.$.group_by.setAttribute("label", ln["groupBy_" + ln["localization"]]);
              },
  
              _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;
              },
  
0f4f5f1b   Renato De Donato   new datalets mult...
396
397
398
399
              getFields : function () {
                  return this.selectedFields2;
              },
  
fb05b400   Renato De Donato   controllet 2.0, n...
400
401
402
403
              _addInput : function(e){
                  var selectedFields = this._copy(this.selectedFields);
  
                  var ddl_index = $(e.target).parents("paper-dropdown-menu")[0].id;
0f4f5f1b   Renato De Donato   new datalets mult...
404
  
fb05b400   Renato De Donato   controllet 2.0, n...
405
406
407
408
409
                  var index = e.target.id;
                  selectedFields[ddl_index] = this.fields[index];
  
                  this.selectedFields = this._copy(selectedFields);
  
0f4f5f1b   Renato De Donato   new datalets mult...
410
411
412
  //                console.log(this.inputs[ddl_index].name);
                  this.selectedFields2[ddl_index] = {field: this.fields[index], input: this.inputs[ddl_index].name};
  
fb05b400   Renato De Donato   controllet 2.0, n...
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
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
                  if(!this._isReady()) {
                      this.$.group_by.setAttribute("disabled", "");
  
                      this.groupableFields = [];
                      this.aggregateFields = [];
                  }
                  else {
                      this.$.group_by.removeAttribute("disabled");
  
                      var groupableFields = [];
                      for (var i = 0; i < this.selectedFields.length; i++) {
                          if(this.selectedFields[i])
                              groupableFields.push(this.selectedFields[i]);
                      }
                      this.groupableFields = this._copy(groupableFields);
                      this.aggregateFields = [];
  
                      this.async(function () {
                          var menu = $(this.$.group_by).find("paper-menu")[0];
                          menu.select(-1);
                      }, 0);
                  }
                  this._setAggregators();
              },
  
              _setAggregatorsFields : function(e){
                  var index = e.target.id;
                  var aggregateFields = [];
                  for (var i = 0; i < this.groupableFields.length; i++) {
                      if (i != index && this.groupableFields[i])
                          aggregateFields.push(this.groupableFields[i]);
                  }
                  this.aggregateFields = this._copy(aggregateFields);
  
                  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);
                          }
                      }
  
                      this._setAggregators();
                  }, 0);
              },
  
              _setAggregators : function(){
                  this.async(function() {
                      this.aggregators = [];
  
                      this._resetOrders();
  
                      var gb_menu = $(this.$.group_by).find("paper-menu")[0];
                      var groupByField = this.groupableFields[gb_menu.selected];
                      if(groupByField) {
                          this.aggregators.push({"field": groupByField, "operation": "GROUP BY"});
                          for (var i = 0; i < this.aggregateFields.length; i++){
                              var c_menu = $("#calculate_"+i).find("paper-menu")[0];
                              var operationIndex = c_menu.selectedItem.id;
                              this.aggregators.push({"field": this.aggregateFields[i], "operation": this.functions[operationIndex]})
                          }
                      }
  
                      this.fireReady();
                  }, 1);
              },
  
              _setOrders : 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 id = t.getAttribute("id");
                  var field = this.selectedFields[id];
  
                  if(icon.indexOf("unfold-more") > -1){
                      t.setAttribute("icon", "expand-less");
                      t.setAttribute("title", ln["sortAscending_" + ln["localization"]]);
                      var orders = this.orders.filter(function (el) { return el.field !== field; });
                      orders.unshift({"field": field, "operation": "ASC"});
                      this.orders = this._copy(orders);
                  }
                  else if(icon.indexOf("expand-less") > -1){
                      t.setAttribute("icon", "expand-more");
                      t.setAttribute("title", ln["sortDescending_" + ln["localization"]]);
                      var orders = this.orders.filter(function (el) { return el.field !== field; });
                      orders.unshift({"field": field, "operation": "DESC"});
                      this.orders = this._copy(orders);
                  }
                  else if(icon.indexOf("expand-more") > -1){
                      t.setAttribute("icon", "unfold-more");
                      t.setAttribute("title", ln["unsort_" + ln["localization"]]);
                      var orders = this.orders.filter(function (el) { return el.field !== field; });
                      this.orders = this._copy(orders);
                  }
  
                  this.fireReady();
              },
  
              _resetOrders : function(){
                  var icons = this.$.inputs_container.querySelectorAll("paper-icon-button");
                  for (var i = 0; i < icons.length; i++){
                      icons[i].setAttribute("icon", "unfold-more");
                      icons[i].setAttribute("title", ln["unsort_" + ln["localization"]]);
                  }
                  this.orders = [];
              },
  
              _fieldName : function(field) {
                  return field.substring(field.lastIndexOf(",")+1, field.length);
              },
  
              _getLabelName: function(key) {
                  if(key.indexOf("Column") > -1) {
                      return ln["Column" + "_" +ln["localization"]] + key.slice(-2);
                  }
9819a403   Renato De Donato   bubble scatter tr...
532
533
534
                  if(key.indexOf("Level") > -1) {
                      return ln["Level" + "_" +ln["localization"]] + key.slice(-2);
                  }
fb05b400   Renato De Donato   controllet 2.0, n...
535
536
537
                  if(key.indexOf("BalloonContent") > -1) {
                      return ln["BalloonContent" + "_" +ln["localization"]] + key.slice(-2);
                  }
9819a403   Renato De Donato   bubble scatter tr...
538
539
540
  //                if(key.indexOf("BubbleContent") > -1) {
  //                    return ln["BubbleContent" + "_" +ln["localization"]] + key.slice(-2);
  //                }
0f4f5f1b   Renato De Donato   new datalets mult...
541
542
543
                  if(key.indexOf("NumericYAxis") > -1) {
                      return ln["NumericYAxis" + "_" +ln["localization"]] + key.slice(-2);
                  }
fb05b400   Renato De Donato   controllet 2.0, n...
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
  
                  return ln[key + "_" +ln["localization"]];
              },
  
              _operationName: function(index) {
                  var key = this.functions[index];
                  return ln[key + "_" +ln["localization"]];
              },
  
              _calculateLabel: function() {
                  return ln["calculate" + "_" +ln["localization"]];
              },
  
              _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;
              }
  
          });
  
      </script>
  
  </dom-module>