Improve entry loading on extremes selection.
This commit is contained in:
parent
eea61a3a9b
commit
120e22c1fe
@ -31,11 +31,18 @@ accountantApp.controller(
|
|||||||
$scope.begin = moment.utc().startOf('month');
|
$scope.begin = moment.utc().startOf('month');
|
||||||
$scope.end = moment.utc().endOf('month');
|
$scope.end = moment.utc().endOf('month');
|
||||||
|
|
||||||
$scope.selectRange = function(e) {
|
$scope.setExtremes = function(e) {
|
||||||
$scope.begin = moment.utc(e.min);
|
begin = moment.utc(e.min);
|
||||||
$scope.end = moment.utc(e.max);
|
end = moment.utc(e.max);
|
||||||
|
|
||||||
$scope.loadEntries($scope.account);
|
$scope.selectRange(begin, end);
|
||||||
|
};
|
||||||
|
|
||||||
|
$scope.selectRange = function(begin, end) {
|
||||||
|
$scope.begin = begin;
|
||||||
|
$scope.end = end;
|
||||||
|
|
||||||
|
$scope.$emit("rangeSelectedEvent", {begin: begin, end: end});
|
||||||
};
|
};
|
||||||
|
|
||||||
// Configure pie chart for categories.
|
// Configure pie chart for categories.
|
||||||
@ -153,7 +160,7 @@ accountantApp.controller(
|
|||||||
},
|
},
|
||||||
minRange: 3600 * 1000 * 24 * 14, // 2 weeks
|
minRange: 3600 * 1000 * 24 * 14, // 2 weeks
|
||||||
events: {
|
events: {
|
||||||
afterSetExtremes: $scope.selectRange
|
afterSetExtremes: $scope.setExtremes
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
yAxis: {
|
yAxis: {
|
||||||
@ -203,11 +210,15 @@ accountantApp.controller(
|
|||||||
// Note: expenses and revenues must be in the same order than in series[0].
|
// Note: expenses and revenues must be in the same order than in series[0].
|
||||||
config.series[1].data = revenues.concat(expenses);
|
config.series[1].data = revenues.concat(expenses);
|
||||||
|
|
||||||
|
$scope.categoriesChartConfig.loaded = true;
|
||||||
|
|
||||||
$scope.loadSolds();
|
$scope.loadSolds();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.loadSolds = function() {
|
$scope.loadSolds = function() {
|
||||||
|
$scope.soldChartConfig.loaded = true;
|
||||||
|
|
||||||
$http.get("/api/solds", {
|
$http.get("/api/solds", {
|
||||||
params: {
|
params: {
|
||||||
account: $scope.account.id,
|
account: $scope.account.id,
|
||||||
@ -224,16 +235,28 @@ accountantApp.controller(
|
|||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
$scope.loadEntries($scope.account);
|
$scope.loadEntries();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.getAccountStatus = function(account, month) {
|
$rootScope.$on("accountSelectedEvent", function(event, args) {
|
||||||
// Note: Month is 0 indexed.
|
$scope.account = args.account;
|
||||||
$scope.begin = moment({year: month.year, month: month.month - 1, day: 1});
|
|
||||||
$scope.end = $scope.begin.clone().endOf('month');
|
|
||||||
|
|
||||||
$http.get("/api/accounts/" + account.id, {
|
$scope.getAccountStatus();
|
||||||
|
});
|
||||||
|
|
||||||
|
$rootScope.$on("rangeSelectedEvent", function(event, args) {
|
||||||
|
$scope.getAccountStatus();
|
||||||
|
});
|
||||||
|
|
||||||
|
$rootScope.$on("entriesLoadedEvent", function(event, args) {
|
||||||
|
//$scope.loadCategories();
|
||||||
|
});
|
||||||
|
|
||||||
|
$scope.getAccountStatus = function() {
|
||||||
|
$scope.categoriesChartConfig.loaded = true;
|
||||||
|
|
||||||
|
$http.get("/api/accounts/" + $scope.account.id, {
|
||||||
params: {
|
params: {
|
||||||
begin: $scope.begin.format('YYYY-MM-DD'),
|
begin: $scope.begin.format('YYYY-MM-DD'),
|
||||||
end: $scope.end.format('YYYY-MM-DD')
|
end: $scope.end.format('YYYY-MM-DD')
|
||||||
@ -265,58 +288,49 @@ accountantApp.controller(
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Function to load entries from server for a specific account and month.
|
// Function to load entries from server for a specific account and month.
|
||||||
$scope.loadEntries = function(account, month) {
|
$scope.loadEntries = function() {
|
||||||
if(account) {
|
|
||||||
$scope.account = account;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Clean up selected entry.
|
// Clean up selected entry.
|
||||||
$scope.selectedItem = null;
|
$scope.selectedItem = null;
|
||||||
$scope.savedItem = null;
|
$scope.savedItem = null;
|
||||||
|
|
||||||
if(account && !$scope.soldChartConfig.loading) {
|
if(!$scope.entriesLoading) {
|
||||||
$scope.soldChartConfig.loading = true;
|
$scope.entriesLoading = true;
|
||||||
|
|
||||||
$http.get("/api/entries", {
|
$http.get("/api/entries", {
|
||||||
params: {
|
params: {
|
||||||
account: account.id,
|
account: $scope.account.id,
|
||||||
begin: $scope.begin.format('YYYY-MM-DD'),
|
begin: $scope.begin.format('YYYY-MM-DD'),
|
||||||
end: $scope.end.format('YYYY-MM-DD')
|
end: $scope.end.format('YYYY-MM-DD')
|
||||||
}
|
}
|
||||||
}).success($scope.loadEntries_success);
|
}).success(function(data) {
|
||||||
} else {
|
var entries = [{
|
||||||
$scope.loadEntries_success(null);
|
id: null,
|
||||||
|
pointed: false,
|
||||||
|
operation_date: null,
|
||||||
|
label: null,
|
||||||
|
value: null,
|
||||||
|
sold: null,
|
||||||
|
pointedsold: null,
|
||||||
|
category: null,
|
||||||
|
account_id: null,
|
||||||
|
state: 'new',
|
||||||
|
canceled: false,
|
||||||
|
scheduled_operation_id: null
|
||||||
|
}];
|
||||||
|
|
||||||
|
if(data) {
|
||||||
|
entries = entries.concat(angular.fromJson(data));
|
||||||
|
}
|
||||||
|
|
||||||
|
$scope.entries = entries;
|
||||||
|
|
||||||
|
$scope.entriesLoading = false;
|
||||||
|
|
||||||
|
$scope.$emit("entriesLoadedEvent", {entries: entries});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Load entries success callback
|
|
||||||
$scope.loadEntries_success = function(data) {
|
|
||||||
var entries = [{
|
|
||||||
id: null,
|
|
||||||
pointed: false,
|
|
||||||
operation_date: null,
|
|
||||||
label: null,
|
|
||||||
value: null,
|
|
||||||
sold: null,
|
|
||||||
pointedsold: null,
|
|
||||||
category: null,
|
|
||||||
account_id: null,
|
|
||||||
state: 'new',
|
|
||||||
canceled: false,
|
|
||||||
scheduled_operation_id: null
|
|
||||||
}];
|
|
||||||
|
|
||||||
if(data) {
|
|
||||||
entries = entries.concat(angular.fromJson(data));
|
|
||||||
}
|
|
||||||
|
|
||||||
$scope.entries = entries;
|
|
||||||
|
|
||||||
$scope.soldChartConfig.loading = false;
|
|
||||||
|
|
||||||
$scope.$emit("entriesLoadedEvent", {entries: entries});
|
|
||||||
};
|
|
||||||
|
|
||||||
// Returns the CSS class for a pointed entry.
|
// Returns the CSS class for a pointed entry.
|
||||||
$scope.pointedEntryClass = function(entry) {
|
$scope.pointedEntryClass = function(entry) {
|
||||||
if(entry.pointed) {
|
if(entry.pointed) {
|
||||||
@ -523,12 +537,4 @@ accountantApp.controller(
|
|||||||
modalScope.dismiss();
|
modalScope.dismiss();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
$rootScope.$on("monthsLoadedEvent", function(event, args){
|
|
||||||
$scope.loadEntries(args.account, args.month);
|
|
||||||
});
|
|
||||||
|
|
||||||
$rootScope.$on("monthsLoadedEvent", function(event, args){
|
|
||||||
$scope.getAccountStatus(args.account, args.month);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user