diff --git a/src/operations/index.ts b/src/operations/index.ts
index b34c81e..140ca28 100644
--- a/src/operations/index.ts
+++ b/src/operations/index.ts
@@ -44,18 +44,8 @@ export default angular.module('accountant.operations', [
accountModule,
])
- .factory('toastrService', downgradeInjectable(ToastrService))
-
- .factory('operationService', downgradeInjectable(OperationService))
-
- .controller('OperationController', OperationController)
-
- .directive('balanceChart', downgradeComponent({
- component: BalanceChartComponent
- }) as angular.IDirectiveFactory)
-
- .directive('categoryChart', downgradeComponent({
- component: CategoryChartComponent
- }) as angular.IDirectiveFactory)
+ .directive('operationListComponent', downgradeComponent({
+ component: OperationController
+ }))
.name;
diff --git a/src/operations/operation.controller.ts b/src/operations/operation.controller.ts
index 9077cf2..4dc0c5e 100644
--- a/src/operations/operation.controller.ts
+++ b/src/operations/operation.controller.ts
@@ -11,20 +11,72 @@ import { AccountService } from '../accounts/account.service';
import { Operation } from './operation';
import { OperationService } from './operation.service';
-export class OperationController {
+@Component({
+ selector: 'operation-list',
+ template: `
+
+
+
+
+
+
+
+ Date d'op. |
+ Libellé de l'opération |
+ Montant |
+ Solde |
+ Catégorie |
+ Actions |
+
+
+
+
+
+
+
+ |
+
+
+
+
+
+
+
+
+ `
+})
+export class OperationController implements OnInit {
private account: Account;
private minDate: Date;
private maxDate: Date;
private operations: Operation[];
constructor(
- private $modal,
- private accountIdService,
+ @Inject("$modal") private $modal,
+ @Inject("accountIdService") private accountIdService,
private toastrService: ToastrService,
private operationService: OperationService,
- private AccountService: AccountService
- ){
- AccountService.get(this.accountIdService.get()).subscribe(account => {
+ private accountService: AccountService
+ ) {}
+
+ ngOnInit() {
+ this.accountService.get(this.accountIdService.get()).subscribe(account => {
this.account = account
});
}
@@ -51,28 +103,10 @@ export class OperationController {
minDate,
maxDate
).subscribe((operations: Operation[]) => {
- this.operations = operations;
+ this.operations = operations.reverse();
});
};
- /*
- * Toggle pointed indicator for an operation.
- */
- togglePointed(operation, rowform) {
- operation.pointed = !operation.pointed;
-
- this.save(operation);
- };
-
- /*
- * Toggle cancel indicator for an operation.
- */
- toggleCanceled(operation) {
- operation.canceled = !operation.canceled;
-
- this.save(operation);
- };
-
/*
* Save an operation and return a promise.
*/
@@ -100,60 +134,9 @@ export class OperationController {
});
};
- /*
- * Delete an operation and return a promise.
- */
- confirmDelete(operation) {
- var title = "Delete operation #" + operation.id;
-
- this.$modal({
- templateUrl: operationDeleteTmpl,
- controller: function($scope, title, operation, $delete) {
- $scope.title = title;
- $scope.operation = operation;
- $scope.$delete = () => {
- $scope.$hide();
- $delete($scope.operation);
- };
- },
- locals: {
- title: title,
- operation: operation,
- $delete: (operation: Operation) => {
- this.delete(operation);
- }
- }
- });
- };
-
- delete(operation) {
- var id = operation.id;
-
- return this.operationService.delete(operation).subscribe(() => {
- this.toastrService.success('Operation #' + id + ' deleted.');
-
- this.load(this.minDate, this.maxDate);
-
- return operation;
- }, (result) => {
- this.toastrService.error(
- 'An error occurred while trying to delete operation #' +
- id + ':
' + result
- );
- });
- };
-
- /*
- * Open the popup to modify the operation, save it on confirm.
- * @returns a promise.
- */
modify(operation) {
// FIXME Alexis Lahouze 2017-06-15 i18n
- var title = "Operation";
-
- if (operation.id) {
- title = title + " #" + operation.id;
- }
+ var title = "New operation";
this.$modal({
templateUrl: operationFormTmpl,
diff --git a/src/operations/operation.module.ts b/src/operations/operation.module.ts
index 34f87ef..0ef9db3 100644
--- a/src/operations/operation.module.ts
+++ b/src/operations/operation.module.ts
@@ -13,6 +13,7 @@ import { CategoryChartComponent } from './categoryChart.component';
import { OperationRowComponent } from './operationRow.component';
import { CategoryService } from './category.service';
import { OperationService } from './operation.service';
+import { OperationController } from './operation.controller';
export function $modalServiceFactory(i: any) {
return i.get('$modal');
@@ -47,11 +48,13 @@ export function accountIdServiceFactory(i: any) {
BalanceChartComponent,
CategoryChartComponent,
OperationRowComponent,
+ OperationController,
],
entryComponents: [
BalanceChartComponent,
CategoryChartComponent,
OperationRowComponent,
+ OperationController,
]
})
export class OperationModule {}
diff --git a/src/operations/operation.states.ts b/src/operations/operation.states.ts
index 0998ad9..f3af619 100644
--- a/src/operations/operation.states.ts
+++ b/src/operations/operation.states.ts
@@ -1,11 +1,7 @@
// vim: set tw=80 ts=2 sw=2 sts=2 :
-var operationsTmpl = require('./operations.html');
-
export const OperationListState = {
name: 'operations',
url: '/account/:accountId/operations',
- templateUrl: operationsTmpl,
- controller: 'OperationController',
- controllerAs: 'operationsCtrl'
+ component: 'operationListComponent'
}