mirror of
https://github.com/aclindsa/moneygo.git
synced 2025-06-13 05:29:24 -04:00
Add lots of backend and back-frontend report infrastructure
This commit is contained in:
@ -4,55 +4,116 @@ var ErrorActions = require('./ErrorActions');
|
||||
|
||||
var models = require('../models.js');
|
||||
var Report = models.Report;
|
||||
var Tabulation = models.Tabulation;
|
||||
var Error = models.Error;
|
||||
|
||||
function fetchReport(reportName) {
|
||||
function fetchReports() {
|
||||
return {
|
||||
type: ReportConstants.FETCH_REPORT,
|
||||
reportName: reportName
|
||||
type: ReportConstants.FETCH_REPORTS
|
||||
}
|
||||
}
|
||||
|
||||
function reportFetched(report) {
|
||||
function reportsFetched(reports) {
|
||||
return {
|
||||
type: ReportConstants.REPORT_FETCHED,
|
||||
type: ReportConstants.REPORTS_FETCHED,
|
||||
reports: reports
|
||||
}
|
||||
}
|
||||
|
||||
function createReport() {
|
||||
return {
|
||||
type: ReportConstants.CREATE_REPORT
|
||||
}
|
||||
}
|
||||
|
||||
function reportCreated(report) {
|
||||
return {
|
||||
type: ReportConstants.REPORT_CREATED,
|
||||
report: report
|
||||
}
|
||||
}
|
||||
|
||||
function selectReport(report, seriesTraversal) {
|
||||
function updateReport() {
|
||||
return {
|
||||
type: ReportConstants.SELECT_REPORT,
|
||||
report: report,
|
||||
seriesTraversal: seriesTraversal
|
||||
type: ReportConstants.UPDATE_REPORT
|
||||
}
|
||||
}
|
||||
|
||||
function reportSelected(flattenedReport, seriesTraversal) {
|
||||
function reportUpdated(report) {
|
||||
return {
|
||||
type: ReportConstants.REPORT_UPDATED,
|
||||
report: report
|
||||
}
|
||||
}
|
||||
|
||||
function removeReport() {
|
||||
return {
|
||||
type: ReportConstants.REMOVE_REPORT
|
||||
}
|
||||
}
|
||||
|
||||
function reportRemoved(reportId) {
|
||||
return {
|
||||
type: ReportConstants.REPORT_REMOVED,
|
||||
reportId: reportId
|
||||
}
|
||||
}
|
||||
|
||||
function reportSelected(report) {
|
||||
return {
|
||||
type: ReportConstants.REPORT_SELECTED,
|
||||
report: flattenedReport,
|
||||
report: report
|
||||
}
|
||||
}
|
||||
|
||||
function tabulateReport(report) {
|
||||
return {
|
||||
type: ReportConstants.TABULATE_REPORT,
|
||||
report: report
|
||||
}
|
||||
}
|
||||
|
||||
function reportTabulated(report, tabulation) {
|
||||
return {
|
||||
type: ReportConstants.REPORT_TABULATED,
|
||||
report: report,
|
||||
tabulation: tabulation
|
||||
}
|
||||
}
|
||||
|
||||
function selectionCleared() {
|
||||
return {
|
||||
type: ReportConstants.SELECTION_CLEARED
|
||||
}
|
||||
}
|
||||
|
||||
function seriesSelected(flattenedTabulation, seriesTraversal) {
|
||||
return {
|
||||
type: ReportConstants.SERIES_SELECTED,
|
||||
tabulation: flattenedTabulation,
|
||||
seriesTraversal: seriesTraversal
|
||||
}
|
||||
}
|
||||
|
||||
function fetch(report) {
|
||||
function fetchAll() {
|
||||
return function (dispatch) {
|
||||
dispatch(fetchReport(report));
|
||||
dispatch(fetchReports());
|
||||
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
dataType: "json",
|
||||
url: "report/"+report+"/",
|
||||
url: "report/",
|
||||
success: function(data, status, jqXHR) {
|
||||
var e = new Error();
|
||||
e.fromJSON(data);
|
||||
if (e.isError()) {
|
||||
dispatch(ErrorActions.serverError(e));
|
||||
} else {
|
||||
var r = new Report();
|
||||
r.fromJSON(data);
|
||||
dispatch(reportFetched(r));
|
||||
dispatch(reportsFetched(data.reports.map(function(json) {
|
||||
var r = new Report();
|
||||
r.fromJSON(json);
|
||||
return r;
|
||||
})));
|
||||
}
|
||||
},
|
||||
error: function(jqXHR, status, error) {
|
||||
@ -62,14 +123,117 @@ function fetch(report) {
|
||||
};
|
||||
}
|
||||
|
||||
function select(report, seriesTraversal) {
|
||||
function create(report) {
|
||||
return function (dispatch) {
|
||||
dispatch(createReport());
|
||||
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
dataType: "json",
|
||||
url: "report/",
|
||||
data: {report: report.toJSON()},
|
||||
success: function(data, status, jqXHR) {
|
||||
var e = new Error();
|
||||
e.fromJSON(data);
|
||||
if (e.isError()) {
|
||||
dispatch(ErrorActions.serverError(e));
|
||||
} else {
|
||||
var a = new Report();
|
||||
a.fromJSON(data);
|
||||
dispatch(reportCreated(a));
|
||||
}
|
||||
},
|
||||
error: function(jqXHR, status, error) {
|
||||
dispatch(ErrorActions.ajaxError(error));
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
function update(report) {
|
||||
return function (dispatch) {
|
||||
dispatch(updateReport());
|
||||
|
||||
$.ajax({
|
||||
type: "PUT",
|
||||
dataType: "json",
|
||||
url: "report/"+report.ReportId+"/",
|
||||
data: {report: report.toJSON()},
|
||||
success: function(data, status, jqXHR) {
|
||||
var e = new Error();
|
||||
e.fromJSON(data);
|
||||
if (e.isError()) {
|
||||
dispatch(ErrorActions.serverError(e));
|
||||
} else {
|
||||
var a = new Report();
|
||||
a.fromJSON(data);
|
||||
dispatch(reportUpdated(a));
|
||||
}
|
||||
},
|
||||
error: function(jqXHR, status, error) {
|
||||
dispatch(ErrorActions.ajaxError(error));
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
function remove(report) {
|
||||
return function(dispatch) {
|
||||
dispatch(removeReport());
|
||||
|
||||
$.ajax({
|
||||
type: "DELETE",
|
||||
dataType: "json",
|
||||
url: "report/"+report.ReportId+"/",
|
||||
success: function(data, status, jqXHR) {
|
||||
var e = new Error();
|
||||
e.fromJSON(data);
|
||||
if (e.isError()) {
|
||||
dispatch(ErrorActions.serverError(e));
|
||||
} else {
|
||||
dispatch(reportRemoved(report.ReportId));
|
||||
}
|
||||
},
|
||||
error: function(jqXHR, status, error) {
|
||||
dispatch(ErrorActions.ajaxError(error));
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
function tabulate(report) {
|
||||
return function (dispatch) {
|
||||
dispatch(tabulateReport(report));
|
||||
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
dataType: "json",
|
||||
url: "report/"+report.ReportId+"/tabulation/",
|
||||
success: function(data, status, jqXHR) {
|
||||
var e = new Error();
|
||||
e.fromJSON(data);
|
||||
if (e.isError()) {
|
||||
dispatch(ErrorActions.serverError(e));
|
||||
} else {
|
||||
var t = new Tabulation();
|
||||
t.fromJSON(data);
|
||||
dispatch(reportTabulated(report, t));
|
||||
}
|
||||
},
|
||||
error: function(jqXHR, status, error) {
|
||||
dispatch(ErrorActions.ajaxError(error));
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
function selectSeries(tabulation, seriesTraversal) {
|
||||
return function (dispatch) {
|
||||
if (!seriesTraversal)
|
||||
seriesTraversal = [];
|
||||
dispatch(selectReport(report, seriesTraversal));
|
||||
|
||||
// Descend the tree to the right series to flatten
|
||||
var series = report;
|
||||
var series = tabulation;
|
||||
for (var i=0; i < seriesTraversal.length; i++) {
|
||||
if (!series.Series.hasOwnProperty(seriesTraversal[i])) {
|
||||
dispatch(ErrorActions.clientError("Invalid series"));
|
||||
@ -87,23 +251,27 @@ function select(report, seriesTraversal) {
|
||||
|
||||
// Add back in any values from the current level
|
||||
if (series.hasOwnProperty('Values'))
|
||||
flattenedSeries[Report.topLevelAccountName()] = series.Values;
|
||||
flattenedSeries[Tabulation.topLevelSeriesName()] = series.Values;
|
||||
|
||||
var flattenedReport = new Report();
|
||||
var flattenedTabulation = new Tabulation();
|
||||
|
||||
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;
|
||||
flattenedTabulation.ReportId = tabulation.ReportId;
|
||||
flattenedTabulation.Title = tabulation.Title;
|
||||
flattenedTabulation.Subtitle = tabulation.Subtitle;
|
||||
flattenedTabulation.Units = tabulation.Units;
|
||||
flattenedTabulation.Labels = tabulation.Labels.slice();
|
||||
flattenedTabulation.FlattenedSeries = flattenedSeries;
|
||||
|
||||
dispatch(reportSelected(flattenedReport, seriesTraversal));
|
||||
dispatch(seriesSelected(flattenedTabulation, seriesTraversal));
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
fetch: fetch,
|
||||
select: select
|
||||
fetchAll: fetchAll,
|
||||
create: create,
|
||||
update: update,
|
||||
remove: remove,
|
||||
tabulate: tabulate,
|
||||
select: reportSelected,
|
||||
selectSeries: selectSeries
|
||||
};
|
||||
|
@ -6,87 +6,101 @@ var Button = ReactBootstrap.Button;
|
||||
var Panel = ReactBootstrap.Panel;
|
||||
|
||||
var StackedBarChart = require('../components/StackedBarChart');
|
||||
var PieChart = require('../components/PieChart');
|
||||
|
||||
var models = require('../models')
|
||||
var Report = models.Report;
|
||||
var Tabulation = models.Tabulation;
|
||||
|
||||
class ReportsTab extends React.Component {
|
||||
constructor() {
|
||||
super();
|
||||
this.state = {
|
||||
initialized: false
|
||||
}
|
||||
this.onSelectSeries = this.handleSelectSeries.bind(this);
|
||||
}
|
||||
componentWillMount() {
|
||||
this.props.onFetchReport("monthly_expenses");
|
||||
this.props.onFetchAllReports();
|
||||
}
|
||||
componentWillReceiveProps(nextProps) {
|
||||
if (nextProps.reports['monthly_expenses'] && !nextProps.selectedReport.report) {
|
||||
this.props.onSelectReport(nextProps.reports['monthly_expenses'], []);
|
||||
var selected = nextProps.reports.selected;
|
||||
if (!this.state.initialized) {
|
||||
if (selected == -1 &&
|
||||
nextProps.reports.list.length > 0)
|
||||
nextProps.onSelectReport(nextProps.reports.map[nextProps.reports.list[0]]);
|
||||
this.setState({initialized: true});
|
||||
} else if (selected != -1 && !nextProps.reports.tabulations.hasOwnProperty(selected)) {
|
||||
nextProps.onTabulateReport(nextProps.reports.map[nextProps.reports.list[0]]);
|
||||
} else if (selected != -1 && nextProps.reports.selectedTabulation == null) {
|
||||
nextProps.onSelectSeries(nextProps.reports.tabulations[nextProps.reports.list[0]]);
|
||||
}
|
||||
}
|
||||
handleSelectSeries(series) {
|
||||
if (series == Report.topLevelAccountName())
|
||||
if (series == Tabulation.topLevelSeriesName())
|
||||
return;
|
||||
var seriesTraversal = this.props.selectedReport.seriesTraversal.slice();
|
||||
var seriesTraversal = this.props.selectedTabulation.seriesTraversal.slice();
|
||||
seriesTraversal.push(series);
|
||||
this.props.onSelectReport(this.props.reports[this.props.selectedReport.report.ReportId], seriesTraversal);
|
||||
var selectedTabulation = this.props.reports.tabulations[this.props.reports.selected];
|
||||
this.props.onSelectSeries(selectedTabulation, seriesTraversal);
|
||||
}
|
||||
render() {
|
||||
var report = [];
|
||||
if (this.props.selectedReport.report) {
|
||||
var titleTracks = [];
|
||||
var seriesTraversal = [];
|
||||
|
||||
for (var i = 0; i < this.props.selectedReport.seriesTraversal.length; i++) {
|
||||
var name = this.props.selectedReport.report.Title;
|
||||
if (i > 0)
|
||||
name = this.props.selectedReport.seriesTraversal[i-1];
|
||||
|
||||
// Make a closure for going up the food chain
|
||||
var self = this;
|
||||
var navOnClick = function() {
|
||||
var onSelectReport = self.props.onSelectReport;
|
||||
var report = self.props.reports[self.props.selectedReport.report.ReportId];
|
||||
var mySeriesTraversal = seriesTraversal.slice();
|
||||
return function() {
|
||||
onSelectReport(report, mySeriesTraversal);
|
||||
};
|
||||
}();
|
||||
titleTracks.push((
|
||||
<Button key={i*2} bsStyle="link"
|
||||
onClick={navOnClick}>
|
||||
{name}
|
||||
</Button>
|
||||
));
|
||||
titleTracks.push((<span key={i*2+1}>/</span>));
|
||||
seriesTraversal.push(this.props.selectedReport.seriesTraversal[i]);
|
||||
}
|
||||
if (titleTracks.length == 0) {
|
||||
titleTracks.push((
|
||||
<Button key={0} bsStyle="link">
|
||||
{this.props.selectedReport.report.Title}
|
||||
</Button>
|
||||
));
|
||||
} else {
|
||||
var i = this.props.selectedReport.seriesTraversal.length-1;
|
||||
titleTracks.push((
|
||||
<Button key={i*2+2} bsStyle="link">
|
||||
{this.props.selectedReport.seriesTraversal[i]}
|
||||
</Button>
|
||||
));
|
||||
}
|
||||
|
||||
report = (<Panel header={titleTracks}>
|
||||
<StackedBarChart
|
||||
report={this.props.selectedReport.report}
|
||||
onSelectSeries={this.onSelectSeries}
|
||||
seriesTraversal={this.props.selectedReport.seriesTraversal} />
|
||||
</Panel>
|
||||
var selectedTabulation = this.props.reports.selectedTabulation;
|
||||
if (!selectedTabulation) {
|
||||
return (
|
||||
<div></div>
|
||||
);
|
||||
}
|
||||
|
||||
var titleTracks = [];
|
||||
var seriesTraversal = [];
|
||||
|
||||
for (var i = 0; i < this.props.selectedTabulation.seriesTraversal.length; i++) {
|
||||
var name = this.props.selectedTabulation.tabulation.Title;
|
||||
if (i > 0)
|
||||
name = this.props.selectedTabulation.seriesTraversal[i-1];
|
||||
|
||||
// Make a closure for going up the food chain
|
||||
var self = this;
|
||||
var navOnClick = function() {
|
||||
var onSelectTabulation = self.props.onSelectTabulation;
|
||||
var report = self.props.reports[self.props.selectedTabulation.tabulation.ReportId];
|
||||
var mySeriesTraversal = seriesTraversal.slice();
|
||||
return function() {
|
||||
onSelectTabulation(report, mySeriesTraversal);
|
||||
};
|
||||
}();
|
||||
titleTracks.push((
|
||||
<Button key={i*2} bsStyle="link"
|
||||
onClick={navOnClick}>
|
||||
{name}
|
||||
</Button>
|
||||
));
|
||||
titleTracks.push((<span key={i*2+1}>/</span>));
|
||||
seriesTraversal.push(this.props.selectedTabulation.seriesTraversal[i]);
|
||||
}
|
||||
if (titleTracks.length == 0) {
|
||||
titleTracks.push((
|
||||
<Button key={0} bsStyle="link">
|
||||
{this.props.selectedTabulation.tabulation.Title}
|
||||
</Button>
|
||||
));
|
||||
} else {
|
||||
var i = this.props.selectedTabulation.seriesTraversal.length-1;
|
||||
titleTracks.push((
|
||||
<Button key={i*2+2} bsStyle="link">
|
||||
{this.props.selectedTabulation.seriesTraversal[i]}
|
||||
</Button>
|
||||
));
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
{report}
|
||||
</div>
|
||||
<Panel header={titleTracks}>
|
||||
<PieChart
|
||||
report={this.props.selectedTabulation.tabulation}
|
||||
onSelectSeries={this.onSelectSeries}
|
||||
seriesTraversal={this.props.selectedTabulation.seriesTraversal} />
|
||||
</Panel>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,17 @@
|
||||
var keyMirror = require('keymirror');
|
||||
|
||||
module.exports = keyMirror({
|
||||
FETCH_REPORT: null,
|
||||
REPORT_FETCHED: null,
|
||||
SELECT_REPORT: null,
|
||||
REPORT_SELECTED: null
|
||||
FETCH_REPORTS: null,
|
||||
REPORTS_FETCHED: null,
|
||||
CREATE_REPORT: null,
|
||||
REPORT_CREATED: null,
|
||||
UPDATE_REPORT: null,
|
||||
REPORT_UPDATED: null,
|
||||
REMOVE_REPORT: null,
|
||||
REPORT_REMOVED: null,
|
||||
TABULATE_REPORT: null,
|
||||
REPORT_TABULATED: null,
|
||||
REPORT_SELECTED: null,
|
||||
SELECTION_CLEARED: null,
|
||||
SERIES_SELECTED: null
|
||||
});
|
||||
|
@ -5,15 +5,19 @@ var ReportsTab = require('../components/ReportsTab');
|
||||
|
||||
function mapStateToProps(state) {
|
||||
return {
|
||||
reports: state.reports,
|
||||
selectedReport: state.selectedReport
|
||||
reports: state.reports
|
||||
}
|
||||
}
|
||||
|
||||
function mapDispatchToProps(dispatch) {
|
||||
return {
|
||||
onFetchReport: function(reportname) {dispatch(ReportActions.fetch(reportname))},
|
||||
onSelectReport: function(report, seriesTraversal) {dispatch(ReportActions.select(report, seriesTraversal))}
|
||||
onFetchAllReports: function() {dispatch(ReportActions.fetchAll())},
|
||||
onCreateReport: function(report) {dispatch(ReportActions.create(report))},
|
||||
onUpdateReport: function(report) {dispatch(ReportActions.update(report))},
|
||||
onDeleteReport: function(report) {dispatch(ReportActions.remove(report))},
|
||||
onSelectReport: function(report) {dispatch(ReportActions.select(report))},
|
||||
onTabulateReport: function(report) {dispatch(ReportActions.tabulate(report))},
|
||||
onSelectSeries: function(tabulation, seriesTraversal) {dispatch(ReportActions.selectSeries(tabulation, seriesTraversal))}
|
||||
}
|
||||
}
|
||||
|
||||
|
18
js/models.js
18
js/models.js
@ -494,18 +494,17 @@ class Series {
|
||||
}
|
||||
}
|
||||
|
||||
class Report {
|
||||
class Tabulation {
|
||||
constructor() {
|
||||
this.ReportId = "";
|
||||
this.Title = "";
|
||||
this.Subtitle = "";
|
||||
this.XAxisLabel = "";
|
||||
this.YAxisLabel = "";
|
||||
this.Units = "";
|
||||
this.Labels = [];
|
||||
this.Series = {};
|
||||
this.FlattenedSeries = {};
|
||||
}
|
||||
static topLevelAccountName() {
|
||||
static topLevelSeriesName() {
|
||||
return "(top level)"
|
||||
}
|
||||
toJSON() {
|
||||
@ -513,8 +512,7 @@ class Report {
|
||||
json_obj.ReportId = this.ReportId;
|
||||
json_obj.Title = this.Title;
|
||||
json_obj.Subtitle = this.Subtitle;
|
||||
json_obj.XAxisLabel = this.XAxisLabel;
|
||||
json_obj.YAxisLabel = this.YAxisLabel;
|
||||
json_obj.Units = this.Units;
|
||||
json_obj.Labels = this.Labels;
|
||||
json_obj.Series = {};
|
||||
for (var series in this.Series) {
|
||||
@ -532,10 +530,8 @@ class Report {
|
||||
this.Title = json_obj.Title;
|
||||
if (json_obj.hasOwnProperty("Subtitle"))
|
||||
this.Subtitle = json_obj.Subtitle;
|
||||
if (json_obj.hasOwnProperty("XAxisLabel"))
|
||||
this.XAxisLabel = json_obj.XAxisLabel;
|
||||
if (json_obj.hasOwnProperty("YAxisLabel"))
|
||||
this.YAxisLabel = json_obj.YAxisLabel;
|
||||
if (json_obj.hasOwnProperty("Units"))
|
||||
this.Units = json_obj.Units;
|
||||
if (json_obj.hasOwnProperty("Labels"))
|
||||
this.Labels = json_obj.Labels;
|
||||
if (json_obj.hasOwnProperty("Series")) {
|
||||
@ -582,7 +578,7 @@ module.exports = {
|
||||
Account: Account,
|
||||
Split: Split,
|
||||
Transaction: Transaction,
|
||||
Report: Report,
|
||||
Tabulation: Tabulation,
|
||||
OFXDownload: OFXDownload,
|
||||
Error: Error,
|
||||
|
||||
|
@ -8,7 +8,6 @@ var SecurityTemplateReducer = require('./SecurityTemplateReducer');
|
||||
var SelectedAccountReducer = require('./SelectedAccountReducer');
|
||||
var SelectedSecurityReducer = require('./SelectedSecurityReducer');
|
||||
var ReportReducer = require('./ReportReducer');
|
||||
var SelectedReportReducer = require('./SelectedReportReducer');
|
||||
var TransactionReducer = require('./TransactionReducer');
|
||||
var TransactionPageReducer = require('./TransactionPageReducer');
|
||||
var ImportReducer = require('./ImportReducer');
|
||||
@ -23,7 +22,6 @@ module.exports = Redux.combineReducers({
|
||||
selectedAccount: SelectedAccountReducer,
|
||||
selectedSecurity: SelectedSecurityReducer,
|
||||
reports: ReportReducer,
|
||||
selectedReport: SelectedReportReducer,
|
||||
transactions: TransactionReducer,
|
||||
transactionPage: TransactionPageReducer,
|
||||
imports: ImportReducer,
|
||||
|
@ -3,15 +3,78 @@ var assign = require('object-assign');
|
||||
var ReportConstants = require('../constants/ReportConstants');
|
||||
var UserConstants = require('../constants/UserConstants');
|
||||
|
||||
module.exports = function(state = {}, action) {
|
||||
const initialState = {
|
||||
map: {},
|
||||
tabulations: {},
|
||||
list: [],
|
||||
selected: -1,
|
||||
selectedTabulation: null,
|
||||
seriesTraversal: []
|
||||
};
|
||||
|
||||
module.exports = function(state = initialState, action) {
|
||||
switch (action.type) {
|
||||
case ReportConstants.REPORT_FETCHED:
|
||||
var report = action.report;
|
||||
case ReportConstants.REPORTS_FETCHED:
|
||||
var selected = -1;
|
||||
var reports = {};
|
||||
var list = [];
|
||||
for (var i = 0; i < action.reports.length; i++) {
|
||||
var report = action.reports[i];
|
||||
reports[report.ReportId] = report;
|
||||
list.push(report.ReportId);
|
||||
if (state.selected == report.ReportId)
|
||||
selected = state.selected;
|
||||
}
|
||||
return assign({}, state, {
|
||||
map: reports,
|
||||
list: list,
|
||||
tabulations: {},
|
||||
selected: selected
|
||||
});
|
||||
case ReportConstants.REPORT_CREATED:
|
||||
case ReportConstants.REPORT_UPDATED:
|
||||
var report = action.report;
|
||||
var reports = assign({}, state.map, {
|
||||
[report.ReportId]: report
|
||||
});
|
||||
|
||||
var list = [];
|
||||
for (var reportId in reports) {
|
||||
if (reports.hasOwnProperty(reportId))
|
||||
list.push(report.ReportId);
|
||||
}
|
||||
return assign({}, state, {
|
||||
map: reports,
|
||||
list: list
|
||||
});
|
||||
case ReportConstants.REPORT_REMOVED:
|
||||
var selected = state.selected;
|
||||
if (action.reportId == selected)
|
||||
selected = -1;
|
||||
var reports = assign({}, state.map);
|
||||
delete reports[action.reportId];
|
||||
return assign({}, state, {
|
||||
map: reports,
|
||||
selected: selected
|
||||
});
|
||||
case ReportConstants.REPORT_SELECTED:
|
||||
return assign({}, state, {
|
||||
selected: action.report.ReportId,
|
||||
selectedTabulation: null,
|
||||
seriesTraversal: []
|
||||
});
|
||||
case ReportConstants.TABULATION_FETCHED:
|
||||
var tabulation = action.tabulation;
|
||||
return assign({}, state, {
|
||||
[tabulation.ReportId]: tabulation
|
||||
});
|
||||
case ReportConstants.SERIES_SELECTED:
|
||||
return {
|
||||
selectedTabulation: action.tabulation,
|
||||
seriesTraversal: action.seriesTraversal
|
||||
};
|
||||
case UserConstants.USER_LOGGEDOUT:
|
||||
return {};
|
||||
return initialState;
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
|
@ -1,23 +0,0 @@
|
||||
var assign = require('object-assign');
|
||||
|
||||
var ReportConstants = require('../constants/ReportConstants');
|
||||
var UserConstants = require('../constants/UserConstants');
|
||||
|
||||
const initialState = {
|
||||
report: null,
|
||||
seriesTraversal: []
|
||||
};
|
||||
|
||||
module.exports = function(state = initialState, action) {
|
||||
switch (action.type) {
|
||||
case ReportConstants.REPORT_SELECTED:
|
||||
return {
|
||||
report: action.report,
|
||||
seriesTraversal: action.seriesTraversal
|
||||
};
|
||||
case UserConstants.USER_LOGGEDOUT:
|
||||
return initialState;
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
};
|
Reference in New Issue
Block a user