Blame view

controllets/select-visualization-controllet/select-visualization-controllet.html 14 KB
93ba7167   Renato De Donato   filters bug fix + ln
1
2
3
4
  <link rel="import" href="../../bower_components/polymer/polymer.html" />
  
  <link rel="import" href="../../bower_components/paper-material/paper-material.html" />
  
93ba7167   Renato De Donato   filters bug fix + ln
5
6
  <link rel="import" href="../../bower_components/paper-button/paper-button.html">
  
93ba7167   Renato De Donato   filters bug fix + ln
7
  <link rel="import" href="../items-vslider-controllet/items-vslider-controllet.html" />
fb05b400   Renato De Donato   controllet 2.0, n...
8
9
10
  <link rel="import" href="select-datalet-inputs_series.html" />
  <link rel="import" href="select-datalet-inputs.html" />
  <link rel="import" href="select-datalet-options.html" />
93ba7167   Renato De Donato   filters bug fix + ln
11
12
13
  
  <script src="../../../DEEPCLIENT/js/deepClient.js"></script>
  
fb05b400   Renato De Donato   controllet 2.0, n...
14
  <dom-module id="select-visualization-controllet">
93ba7167   Renato De Donato   filters bug fix + ln
15
16
17
18
  
      <template>
  
          <style is="custom-style">
fb05b400   Renato De Donato   controllet 2.0, n...
19
              #select_visualization_container {
93ba7167   Renato De Donato   filters bug fix + ln
20
21
22
23
24
25
26
27
28
29
30
31
32
                  display: flex;
                  font-family: 'Roboto', 'Helvetica Neue', Helvetica, Arial, sans-serif;
                  font-size: 16px;
                  margin-top: 8px;
              }
  
              #items_vslider_controllet {
                  position: relative;
                  min-width: 172px;
              }
  
              #datalet_selection_inputs {
                  position: relative;
93ba7167   Renato De Donato   filters bug fix + ln
33
34
35
36
                  margin-left: 32px;
                  min-width: 258px;
              }
  
fb05b400   Renato De Donato   controllet 2.0, n...
37
              #datalet_selection_options {
93ba7167   Renato De Donato   filters bug fix + ln
38
                  position: relative;
93ba7167   Renato De Donato   filters bug fix + ln
39
40
41
42
                  margin-left: 32px;
                  min-width: 258px;
              }
  
fb05b400   Renato De Donato   controllet 2.0, n...
43
              #datalet_preview_container {
93ba7167   Renato De Donato   filters bug fix + ln
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
                  position: relative;
                  width: 100%;
                  margin-left: 32px;
              }
  
              #datalet_selection_datalet {
                  position: relative;
                  height: 100vh;
                  width: 100%;
              }
  
              #datalet_selection_datalet_placeholder {
                  padding: 16px;
              }
  
93ba7167   Renato De Donato   filters bug fix + ln
59
60
61
62
63
64
65
66
              .input_header {
                  height: 32px;
                  padding-top: 16px;
                  text-align: center;
                  font-weight: 700;
                  background-color: #B6B6B6;
              }
  
93ba7167   Renato De Donato   filters bug fix + ln
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
              paper-button {
                  position: absolute;
                  bottom: 16px;
                  right: 11px;
  
                  height: 48px;
                  width: 172px;
                  background-color: #00BCD4;
                  color: white;
                  font-weight: 700;
                  padding: 16px;
              }
  
              paper-button:hover {
                  background-color: #00AABF;
  
                  box-shadow: 0px 8px 12px #888;
                  -webkit-box-shadow: 0px 8px 12px #888;
                  -moz-box-shadow: 0px 8px 12px #888;
              }
  
              paper-button[disabled] {
                  background-color: #B6B6B6;
              }
93ba7167   Renato De Donato   filters bug fix + ln
91
92
93
94
          </style>
  
          <iron-ajax id="selectedDatalet_request" on-response="_handleSelectedDatalet"></iron-ajax>
  
fb05b400   Renato De Donato   controllet 2.0, n...
95
          <div id="select_visualization_container">
93ba7167   Renato De Donato   filters bug fix + ln
96
97
98
99
100
  
              <div id="items_vslider_controllet">
                  <items-vslider-controllet id="vslider" datalets-list-url={{dataletsListUrl}} preselected-datalet={{preselectedDatalet}}></items-vslider-controllet>
              </div>
  
fb05b400   Renato De Donato   controllet 2.0, n...
101
102
103
              <div id="datalet_selection_inputs">
                  <template is="dom-if" if="{{_checkType(type, 'multiseries')}}">
                      <select-datalet-inputs_series id="inputs_series"></select-datalet-inputs_series>
93ba7167   Renato De Donato   filters bug fix + ln
104
                  </template>
fb05b400   Renato De Donato   controllet 2.0, n...
105
106
107
108
109
                  <template is="dom-if" if="{{_checkType(type, 'default')}}">
                      <select-datalet-inputs id="inputs"></select-datalet-inputs>
                  </template>
                  <template is="dom-if" if="{{_checkType(type, '')}}">
                      <select-datalet-inputs></select-datalet-inputs>
93ba7167   Renato De Donato   filters bug fix + ln
110
                  </template>
fb05b400   Renato De Donato   controllet 2.0, n...
111
              </div>
93ba7167   Renato De Donato   filters bug fix + ln
112
  
fb05b400   Renato De Donato   controllet 2.0, n...
113
114
115
              <div id="datalet_selection_options">
                  <select-datalet-options id="options"></select-datalet-options>
              </div>
93ba7167   Renato De Donato   filters bug fix + ln
116
  
fb05b400   Renato De Donato   controllet 2.0, n...
117
              <div id="datalet_preview_container">
93ba7167   Renato De Donato   filters bug fix + ln
118
119
120
121
  
                  <paper-material id="datalet_selection_datalet" elevation="5">
                      <div class="input_header"><span id="dataletPreview"></span></div>
                      <div id="datalet_selection_datalet_placeholder"></div>
93ba7167   Renato De Donato   filters bug fix + ln
122
123
124
125
126
127
                  </paper-material>
  
                  <paper-button id="add_button" disabled raised on-click="_addDatalet"></paper-button>
  
              </div>
  
93ba7167   Renato De Donato   filters bug fix + ln
128
129
130
131
132
133
134
135
          </div>
  
      </template>
  
      <script>
  
          Polymer({
  
fb05b400   Renato De Donato   controllet 2.0, n...
136
              is : 'select-visualization-controllet',
93ba7167   Renato De Donato   filters bug fix + ln
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
  
              properties : {
  
                  deepUrl : {
                      type : String,
                      value : undefined
                  },
  
                  dataletsListUrl : {
                      type : String,
                      value : undefined
                  },
  
                  selectedDatalet : {
                      type  : String,
                      value : undefined
                  },
  
                  preselectedDatalet : {
                      type  : String,
                      value : undefined
                  },
  
93ba7167   Renato De Donato   filters bug fix + ln
160
161
                  type : {
                      type : String,
fb05b400   Renato De Donato   controllet 2.0, n...
162
                      value : ""
93ba7167   Renato De Donato   filters bug fix + ln
163
164
165
166
167
168
169
                  },
  
                  filters : {
                      type : Array,
                      value : []
                  },
  
93ba7167   Renato De Donato   filters bug fix + ln
170
171
172
173
174
175
176
177
178
179
                  fields : {
                      type : Array,
                      value : []
                  },
  
                  selectedFields : {
                      type : Array,
                      value : []
                  },
  
93ba7167   Renato De Donato   filters bug fix + ln
180
181
182
183
184
                  dataletPreset : {
                      type  : Object,
                      value : []
                  },
  
93ba7167   Renato De Donato   filters bug fix + ln
185
186
187
188
189
190
191
192
                  dataUrl : {
                      type  : String,
                      value : undefined
                  },
  
                  params:{
                      type: Object,
                      value: undefined
89558a41   Renato De Donato   datatype, provide...
193
194
195
196
197
198
                  },
  
                  data : {
                      type  : Object,
                      value : undefined
                  },
93ba7167   Renato De Donato   filters bug fix + ln
199
200
201
202
  
              },
  
              listeners: {
89558a41   Renato De Donato   datatype, provide...
203
204
  //                'select-fields-controllet_selected-fields': '_updateFields',
  //                'filters-controllet_filters': '_updateFilters',
93ba7167   Renato De Donato   filters bug fix + ln
205
                  'items-vslider-controllet_selected-datalet': '_selectDatalet',
fb05b400   Renato De Donato   controllet 2.0, n...
206
                  'select_visualization_inputs_ready': '_loadDatalet',
89558a41   Renato De Donato   datatype, provide...
207
                  'select_visualization_options_changed': '_tryLoadDatalet'
93ba7167   Renato De Donato   filters bug fix + ln
208
209
210
211
              },
  
              ready : function() {
                  this._resize();
fb05b400   Renato De Donato   controllet 2.0, n...
212
  
93ba7167   Renato De Donato   filters bug fix + ln
213
214
                  $(this.$.datalet_selection_datalet).perfectScrollbar();
  
a53fbbed   Renato De Donato   select-dataset ne...
215
  //                this.params = {'data-url' : this.dataUrl};//not here
93ba7167   Renato De Donato   filters bug fix + ln
216
217
218
219
220
221
222
223
224
225
226
              },
  
              attached : function() {
                  this._resize();
                  var that = this;
                  window.addEventListener("resize", function() { that._resize(); });
  
                  this._translate();
              },
  
              setFilters : function(filters) {
fb05b400   Renato De Donato   controllet 2.0, n...
227
                  this.filters = this._copy(filters);
93ba7167   Renato De Donato   filters bug fix + ln
228
229
230
              },
  
              setFields : function(fields) {
89558a41   Renato De Donato   datatype, provide...
231
232
  //                if (this.fields.length > 0 && JSON.stringify(this.fields) != JSON.stringify(fields))
  //                    this.init();
a53fbbed   Renato De Donato   select-dataset ne...
233
  
fb05b400   Renato De Donato   controllet 2.0, n...
234
235
236
                  this.fields = this._copy(fields);
  
                  var inputs = this._getInputs();
a53fbbed   Renato De Donato   select-dataset ne...
237
                  if (inputs)
fb05b400   Renato De Donato   controllet 2.0, n...
238
                      inputs.setFields(this.fields);
93ba7167   Renato De Donato   filters bug fix + ln
239
240
              },
  
89558a41   Renato De Donato   datatype, provide...
241
242
243
244
245
              setData : function(data) {
                  this.data = this._copy(data);
              },
  
              init : function() {
fb05b400   Renato De Donato   controllet 2.0, n...
246
                  this.$.vslider._reset();
a53fbbed   Renato De Donato   select-dataset ne...
247
248
249
              },
  
              show : function() {//show --> preselect
20f33314   Renato De Donato   preselect strikes...
250
251
  //                if(this.preselectedDatalet)
                  if(this.dataletPreset)
a53fbbed   Renato De Donato   select-dataset ne...
252
                      this._preselectDatalet();
20f33314   Renato De Donato   preselect strikes...
253
                  
a53fbbed   Renato De Donato   select-dataset ne...
254
255
256
257
  //                if (this.$.datalet_selection_datalet_placeholder.innerHTML == "") {
  //                    var inputs = this._getInputs();
  //                    inputs.fireReady();
  //                }
93ba7167   Renato De Donato   filters bug fix + ln
258
259
260
              },
  
              _translate : function(){
fb05b400   Renato De Donato   controllet 2.0, n...
261
262
263
264
                  if(this.preselectedDatalet)
                      this.$.add_button.innerHTML = ln["modifyDatalet_" + ln["localization"]];
                  else
                      this.$.add_button.innerHTML = ln["addDatalet_" + ln["localization"]];
93ba7167   Renato De Donato   filters bug fix + ln
265
  
93ba7167   Renato De Donato   filters bug fix + ln
266
                  this.$.dataletPreview.innerHTML = ln["dataletPreview_" + ln["localization"]];
93ba7167   Renato De Donato   filters bug fix + ln
267
268
269
              },
  
              _selectDatalet : function(e){
fb05b400   Renato De Donato   controllet 2.0, n...
270
  
93ba7167   Renato De Donato   filters bug fix + ln
271
272
273
274
275
276
277
                  this.$.add_button.setAttribute("disabled", "true");
  
                  this.selectedDatalet = e.detail.datalet;
  
                  this.$.datalet_selection_datalet_placeholder.innerHTML = "";
  
                  if(!this.selectedDatalet){
fb05b400   Renato De Donato   controllet 2.0, n...
278
279
                      this.type = "";
                      this.$.options.setOptions([]);
93ba7167   Renato De Donato   filters bug fix + ln
280
281
282
283
                  }
                  else{
                      this.$.selectedDatalet_request.url = this.deepUrl + e.detail.datalet + "-datalet";
                      this.$.selectedDatalet_request.generateRequest();
93ba7167   Renato De Donato   filters bug fix + ln
284
285
286
                  }
              },
  
93ba7167   Renato De Donato   filters bug fix + ln
287
288
289
290
              _handleSelectedDatalet : function(e){
  
                  if(this.type != e.detail.response.type) {
  
fb05b400   Renato De Donato   controllet 2.0, n...
291
                      this.type = e.detail.response.type;
93ba7167   Renato De Donato   filters bug fix + ln
292
  
fb05b400   Renato De Donato   controllet 2.0, n...
293
294
295
296
297
                      this.async(function () {
                          var inputs = this._getInputs();
                          inputs.setFields(this.fields);
                          inputs.setInputs(e.detail.response.idm.inputs.input);// Cannot read property '0' of undefined
                      }, 0);
93ba7167   Renato De Donato   filters bug fix + ln
298
  
fb05b400   Renato De Donato   controllet 2.0, n...
299
                      this.$.options.setOptions(e.detail.response.idm.inputs.layouts.input);
93ba7167   Renato De Donato   filters bug fix + ln
300
301
                  }
                  else {
20f33314   Renato De Donato   preselect strikes...
302
                      this.$.options.checkOptions(e.detail.response.idm.inputs.layouts.input);
93ba7167   Renato De Donato   filters bug fix + ln
303
304
                  }
  
fb05b400   Renato De Donato   controllet 2.0, n...
305
306
307
308
                  this.async(function () {
                      var inputs = this._getInputs();
                      inputs.fireReady();
                  }, 0);
a53fbbed   Renato De Donato   select-dataset ne...
309
310
311
312
313
314
315
  
  //                this.async(function () {
  //                    if(this.preselectedDatalet)
  //                        this._preselectDatalet();
  //                }, 1);
              },
  
12769acc   Renato De Donato   preselect bug
316
              _preselectDatalet : function() {
20f33314   Renato De Donato   preselect strikes...
317
                  this.$.vslider._preselectDatalet();
a53fbbed   Renato De Donato   select-dataset ne...
318
  
20f33314   Renato De Donato   preselect strikes...
319
320
321
322
323
324
325
326
327
                  this.async(function () {
                      this.$.options._preselectOptions(this.dataletPreset);
                  }, 100);
  
                  this.async(function () {
                      var inputs = this._getInputs();
                      inputs._preselectInputs(this.fields, this.dataletPreset["aggregators"], this.dataletPreset["orders"]);
                      this.dataletPreset = undefined;
                  }, 200);
93ba7167   Renato De Donato   filters bug fix + ln
328
329
              },
  
fb05b400   Renato De Donato   controllet 2.0, n...
330
331
332
              _tryLoadDatalet : function(){
                  var inputs = this._getInputs();
                  inputs.fireReady();
93ba7167   Renato De Donato   filters bug fix + ln
333
334
              },
  
9819a403   Renato De Donato   bubble scatter tr...
335
336
337
338
339
340
              _loadDatalet : function(e){
                  if(!e.detail.isReady) {
                      this.$.datalet_selection_datalet_placeholder.innerHTML = "";
                      return;
                  }
  
fb05b400   Renato De Donato   controllet 2.0, n...
341
                  var inputs = this._getInputs();
93ba7167   Renato De Donato   filters bug fix + ln
342
  
fb05b400   Renato De Donato   controllet 2.0, n...
343
                  this.selectedFields = inputs.getSelectedFields();
93ba7167   Renato De Donato   filters bug fix + ln
344
  
0f4f5f1b   Renato De Donato   new datalets mult...
345
346
  //                console.log(inputs.getFields());
  
4cbf1380   Renato De Donato   preview cache
347
348
                  this.params = {'data-url' : this.dataUrl};//??????????????????
  //                this.params = {};
a53fbbed   Renato De Donato   select-dataset ne...
349
  
0f4f5f1b   Renato De Donato   new datalets mult...
350
351
                  this.params["selectedFields"] = JSON.stringify(inputs.getFields());
  
93ba7167   Renato De Donato   filters bug fix + ln
352
                  this.params["filters"] = JSON.stringify(this.filters);
fb05b400   Renato De Donato   controllet 2.0, n...
353
354
                  this.params["aggregators"] = JSON.stringify(inputs.getAggregators());
                  this.params["orders"] = JSON.stringify(inputs.getOrders());
93ba7167   Renato De Donato   filters bug fix + ln
355
  
382b55e7   Renato De Donato   ortelio
356
357
                  this.params["export_menu"] = "0";
  
fb05b400   Renato De Donato   controllet 2.0, n...
358
359
                  var params = this.$.options.getParams();
                  for (var key in params) { this.params[key] = params[key]; }
93ba7167   Renato De Donato   filters bug fix + ln
360
  
89558a41   Renato De Donato   datatype, provide...
361
362
                  var data = alasql_complexSelectData(this.data, this.selectedFields, this.filters, inputs.getAggregators(), inputs.getOrders());
                  data = transformData(data, this.selectedFields, true);
0f4f5f1b   Renato De Donato   new datalets mult...
363
364
365
  
                  //use cache
  //                this.params["data"] = JSON.stringify(data).replace(/'/g, "&#39;");
89558a41   Renato De Donato   datatype, provide...
366
  
93ba7167   Renato De Donato   filters bug fix + ln
367
                  var dataletParams ={
89558a41   Renato De Donato   datatype, provide...
368
                      component: this.selectedDatalet+"-datalet",
89558a41   Renato De Donato   datatype, provide...
369
                      fields: this.selectedFields,
4cbf1380   Renato De Donato   preview cache
370
                      params: this.params,
89558a41   Renato De Donato   datatype, provide...
371
                      placeHolder: this.$.datalet_selection_datalet_placeholder,
93ba7167   Renato De Donato   filters bug fix + ln
372
373
374
375
376
377
378
379
380
                  };
  
                  ComponentService.deep_url = this.deepUrl;
                  ComponentService.getComponent(dataletParams);
  
                  this.$.add_button.removeAttribute("disabled");
              },
  
              _addDatalet : function(){
9124e8df   Renato De Donato   export_menu bug fix
381
                  delete this.params["export_menu"];
8c43b0b4   Renato De Donato   remove cache on a...
382
                  delete this.params["data"];
9124e8df   Renato De Donato   export_menu bug fix
383
  
93ba7167   Renato De Donato   filters bug fix + ln
384
                  var data = {
89558a41   Renato De Donato   datatype, provide...
385
                      dataUrl: this.dataUrl,
89558a41   Renato De Donato   datatype, provide...
386
                      datalet: this.selectedDatalet+"-datalet",
4cbf1380   Renato De Donato   preview cache
387
388
                      fields: this.selectedFields,
                      params: this.params,
89558a41   Renato De Donato   datatype, provide...
389
                      staticData: JSON.stringify(this.$.datalet_selection_datalet_placeholder.children[1].behavior.data)
93ba7167   Renato De Donato   filters bug fix + ln
390
391
392
                  }
  
                  this.fire('data-sevc-controllet.dataletCreated', {data : data});
93ba7167   Renato De Donato   filters bug fix + ln
393
394
              },
  
fb05b400   Renato De Donato   controllet 2.0, n...
395
396
397
398
399
400
              _checkType: function(type, check){
                  if (type == "multiseries" || type == "")
                      return (type == check);
                  else if(check == "default")
                      return true;
                  return false;
93ba7167   Renato De Donato   filters bug fix + ln
401
402
              },
  
fb05b400   Renato De Donato   controllet 2.0, n...
403
404
405
406
              _getInputs  : function(){
                  if(this.type == "multiseries")
                      return this.$$("#inputs_series")
                  return this.$$("#inputs");
93ba7167   Renato De Donato   filters bug fix + ln
407
408
409
410
411
412
413
414
415
416
417
418
              },
  
              _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;
              },
  
93ba7167   Renato De Donato   filters bug fix + ln
419
420
421
422
              _resize : function(){
                  var h = Math.max(document.documentElement.clientHeight, window.innerHeight || 0) - 16;
                  h = h - 64 - 8; //height with page scroller
  
fb05b400   Renato De Donato   controllet 2.0, n...
423
                  $("#items_vslider_controllet").height(h);//vslider controllet
93ba7167   Renato De Donato   filters bug fix + ln
424
                  $("#datalet_selection_inputs").height(h);
fb05b400   Renato De Donato   controllet 2.0, n...
425
426
                  $("#datalet_selection_options").height(h);
  
93ba7167   Renato De Donato   filters bug fix + ln
427
428
429
430
431
432
433
434
                  $("#datalet_selection_datalet").height(h);
              }
  
          });
  
      </script>
  
  </dom-module>