diff --git a/src/app/app.module.ts b/src/app/app.module.ts index d51ba98..3c28ebd 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -17,6 +17,8 @@ import { AppRoutingModule } from './app.routing'; import { AuthGuard } from './_guards/auth.guard'; import { ApiService } from './providers/api-service'; +import { OrgGraphsService } from './providers/org-graphs.service'; + // Layouts import { FullLayoutComponent } from './layouts/full-layout.component'; import { SimpleLayoutComponent } from './layouts/simple-layout.component'; @@ -54,6 +56,7 @@ import { DashboardModule } from './dashboard/dashboard.module'; providers: [ AuthGuard, ApiService, + OrgGraphsService, { provide: LocationStrategy, useClass: HashLocationStrategy diff --git a/src/app/dashboard/dashboard.component.html b/src/app/dashboard/dashboard.component.html index 4ffd263..5ef8899 100644 --- a/src/app/dashboard/dashboard.component.html +++ b/src/app/dashboard/dashboard.component.html @@ -61,7 +61,7 @@
- +
diff --git a/src/app/providers/api-service.ts b/src/app/providers/api-service.ts index 73bb013..7aa4ffa 100644 --- a/src/app/providers/api-service.ts +++ b/src/app/providers/api-service.ts @@ -18,6 +18,16 @@ export class ApiService { } } + public post(url, data) { + if ( this.sessionKey != null ) { + data.session_key = this.sessionKey; + } + return this.http.post( + this.apiUrl + url, + data + ).map( response => response.json() ); + } + // Login API private getSessionKey() { diff --git a/src/app/providers/org-graphs.service.ts b/src/app/providers/org-graphs.service.ts new file mode 100644 index 0000000..aeea889 --- /dev/null +++ b/src/app/providers/org-graphs.service.ts @@ -0,0 +1,13 @@ +import { Injectable } from '@angular/core'; +import { ApiService } from './api-service'; + +@Injectable() +export class OrgGraphsService { + private orgGraphUrl = '/v1/organisation/graphs'; + + constructor(private api: ApiService) { } + + public getGraph(name: string) { + return this.api.post(this.orgGraphUrl, { graph: name }); + } +} diff --git a/src/app/widgets/customers.component.ts b/src/app/widgets/customers.component.ts index f9bebe4..7ccc692 100644 --- a/src/app/widgets/customers.component.ts +++ b/src/app/widgets/customers.component.ts @@ -1,18 +1,24 @@ import { Component, OnInit } from '@angular/core'; -import { ApiService } from '../providers/api-service'; +import { OrgGraphsService } from '../providers/org-graphs.service'; + +interface ChartData { + data: Array; + label: string; +} @Component({ - selector: 'widget-customer-7-days', + selector: 'widget-customers-last-7-days', templateUrl: 'customers.component.html', }) export class Customer7DayWidget implements OnInit { - public lineChartData: Array = [ + + public lineChartData: Array = [ { data: [], label: 'Series A' } ]; - public lineChartLabels: Array = []; + public lineChartLabels: Array; public lineChartOptions: any = { maintainAspectRatio: false, scales: { @@ -59,16 +65,15 @@ export class Customer7DayWidget implements OnInit { public customerSum: Number = 0; - constructor(private api: ApiService) { } + constructor(private graphService: OrgGraphsService) { } ngOnInit(): void { - this.api.graph_data(undefined) + this.graphService.getGraph('customers_last_7_days') .subscribe( result => { console.log(result); - const customersThisWeek = result.data.customersthisweek; - this.lineChartData[0].data = customersThisWeek.customerno; - this.lineChartLabels = customersThisWeek.day; + this.lineChartData[0].data = result.graph.count; + this.lineChartLabels = result.graph.day; this.customerSum = this.lineChartData[0].data.reduce((a, b) => a + b, 0); } );