From f62d512018b03a9f9421167bc8afaf0007786063 Mon Sep 17 00:00:00 2001 From: Swagata Prateek Date: Sat, 8 Apr 2017 16:42:25 +0200 Subject: [PATCH] Added some type definition for the WidgetConfig and made sure the bar-chart supports multiple data --- env.json | 2 +- src/app/data/data.service.ts | 2 +- src/app/ui-toolbox/bar-chart/bar-chart.component.ts | 11 +++++++---- src/app/ui-toolbox/widget/widget-config.ts | 2 ++ 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/env.json b/env.json index 806454a..dc6367d 100644 --- a/env.json +++ b/env.json @@ -1,5 +1,5 @@ { - "API_BASE": "http://localhost:5000/api/", + "API_BASE": "http://datacat.nerdcats.io/api/", "AUTH_BASE": "http://auth.nerdcats.co/", "AUTH_ENDPOINT": "connect/token", "CLIENT_ID": "datacat.client", diff --git a/src/app/data/data.service.ts b/src/app/data/data.service.ts index 94eff33..78405ae 100644 --- a/src/app/data/data.service.ts +++ b/src/app/data/data.service.ts @@ -39,7 +39,7 @@ export class DataService { } // INFO: Temporary test method to test out how a widget could have behaved. - getSampleWidgetConfig(): any { + getSampleWidgetConfig(): WidgetConfig { // INLINE query, these needs to be saved in the database of course let aggDocument: any = { 'aggregate': [ diff --git a/src/app/ui-toolbox/bar-chart/bar-chart.component.ts b/src/app/ui-toolbox/bar-chart/bar-chart.component.ts index b379f96..af75b52 100644 --- a/src/app/ui-toolbox/bar-chart/bar-chart.component.ts +++ b/src/app/ui-toolbox/bar-chart/bar-chart.component.ts @@ -40,20 +40,23 @@ export class BarChartComponent implements Widget { .subscribe(result => { let barChartLabels: string[] = []; let barChartData: any[]; - let jobCountArray: any[] = []; + let barChartDataArray: any[] = []; if (result) { let res: any[] = result; - // Currently we only support a single dataset - jobCountArray = jsonpath.query(res, datamap.datasets[0].path); barChartLabels = jsonpath.query(res, datamap.labels.path); if (datamap.labels.type) { barChartLabels = barChartLabels.map(x => this.dataConverterService.convert(x, datamap.labels.type)); } + + for (let i = 0; i < datamap.datasets.length; i++) { + let jobCountArray = jsonpath.query(res, datamap.datasets[i].path); + barChartDataArray.push({ data: jobCountArray, label: datamap.datasets[i].label }); + } } - barChartData = [{ data: jobCountArray, label: datamap.datasets[0].label }]; + barChartData = barChartDataArray; this.data = { labels: barChartLabels, datasets: barChartData }; this.isDataAvailable = true; }, error => { diff --git a/src/app/ui-toolbox/widget/widget-config.ts b/src/app/ui-toolbox/widget/widget-config.ts index 2594989..90564b9 100644 --- a/src/app/ui-toolbox/widget/widget-config.ts +++ b/src/app/ui-toolbox/widget/widget-config.ts @@ -3,4 +3,6 @@ export interface WidgetConfig { connectionId: string; collectionName: string; type: string; + datamap: { [key: string]: any }; + config: any; }