2015-03-13 12:08:13 +00:00
|
|
|
var ChartDataMixin = {
|
|
|
|
apiParams: function() {
|
|
|
|
var params = _.clone(this.props.params);
|
|
|
|
params['item'] = this.state.item;
|
2015-03-15 12:10:02 +00:00
|
|
|
if (this.getQuery().f && this.getQuery().t) {
|
|
|
|
params['from'] = parseInt(this.getQuery().f, 10)*100;
|
|
|
|
params['to'] = parseInt(this.getQuery().t, 10)*100;
|
|
|
|
}
|
2015-03-13 12:08:13 +00:00
|
|
|
return params;
|
|
|
|
},
|
|
|
|
|
|
|
|
apiParamsHash: function() {
|
|
|
|
var params = this.apiParams();
|
|
|
|
var pairs = _.chain(params)
|
|
|
|
.keys()
|
|
|
|
.sort()
|
|
|
|
.map(function(param) {
|
|
|
|
return [param, params[param]];
|
|
|
|
})
|
|
|
|
.value();
|
|
|
|
return JSON.stringify(pairs);
|
|
|
|
},
|
|
|
|
|
|
|
|
fetchData: function() {
|
|
|
|
var paramsHash = this.apiParamsHash();
|
|
|
|
|
|
|
|
if (!this.state.item) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (this.state.currentApi === this.props.api && this.state.currentParams === paramsHash) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// console.log('-----> fetching', this.props.api, this.state.item);
|
|
|
|
this.setState({
|
|
|
|
currentApi: this.props.api,
|
|
|
|
currentParams: paramsHash,
|
|
|
|
state: 'loadingData'
|
|
|
|
}, function() {
|
2015-03-17 09:18:13 +00:00
|
|
|
getURL(this.props.api, this.apiParams(), function(res){
|
2015-03-13 12:08:13 +00:00
|
|
|
this.setState({
|
2015-03-15 12:10:02 +00:00
|
|
|
rawData: res || [],
|
2015-03-13 12:08:13 +00:00
|
|
|
state: 'newData'
|
|
|
|
}, this.handleNewData);
|
|
|
|
}.bind(this));
|
|
|
|
}.bind(this));
|
|
|
|
}
|
|
|
|
};
|