mirror of
https://github.com/aclindsa/moneygo.git
synced 2025-06-13 13:39:23 -04:00
reports: Allow drilling down
This commit is contained in:
@ -21,6 +21,17 @@ function ajaxError(error) {
|
||||
};
|
||||
}
|
||||
|
||||
function clientError(error) {
|
||||
var e = new Error();
|
||||
e.ErrorId = 999;
|
||||
e.ErrorString = "Client Error: " + error;
|
||||
|
||||
return {
|
||||
type: ErrorConstants.ERROR_CLIENT,
|
||||
error: e
|
||||
};
|
||||
}
|
||||
|
||||
function clearError() {
|
||||
return {
|
||||
type: ErrorConstants.CLEAR_ERROR,
|
||||
@ -30,5 +41,6 @@ function clearError() {
|
||||
module.exports = {
|
||||
serverError: serverError,
|
||||
ajaxError: ajaxError,
|
||||
clientError: clientError,
|
||||
clearError: clearError
|
||||
};
|
||||
|
@ -6,9 +6,10 @@ var models = require('../models.js');
|
||||
var Report = models.Report;
|
||||
var Error = models.Error;
|
||||
|
||||
function fetchReport() {
|
||||
function fetchReport(reportName) {
|
||||
return {
|
||||
type: ReportConstants.FETCH_REPORT
|
||||
type: ReportConstants.FETCH_REPORT,
|
||||
reportName: reportName
|
||||
}
|
||||
}
|
||||
|
||||
@ -19,9 +20,25 @@ function reportFetched(report) {
|
||||
}
|
||||
}
|
||||
|
||||
function selectReport(report, seriesTraversal) {
|
||||
return {
|
||||
type: ReportConstants.SELECT_REPORT,
|
||||
report: report,
|
||||
seriesTraversal: seriesTraversal
|
||||
}
|
||||
}
|
||||
|
||||
function reportSelected(flattenedReport, seriesTraversal) {
|
||||
return {
|
||||
type: ReportConstants.REPORT_SELECTED,
|
||||
report: flattenedReport,
|
||||
seriesTraversal: seriesTraversal
|
||||
}
|
||||
}
|
||||
|
||||
function fetch(report) {
|
||||
return function (dispatch) {
|
||||
dispatch(fetchReport());
|
||||
dispatch(fetchReport(report));
|
||||
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
@ -45,6 +62,48 @@ function fetch(report) {
|
||||
};
|
||||
}
|
||||
|
||||
function select(report, seriesTraversal) {
|
||||
return function (dispatch) {
|
||||
if (!seriesTraversal)
|
||||
seriesTraversal = [];
|
||||
dispatch(selectReport(report, seriesTraversal));
|
||||
|
||||
// Descend the tree to the right series to flatten
|
||||
var series = report;
|
||||
for (var i=0; i < seriesTraversal.length; i++) {
|
||||
if (!series.Series.hasOwnProperty(seriesTraversal[i])) {
|
||||
dispatch(ErrorActions.clientError("Invalid series"));
|
||||
return;
|
||||
}
|
||||
series = series.Series[seriesTraversal[i]];
|
||||
}
|
||||
|
||||
// Actually flatten the data
|
||||
var flattenedSeries = series.mapReduceChildren(null,
|
||||
function(accumulator, currentValue, currentIndex, array) {
|
||||
return accumulator + currentValue;
|
||||
}
|
||||
);
|
||||
|
||||
// Add back in any values from the current level
|
||||
if (series.hasOwnProperty('Values'))
|
||||
flattenedSeries[report.topLevelAccountName] = series.Values;
|
||||
|
||||
var flattenedReport = new Report();
|
||||
|
||||
flattenedReport.ReportId = report.ReportId;
|
||||
flattenedReport.Title = report.Title;
|
||||
flattenedReport.Subtitle = report.Subtitle;
|
||||
flattenedReport.XAxisLabel = report.XAxisLabel;
|
||||
flattenedReport.YAxisLabel = report.YAxisLabel;
|
||||
flattenedReport.Labels = report.Labels.slice();
|
||||
flattenedReport.FlattenedSeries = flattenedSeries;
|
||||
|
||||
dispatch(reportSelected(flattenedReport, seriesTraversal));
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
fetch: fetch
|
||||
fetch: fetch,
|
||||
select: select
|
||||
};
|
||||
|
Reference in New Issue
Block a user