Skip to content

Commit

Permalink
Update logic for fetching chart data
Browse files Browse the repository at this point in the history
The new cohort analysis endpoint gives a paginated response, unlike
the v1 API. This breaks out the logic for retrieving data into a fn
that can handle both API versions.
  • Loading branch information
brittanydionigi committed Feb 8, 2016
1 parent 6ed52ff commit 763659e
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions kitsune/sumo/static/sumo/js/kpi.dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,32 @@

}

function getChartData(url, propertyKey) {
let dataReady = $.Deferred();
let datumsToCollect = propertyKey;
let fetchData = function(url, existingData) {
$.getJSON(url, function(data) {
existingData = existingData.concat(data[datumsToCollect] || data);
if (data.next) {
return fetchData(data.next, existingData);
} else {
dataReady.resolve(existingData);
}
}).fail(function(error) {
dataReady.reject(error);
});
}

fetchData(url, []);
return dataReady;
}

function makeKPIGraph($container, bucket, descriptors) {
$.getJSON($container.data('url'), function(data) {
let fetchDataset = getChartData($container.data('url'), 'objects');
fetchDataset.done(function(data) {
new k.Graph($container, {
data: {
datums: data.objects,
datums: data,
seriesSpec: descriptors
},
options: {
Expand All @@ -189,9 +210,12 @@
height: 300
},
}).render();
}).fail(function(error) {
console.log('There was an error retrieving the data: ', error);
});
}


$(init);

})();

0 comments on commit 763659e

Please sign in to comment.