Blame view

controllets/select-visualization-controllet/select-visualization-controllet.html 13.1 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
93ba7167   Renato De Donato   filters bug fix + ln
193
194
195
196
197
198
                  }
  
              },
  
              listeners: {
                  'items-vslider-controllet_selected-datalet': '_selectDatalet',
fb05b400   Renato De Donato   controllet 2.0, n...
199
200
                  'select_visualization_inputs_ready': '_loadDatalet',
                  'select_visualization_options_changed': '_tryLoadDatalet',
93ba7167   Renato De Donato   filters bug fix + ln
201
202
203
204
              },
  
              ready : function() {
                  this._resize();
fb05b400   Renato De Donato   controllet 2.0, n...
205
  
93ba7167   Renato De Donato   filters bug fix + ln
206
207
                  $(this.$.datalet_selection_datalet).perfectScrollbar();
  
a53fbbed   Renato De Donato   select-dataset ne...
208
  //                this.params = {'data-url' : this.dataUrl};//not here
93ba7167   Renato De Donato   filters bug fix + ln
209
210
211
212
213
214
215
216
217
218
219
              },
  
              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...
220
                  this.filters = this._copy(filters);
93ba7167   Renato De Donato   filters bug fix + ln
221
222
223
              },
  
              setFields : function(fields) {
a53fbbed   Renato De Donato   select-dataset ne...
224
225
226
                  if (this.fields.length > 0 && JSON.stringify(this.fields) != JSON.stringify(fields))
                      this.reset();
  
fb05b400   Renato De Donato   controllet 2.0, n...
227
228
229
                  this.fields = this._copy(fields);
  
                  var inputs = this._getInputs();
a53fbbed   Renato De Donato   select-dataset ne...
230
                  if (inputs)
fb05b400   Renato De Donato   controllet 2.0, n...
231
                      inputs.setFields(this.fields);
93ba7167   Renato De Donato   filters bug fix + ln
232
233
234
              },
  
              reset : function() {
fb05b400   Renato De Donato   controllet 2.0, n...
235
                  this.$.vslider._reset();
a53fbbed   Renato De Donato   select-dataset ne...
236
237
238
              },
  
              show : function() {//show --> preselect
20f33314   Renato De Donato   preselect strikes...
239
240
  //                if(this.preselectedDatalet)
                  if(this.dataletPreset)
a53fbbed   Renato De Donato   select-dataset ne...
241
                      this._preselectDatalet();
20f33314   Renato De Donato   preselect strikes...
242
                  
a53fbbed   Renato De Donato   select-dataset ne...
243
244
245
246
  //                if (this.$.datalet_selection_datalet_placeholder.innerHTML == "") {
  //                    var inputs = this._getInputs();
  //                    inputs.fireReady();
  //                }
93ba7167   Renato De Donato   filters bug fix + ln
247
248
249
              },
  
              _translate : function(){
fb05b400   Renato De Donato   controllet 2.0, n...
250
251
252
253
                  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
254
  
93ba7167   Renato De Donato   filters bug fix + ln
255
                  this.$.dataletPreview.innerHTML = ln["dataletPreview_" + ln["localization"]];
93ba7167   Renato De Donato   filters bug fix + ln
256
257
258
              },
  
              _selectDatalet : function(e){
fb05b400   Renato De Donato   controllet 2.0, n...
259
  
93ba7167   Renato De Donato   filters bug fix + ln
260
261
262
263
264
265
266
                  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...
267
268
                      this.type = "";
                      this.$.options.setOptions([]);
93ba7167   Renato De Donato   filters bug fix + ln
269
270
271
272
                  }
                  else{
                      this.$.selectedDatalet_request.url = this.deepUrl + e.detail.datalet + "-datalet";
                      this.$.selectedDatalet_request.generateRequest();
93ba7167   Renato De Donato   filters bug fix + ln
273
274
275
                  }
              },
  
93ba7167   Renato De Donato   filters bug fix + ln
276
277
278
279
              _handleSelectedDatalet : function(e){
  
                  if(this.type != e.detail.response.type) {
  
fb05b400   Renato De Donato   controllet 2.0, n...
280
                      this.type = e.detail.response.type;
93ba7167   Renato De Donato   filters bug fix + ln
281
  
fb05b400   Renato De Donato   controllet 2.0, n...
282
283
284
285
286
                      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
287
  
fb05b400   Renato De Donato   controllet 2.0, n...
288
                      this.$.options.setOptions(e.detail.response.idm.inputs.layouts.input);
93ba7167   Renato De Donato   filters bug fix + ln
289
290
                  }
                  else {
20f33314   Renato De Donato   preselect strikes...
291
                      this.$.options.checkOptions(e.detail.response.idm.inputs.layouts.input);
93ba7167   Renato De Donato   filters bug fix + ln
292
293
                  }
  
fb05b400   Renato De Donato   controllet 2.0, n...
294
295
296
297
                  this.async(function () {
                      var inputs = this._getInputs();
                      inputs.fireReady();
                  }, 0);
a53fbbed   Renato De Donato   select-dataset ne...
298
299
300
301
302
303
304
  
  //                this.async(function () {
  //                    if(this.preselectedDatalet)
  //                        this._preselectDatalet();
  //                }, 1);
              },
  
20f33314   Renato De Donato   preselect strikes...
305
306
              _preselectDatalet : function() {console.log("preselzionando si impara");
                  this.$.vslider._preselectDatalet();
a53fbbed   Renato De Donato   select-dataset ne...
307
  
20f33314   Renato De Donato   preselect strikes...
308
309
310
311
312
313
314
315
316
                  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
317
318
              },
  
fb05b400   Renato De Donato   controllet 2.0, n...
319
320
321
              _tryLoadDatalet : function(){
                  var inputs = this._getInputs();
                  inputs.fireReady();
93ba7167   Renato De Donato   filters bug fix + ln
322
323
              },
  
9819a403   Renato De Donato   bubble scatter tr...
324
325
326
327
328
329
              _loadDatalet : function(e){
                  if(!e.detail.isReady) {
                      this.$.datalet_selection_datalet_placeholder.innerHTML = "";
                      return;
                  }
  
fb05b400   Renato De Donato   controllet 2.0, n...
330
                  var inputs = this._getInputs();
93ba7167   Renato De Donato   filters bug fix + ln
331
  
fb05b400   Renato De Donato   controllet 2.0, n...
332
                  this.selectedFields = inputs.getSelectedFields();
93ba7167   Renato De Donato   filters bug fix + ln
333
  
a53fbbed   Renato De Donato   select-dataset ne...
334
335
                  this.params = {'data-url' : this.dataUrl};
  
93ba7167   Renato De Donato   filters bug fix + ln
336
                  this.params["filters"] = JSON.stringify(this.filters);
fb05b400   Renato De Donato   controllet 2.0, n...
337
338
                  this.params["aggregators"] = JSON.stringify(inputs.getAggregators());
                  this.params["orders"] = JSON.stringify(inputs.getOrders());
93ba7167   Renato De Donato   filters bug fix + ln
339
  
382b55e7   Renato De Donato   ortelio
340
341
                  this.params["export_menu"] = "0";
  
fb05b400   Renato De Donato   controllet 2.0, n...
342
343
                  var params = this.$.options.getParams();
                  for (var key in params) { this.params[key] = params[key]; }
93ba7167   Renato De Donato   filters bug fix + ln
344
345
346
347
  
                  var dataletParams ={
                      component   : this.selectedDatalet+"-datalet",
                      params      : this.params,
fb05b400   Renato De Donato   controllet 2.0, n...
348
                      fields      : this.selectedFields,
93ba7167   Renato De Donato   filters bug fix + ln
349
350
351
352
353
354
355
356
357
358
                      placeHolder : this.$.datalet_selection_datalet_placeholder
                  };
  
                  ComponentService.deep_url = this.deepUrl;
                  ComponentService.getComponent(dataletParams);
  
                  this.$.add_button.removeAttribute("disabled");
              },
  
              _addDatalet : function(){
93ba7167   Renato De Donato   filters bug fix + ln
359
360
361
                  var data = {
                      dataUrl : this.dataUrl,
                      params :  this.params,
fb05b400   Renato De Donato   controllet 2.0, n...
362
                      fields :  this.selectedFields,
93ba7167   Renato De Donato   filters bug fix + ln
363
                      datalet : this.selectedDatalet+"-datalet",
93ba7167   Renato De Donato   filters bug fix + ln
364
365
366
367
                      staticData : JSON.stringify(this.$.datalet_selection_datalet_placeholder.children[1].behavior.data)
                  }
  
                  this.fire('data-sevc-controllet.dataletCreated', {data : data});
93ba7167   Renato De Donato   filters bug fix + ln
368
369
              },
  
fb05b400   Renato De Donato   controllet 2.0, n...
370
371
372
373
374
375
              _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
376
377
              },
  
fb05b400   Renato De Donato   controllet 2.0, n...
378
379
380
381
              _getInputs  : function(){
                  if(this.type == "multiseries")
                      return this.$$("#inputs_series")
                  return this.$$("#inputs");
93ba7167   Renato De Donato   filters bug fix + ln
382
383
384
385
386
387
388
389
390
391
392
393
              },
  
              _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
394
395
396
397
              _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...
398
                  $("#items_vslider_controllet").height(h);//vslider controllet
93ba7167   Renato De Donato   filters bug fix + ln
399
                  $("#datalet_selection_inputs").height(h);
fb05b400   Renato De Donato   controllet 2.0, n...
400
401
                  $("#datalet_selection_options").height(h);
  
93ba7167   Renato De Donato   filters bug fix + ln
402
403
404
405
406
407
408
409
                  $("#datalet_selection_datalet").height(h);
              }
  
          });
  
      </script>
  
  </dom-module>