From c986cf5186394f1054ea63aa9a6f5402814cd9d3 Mon Sep 17 00:00:00 2001 From: Alexis Lahouze Date: Fri, 21 Aug 2015 00:57:59 +0200 Subject: [PATCH] Renaming. --- accountant/frontend/static/js/app.js | 6 +- accountant/frontend/static/js/entries.js | 241 +++++++++--------- .../frontend/static/templates/accounts.html | 4 +- .../{entries.html => operations.html} | 68 ++--- .../frontend/static/templates/scheduler.html | 2 +- 5 files changed, 164 insertions(+), 157 deletions(-) rename accountant/frontend/static/templates/{entries.html => operations.html} (62%) diff --git a/accountant/frontend/static/js/app.js b/accountant/frontend/static/js/app.js index 63cd384..f5dc8f3 100644 --- a/accountant/frontend/static/js/app.js +++ b/accountant/frontend/static/js/app.js @@ -41,9 +41,9 @@ var accountantApp = angular.module("accountantApp", [ }; }); - $routeProvider.when('/account/:accountId/entries', { - templateUrl: 'static/templates/entries.html', - controller: 'EntryController' + $routeProvider.when('/account/:accountId/operations', { + templateUrl: 'static/templates/operations.html', + controller: 'OperationController' }).when('/account/:accountId/scheduler', { templateUrl: 'static/templates/scheduler.html', controller: 'SchedulerController' diff --git a/accountant/frontend/static/js/entries.js b/accountant/frontend/static/js/entries.js index 2473ff8..ced05a1 100644 --- a/accountant/frontend/static/js/entries.js +++ b/accountant/frontend/static/js/entries.js @@ -16,7 +16,7 @@ */ accountantApp -.factory("Entries", [ "$resource", function($resource) { +.factory("Operation", [ "$resource", function($resource) { return $resource( "/api/entries/:id", { id: "@id" @@ -171,7 +171,7 @@ accountantApp "SoldChartController", [ "$rootScope", "$scope", "$http", "$routeParams", function($rootScope, $scope, $http, $routeParams) { - // Configure chart for entries. + // Configure chart for operations. $scope.config = { options: { chart: { @@ -271,10 +271,10 @@ accountantApp }).success(function(data) { $scope.config.series[0].data = []; - angular.forEach(data, function(entry) { + angular.forEach(data, function(operation) { $scope.config.series[0].data.push([ - moment.utc(entry.operation_date).valueOf(), - entry.open, entry.high, entry.low, entry.close + moment.utc(operation.operation_date).valueOf(), + operation.open, operation.high, operation.low, operation.close ]); }); @@ -287,13 +287,13 @@ accountantApp }); }; - // Reload solds when an entry is saved. - $rootScope.$on("entrySavedEvent", function(e, entry) { + // Reload solds when an operation is saved. + $rootScope.$on("operationSavedEvent", function(e, operation) { $scope.loadSolds(); }); - // Reload solds when an entry is deleted. - $rootScope.$on("entryDeletedEvent", function(e, entry) { + // Reload solds when an operation is deleted. + $rootScope.$on("operationDeletedEvent", function(e, operation) { $scope.loadSolds(); }); @@ -307,113 +307,122 @@ accountantApp }]) .controller( - "EntryController", [ - "$scope", "$http", "$rootScope", "$filter", "$routeParams", "notificationService", "Entries", - function($scope, $http, $rootScope, $filter, $routeParams, notificationService, Entries) { - // Entry store and selection - $scope.entries = []; + "OperationController", [ + "$scope", "$http", "$rootScope", "$filter", "$routeParams", "notificationService", "Operation", + function($scope, $http, $rootScope, $filter, $routeParams, notificationService, Operation) { + // Operation store. + $scope.operations = []; - // Function to reset the new entry. - $scope.addEntry = function() { - entry = new Entries(); - entry.account_id = $routeParams.accountId; - $scope.entries.splice(0, 0, entry); - }; - - // Function to load entries from server for a specific account and month. - $scope.loadEntries = function(begin, end) { - // Clean up selected entry. - $scope.selectedItem = null; - $scope.savedItem = null; - - $scope.entries = Entries.query({ - account: $routeParams.accountId, - begin: begin.format('YYYY-MM-DD'), - end: end.format('YYYY-MM-DD') - }, function(data) { - $scope.$emit("entriesLoadedEvent", {entries: data}); - }); - }; - - // Cancel current editing entry or clears field if a new one. - $scope.cancelEditEntry = function(entry, rowform, $index) { - if(!entry.id) { - $scope.entries.splice($index, 1); - } else { - rowform.$cancel(); - } - }; - - /* - * Toggle pointed indicator for an entry. - */ - $scope.togglePointedEntry = function(entry, rowform) { - entry.pointed = !entry.pointed; - - // Save entry if not editing it. - if(!rowform.$visible) { - $scope.saveEntry(entry); - } - }; - - /* - * Toggle cancel indicator for an entry. - */ - $scope.toggleCanceledEntry = function(entry) { - entry.canceled = !entry.canceled; - - $scope.saveEntry(entry); - }; - - /* - * Save an entry and emit entrySavedEvent. - */ - $scope.saveEntry = function($data, $index) { - // Check if $data is already a resource. - var entry; - - if($data.$save) { - entry = $data; - } else { - entry = $scope.entries[$index]; - entry = angular.merge(entry, $data); - } - - entry.confirmed = true; - - return entry.$save().then(function(data) { - notificationService.success("Entry #" + data.id + " saved."); - $scope.$emit("entrySavedEvent", data); - - return data; - }); - }; - - /* - * Delete an entry and emit entryDeletedEvent. - */ - $scope.deleteEntry = function(entry, $index) { - var id = entry.id; - - bootbox.confirm( - "Voulez-vous supprimer l'entrée \"" + entry.label + "\" ?", - function(result) { - if(result) { - entry.$delete().then(function() { - notificationService.success("Entry #" + id + " deleted."); - - // Remove entry from array. - $scope.entries.splice($index, 1); - - $scope.$emit("entryDeletedEvent", entry); - }); - } - } - ); - }; - - // Reload entries on range selection. - $rootScope.$on("rangeSelectedEvent", function(e, args) { - $scope.loadEntries(args.begin, args.end); + /* + * Add a new operation. + */ + $scope.addOperation = function() { + var operation = new Operation({ + account_id: $routeParams.accountId }); + + $scope.operations.splice(0, 0, operation); + }; + + /* + * Load operations. + */ + $scope.load = function(begin, end) { + $scope.operations = Operation.query({ + account: $routeParams.accountId, + begin: begin.format('YYYY-MM-DD'), + end: end.format('YYYY-MM-DD') + }); + }; + + /* + * Cancel edition. + */ + $scope.cancelEdit = function(operation, rowform, $index) { + if(!operation.id) { + $scope.operations.splice($index, 1); + } else { + rowform.$cancel(); + } + }; + + /* + * Toggle pointed indicator for an operation. + */ + $scope.togglePointed = function(operation, rowform) { + operation.pointed = !operation.pointed; + + // Save operation if not editing it. + if(!rowform.$visible) { + $scope.save(operation); + } + }; + + /* + * Toggle cancel indicator for an operation. + */ + $scope.toggleCanceled = function(operation) { + operation.canceled = !operation.canceled; + + $scope.save(operation); + }; + + /* + * Save an operation and emit operationSavedEvent. + */ + $scope.save = function($data, $index) { + // Check if $data is already a resource. + var operation; + + if($data.$save) { + operation = $data; + } else { + operation = $scope.operations[$index]; + operation = angular.merge(operation, $data); + } + + operation.confirmed = true; + + return operation.$save().then(function(data) { + notificationService.success("Operation #" + data.id + " saved."); + $scope.$emit("operationSavedEvent", data); + }); + }; + + /* + * Delete an operation and emit operationDeletedEvent. + */ + $scope.delete = function(operation, $index) { + var id = operation.id; + + bootbox.confirm( + "Voulez-vous supprimer l'opération \"" + operation.label + "\" ?", + function(result) { + if(result) { + operation.$delete().then(function() { + notificationService.success("Operation #" + id + " deleted."); + + // Remove operation from array. + $scope.operation.splice($index, 1); + + $scope.$emit("operationDeletedEvent", operation); + }); + } + } + ); + }; + + /* + * Save account in scope to colorize with authorized overdraft. + */ + $rootScope.$on("accountLoadedEvent", function(e, account) { + $scope.account = account; + }); + + /* + * Reload operations on rangeSelectedEvent. + */ + $rootScope.$on("rangeSelectedEvent", function(e, args) { + $scope.load(args.begin, args.end); + }); }]); diff --git a/accountant/frontend/static/templates/accounts.html b/accountant/frontend/static/templates/accounts.html index 3d12c26..6a94cba 100644 --- a/accountant/frontend/static/templates/accounts.html +++ b/accountant/frontend/static/templates/accounts.html @@ -15,7 +15,6 @@ along with Accountant. If not, see . --> -
@@ -29,7 +28,6 @@ - diff --git a/accountant/frontend/static/templates/entries.html b/accountant/frontend/static/templates/operations.html similarity index 62% rename from accountant/frontend/static/templates/entries.html rename to accountant/frontend/static/templates/operations.html index ae7654c..1fa68dc 100644 --- a/accountant/frontend/static/templates/entries.html +++ b/accountant/frontend/static/templates/operations.html @@ -48,101 +48,101 @@ - + -
@@ -46,7 +44,7 @@ e-placeholder="Nom du compte" e-style="width: 100%" e-name="name" e-form="rowform" e-required> - {{ account.name }} + {{ account.name }}
-
- - {{ entry.operation_date | date:"yyyy-MM-dd" }} + {{ operation.operation_date | date:"yyyy-MM-dd" }} - - {{ entry.label }} + {{ operation.label }} - - {{ entry.value }} + {{ operation.value }} - {{ entry.sold }} + + {{ operation.sold }} - - {{ entry.category }} + {{ operation.category }}
+ onbeforesave="save($data, $index)" + shown="!operation.id">
- + - + - + - + - + - +
diff --git a/accountant/frontend/static/templates/scheduler.html b/accountant/frontend/static/templates/scheduler.html index f651142..a1bad06 100644 --- a/accountant/frontend/static/templates/scheduler.html +++ b/accountant/frontend/static/templates/scheduler.html @@ -131,7 +131,7 @@