Add loading of entries on extremes change in sold chart.

This commit is contained in:
Alexis Lahouze 2015-06-16 18:09:22 +02:00
parent 92005e5a56
commit 67db964546

View File

@ -28,6 +28,16 @@ accountantApp.controller(
// Placeholder for saved value to cancel entry edition
$scope.savedItem = null;
$scope.begin = moment.utc().startOf('month');
$scope.end = moment.utc().endOf('month');
$scope.selectRange = function(e) {
$scope.begin = moment.utc(e.min);
$scope.end = moment.utc(e.max);
$scope.loadEntries($scope.account);
};
// Configure pie chart for categories.
$scope.categoriesChartConfig = {
options: {
@ -86,8 +96,31 @@ accountantApp.controller(
zoomType: 'x'
},
rangeSelector: {
buttons: [{
type: 'month',
count: 1,
text: "1m"
}, {
type: "month",
count: 3,
text: "3m"
}, {
type: "month",
count: 6,
text: "6m"
}, {
type: "year",
count: 1,
text: "1y"
}, {
type: "all",
text: "All"
}],
selected: 0,
},
navigator: {
enabled: true
},
tooltip: {
crosshairs: true,
shared: true,
@ -117,6 +150,10 @@ accountantApp.controller(
dateTimeLabelFormats: {
month: "%e. %b",
year: "%Y"
},
minRange: 3600 * 1000 * 24 * 14, // 2 weeks
events: {
afterSetExtremes: $scope.selectRange
}
},
yAxis: {
@ -186,6 +223,8 @@ accountantApp.controller(
entry.open, entry.high, entry.low, entry.close
]);
});
$scope.loadEntries($scope.account);
});
};
@ -235,16 +274,14 @@ accountantApp.controller(
$scope.selectedItem = null;
$scope.savedItem = null;
if(account && month) {
// Note: Month is 0 indexed.
var begin = moment({year: month.year, month: month.month - 1, day: 1});
var end = begin.clone().endOf('month');
if(account && !$scope.soldChartConfig.loading) {
$scope.soldChartConfig.loading = true;
$http.get("/api/entries", {
params: {
account: account.id,
begin: begin.format('YYYY-MM-DD'),
end: end.format('YYYY-MM-DD')
begin: $scope.begin.format('YYYY-MM-DD'),
end: $scope.end.format('YYYY-MM-DD')
}
}).success($scope.loadEntries_success);
} else {
@ -275,6 +312,8 @@ accountantApp.controller(
$scope.entries = entries;
$scope.soldChartConfig.loading = false;
$scope.$emit("entriesLoadedEvent", {entries: entries});
};