From 67db964546c10ff1cb048d7090cf157d71eed7d8 Mon Sep 17 00:00:00 2001 From: Alexis Lahouze Date: Tue, 16 Jun 2015 18:09:22 +0200 Subject: [PATCH] Add loading of entries on extremes change in sold chart. --- accountant/frontend/static/js/entries.js | 51 +++++++++++++++++++++--- 1 file changed, 45 insertions(+), 6 deletions(-) diff --git a/accountant/frontend/static/js/entries.js b/accountant/frontend/static/js/entries.js index 8caa3da..ac81798 100644 --- a/accountant/frontend/static/js/entries.js +++ b/accountant/frontend/static/js/entries.js @@ -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}); };