Blame view

controllets/datalet-selection-controllet/datalet-selection-controllet.html 15.2 KB
a31f0660   root   sevc-controllet i...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
  <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">
  
  <link rel="import" href="../../bower_components/paper-input/paper-textarea.html">
  
  <link rel="import" href="../../bower_components/paper-button/paper-button.html">
  
  <link rel="import" href="../items-vslider-controllet/items-vslider-controllet.html" />
  
0f6424fe   root   update new data-s...
19
  <script src="../../../DEEPCLIENT/js/deepClient.js"></script>
a31f0660   root   sevc-controllet i...
20
21
22
23
24
25
26
27
28
29
30
  
  <dom-module id="datalet-selection-controllet">
  
      <template>
  
          <style is="custom-style">
  
              #datalet_selection_container {
                  display: flex;
                  font-family: 'Roboto', 'Helvetica Neue', Helvetica, Arial, sans-serif;
                  font-size: 16px;
0f6424fe   root   update new data-s...
31
                  margin-top: 8px;
a31f0660   root   sevc-controllet i...
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
              }
  
              #datalet_selection_inputs {
                  position: relative;
                  height: 100vh;
                  margin-left: 32px;
                  width: 344px;
              }
  
              #datalet_selection_labels {
                  position: relative;
                  height: 100vh;
                  margin-left: 32px;
                  width: 344px;
              }
  
              #datalet_selection_column {
                  position: relative;
                  width: 100%;
                  margin-left: 32px;
              }
  
              #datalet_selection_datalet {
                  position: relative;
                  height: 100vh;
                  width: 100%;
                  /*margin-left: 32px;*/
                  /*margin-top: 32px;*/
                  /*margin-bottom: 32px;*/
              }
  
              #datalet_selection_comment{
                  width: 100%;
                  margin-bottom: 32px;
              }
  
              #datalet_selection_datalet_placeholder {
                  padding: 16px;
              }
  
              .inputs{
                  position: relative;
                  /*margin-left: 16px;*/
                  /*margin-right: 16px;*/
              }
  
              .input_name{
                  height: 16px;
                  padding: 16px;
                  /*background-color: #B6B6B6;*/
  
                  background-color: #2196F3;
                  color: #FFFFFF;
                  font-weight: 700;
              }
  
              .input_header{
                  /*height: 16px;*/
                  padding: 16px;
                  background-color: #B6B6B6;
                  text-align: center;
                  font-weight: 700;
              }
  
              .info_button {
                  position: absolute;
                  top: 4px;
                  right: 0px;
              }
  
              paper-textarea {
                  height: 48px;
                  padding: 0px 8px;
                  --paper-input-container-focus-color: #2196F3;
              }
  
              paper-dropdown-menu {
                  height: 48px;
                  padding: 0px 8px;
                  --paper-input-container-focus-color: #2196F3;
              }
  
              paper-item.iron-selected {
                  background-color: #2196F3;
                  color: #FFFFFF;
              }
  
              paper-icon-button {
                  /*color: #2196F3;*/
                  color: #FFFFFF;
                  --paper-icon-button-ink-color: #2196F3;
                  /*padding: 0px;*/
              }
  
              paper-button {
                  /*display: block;*/
                  position: absolute;
                  bottom: 16px;
                  right: 11px;
  
                  /*float: right;*/
                  /*margin-right: 11px;*/
  
  
  
  
                  height: 48px;
                  width: 172px;
                  background-color: #00BCD4;
                  color: white;
                  font-weight: 700;
                  padding: 16px;
              }
  
              paper-button:hover {
                  background-color: #00AABF;
              }
0f6424fe   root   update new data-s...
149
150
151
152
  
              paper-button[disabled] {
                  background-color: #B6B6B6;
              }
a31f0660   root   sevc-controllet i...
153
154
          </style>
  
0f6424fe   root   update new data-s...
155
          <iron-ajax id="selectedDatalet_request" on-response="_handleSelectedDatalet"></iron-ajax>
a31f0660   root   sevc-controllet i...
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
  
          <div id="datalet_selection_container">
              <items-vslider-controllet datalets-list-url={{dataletsListUrl}}></items-vslider-controllet>
  
  
              <paper-material id="datalet_selection_inputs" elevation="5">
                  <div class="input_header">INPUTS</div>
                  <template is="dom-repeat" items="{{inputs}}" index-as="index">
                      <div class="inputs">
                          <div class="input_name">
                              {{item.name}}
                              <div class="info_button">
                                  <paper-icon-button id="info_button" on-click="_showInfo" icon="info-outline" title="{{item.name}} info"></paper-icon-button>
                              </div>
                          </div>
                          <paper-dropdown-menu no-label-float label={{item.name}}>
                              <paper-menu class="dropdown-content">
0f6424fe   root   update new data-s...
173
                                  <template is="dom-repeat" items={{selectableFields}}>
a31f0660   root   sevc-controllet i...
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
                                      <paper-item id={{index}} on-tap="_loadDatalet">{{item}}</paper-item>
                                  </template>
                              </paper-menu>
                          </paper-dropdown-menu>
                      </div>
                  </template>
              </paper-material>
  
              <paper-material id="datalet_selection_labels" elevation="5">
                  <div class="input_header">LABELS</div>
                  <template is="dom-repeat" items="{{labels}}" index-as="index">
                      <div class="inputs">
                          <div class="input_name">
                              {{item.name}}
                              <div class="info_button">
                                  <paper-icon-button id="info_button" on-click="_showInfo" icon="info-outline" title="{{item.name}} info"></paper-icon-button>
                              </div>
                          </div>
                          <paper-textarea no-label-float label={{item.name}}></paper-textarea>
                      </div>
                  </template>
              </paper-material>
  
  
              <div id="datalet_selection_column">
                  <paper-material id="datalet_selection_comment" elevation="5">
                      <div class="input_header">COMMENT</div>
0f6424fe   root   update new data-s...
201
                      <paper-textarea id="comment" no-label-float maxlength="100" label="comment (max 100 characters)"></paper-textarea>
a31f0660   root   sevc-controllet i...
202
203
204
205
206
207
208
209
                  </paper-material>
  
                  <paper-material id="datalet_selection_datalet" elevation="5">
                      <div class="input_header">DATALET PREVIEW</div>
                      <div id="datalet_selection_datalet_placeholder"></div>
  
                  </paper-material>
  
0f6424fe   root   update new data-s...
210
                  <paper-button id="add_button" disabled raised on-click="_addDatalet">ADD DATALET</paper-button>
a31f0660   root   sevc-controllet i...
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
  
              </div>
  
          </div>
  
      </template>
  
      <script>
  
          Polymer({
  
              is : 'datalet-selection-controllet',
  
              properties : {
  
                  deepUrl : {
                      type : String,
                      value : undefined
                  },
  
                  dataletsListUrl : {
                      type : String,
                      value : undefined
                  },
  
                  selectedDatalet : {
                      type  : String,
                      value : undefined
                  },
  
                  inputs : {
                      type : Array,
                      value : []
                  },
  
                  labels : {
                      type : Array,
                      value : []
                  },
  
                  fields : {
                      type : Array,
0f6424fe   root   update new data-s...
253
254
255
256
257
258
259
260
261
262
263
                      value : []
                  },
  
                  selectedFields : {
                      type : Array,
                      value : []
                  },
  
                  selectableFields : {
                      type : Array,
                      value : []
a31f0660   root   sevc-controllet i...
264
265
266
267
                  },
  
                  dataUrl : {
                      type  : String,
0f6424fe   root   update new data-s...
268
                      value : undefined
a31f0660   root   sevc-controllet i...
269
270
271
272
273
274
                  }
  
              },
  
              listeners: {
                  'items-vslider-controllet_selected-datalet': '_dataletSelected'
0f6424fe   root   update new data-s...
275
  //                'tree-view-controllet_selected-fields': '_updateSelectedFields'
a31f0660   root   sevc-controllet i...
276
277
278
279
280
281
282
              },
  
              ready : function() {
                  this._resize();
                  $(this.$.datalet_selection_inputs).perfectScrollbar();
                  $(this.$.datalet_selection_labels).perfectScrollbar();
                  $(this.$.datalet_selection_datalet).perfectScrollbar();
0f6424fe   root   update new data-s...
283
284
  
                  this.selectableFields = this._copy(this.fields);
a31f0660   root   sevc-controllet i...
285
286
287
288
289
290
291
292
              },
  
              attached : function() {
                  this._resize();
                  var that = this;
                  window.addEventListener("resize", function() { that._resize(); });
              },
  
0f6424fe   root   update new data-s...
293
294
295
296
              setFields : function(fields) {
                  this.fields = fields;
              },
  
a31f0660   root   sevc-controllet i...
297
              _dataletSelected : function(e){
0f6424fe   root   update new data-s...
298
299
                  this.$.add_button.setAttribute("disabled", "true");
  
a31f0660   root   sevc-controllet i...
300
                  this.selectedDatalet = e.detail.datalet;
0f6424fe   root   update new data-s...
301
302
303
                  this.inputs = [];
                  this.labels = [];
  
a31f0660   root   sevc-controllet i...
304
305
306
307
                  if(this.selectedDatalet){
                      this.$.selectedDatalet_request.url = this.deepUrl + e.detail.datalet + "-datalet";
                      this.$.selectedDatalet_request.generateRequest();
                  }
0f6424fe   root   update new data-s...
308
309
310
311
312
313
314
  //                else {
  //                    this.inputs = [];
  //                    this.labels = [];
  //                }
  
                  this.$.datalet_selection_datalet_placeholder.innerHTML = "";
                  this.selectedFields = [];
29124159   root   ckan tree-view up...
315
                  this.selectableFields =  this._copy(this.fields);
0f6424fe   root   update new data-s...
316
317
318
  
  //                this.async(function(){this._loadPreview();}, 1000);
                  this._loadPreview();
a31f0660   root   sevc-controllet i...
319
320
              },
  
0f6424fe   root   update new data-s...
321
322
323
324
              _handleSelectedDatalet : function(e){
  
  
  //                console.log(e.detail.response.idm.inputs);
a31f0660   root   sevc-controllet i...
325
326
327
328
329
330
  //                console.log(e.detail.response.idm.inputs.layouts.input);
                  var inputs = e.detail.response.idm.inputs.input;
                  var labels = e.detail.response.idm.inputs.layouts.input;
  
                  if(inputs.constructor == Object) {//not Array && inputs.input.selection == "*"
                      var name = inputs.name;
0f6424fe   root   update new data-s...
331
332
                      var description = inputs.description;
                      var selection = inputs.selection;
a31f0660   root   sevc-controllet i...
333
334
                      inputs = [];
                      for(var i in this.fields)
0f6424fe   root   update new data-s...
335
                          inputs.push({name: name + " " + i, description: description, selection: selection});
a31f0660   root   sevc-controllet i...
336
337
338
339
340
341
342
  
                  }
  
                  this.inputs = inputs;
                  this.labels = labels;
              },
  
0f6424fe   root   update new data-s...
343
344
345
346
347
348
349
350
351
352
353
354
              _copy : function(o) {
                  var out, v, key;
                  out = Array.isArray(o) ? [] : {};
                  for (key in o) {
                      v = o[key];
                      out[key] = (typeof v === "object") ? this._copy(v) : v;
                  }
                  return out;
              },
  
              _loadDatalet : function(e){
                  var selectedFields = this._copy(this.selectedFields);
29124159   root   ckan tree-view up...
355
                  var selectableFields = this._copy(this.selectableFields);
0f6424fe   root   update new data-s...
356
357
358
359
360
361
362
363
364
365
366
367
368
369
  
                  if($(e.target).parents("paper-dropdown-menu")[0].selectedItem) {
                      var prevSelected = $(e.target).parents("paper-dropdown-menu")[0].selectedItem.innerText;
                      var index = this.selectedFields.indexOf(prevSelected);
                      selectedFields.splice(index, 1);
  //                    selectableFields.push(prevSelected);
                  }
  
                  var selected = e.target.innerText;
  //                var index = this.selectableFields.indexOf(selected);
  //                selectableFields.splice(index, 1);
                  selectedFields.push(selected);
  
                  this.selectedFields = selectedFields;
29124159   root   ckan tree-view up...
370
                  this.selectableFields = selectableFields;
0f6424fe   root   update new data-s...
371
  
29124159   root   ckan tree-view up...
372
373
                  console.log(this.selectedFields);
                  console.log(this.selectableFields);
0f6424fe   root   update new data-s...
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
  
                  var load = false;
                  if(this.selectedFields.length > 0 && this.inputs[0].selection == "*")
                      load = true;
                  else if(this.selectedFields.length == this.inputs.length)
                      load = true;
  
                  if(load){
                      var params = {'data-url' : this.dataUrl};
  
                      var dataletParams ={
                          component   : this.selectedDatalet+"-datalet",
                          params      : params,
                          fields      : this.selectedFields,
                          placeHolder : datalet_selection_datalet_placeholder
                      };
  
                      ComponentService.deep_url = this.deepUrl;
                      ComponentService.getComponent(dataletParams);
  
                      this.async(function(){this.$.add_button.removeAttribute("disabled");}, 1111);
                  }
  
  //                this.$.datalet_selection_datalet_placeholder.innerHTML = "<datatable-datalet data-url=\"http://ckan.routetopa.eu/api/action/datastore_search?resource_id=73e02092-85a1-434e-85fe-0c9a43aa9a52&amp;limit=10000\" fields='[\"result,records,Lat\",\"result,records,Lng\"]'>we";
  //                this.$.datalet_selection_datalet_placeholder.innerHTML = "<"+this.selectedDatalet+"-datalet data-url=\""+this.dataUrl+"\" fields='"+JSON.stringify(this.fields)+"'></"+this.selectedDatalet+">";
a31f0660   root   sevc-controllet i...
399
400
401
402
403
404
  
  //                $("#base_datalet_container").html("");
                  $("#base_datalet_container").css('visibility','hidden');
                  $("#base_datalet_container").css('padding','0px');
                  $("#base_datalet_container").css('height','0px');
  //                console.log($("#base_datalet_container"));
0f6424fe   root   update new data-s...
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
              },
  
              _addDatalet : function(){console.log("we");
  
                  var data = {
                      dataUrl : this.dataUrl,
  //                    params :  this.paramsFields,
                      params :  {'data-url' : this.dataUrl},
                      fields :  this.selectedFields,
                      datalet : this.selectedDatalet+"-datalet",
                      comment : this.$.comment.value,
                      staticData : JSON.stringify(this.$.datalet_selection_datalet_placeholder.children[1].behavior.data)
                  }
  
                  this.fire('data-sevc-controllet.dataletCreated', {data : data});
a31f0660   root   sevc-controllet i...
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
  
              },
  
              _resize : function(){
                  var h = Math.max(document.documentElement.clientHeight, window.innerHeight || 0) - 16;
                  h = h - 64 - 8; //height with page scroller
  
                  $("#items_vslider_container").height(h);//vslider controllet
  
                  $("#datalet_selection_inputs").height(h);
                  $("#datalet_selection_labels").height(h);
                  $("#datalet_selection_datalet").height(h-132);
              }
  
          });
  
      </script>
  
  </dom-module>