From 44e6ba4c8be8c62abf4fa8f21a6fd716066ed437 Mon Sep 17 00:00:00 2001 From: Tom Bloor Date: Thu, 7 Sep 2017 13:32:06 +0100 Subject: [PATCH 01/11] Added data-type enum package --- src/app/shared/data-types.enum.ts | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 src/app/shared/data-types.enum.ts diff --git a/src/app/shared/data-types.enum.ts b/src/app/shared/data-types.enum.ts new file mode 100644 index 0000000..7cf23fa --- /dev/null +++ b/src/app/shared/data-types.enum.ts @@ -0,0 +1,4 @@ +export enum DataType { + number, + currency, +} From dd735e517e50cd6c6fffbe36270957c2ef8fd840 Mon Sep 17 00:00:00 2001 From: Tom Bloor Date: Thu, 7 Sep 2017 13:32:42 +0100 Subject: [PATCH 02/11] Give graph ability to support different datatypes --- src/app/widgets/graph-widget.component.html | 3 +- src/app/widgets/graph-widget.component.ts | 33 +++++++++++++++++++-- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/app/widgets/graph-widget.component.html b/src/app/widgets/graph-widget.component.html index 9c008e3..b94d92e 100644 --- a/src/app/widgets/graph-widget.component.html +++ b/src/app/widgets/graph-widget.component.html @@ -3,7 +3,8 @@ -

{{ graphSum }}

+

{{ graphSum }}

+

{{ graphSum | currency:'GBP':true:'1.2-2' }}

{{ graphTitle }}

diff --git a/src/app/widgets/graph-widget.component.ts b/src/app/widgets/graph-widget.component.ts index aaa4f9a..1339db9 100644 --- a/src/app/widgets/graph-widget.component.ts +++ b/src/app/widgets/graph-widget.component.ts @@ -1,5 +1,7 @@ import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core'; +import { CurrencyPipe } from '@angular/common'; import { OrgGraphsService } from '../providers/org-graphs.service'; +import { DataType } from '../shared/data-types.enum'; interface ChartData { data: Array; @@ -14,11 +16,13 @@ export class GraphWidget implements OnInit { @Input() public graphName: string; @Input() public graphTitle = 'Graph'; @Input() public graphIcon = 'icon-graph'; + @Input() public dataType: DataType = DataType.number; @Output() public graphHover = new EventEmitter(); @Output() public graphClick = new EventEmitter(); public graphSum: Number = 0; + public availableDataTypes = DataType; public lineChartData: Array = [ { @@ -60,7 +64,14 @@ export class GraphWidget implements OnInit { }, legend: { display: false - } + }, + tooltips: { + callbacks: { + label: (tooltip, data) => { + return this.tooltipLabelCallback(tooltip, data); + }, + }, + }, }; public lineChartColours: Array = [ { @@ -72,12 +83,22 @@ export class GraphWidget implements OnInit { public lineChartType = 'line'; - constructor(private graphService: OrgGraphsService) { } + constructor( + private graphService: OrgGraphsService, + private currencyPipe: CurrencyPipe, + ) { } ngOnInit(): void { if ( this.graphName == null ) { throw new Error('Attribute \'graphName\' is required on component \'widget-graph\''); } + if ( this.dataType === undefined ) { + // Need to do this as it may be passed in a loop with an undefined value + this.dataType = DataType.number; + } + if ( !( this.dataType in DataType ) ) { + console.warn('Unknown DataType for graph \'' + this.graphName + '\' - defaulting to number'); + } this.graphService.getGraph(this.graphName) .subscribe( result => this.setData(result.graph) ); } @@ -112,4 +133,12 @@ export class GraphWidget implements OnInit { public chartHovered(e: any): void { console.log(e); } + + private tooltipLabelCallback(tooltipItem: any, data: any) { + const value = tooltipItem.yLabel; + if ( this.dataType === DataType.currency ) { + return this.currencyPipe.transform(value, 'GBP', true, '1.2-2'); + } + return value || '0'; + } } From 555675c31304699b45ee4d84144afb786c216224 Mon Sep 17 00:00:00 2001 From: Tom Bloor Date: Thu, 7 Sep 2017 13:32:59 +0100 Subject: [PATCH 03/11] Add update to dashboard for widget graph types --- src/app/dashboard/dashboard.component.html | 6 +++++- src/app/dashboard/dashboard.component.ts | 5 +++++ src/app/dashboard/dashboard.module.ts | 7 ++++++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/app/dashboard/dashboard.component.html b/src/app/dashboard/dashboard.component.html index 324e795..3e2cc46 100644 --- a/src/app/dashboard/dashboard.component.html +++ b/src/app/dashboard/dashboard.component.html @@ -23,7 +23,11 @@
- +
diff --git a/src/app/dashboard/dashboard.component.ts b/src/app/dashboard/dashboard.component.ts index 407d643..43ec8c1 100644 --- a/src/app/dashboard/dashboard.component.ts +++ b/src/app/dashboard/dashboard.component.ts @@ -3,6 +3,7 @@ import { Http, Response } from '@angular/http'; import { ApiService } from '../providers/api-service'; import { Router } from '@angular/router'; import { GraphWidget } from '../widgets/graph-widget.component'; +import { DataType } from '../shared/data-types.enum'; @Component({ templateUrl: 'dashboard.component.html' @@ -44,22 +45,26 @@ export class DashboardComponent implements OnInit { name: 'sales_last_7_days', icon: 'icon-diamond', title: 'Sales Last 7 Days', + dataType: DataType.currency, }, { type: 'graph', name: 'sales_last_30_days', icon: 'icon-diamond', title: 'Sales Last 30 Days', + dataType: DataType.currency, }, { type: 'graph', name: 'purchases_last_7_days', title: 'Purchases Last 7 Days', + dataType: DataType.currency, }, { type: 'graph', name: 'purchases_last_30_days', title: 'Purchases Last 30 Days', + dataType: DataType.currency, }, ]; diff --git a/src/app/dashboard/dashboard.module.ts b/src/app/dashboard/dashboard.module.ts index 117f427..005e72b 100644 --- a/src/app/dashboard/dashboard.module.ts +++ b/src/app/dashboard/dashboard.module.ts @@ -4,6 +4,8 @@ import { FormsModule, ReactiveFormsModule } from '@angular/forms'; import { ChartsModule } from 'ng2-charts/ng2-charts'; import { BsDropdownModule } from 'ngx-bootstrap/dropdown'; +import { CurrencyPipe } from '@angular/common'; + import { DashboardComponent } from './dashboard.component'; import { DashboardCustomerComponent } from './dashboard-customer.component'; import { AccountEditComponent } from './account-edit.component'; @@ -35,6 +37,9 @@ import { OrgTableComponent } from '../shared/org-table.component'; OrgTableComponent, FeedbackComponent, GraphWidget, - ] + ], + providers: [ + CurrencyPipe + ], }) export class DashboardModule { } From e19db92a2054054cc38fe8ae6d32b386b00598ab Mon Sep 17 00:00:00 2001 From: Tom Bloor Date: Thu, 7 Sep 2017 13:45:14 +0100 Subject: [PATCH 04/11] Removed unused graphs from display --- src/app/dashboard/dashboard.component.html | 199 --------------------- 1 file changed, 199 deletions(-) diff --git a/src/app/dashboard/dashboard.component.html b/src/app/dashboard/dashboard.component.html index 3e2cc46..299e946 100644 --- a/src/app/dashboard/dashboard.component.html +++ b/src/app/dashboard/dashboard.component.html @@ -28,205 +28,6 @@ [graphTitle]="widget.title" [graphIcon]="widget.icon" [dataType]="widget.dataType"> -
-
-
-
-
{{noOfCustomersSector}}
-
No. of Customers in your Sector
-
-
-
- Lorem ipsum dolor sit amet enim. -
-
-
-
-
-
-
{{percentOfCustomersSector}}%
-
Customers in your Sector
-
-
-
- Lorem ipsum dolor sit amet enim. -
-
-
-
-
-
- -

9.823

-

Customers last year

-
-
- -
-
-
-
-
-
- -

9.823

-

Returning Customers last week

-
-
- -
-
-
-
-
-
- -

9.823

-

Returning Customers last month

-
-
- -
-
-
-
-
-
- -

9.823

-

Returning Customers last year

-
-
- -
-
-
-
-
-
- -

9.823

-

Points earned this week

-
-
- -
-
-
-
-
-
- -

9.823

-

Points earned last week

-
-
- -
-
-
-
-
-
-
Your suppliers that are local vs a local competitor
-
    -
  • - - Yours - {{percentOfLocalSuppliers}}% -
    -
    -
    -
    -
    -
  • -
  • - - A competitor - {{percentOfSingleCompetitorLocalSuppliers}}% -
    -
    -
    -
    -
    -
  • -
-
-
From 9bc9e34c510e837ad5d05f0d1fd8cc02ab25ccc4 Mon Sep 17 00:00:00 2001 From: Tom Bloor Date: Thu, 7 Sep 2017 13:58:25 +0100 Subject: [PATCH 05/11] Remove if blocks from snippets --- src/app/dashboard/dashboard.component.html | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/app/dashboard/dashboard.component.html b/src/app/dashboard/dashboard.component.html index 299e946..3e10bbc 100644 --- a/src/app/dashboard/dashboard.component.html +++ b/src/app/dashboard/dashboard.component.html @@ -2,19 +2,19 @@