From 6168c8e1e208a5ef5f294c45f63f160ece6341f1 Mon Sep 17 00:00:00 2001 From: Ben Goldsworthy Date: Sun, 29 Nov 2020 16:29:06 +0000 Subject: [PATCH] Fix invalid graph errors + no data errors --- .../dashboard-customer.component.html | 10 +++---- .../dashboard/dashboard-customer.component.ts | 30 ++++++++++--------- src/app/dashboard/dashboard.component.html | 10 +++---- src/app/dashboard/dashboard.component.ts | 5 +++- src/app/widgets/graph-widget.component.ts | 6 ++-- 5 files changed, 34 insertions(+), 27 deletions(-) diff --git a/src/app/dashboard/dashboard-customer.component.html b/src/app/dashboard/dashboard-customer.component.html index 3638329..a2bf5e4 100644 --- a/src/app/dashboard/dashboard-customer.component.html +++ b/src/app/dashboard/dashboard-customer.component.html @@ -10,7 +10,7 @@ -
+
-
+
@@ -82,15 +82,15 @@
-
+
-
+

Global Puchases by Category

-
+
  • diff --git a/src/app/dashboard/dashboard-customer.component.ts b/src/app/dashboard/dashboard-customer.component.ts index 8870b69..2f5399e 100644 --- a/src/app/dashboard/dashboard-customer.component.ts +++ b/src/app/dashboard/dashboard-customer.component.ts @@ -9,7 +9,7 @@ import { CustBarSnippetComponent } from '../snippets/cust-snippet-bar.component' import { PiePanel } from '../panels/pie-panel.component'; import { DataType } from '../shared/data-types.enum'; import * as moment from 'moment'; -import { MoreStuffComponent } from '../dashboard/more-graphs-and-tables.component'; +//import { MoreStuffComponent } from '../dashboard/more-graphs-and-tables.component'; // import { StackedBarChartComponent } from '../panels/stacked-bar.component'; interface SuppliersComponent { @@ -186,20 +186,22 @@ export class DashboardCustomerComponent implements OnInit { this.setDate(); this.api.customerStats().subscribe( result => { - this.setWeekPurchaseList(result.weeks); - this.setWeekData(result); - this.setChartData(result.data.cat_total); - this.totalCategoryList = result.data.cat_list; - if (this.totalCategoryList) { - this.showTotalCategoryList = true; + if (result.data.cat_list.length > 0) { + this.setWeekPurchaseList(result.weeks); + this.setWeekData(result); + this.setChartData(result.data.cat_total); + this.totalCategoryList = result.data.cat_list; + if (this.totalCategoryList) { + this.showTotalCategoryList = true; + } + this.purchaseEssential = result.data.essentials.purchase_no_essential_total; + this.purchaseNotEssential = result.data.essentials.purchase_no_total - this.purchaseEssential; + this.barChartDataEssential = [ + {data: [this.purchaseEssential], label: 'Essential', stack: '1'}, + {data: [this.purchaseNotEssential], label: 'Non-Essential', stack: '1'}, + ]; + this.showEssentialBarChart = true; } - this.purchaseEssential = result.data.essentials.purchase_no_essential_total; - this.purchaseNotEssential = result.data.essentials.purchase_no_total - this.purchaseEssential; - this.barChartDataEssential = [ - {data: [this.purchaseEssential], label: 'Essential', stack: '1'}, - {data: [this.purchaseNotEssential], label: 'Non-Essential', stack: '1'}, - ]; - this.showEssentialBarChart = true; }, error => { console.log('Retrieval Error'); diff --git a/src/app/dashboard/dashboard.component.html b/src/app/dashboard/dashboard.component.html index 98901c3..9f6c96e 100644 --- a/src/app/dashboard/dashboard.component.html +++ b/src/app/dashboard/dashboard.component.html @@ -13,7 +13,7 @@
-
+
@@ -21,7 +21,7 @@

Number of Essential Purchases

-
+
-
+
@@ -80,7 +80,7 @@
-
+
@@ -88,7 +88,7 @@

Global Puchases by Category

-
+
  • diff --git a/src/app/dashboard/dashboard.component.ts b/src/app/dashboard/dashboard.component.ts index f15669b..1c6b481 100644 --- a/src/app/dashboard/dashboard.component.ts +++ b/src/app/dashboard/dashboard.component.ts @@ -44,6 +44,7 @@ export class DashboardComponent { title: 'Sales Last 30 Days', dataType: DataType.currency, }, + /* Not implemented on server { type: 'graph', name: 'sales_last_quart', @@ -51,6 +52,7 @@ export class DashboardComponent { title: 'Sales Last Quart', dataType: DataType.currency, }, + */ { type: 'graph', name: 'purchases_last_7_days', @@ -63,12 +65,14 @@ export class DashboardComponent { title: 'Purchases Last 30 Days', dataType: DataType.currency, }, + /* Not implemented on server { type: 'graph', name: 'purchases_last_quart;', title: 'Purchases Last Quart', dataType: DataType.currency, }, + */ ]; disableCategoryButton: boolean = false; @@ -286,7 +290,6 @@ export class DashboardComponent { {data: [this.purchaseNotEssential], label: 'Non-Essential', stack: '1'}, ]; this.showEssentialBarChart = true; - console.log(this.barChartDataEssential); } private setChartDataCat(dataCat: any) { diff --git a/src/app/widgets/graph-widget.component.ts b/src/app/widgets/graph-widget.component.ts index 65ec024..a3bd012 100644 --- a/src/app/widgets/graph-widget.component.ts +++ b/src/app/widgets/graph-widget.component.ts @@ -109,8 +109,10 @@ export class GraphWidget implements OnInit { 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) ); + if (localStorage.getItem('usertype') === 'organisation') { + this.graphService.getGraph(this.graphName) + .subscribe( result => this.setData(result.graph) ); + } } private setData(data: any) {