Blame view

controllets/select-visualization-controllet/select-visualization-controllet.html 12.5 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
208
209
                  $(this.$.datalet_selection_datalet).perfectScrollbar();
  
                  this.params = {'data-url' : this.dataUrl};
  
fb05b400   Renato De Donato   controllet 2.0, n...
210
211
                  if(this.preselectedDatalet)
                      this._preselectDatalet();
93ba7167   Renato De Donato   filters bug fix + ln
212
213
214
215
216
217
218
219
220
221
222
              },
  
              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...
223
                  this.filters = this._copy(filters);
93ba7167   Renato De Donato   filters bug fix + ln
224
225
226
              },
  
              setFields : function(fields) {
fb05b400   Renato De Donato   controllet 2.0, n...
227
228
229
230
231
                  this.fields = this._copy(fields);
  
                  var inputs = this._getInputs();
                  if(inputs)
                      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
236
                  this.$.vslider._reset();
                  this.type = "";
93ba7167   Renato De Donato   filters bug fix + ln
237
                  this.$.datalet_selection_datalet_placeholder.innerHTML = "";
93ba7167   Renato De Donato   filters bug fix + ln
238
239
240
              },
  
              _translate : function(){
fb05b400   Renato De Donato   controllet 2.0, n...
241
242
243
244
                  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
245
  
93ba7167   Renato De Donato   filters bug fix + ln
246
                  this.$.dataletPreview.innerHTML = ln["dataletPreview_" + ln["localization"]];
93ba7167   Renato De Donato   filters bug fix + ln
247
248
249
              },
  
              _selectDatalet : function(e){
fb05b400   Renato De Donato   controllet 2.0, n...
250
  
93ba7167   Renato De Donato   filters bug fix + ln
251
252
253
254
255
256
257
                  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...
258
259
                      this.type = "";
                      this.$.options.setOptions([]);
93ba7167   Renato De Donato   filters bug fix + ln
260
261
262
263
                  }
                  else{
                      this.$.selectedDatalet_request.url = this.deepUrl + e.detail.datalet + "-datalet";
                      this.$.selectedDatalet_request.generateRequest();
93ba7167   Renato De Donato   filters bug fix + ln
264
265
266
267
                  }
              },
  
              _preselectDatalet : function() {
fb05b400   Renato De Donato   controllet 2.0, n...
268
269
270
271
  //                console.log("_preselectDatalet to implement");
  //                console.log(this.preselectedDatalet);
  //                console.log(this.fields);
  //                console.log(this.dataletPreset);
93ba7167   Renato De Donato   filters bug fix + ln
272
  
fb05b400   Renato De Donato   controllet 2.0, n...
273
274
275
276
277
278
                  var dataletParams ={
                      component   : this.preselectedDatalet+"-datalet",
                      params      : this.dataletPreset,
                      fields      : this.fields,
                      placeHolder : this.$.datalet_selection_datalet_placeholder
                  };
93ba7167   Renato De Donato   filters bug fix + ln
279
  
fb05b400   Renato De Donato   controllet 2.0, n...
280
281
                  ComponentService.deep_url = this.deepUrl;
                  ComponentService.getComponent(dataletParams);
93ba7167   Renato De Donato   filters bug fix + ln
282
  
fb05b400   Renato De Donato   controllet 2.0, n...
283
                  this.$.add_button.removeAttribute("disabled");
93ba7167   Renato De Donato   filters bug fix + ln
284
285
286
287
288
289
              },
  
              _handleSelectedDatalet : function(e){
  
                  if(this.type != e.detail.response.type) {
  
fb05b400   Renato De Donato   controllet 2.0, n...
290
                      this.type = e.detail.response.type;
93ba7167   Renato De Donato   filters bug fix + ln
291
  
fb05b400   Renato De Donato   controllet 2.0, n...
292
293
294
295
296
                      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
297
  
fb05b400   Renato De Donato   controllet 2.0, n...
298
                      this.$.options.setOptions(e.detail.response.idm.inputs.layouts.input);
93ba7167   Renato De Donato   filters bug fix + ln
299
300
                  }
                  else {
fb05b400   Renato De Donato   controllet 2.0, n...
301
                      this.$.options.ceckOptions(e.detail.response.idm.inputs.layouts.input);
93ba7167   Renato De Donato   filters bug fix + ln
302
303
                  }
  
fb05b400   Renato De Donato   controllet 2.0, n...
304
305
306
307
                  this.async(function () {
                      var inputs = this._getInputs();
                      inputs.fireReady();
                  }, 0);
93ba7167   Renato De Donato   filters bug fix + ln
308
309
              },
  
fb05b400   Renato De Donato   controllet 2.0, n...
310
311
312
              _tryLoadDatalet : function(){
                  var inputs = this._getInputs();
                  inputs.fireReady();
93ba7167   Renato De Donato   filters bug fix + ln
313
314
              },
  
fb05b400   Renato De Donato   controllet 2.0, n...
315
316
              _loadDatalet : function(){
                  var inputs = this._getInputs();
93ba7167   Renato De Donato   filters bug fix + ln
317
  
fb05b400   Renato De Donato   controllet 2.0, n...
318
                  this.selectedFields = inputs.getSelectedFields();
93ba7167   Renato De Donato   filters bug fix + ln
319
320
  
                  this.params["filters"] = JSON.stringify(this.filters);
fb05b400   Renato De Donato   controllet 2.0, n...
321
322
                  this.params["aggregators"] = JSON.stringify(inputs.getAggregators());
                  this.params["orders"] = JSON.stringify(inputs.getOrders());
93ba7167   Renato De Donato   filters bug fix + ln
323
  
fb05b400   Renato De Donato   controllet 2.0, n...
324
325
                  var params = this.$.options.getParams();
                  for (var key in params) { this.params[key] = params[key]; }
93ba7167   Renato De Donato   filters bug fix + ln
326
327
328
329
  
                  var dataletParams ={
                      component   : this.selectedDatalet+"-datalet",
                      params      : this.params,
fb05b400   Renato De Donato   controllet 2.0, n...
330
                      fields      : this.selectedFields,
93ba7167   Renato De Donato   filters bug fix + ln
331
332
333
334
335
336
337
338
339
340
                      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
341
342
343
                  var data = {
                      dataUrl : this.dataUrl,
                      params :  this.params,
fb05b400   Renato De Donato   controllet 2.0, n...
344
                      fields :  this.selectedFields,
93ba7167   Renato De Donato   filters bug fix + ln
345
                      datalet : this.selectedDatalet+"-datalet",
93ba7167   Renato De Donato   filters bug fix + ln
346
347
348
349
                      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
350
351
              },
  
fb05b400   Renato De Donato   controllet 2.0, n...
352
353
354
355
356
357
              _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
358
359
              },
  
fb05b400   Renato De Donato   controllet 2.0, n...
360
361
362
363
              _getInputs  : function(){
                  if(this.type == "multiseries")
                      return this.$$("#inputs_series")
                  return this.$$("#inputs");
93ba7167   Renato De Donato   filters bug fix + ln
364
365
366
367
368
369
370
371
372
373
374
375
              },
  
              _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
376
377
378
379
              _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...
380
                  $("#items_vslider_controllet").height(h);//vslider controllet
93ba7167   Renato De Donato   filters bug fix + ln
381
                  $("#datalet_selection_inputs").height(h);
fb05b400   Renato De Donato   controllet 2.0, n...
382
383
                  $("#datalet_selection_options").height(h);
  
93ba7167   Renato De Donato   filters bug fix + ln
384
385
386
387
388
389
390
391
                  $("#datalet_selection_datalet").height(h);
              }
  
          });
  
      </script>
  
  </dom-module>