Add category service in Angular2.

This commit is contained in:
Alexis Lahouze 2017-07-29 16:33:24 +02:00
parent 2812891b23
commit a6a7c1cd77
4 changed files with 36 additions and 0 deletions

View File

@ -0,0 +1,22 @@
// vim: set tw=80 ts=2 sw=2 sts=2:
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/Rx';
import { Restangular } from "ngx-restangular";
import { Category } from './category';
@Injectable()
export class CategoryService {
constructor(
private restangular: Restangular
) {}
query(id: number, minDate: Date = null, maxDate: Date = null): Observable<Category[]> {
return this.restangular.one('account', id).getList('category', {
begin: minDate,
end: maxDate
});
}
}

View File

@ -0,0 +1,7 @@
// vim: set tw=80 ts=2 sw=2 sts=2 :
export class Category {
category: string;
expenses: number;
revenues: number;
}

View File

@ -35,6 +35,7 @@ var categoryChartModule = require('./category-chart.component');
import accountModule from '@accountant/accounts'; import accountModule from '@accountant/accounts';
import { BalanceChartComponent } from './balanceChart.component'; import { BalanceChartComponent } from './balanceChart.component';
import { CategoryService } from './category.service';
var OperationFactory = require('./operation.factory'); var OperationFactory = require('./operation.factory');
var OperationController = require('./operation.controller'); var OperationController = require('./operation.controller');
@ -52,6 +53,8 @@ export default angular.module('accountant.operations', [
.controller('OperationController', OperationController) .controller('OperationController', OperationController)
.factory('categoryService', downgradeInjectable(CategoryService))
.directive('balanceChart', downgradeComponent({ .directive('balanceChart', downgradeComponent({
component: BalanceChartComponent component: BalanceChartComponent
}) as angular.IDirectiveFactory) }) as angular.IDirectiveFactory)

View File

@ -9,6 +9,7 @@ import { NgLoggerModule, Level } from '@nsalaun/ng-logger';
import { RestangularModule } from 'ngx-restangular'; import { RestangularModule } from 'ngx-restangular';
import { BalanceChartComponent } from './balanceChart.component'; import { BalanceChartComponent } from './balanceChart.component';
import { CategoryService } from './category.service'
@NgModule({ @NgModule({
imports: [ imports: [
@ -18,6 +19,9 @@ import { BalanceChartComponent } from './balanceChart.component';
NgLoggerModule, NgLoggerModule,
RestangularModule, RestangularModule,
], ],
providers: [
CategoryService,
],
declarations: [ declarations: [
BalanceChartComponent, BalanceChartComponent,
], ],