Blame view

controllets/select-data-controllet/select-data-controllet.html 8.36 KB
0af843be   Renato De Donato   filters + alasql
1
2
  <link rel="import" href="../../bower_components/polymer/polymer.html" />
  
89558a41   Renato De Donato   datatype, provide...
3
4
  <link rel="import" href="../select-fields-controllet/select-fields-controllet.html" />
  <link rel="import" href="../data-table-controllet/data-table-controllet.html" />
0af843be   Renato De Donato   filters + alasql
5
6
  <link rel="import" href="../filters-controllet/filters-controllet.html" />
  
89558a41   Renato De Donato   datatype, provide...
7
8
9
10
11
  <link rel="import" href="../providers-utility-controllet/providers-utility-controllet.html" />
  
  <script type="text/javascript" src="../../alasql-utility/alasql.min.js"></script>
  <script type="text/javascript" src="../../alasql-utility/alasql-utility.js"></script>
  
706288a2   Renato De Donato   geojson incoming
12
  <script type="text/javascript" src="../../bower_components/jsdatachecker/jsdatachecker.min.js"></script>
89558a41   Renato De Donato   datatype, provide...
13
  
0af843be   Renato De Donato   filters + alasql
14
15
16
  <dom-module id="select-data-controllet">
  
      <style is="custom-style">
89558a41   Renato De Donato   datatype, provide...
17
18
  
          #select_data_controllet_container {
0af843be   Renato De Donato   filters + alasql
19
20
              display: flex;
              flex-direction: row;
89558a41   Renato De Donato   datatype, provide...
21
              margin-top: 8px;
0af843be   Renato De Donato   filters + alasql
22
          }
89558a41   Renato De Donato   datatype, provide...
23
24
25
26
27
  
          #select_data_controllet_container * {
              font-family: 'Roboto', 'Helvetica Neue', Helvetica, Arial, sans-serif;
              font-size: 16px;
              line-height: 24px;
0af843be   Renato De Donato   filters + alasql
28
          }
0af843be   Renato De Donato   filters + alasql
29
  
89558a41   Renato De Donato   datatype, provide...
30
31
32
33
34
35
36
37
38
39
          #select_data_controllet_container #fields_container {
              height: 100%;
              width: 20%;
              min-width: 192px;
          }
  
          #select_data_controllet_container #right_container {
              height: 100%;
              width: calc(80% - 24px);
              margin-left: 24px;
0af843be   Renato De Donato   filters + alasql
40
41
          }
  
89558a41   Renato De Donato   datatype, provide...
42
43
          #select_data_controllet_container #table_container {
              height: calc(100% - 72px);
0af843be   Renato De Donato   filters + alasql
44
              width: 100%;
0af843be   Renato De Donato   filters + alasql
45
          }
89558a41   Renato De Donato   datatype, provide...
46
47
48
  
          #select_data_controllet_container #filters_container {
              height: 48px;
0af843be   Renato De Donato   filters + alasql
49
              width: 100%;
89558a41   Renato De Donato   datatype, provide...
50
              margin-top: 24px;
0af843be   Renato De Donato   filters + alasql
51
          }
89558a41   Renato De Donato   datatype, provide...
52
  
0af843be   Renato De Donato   filters + alasql
53
54
55
56
      </style>
  
      <template>
  
89558a41   Renato De Donato   datatype, provide...
57
58
59
60
61
62
63
64
65
          <providers-utility-controllet></providers-utility-controllet>
  
          <div id="select_data_controllet_container">
              <div id="fields_container">
                  <select-fields-controllet id="select_fields"></select-fields-controllet>
              </div>
              <div id="right_container">
                  <div id="table_container">
                      <data-table-controllet id="data_table"></data-table-controllet>
0af843be   Renato De Donato   filters + alasql
66
                  </div>
89558a41   Renato De Donato   datatype, provide...
67
                  <div id="filters_container">
0af843be   Renato De Donato   filters + alasql
68
69
                      <filters-controllet id="filters"></filters-controllet>
                  </div>
89558a41   Renato De Donato   datatype, provide...
70
              </div>
0af843be   Renato De Donato   filters + alasql
71
72
          </div>
  
89558a41   Renato De Donato   datatype, provide...
73
  
0af843be   Renato De Donato   filters + alasql
74
75
76
77
78
79
80
81
82
      </template>
  
      <script>
          Polymer({
  
              is : 'select-data-controllet',
  
              properties : {
  
89558a41   Renato De Donato   datatype, provide...
83
                  dataUrl : {
0af843be   Renato De Donato   filters + alasql
84
                      type  : String,
89558a41   Renato De Donato   datatype, provide...
85
86
                      value : undefined
  //                    observer : '_init'
0af843be   Renato De Donato   filters + alasql
87
88
                  },
  
89558a41   Renato De Donato   datatype, provide...
89
90
                  data : {
                      type  : Object,
0af843be   Renato De Donato   filters + alasql
91
92
93
                      value : undefined
                  },
  
89558a41   Renato De Donato   datatype, provide...
94
95
96
                  filters : {
                      type  : Array,
                      value : []
98d9d8a5   Renato De Donato   filters+groupby
97
98
                  },
  
89558a41   Renato De Donato   datatype, provide...
99
                  selectedFields : {
98d9d8a5   Renato De Donato   filters+groupby
100
                      type : Array,
a53fbbed   Renato De Donato   select-dataset ne...
101
                      value : []
89558a41   Renato De Donato   datatype, provide...
102
                  }
0af843be   Renato De Donato   filters + alasql
103
104
105
106
  
              },
  
              listeners: {
89558a41   Renato De Donato   datatype, provide...
107
108
                  'filters-controllet_show': '_resizeFilters',
                  'select-fields-controllet_selected-fields': '_updateFields',
98d9d8a5   Renato De Donato   filters+groupby
109
                  'filters-controllet_filters': '_updateFilters'
0af843be   Renato De Donato   filters + alasql
110
111
112
              },
  
              ready : function() {
89558a41   Renato De Donato   datatype, provide...
113
                  this.showFilter = false;
0af843be   Renato De Donato   filters + alasql
114
115
116
117
118
119
              },
  
              attached : function(){
                  this._resize();
                  var that = this;
                  window.addEventListener("resize", function() { that._resize(); });
a53fbbed   Renato De Donato   select-dataset ne...
120
121
              },
  
89558a41   Renato De Donato   datatype, provide...
122
123
              getSelectedFields : function() {
                  return utility_getSelectedFields(this.fields, this.selectedFields);;
0af843be   Renato De Donato   filters + alasql
124
125
              },
  
98d9d8a5   Renato De Donato   filters+groupby
126
              getFilters : function() {
89558a41   Renato De Donato   datatype, provide...
127
                  return this.filters;
98d9d8a5   Renato De Donato   filters+groupby
128
129
              },
  
89558a41   Renato De Donato   datatype, provide...
130
              getData : function() {
0f4f5f1b   Renato De Donato   new datalets mult...
131
132
                  //return datatable.getData
                  //this.fields = "*"
420ea6ab   Renato De Donato   workcicle...
133
                  var data = alasql_QUERY(this.data, this.fields, this.filters, null, null);
0f4f5f1b   Renato De Donato   new datalets mult...
134
135
136
137
138
139
                  var converter = new DataTypeConverter();
                  var result = converter.inferJsonDataType(data, ["*"]);
                  result = converter.cast(result);
                  data = result.dataset;
  
                  return data;
0af843be   Renato De Donato   filters + alasql
140
141
              },
  
4f438cd9   Renato De Donato   datalets-modifier
142
143
144
              setSelectedFields : function(selectedFields) {
                  this.async(function() {
                      var selectedIndices = utility_getSelectedIndices(this.fields, selectedFields);
4f438cd9   Renato De Donato   datalets-modifier
145
146
147
148
149
150
151
152
153
154
                      this.$.select_fields.setSelectFields(selectedIndices);
                  }, 0);
              },
  
              setFilters : function(filters) {
                  this.async(function() {
                      this.$.filters.setFilters(filters);
                  }, 0);
              },
  
89558a41   Renato De Donato   datatype, provide...
155
156
157
158
159
160
161
162
163
164
165
166
167
              _resizeFilters : function() {
                  if(!this.showFilter) {
                      this.$.table_container.style.height = "calc(50% - 12px)";
                      this.$.filters_container.style.height = "calc(50% - 12px)";
                  }
                  else {
                      this.$.table_container.style.height = "calc(100% - 72px)";
                      this.$.filters_container.style.height = "48px";
                  }
  
                  this.$.data_table._resize();
  
                  this.showFilter = !this.showFilter;
0af843be   Renato De Donato   filters + alasql
168
169
              },
  
89558a41   Renato De Donato   datatype, provide...
170
171
172
              _updateFields : function(e) {
                  this.selectedFields = e.detail.selectedFields;
                  var fields = utility_getSelectedFields(this.fields, this.selectedFields);
420ea6ab   Renato De Donato   workcicle...
173
                  var data = alasql_QUERY(this.data, fields, this.filters, null, null);
89558a41   Renato De Donato   datatype, provide...
174
175
                  this.$.data_table.setData(data);
              },
0af843be   Renato De Donato   filters + alasql
176
  
89558a41   Renato De Donato   datatype, provide...
177
178
179
              _updateFilters : function(e) {
                  this.filters = e.detail.filters;
                  var fields = utility_getSelectedFields(this.fields, this.selectedFields);
420ea6ab   Renato De Donato   workcicle...
180
                  var data = alasql_QUERY(this.data, fields, this.filters, null, null);
89558a41   Renato De Donato   datatype, provide...
181
                  this.$.data_table.setData(data);
0af843be   Renato De Donato   filters + alasql
182
183
              },
  
89558a41   Renato De Donato   datatype, provide...
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
              init : function() {
                  if(this.dataUrl) {
  
                      var that = this;
  
                      $.ajax({
                          url: this.dataUrl,
                          dataType: "json",
                          success: function(data){
                              that.reset();
  
                              var f = Object.create(providerFactory);
                              var provider = f.getProvider(that.dataUrl);
                              data = provider.selectData(data);
  
                              var converter = new DataTypeConverter();
                              var result = converter.inferJsonDataType(data, ["*"]);
                              result = converter.cast(result);
                              that.fields = utility_getFields(result.types);
                              data = result.dataset;
420ea6ab   Renato De Donato   workcicle...
204
                              that.data = alasql_QUERY(data, that.fields, null, null, null);
89558a41   Renato De Donato   datatype, provide...
205
206
207
  
                              that.$.select_fields.setFields(that.fields);
                              that.$.filters.setFields(that.fields);
89558a41   Renato De Donato   datatype, provide...
208
  
a1dedcfa   Renato De Donato   worning x gg
209
210
211
212
                              that.fire('data-ready', {ready : true});
                          },
                          error: function(){
                              that.fire('data-ready', {ready : false});
89558a41   Renato De Donato   datatype, provide...
213
214
                          }
                      });
0314f487   Renato De Donato   filters opendatasoft
215
                  }
0af843be   Renato De Donato   filters + alasql
216
  
89558a41   Renato De Donato   datatype, provide...
217
218
                  else {
                      this.reset();
0af843be   Renato De Donato   filters + alasql
219
  
89558a41   Renato De Donato   datatype, provide...
220
221
222
223
224
                      var converter = new DataTypeConverter();
                      var result = converter.inferJsonDataType(this.data, ["*"]);
                      result = converter.cast(result);
                      this.fields = utility_getFields(result.types);
                      data = result.dataset;
420ea6ab   Renato De Donato   workcicle...
225
                      this.data = alasql_QUERY(data, this.fields, null, null, null);
89558a41   Renato De Donato   datatype, provide...
226
227
228
  
                      this.$.select_fields.setFields(this.fields);
                      this.$.filters.setFields(this.fields);
89558a41   Renato De Donato   datatype, provide...
229
                  }
0af843be   Renato De Donato   filters + alasql
230
231
              },
  
89558a41   Renato De Donato   datatype, provide...
232
              reset : function() {
89558a41   Renato De Donato   datatype, provide...
233
234
235
236
237
                  this.filters = [];
                  this.selectedFields = [];
                  this.$.select_fields.reset();
                  this.$.data_table.reset();
                  this.$.filters.reset();
98d9d8a5   Renato De Donato   filters+groupby
238
239
              },
  
0af843be   Renato De Donato   filters + alasql
240
241
              _resize : function(){
                  var h = Math.max(document.documentElement.clientHeight, window.innerHeight || 0) - 16;
89558a41   Renato De Donato   datatype, provide...
242
243
                  h = h - 64 - 8; //height with page scroller + margin-top
                  $("#select_data_controllet_container").height(h);
0af843be   Renato De Donato   filters + alasql
244
245
246
247
248
249
250
              }
  
          });
  
      </script>
  
  </dom-module>