Renaming.

This commit is contained in:
Alexis Lahouze 2015-08-21 00:57:59 +02:00
parent ce3181537d
commit c986cf5186
5 changed files with 164 additions and 157 deletions

View File

@ -41,9 +41,9 @@ var accountantApp = angular.module("accountantApp", [
}; };
}); });
$routeProvider.when('/account/:accountId/entries', { $routeProvider.when('/account/:accountId/operations', {
templateUrl: 'static/templates/entries.html', templateUrl: 'static/templates/operations.html',
controller: 'EntryController' controller: 'OperationController'
}).when('/account/:accountId/scheduler', { }).when('/account/:accountId/scheduler', {
templateUrl: 'static/templates/scheduler.html', templateUrl: 'static/templates/scheduler.html',
controller: 'SchedulerController' controller: 'SchedulerController'

View File

@ -16,7 +16,7 @@
*/ */
accountantApp accountantApp
.factory("Entries", [ "$resource", function($resource) { .factory("Operation", [ "$resource", function($resource) {
return $resource( return $resource(
"/api/entries/:id", { "/api/entries/:id", {
id: "@id" id: "@id"
@ -171,7 +171,7 @@ accountantApp
"SoldChartController", [ "SoldChartController", [
"$rootScope", "$scope", "$http", "$routeParams", "$rootScope", "$scope", "$http", "$routeParams",
function($rootScope, $scope, $http, $routeParams) { function($rootScope, $scope, $http, $routeParams) {
// Configure chart for entries. // Configure chart for operations.
$scope.config = { $scope.config = {
options: { options: {
chart: { chart: {
@ -271,10 +271,10 @@ accountantApp
}).success(function(data) { }).success(function(data) {
$scope.config.series[0].data = []; $scope.config.series[0].data = [];
angular.forEach(data, function(entry) { angular.forEach(data, function(operation) {
$scope.config.series[0].data.push([ $scope.config.series[0].data.push([
moment.utc(entry.operation_date).valueOf(), moment.utc(operation.operation_date).valueOf(),
entry.open, entry.high, entry.low, entry.close operation.open, operation.high, operation.low, operation.close
]); ]);
}); });
@ -287,13 +287,13 @@ accountantApp
}); });
}; };
// Reload solds when an entry is saved. // Reload solds when an operation is saved.
$rootScope.$on("entrySavedEvent", function(e, entry) { $rootScope.$on("operationSavedEvent", function(e, operation) {
$scope.loadSolds(); $scope.loadSolds();
}); });
// Reload solds when an entry is deleted. // Reload solds when an operation is deleted.
$rootScope.$on("entryDeletedEvent", function(e, entry) { $rootScope.$on("operationDeletedEvent", function(e, operation) {
$scope.loadSolds(); $scope.loadSolds();
}); });
@ -307,113 +307,122 @@ accountantApp
}]) }])
.controller( .controller(
"EntryController", [ "OperationController", [
"$scope", "$http", "$rootScope", "$filter", "$routeParams", "notificationService", "Entries", "$scope", "$http", "$rootScope", "$filter", "$routeParams", "notificationService", "Operation",
function($scope, $http, $rootScope, $filter, $routeParams, notificationService, Entries) { function($scope, $http, $rootScope, $filter, $routeParams, notificationService, Operation) {
// Entry store and selection // Operation store.
$scope.entries = []; $scope.operations = [];
// Function to reset the new entry. /*
$scope.addEntry = function() { * Add a new operation.
entry = new Entries(); */
entry.account_id = $routeParams.accountId; $scope.addOperation = function() {
$scope.entries.splice(0, 0, entry); var operation = new Operation({
}; account_id: $routeParams.accountId
// 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);
}); });
$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);
});
}]); }]);

View File

@ -15,7 +15,6 @@
along with Accountant. If not, see <http://www.gnu.org/licenses/>. along with Accountant. If not, see <http://www.gnu.org/licenses/>.
--> -->
<!-- vim: set tw=80 ts=2 sw=2 sts=2: --> <!-- vim: set tw=80 ts=2 sw=2 sts=2: -->
<!-- Row with entry table -->
<div class="row"> <div class="row">
<table class="table table-striped table-condensed table-hover"> <table class="table table-striped table-condensed table-hover">
<!-- Head of the table containing column headers and size --> <!-- Head of the table containing column headers and size -->
@ -29,7 +28,6 @@
</tr> </tr>
</thead> </thead>
<!-- Body of the table containing the entries -->
<tbody> <tbody>
<tr> <tr>
<td colspan="5"> <td colspan="5">
@ -46,7 +44,7 @@
e-placeholder="Nom du compte" e-placeholder="Nom du compte"
e-style="width: 100%" e-style="width: 100%"
e-name="name" e-form="rowform" e-required> e-name="name" e-form="rowform" e-required>
<a href="account/{{ account.id }}/entries">{{ account.name }}</a> <a href="account/{{ account.id }}/operations">{{ account.name }}</a>
</span> </span>
</td> </td>

View File

@ -48,101 +48,101 @@
<tbody> <tbody>
<tr> <tr>
<td colspan="6"> <td colspan="6">
<button class="btn btn-success" ng-click="addEntry()"> <button class="btn btn-success" ng-click="add()">
Ajouter Ajouter
</button> </button>
</td> </td>
</tr> </tr>
<tr id="{{ entry.id }}" class="form-inline" <tr id="{{ operation.id }}" class="form-inline"
ng-class="{stroke: entry.canceled, italic: !entry.confirmed, warning: entry.sold < 0, danger: entry.sold < account.authorized_overdraft}" ng-class="{stroke: operation.canceled, italic: !operation.confirmed, warning: operation.sold < 0, danger: operation.sold < account.authorized_overdraft}"
ng-repeat="entry in entries"> ng-repeat="operation in operations">
<td> <td>
<span editable-text="entry.operation_date" <span editable-text="operation.operation_date"
e-data-date-format="yyyy-MM-dd" e-bs-datepicker e-data-date-format="yyyy-MM-dd" e-bs-datepicker
e-class="input-sm" e-style="width: 100%" e-class="input-sm" e-style="width: 100%"
e-name="operation_date" e-form="rowform" e-required> e-name="operation_date" e-form="rowform" e-required>
<small>{{ entry.operation_date | date:"yyyy-MM-dd" }}</small> <small>{{ operation.operation_date | date:"yyyy-MM-dd" }}</small>
</span> </span>
</td> </td>
<td> <td>
<span editable-text="entry.label" <span editable-text="operation.label"
e-style="width: 100%" e-style="width: 100%"
e-placeholder="Libellé de l'opération" e-placeholder="Libellé de l'opération"
e-class="input-sm" e-style="width: 100%" e-class="input-sm" e-style="width: 100%"
e-name="label" e-form="rowform" e-required> e-name="label" e-form="rowform" e-required>
<small>{{ entry.label }}</small> <small>{{ operation.label }}</small>
</span> </span>
</td> </td>
<td> <td>
<span editable-number="entry.value" <span editable-number="operation.value"
e-class="input-sm" e-style="width: 100%" e-class="input-sm" e-style="width: 100%"
e-name="value" e-form="rowform" e-required> e-name="value" e-form="rowform" e-required>
<small>{{ entry.value }}</small> <small>{{ operation.value }}</small>
</span> </span>
</td> </td>
<td ng-class="{'text-warning': entry.sold < 0, 'text-danger': entry.sold < account.authorized_overdraft}"> <td ng-class="{'text-warning': operation.sold < 0, 'text-danger': operation.sold < account.authorized_overdraft}">
<small>{{ entry.sold }}</small> <small>{{ operation.sold }}</small>
</td> </td>
<td> <td>
<span editable-text="entry.category" <span editable-text="operation.category"
e-placeholder="Catégorie" e-placeholder="Catégorie"
e-class="input-sm" e-style="width: 100%" e-class="input-sm" e-style="width: 100%"
e-name="category" e-form="rowform" e-required> e-name="category" e-form="rowform" e-required>
<small>{{ entry.category }}</small> <small>{{ operation.category }}</small>
</span> </span>
</td> </td>
<td> <td>
<form editable-form name="rowform" <form editable-form name="rowform"
onbeforesave="saveEntry($data, $index)" onbeforesave="save($data, $index)"
shown="!entry.id"> shown="!operation.id">
<div class="btn-group btn-group-xs"> <div class="btn-group btn-group-xs">
<!-- Save current entry, for editing and non-confirmed non-canceled entries --> <!-- Save current operation, for editing and non-confirmed non-canceled operation. -->
<button type="submit" class="btn btn-success" <button type="submit" class="btn btn-success"
ng-if="!entry.canceled && (!entry.confirmed || rowform.$visible)" ng-if="!operation.canceled && (!operation.confirmed || rowform.$visible)"
title="Save"> title="Save">
<span class="fa fa-floppy-o"></span> <span class="fa fa-floppy-o"></span>
</button> </button>
<!-- Edit entry, for non-canceled and non-editing entries--> <!-- Edit operation, for non-canceled and non-editing operation -->
<button type="button" class="btn btn-default" <button type="button" class="btn btn-default"
ng-if="!entry.canceled && !rowform.$visible" ng-if="!operation.canceled && !rowform.$visible"
ng-click="rowform.$show()" title="edit"> ng-click="rowform.$show()" title="edit">
<span class="fa fa-pencil-square-o"></span> <span class="fa fa-pencil-square-o"></span>
</button> </button>
<!-- Cancel edition, for editing entries. --> <!-- Cancel edition, for editing operation. -->
<button type="button" class="btn btn-default" <button type="button" class="btn btn-default"
ng-if="rowform.$visible" ng-if="rowform.$visible"
ng-click="cancelEditEntry(entry, rowform)"> ng-click="cancelEdit(operation, rowform)">
<span class="fa fa-times"></span> <span class="fa fa-times"></span>
</button> </button>
<!-- Toggle pointed entry, for non-canceled entries. --> <!-- Toggle pointed operation, for non-canceled operations. -->
<button type="button" class="btn btn-default" <button type="button" class="btn btn-default"
ng-if="!entry.canceled" ng-if="!operation.canceled"
ng-click="togglePointedEntry(entry, rowform)" ng-click="togglePointed(operation, rowform)"
ng-class="{active: entry.pointed}" title="point"> ng-class="{active: operation.pointed}" title="point">
<span ng-class="{'fa fa-check-square-o': entry.pointed, 'fa fa-square-o': !entry.pointed}"></span> <span ng-class="{'fa fa-check-square-o': operation.pointed, 'fa fa-square-o': !operation.pointed}"></span>
</button> </button>
<!-- Toggle canceled entry, for non-editing entries. --> <!-- Toggle canceled operation, for non-editing operations. -->
<button type="button" class="btn btn-default" <button type="button" class="btn btn-default"
ng-click="toggleCanceledEntry(entry)" ng-click="toggleCanceled(operation)"
ng-if="entry.scheduled_operation_id && !rowform.$visible" ng-if="operation.scheduled_operation_id && !rowform.$visible"
ng-class="{active: entry.canceled}" title="cancel"> ng-class="{active: operation.canceled}" title="cancel">
<span class="fa fa-remove"></span> <span class="fa fa-remove"></span>
</button> </button>
<!-- Delete entry, with confirm. --> <!-- Delete operation, with confirm. -->
<button type="button" class="btn btn-default" <button type="button" class="btn btn-default"
ng-if="entry.id && !entry.scheduled_operation_id" ng-if="operation.id && !operation.scheduled_operation_id"
ng-click="deleteEntry(entry, $index)"> ng-click="delete(operation, $index)">
<span class="fa fa-trash-o"></span> <span class="fa fa-trash-o"></span>
</button> </button>
</div> </div>

View File

@ -131,7 +131,7 @@
<!-- Remove operation. --> <!-- Remove operation. -->
<button type="button" class="btn btn-default" <button type="button" class="btn btn-default"
ng-if="!operation.id" ng-if="operation.id"
ng-click="delete(operation, $index)" ng-click="delete(operation, $index)"
title="remove"> title="remove">
<span class="fa fa-trash"></span> <span class="fa fa-trash"></span>