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
|
<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_series">
<template>
<style is="custom-style">
:host {
--paper-dropdown-menu-icon: {
color: #2196F3;
};
}
#inputs_series_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;
}
.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_series_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}}>
|
cc0a0122
Renato De Donato
new scatter + dat...
|
111
|
<paper-item id={{index}} on-tap="_setAggregatorsFields">{{_fieldName(item)}}</paper-item>
|
fb05b400
Renato De Donato
controllet 2.0, n...
|
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
189
|
</template>
</paper-menu>
</paper-dropdown-menu>
<div class="info_button">
<paper-icon-button id="gb" on-click="_setOrders" icon="unfold-more" title="" disabled></paper-icon-button>
</div>
</div>
<template is="dom-repeat" items="{{aggregateFields}}" as="field">
<div class="inputs">
<paper-dropdown-menu id="calculate_{{index}}" label="{{_calculateLabel()}}" disabled>
<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_series',
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_series_container).perfectScrollbar();
},
attached : function() {
this._translate();
},
|
a53fbbed
Renato De Donato
select-dataset ne...
|
190
|
_preselectInputs : function(fields, aggregators, orders) {
|
20f33314
Renato De Donato
preselect strikes...
|
191
192
193
194
195
196
197
|
aggregators = JSON.parse(aggregators);
orders = JSON.parse(orders);
//fields = [f1 gb(opt) f2] --> si può cambiare in f1 f2 gb ???
this.selectedFields = this._copy(fields);
|
a53fbbed
Renato De Donato
select-dataset ne...
|
198
199
|
var ddls = this.$.inputs_series_container.querySelectorAll("paper-dropdown-menu");
|
20f33314
Renato De Donato
preselect strikes...
|
200
201
202
203
204
205
206
207
|
$(ddls[0]).find("paper-menu")[0].select(1);
$(ddls[1]).find("paper-menu")[0].select(2);
if(orders.length > 0) {
this.orders = this._copy(orders);//wrong
}
if(aggregators.length > 0) {
|
12769acc
Renato De Donato
preselect bug
|
208
209
|
if(fields.length == 2) {
this.selectedFields = [fields[0], fields[1]];
|
20f33314
Renato De Donato
preselect strikes...
|
210
|
|
12769acc
Renato De Donato
preselect bug
|
211
212
213
214
|
this.$.group_by.removeAttribute("disabled");
$("#calculate_0")[0].removeAttribute("disabled");
$("#gb")[0].removeAttribute("disabled");
this._showExpertMode();
|
20f33314
Renato De Donato
preselect strikes...
|
215
|
|
12769acc
Renato De Donato
preselect bug
|
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
|
var groupableFields = [];
for (var i = 0; i < this.fields.length; i++) {
if(this.fields[i] != this.selectedFields[1])
groupableFields.push(this.fields[i]);
}
this.groupableFields = this._copy(groupableFields);
this.aggregateFields = [this.selectedFields[1]];
$(ddls[0]).find("paper-menu")[0].select(1);
$(ddls[1]).find("paper-menu")[0].select(2);
this.async(function () {
var i = this.functions.indexOf(aggregators[1].operation);
$(this.$.group_by).find("paper-menu")[0].select(1);
$("#calculate_0").find("paper-menu")[0].select(i);
// this._setAggregators();//if dont --> $("#gb")[0].removeAttribute("disabled");
this.aggregators = this._copy(aggregators);
this.fireReady();
}, 0);
|
a53fbbed
Renato De Donato
select-dataset ne...
|
238
|
}
|
12769acc
Renato De Donato
preselect bug
|
239
240
241
242
243
244
245
|
else/*if(fields.length == 3)*/ {
this.selectedFields = [fields[0], fields[2]];
this.$.group_by.removeAttribute("disabled");
$("#calculate_0")[0].removeAttribute("disabled");
$("#gb")[0].removeAttribute("disabled");
this._showExpertMode();
|
20f33314
Renato De Donato
preselect strikes...
|
246
|
|
12769acc
Renato De Donato
preselect bug
|
247
248
249
250
251
252
253
|
var groupableFields = [];
for (var i = 0; i < this.fields.length; i++) {
if(this.fields[i] != this.selectedFields[1])
groupableFields.push(this.fields[i]);
}
this.groupableFields = this._copy(groupableFields);
this.aggregateFields = [this.selectedFields[1]];
|
20f33314
Renato De Donato
preselect strikes...
|
254
|
|
12769acc
Renato De Donato
preselect bug
|
255
256
|
$(ddls[0]).find("paper-menu")[0].select(1);
$(ddls[1]).find("paper-menu")[0].select(3);
|
20f33314
Renato De Donato
preselect strikes...
|
257
|
|
12769acc
Renato De Donato
preselect bug
|
258
259
260
261
262
|
this.async(function () {
var i = this.functions.indexOf(aggregators[2].operation);
$(this.$.group_by).find("paper-menu")[0].select(2);
$("#calculate_0").find("paper-menu")[0].select(i);
|
20f33314
Renato De Donato
preselect strikes...
|
263
264
|
// this._setAggregators();//if dont --> $("#gb")[0].removeAttribute("disabled");
|
12769acc
Renato De Donato
preselect bug
|
265
|
this.aggregators = this._copy(aggregators);
|
20f33314
Renato De Donato
preselect strikes...
|
266
|
|
12769acc
Renato De Donato
preselect bug
|
267
268
269
|
this.fireReady();
}, 0);
}
|
20f33314
Renato De Donato
preselect strikes...
|
270
|
}
|
576713c8
Renato De Donato
preselect
|
271
272
|
else
this.fireReady();
|
a53fbbed
Renato De Donato
select-dataset ne...
|
273
274
|
},
|
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
292
293
294
295
296
297
|
getSelectedFields : function () {
var gb_menu = $(this.$.group_by).find("paper-menu")[0];
var c_menu = $("#calculate_0").find("paper-menu")[0];
if(gb_menu.selectedItem && c_menu.selectedItem && gb_menu.selectedItem.id != 0) {
var groupByField = this.groupableFields[gb_menu.selected];
if (groupByField != this.selectedFields[0])
return [this.selectedFields[0], groupByField, this.selectedFields[1]];
}
return this.selectedFields;
},
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...
|
298
|
|
a53fbbed
Renato De Donato
select-dataset ne...
|
299
300
301
302
|
if (JSON.stringify(this.fields) != JSON.stringify(temp)) {
this.fields = this._copy(temp);
this._reset();
}
|
fb05b400
Renato De Donato
controllet 2.0, n...
|
303
304
|
},
|
0f4f5f1b
Renato De Donato
new datalets mult...
|
305
306
307
308
|
getFields : function () {
return null;
},
|
fb05b400
Renato De Donato
controllet 2.0, n...
|
309
310
311
312
313
314
|
setInputs : function(inputs) {
this.inputs = this._copy(inputs);
},
fireReady : function() {
if(this.selectedFields[0] != "" && this.selectedFields[1] != "")
|
9819a403
Renato De Donato
bubble scatter tr...
|
315
316
317
|
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...
|
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
|
},
_reset : function() {
//this.fields = []; --> setFields
//this.inputs = []; --> setInputs
this.selectedFields = ["", ""];
this.aggregators = [];
//this.orders = []; --> _resetOrders
this.expert = true;
this._showExpertMode();//expert --> false
this.groupableFields = [];
this.aggregateFields = [""];
this.async(function () {
//reset ddl
|
cc0a0122
Renato De Donato
new scatter + dat...
|
333
|
var ddls = this.$.inputs_series_container.getElementsByTagName("paper-dropdown-menu");
|
fb05b400
Renato De Donato
controllet 2.0, n...
|
334
335
336
337
338
339
340
341
342
343
344
|
for (var i = 0; i < ddls.length; i++)
$(ddls[i]).find("paper-menu")[0].select(-1);
this.$.group_by.setAttribute("disabled", "");
$("#calculate_0")[0].setAttribute("disabled", "");
//reset orders
this._resetOrders();
}, 1);
},
_translate : function(){
this.$.inputs.innerHTML = ln["inputs_" + ln["localization"]];
|
79627d7e
Renato De Donato
controllet ln
|
345
346
|
this.$.groupBy.innerHTML = ln["expertGroupBy_" + ln["localization"]];
|
fb05b400
Renato De Donato
controllet 2.0, n...
|
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
|
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.selectedFields[0] == "" || this.selectedFields[1] == "") {
this.$.group_by.setAttribute("disabled", "");
$("#calculate_0")[0].setAttribute("disabled", "");
this.groupableFields = [];
this.aggregateFields = [""];
var menu = $("#calculate_0").find("paper-menu")[0];
menu.select(-1);
}
else {
this.$.group_by.removeAttribute("disabled");
$("#calculate_0")[0].removeAttribute("disabled");
var groupableFields = [];
for (var i = 0; i < this.fields.length; i++) {
if(this.fields[i] != this.selectedFields[1])
groupableFields.push(this.fields[i]);
}
this.groupableFields = this._copy(groupableFields);
this.aggregateFields = [this.selectedFields[1]];
this.async(function () {
var menu = $(this.$.group_by).find("paper-menu")[0];
menu.select(-1);
var menu = $("#calculate_0").find("paper-menu")[0];
//var selected = menu.selected;
menu.select(-1);
//menu.select(selected);
}, 0);
}
this._setAggregators();
},
|
9819a403
Renato De Donato
bubble scatter tr...
|
407
|
_setAggregatorsFields : function(){
|
cc0a0122
Renato De Donato
new scatter + dat...
|
408
409
410
411
412
413
414
415
416
417
|
this.async(function() {
var c_menu = $("#calculate_0").find("paper-menu")[0];
var selected = c_menu.selected > 0 ? c_menu.selected : 0;
c_menu.select(-1);
c_menu.select(selected);
this._setAggregators();
}, 0);
},
|
fb05b400
Renato De Donato
controllet 2.0, n...
|
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
|
_setAggregators : function(){
this.async(function() {
this.aggregators = [];
this._resetOrders();
$("#gb")[0].setAttribute("disabled", "");
var gb_menu = $(this.$.group_by).find("paper-menu")[0];
var c_menu = $("#calculate_0").find("paper-menu")[0];
if(gb_menu.selectedItem && c_menu.selectedItem && gb_menu.selectedItem.id != 0) {
var groupByField = this.groupableFields[gb_menu.selected];
var operationIndex = c_menu.selectedItem.id;
if (groupByField == this.selectedFields[0]){// X Axis field
this.aggregators.push({"field": groupByField, "operation": "GROUP BY"});
}
else{
$("#gb")[0].removeAttribute("disabled");
this.aggregators.push({"field": this.selectedFields[0], "operation": "GROUP BY"});
this.aggregators.push({"field": groupByField, "operation": "GROUP BY"});
}
this.aggregators.push({"field": this.selectedFields[1], "operation": this.functions[operationIndex]});
}
this.fireReady();
}, 0);
},
_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;
if(id == "gb"){
var gb_menu = $(this.$.group_by).find("paper-menu")[0];
field = this.groupableFields[gb_menu.selected];
}
else {
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_series_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) {
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>
|