2017-08-31 16:06:47 +01:00
import { Directive , Component , OnInit } from '@angular/core' ;
import { ApiService } from '../providers/api-service' ;
import { Router } from '@angular/router' ;
import { GraphWidget } from '../widgets/graph-widget.component' ;
2017-12-12 15:10:44 +00:00
import { CustBarSnippetComponent } from '../snippets/cust-snippet-bar.component' ;
2017-12-13 12:37:11 +00:00
import { PiePanel } from '../panels/pie-panel.component' ;
2017-12-12 15:10:44 +00:00
import { DataType } from '../shared/data-types.enum' ;
2017-08-31 16:06:47 +01:00
@Component ( {
2017-08-31 18:44:17 +01:00
templateUrl : 'dashboard-customer.component.html'
2017-08-31 16:06:47 +01:00
} )
2017-08-31 18:44:17 +01:00
export class DashboardCustomerComponent implements OnInit {
/* Setting up dashboard's main variables*/
name : any ;
2017-09-19 15:04:49 +01:00
email : any ;
2017-08-31 18:44:17 +01:00
myPearPoints : any ;
trends : any ;
myRank : any ;
username : any ;
2017-12-14 20:14:47 +00:00
weekPurchaseList = {
week_0 : 0 ,
week_1 : 0 ,
week_2 : 0 ,
week_3 : 0 ,
week_4 : 0 ,
week_5 : 0 ,
week_6 : 0 ,
} ;
2017-12-13 12:37:11 +00:00
2017-12-15 17:20:18 +00:00
sectorNames = {
A : 'Agriculture, Forestry & Fishing' ,
B : 'Mining & Quarrying' ,
C : 'Manufacturing' ,
D : 'Electricity, Gas, Steam & Air Conditioning' ,
E : 'Water & Waste Management' ,
F : 'Construction' ,
G : 'Wholesale & Retail Trade' ,
H : 'Transportation & Storage' ,
I : 'Accomodation & Food Services' ,
J : 'Information & Communication' ,
K : 'Financial & Insurance Activities' ,
L : 'Real Estate' ,
M : 'Professional, Scientfic & Technical' ,
N : 'Administrative & Support Services' ,
O : 'Public Administration, Defence & Social Security' ,
P : 'Education' ,
Q : 'Human Health & Social Work' ,
R : 'Arts, Entertainment & Recreation' ,
S : 'Other Service Activities' ,
T : 'Household Domestic Business' ,
}
sectorIcons = {
A : 'icon-drop' ,
B : 'icon-diamond' ,
C : 'icon-settings' ,
D : 'icon-energy' ,
E : 'icon-trash' ,
F : 'icon-wrench' ,
G : 'icon-tag' ,
H : 'icon-speedometer' ,
I : 'icon-cup' ,
J : 'icon-globe' ,
K : 'icon-credit-card' ,
L : 'icon-graph' ,
M : 'icon-chemistry' ,
N : 'icon-drawer' ,
O : 'icon-pie-chart' ,
P : 'icon-graduation' ,
Q : 'icon-support' ,
R : 'icon-film' ,
S : 'icon-calendar' ,
T : 'icon-home' ,
}
sectorLetters : string [ ] = [ ] ;
sectorPurchases : number [ ] = [ ] ;
2017-12-14 20:14:47 +00:00
sectorList : any ;
// Graph widgets
2017-12-12 15:10:44 +00:00
public widgetList = [
{
type : 'graph' ,
name : 'total_last_week' ,
icon : 'icon-diamond' ,
title : 'Last Week Total' ,
dataType : DataType.currency ,
} ,
{
type : 'graph' ,
name : 'avg_spend_last_week' ,
icon : 'icon-diamond' ,
title : 'Last Week Avg. Spend' ,
dataType : DataType.currency ,
} ,
{
type : 'graph' ,
name : 'total_last_month' ,
title : 'Last Month Total' ,
dataType : DataType.currency ,
} ,
{
type : 'graph' ,
name : 'avg_spend_last_month' ,
title : 'Last Month Avg. Spend' ,
dataType : DataType.currency ,
} ,
] ;
2017-08-31 16:06:47 +01:00
constructor (
private api : ApiService ,
) {
2017-12-14 20:14:47 +00:00
this . api . basicStats ( ) . subscribe (
result = > {
2017-12-15 17:20:18 +00:00
this . setWeekPurchaseList ( result . weeks ) ;
this . setSectorList ( result . sectors ) ;
2017-12-14 20:14:47 +00:00
} ,
error = > {
console . log ( 'Retrieval Error' ) ;
console . log ( error . _body ) ;
}
) ;
}
public setWeekPurchaseList ( data : any ) {
this . weekPurchaseList = {
week_0 : data.purchases [ 0 ] ,
week_1 : data.purchases [ 1 ] ,
week_2 : data.purchases [ 2 ] ,
week_3 : data.purchases [ 3 ] ,
week_4 : data.purchases [ 4 ] ,
week_5 : data.purchases [ 5 ] ,
week_6 : data.purchases [ 6 ] ,
} ;
//this.maxPurchase = Math.max(...this.weekPurchaseList);
this . maxPurchase = Object . values ( this . weekPurchaseList ) . reduce ( ( a , b ) = > {
if ( ! a ) { a = 0 }
if ( ! b ) { b = 0 }
return Math . max ( a , b ) ;
} ) ;
2017-12-15 17:20:18 +00:00
}
public setSectorList ( data : any ) {
this . sectorLetters = Object . values ( data . sectors ) ;
this . sectorPurchases = Object . values ( data . purchases ) ;
2017-08-31 16:06:47 +01:00
}
ngOnInit ( ) : void {
}
}