0af843be
Renato De Donato
filters + alasql
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
/*
@license
The MIT License (MIT)
Copyright (c) 2015 Dipartimento di Informatica - Universit� di Salerno - Italy
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
/**
* Developed by :
* ROUTE-TO-PA Project - grant No 645860. - www.routetopa.eu
*
*/
var AjaxJsonAlasqlBehavior = {
properties: {
/**
* It contains the json data from async xhr call returned from core-ajax core component
*
* @attribute json_results
* @type object
* @default 'null'.
*/
json_results: {
type: Object,
value: {}
}
|
98d9d8a5
Renato De Donato
filters+groupby
|
48
|
|
0af843be
Renato De Donato
filters + alasql
|
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
|
},
/**
* Make an AJAX call to the dataset URL
*
* @method requestData
*/
requestData: function(){
var comp = this;
$.ajax({
url: this._component.dataUrl,
dataType: "json",
success: function(e){
comp.handleResponse(e);
}
});
},
/**
* Called when core-ajax component receive the json data from called url.
*
* @method handleResponse
*/
handleResponse: function(e) {
this.properties.json_results.value = e;
this.runWorkcycle();
},
|
0af843be
Renato De Donato
filters + alasql
|
78
79
|
/**
|
413bc541
Renato De Donato
data cache
|
80
|
* selectData built a ALASQL query based on the user selected fields then extract data from the JSON response.
|
0af843be
Renato De Donato
filters + alasql
|
81
82
83
84
85
|
* This method built an objects <name, data> for every user selected field and push it into the data array.
*
* @method selectData
*/
selectData : function() {
|
420ea6ab
Renato De Donato
workcicle...
|
86
87
88
|
var f = Object.create(providerFactory);
var provider = f.getProvider(this._component.dataUrl);
var data = provider.selectData(this.properties.json_results.value);
|
0af843be
Renato De Donato
filters + alasql
|
89
|
|
420ea6ab
Renato De Donato
workcicle...
|
90
91
92
93
94
95
96
97
98
|
var converter = new DataTypeConverter();
var result = converter.inferJsonDataType(data, ["*"]);
result = converter.cast(result);
this.data = result.dataset;
},
filterData : function() {
var fields = this._component.fields = JSON.parse(this._component.fields);
|
0f4f5f1b
Renato De Donato
new datalets mult...
|
99
|
|
98d9d8a5
Renato De Donato
filters+groupby
|
100
101
102
103
|
var filters = JSON.parse(this._component.getAttribute("filters"));
var aggregators = JSON.parse(this._component.getAttribute("aggregators"));
var orders = JSON.parse(this._component.getAttribute("orders"));
|
0f4f5f1b
Renato De Donato
new datalets mult...
|
104
|
//preview my space ?
|
0dafdf4f
Renato De Donato
my space bug fix
|
105
|
if(filters && filters[0] && filters[0].constructor == Array){
|
9fb4369c
Renato De Donato
my space on add p...
|
106
107
108
109
110
|
filters = filters[0];
aggregators = aggregators[0];
orders = orders[0];
}
|
89558a41
Renato De Donato
datatype, provide...
|
111
|
var converter = new DataTypeConverter();
|
166db682
Renato De Donato
converter 3 times :(
|
112
|
|
420ea6ab
Renato De Donato
workcicle...
|
113
|
var data = alasql_QUERY(this.data, fields, filters, null, orders);
|
89558a41
Renato De Donato
datatype, provide...
|
114
115
116
|
var result = converter.inferJsonDataType(data, ["*"]);
result = converter.cast(result);
data = result.dataset;
|
68ee970d
Renato De Donato
jsdatachecker
|
117
|
|
420ea6ab
Renato De Donato
workcicle...
|
118
119
120
121
122
123
|
if(aggregators && aggregators.length) {
data = alasql_QUERY(data, fields, null, aggregators, orders);
result = converter.inferJsonDataType(data, ["*"]);
result = converter.cast(result);
data = result.dataset;
}
|
0af843be
Renato De Donato
filters + alasql
|
124
|
|
420ea6ab
Renato De Donato
workcicle...
|
125
|
this.data = alasql_transformData(data, fields, true);
|
0af843be
Renato De Donato
filters + alasql
|
126
|
}
|
98d9d8a5
Renato De Donato
filters+groupby
|
127
|
|
420ea6ab
Renato De Donato
workcicle...
|
128
129
130
131
132
133
134
135
136
137
138
139
|
//var selectedFields = JSON.parse(this._component.getAttribute("selectedFields"));
//if(selectedFields) {
// fields = [];
// var inputs = [];
// for (var i=0; i < selectedFields.length; i++) {
// if (selectedFields[i]) {
// fields.push(selectedFields[i].field);
// inputs.push(selectedFields[i].input);
// }
// }
//}
|
0af843be
Renato De Donato
filters + alasql
|
140
|
};
|