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', {
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'

View File

@ -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);
/*
* Add a new operation.
*/
$scope.addOperation = function() {
var operation = new Operation({
account_id: $routeParams.accountId
});
$scope.operations.splice(0, 0, operation);
};
// 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({
/*
* 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')
}, 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);
/*
* Cancel edition.
*/
$scope.cancelEdit = function(operation, rowform, $index) {
if(!operation.id) {
$scope.operations.splice($index, 1);
} else {
rowform.$cancel();
}
};
/*
* Toggle pointed indicator for an entry.
* Toggle pointed indicator for an operation.
*/
$scope.togglePointedEntry = function(entry, rowform) {
entry.pointed = !entry.pointed;
$scope.togglePointed = function(operation, rowform) {
operation.pointed = !operation.pointed;
// Save entry if not editing it.
// Save operation if not editing it.
if(!rowform.$visible) {
$scope.saveEntry(entry);
$scope.save(operation);
}
};
/*
* Toggle cancel indicator for an entry.
* Toggle cancel indicator for an operation.
*/
$scope.toggleCanceledEntry = function(entry) {
entry.canceled = !entry.canceled;
$scope.toggleCanceled = function(operation) {
operation.canceled = !operation.canceled;
$scope.saveEntry(entry);
$scope.save(operation);
};
/*
* Save an entry and emit entrySavedEvent.
* Save an operation and emit operationSavedEvent.
*/
$scope.saveEntry = function($data, $index) {
$scope.save = function($data, $index) {
// Check if $data is already a resource.
var entry;
var operation;
if($data.$save) {
entry = $data;
operation = $data;
} else {
entry = $scope.entries[$index];
entry = angular.merge(entry, $data);
operation = $scope.operations[$index];
operation = angular.merge(operation, $data);
}
entry.confirmed = true;
operation.confirmed = true;
return entry.$save().then(function(data) {
notificationService.success("Entry #" + data.id + " saved.");
$scope.$emit("entrySavedEvent", data);
return data;
return operation.$save().then(function(data) {
notificationService.success("Operation #" + data.id + " saved.");
$scope.$emit("operationSavedEvent", data);
});
};
/*
* Delete an entry and emit entryDeletedEvent.
* Delete an operation and emit operationDeletedEvent.
*/
$scope.deleteEntry = function(entry, $index) {
var id = entry.id;
$scope.delete = function(operation, $index) {
var id = operation.id;
bootbox.confirm(
"Voulez-vous supprimer l'entrée \"" + entry.label + "\" ?",
"Voulez-vous supprimer l'opération \"" + operation.label + "\" ?",
function(result) {
if(result) {
entry.$delete().then(function() {
notificationService.success("Entry #" + id + " deleted.");
operation.$delete().then(function() {
notificationService.success("Operation #" + id + " deleted.");
// Remove entry from array.
$scope.entries.splice($index, 1);
// Remove operation from array.
$scope.operation.splice($index, 1);
$scope.$emit("entryDeletedEvent", entry);
$scope.$emit("operationDeletedEvent", operation);
});
}
}
);
};
// Reload entries on range selection.
/*
* 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.loadEntries(args.begin, args.end);
$scope.load(args.begin, args.end);
});
}]);

View File

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

View File

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

View File

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