Blame view

controllets/select-visualization-controllet/select-datalet-inputs.html 18.7 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
190
191
192
193
194
195
196
197
198
199
200
              _preselectInputs : function(fields, aggregators, orders) {
                  var ddls = this.$.inputs_container.querySelectorAll("paper-dropdown-menu");
  
  //                this.async(function () {
                  for (var i = 0; i < fields.length; i++) {
                      var menu = $(ddls[i]).find("paper-menu")[0];
                          menu.select(i+1);
                  }
                      this.selectedFields = this._copy(fields);
  //                }, 2);
              },
  
fb05b400   Renato De Donato   controllet 2.0, n...
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
              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...
216
  
a53fbbed   Renato De Donato   select-dataset ne...
217
218
219
220
221
                  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...
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
              },
  
              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...
239
240
241
                      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...
242
                  }
9819a403   Renato De Donato   bubble scatter tr...
243
244
245
246
247
248
249
250
251
  //                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...
252
253
254
255
256
257
258
259
  
                  this.inputs = this._copy(temp);
  
                  this.selectedFields = new Array(temp.length);
              },
  
              fireReady : function() {
                  if(this._isReady())
9819a403   Renato De Donato   bubble scatter tr...
260
261
262
                      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...
263
264
265
266
267
              },
  
              _isReady : function() {
                  var fire = true;
                  for (var i = 0; i < this.selectedFields.length; i++) {
9819a403   Renato De Donato   bubble scatter tr...
268
                      if (!this.selectedFields[i] && this.inputs[i].selection != "+" && this.inputs[i].selection != "*" && this.inputs[i].selection != "?")
fb05b400   Renato De Donato   controllet 2.0, n...
269
                          return false;
9819a403   Renato De Donato   bubble scatter tr...
270
                      if(this.inputs[i].selection == "+")
fb05b400   Renato De Donato   controllet 2.0, n...
271
272
273
274
275
                          fire = false;
                  }
  
                  if(!fire) {
                      for (var i = 0; i < this.selectedFields.length; i++) {
9819a403   Renato De Donato   bubble scatter tr...
276
                          if (this.selectedFields[i] && this.inputs[i].selection == "+") {
fb05b400   Renato De Donato   controllet 2.0, n...
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
                              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...
300
                      var ddls = this.$.inputs_container.getElementsByTagName("paper-dropdown-menu");
fb05b400   Renato De Donato   controllet 2.0, n...
301
302
303
304
305
306
307
308
309
310
                      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
311
312
                  this.$.groupBy.innerHTML = ln["expertGroupBy_" + ln["localization"]];
  
fb05b400   Renato De Donato   controllet 2.0, n...
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
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
                  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;
              },
  
              _addInput : function(e){
                  var selectedFields = this._copy(this.selectedFields);
  
                  var ddl_index = $(e.target).parents("paper-dropdown-menu")[0].id;
                  var index = e.target.id;
                  selectedFields[ddl_index] = this.fields[index];
  
                  this.selectedFields = this._copy(selectedFields);
  
                  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...
459
460
461
                  if(key.indexOf("Level") > -1) {
                      return ln["Level" + "_" +ln["localization"]] + key.slice(-2);
                  }
fb05b400   Renato De Donato   controllet 2.0, n...
462
463
464
                  if(key.indexOf("BalloonContent") > -1) {
                      return ln["BalloonContent" + "_" +ln["localization"]] + key.slice(-2);
                  }
9819a403   Renato De Donato   bubble scatter tr...
465
466
467
  //                if(key.indexOf("BubbleContent") > -1) {
  //                    return ln["BubbleContent" + "_" +ln["localization"]] + key.slice(-2);
  //                }
fb05b400   Renato De Donato   controllet 2.0, n...
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
  
                  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>