Add category service in Angular2.
This commit is contained in:
parent
2812891b23
commit
a6a7c1cd77
22
src/operations/category.service.ts
Normal file
22
src/operations/category.service.ts
Normal 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
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
7
src/operations/category.ts
Normal file
7
src/operations/category.ts
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
// vim: set tw=80 ts=2 sw=2 sts=2 :
|
||||||
|
|
||||||
|
export class Category {
|
||||||
|
category: string;
|
||||||
|
expenses: number;
|
||||||
|
revenues: number;
|
||||||
|
}
|
@ -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)
|
||||||
|
@ -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,
|
||||||
],
|
],
|
||||||
|
Loading…
Reference in New Issue
Block a user