From f2565fce783bcbcd64e3c51c170e0dd9110e8eba Mon Sep 17 00:00:00 2001 From: Swagata Prateek Date: Fri, 7 Apr 2017 17:54:17 +0200 Subject: [PATCH] jsonpath works, so we can use this for our json queries, excellent --- package.json | 1 + src/app/data/data.service.ts | 4 ++-- .../ui-toolbox/widget-layout/widget-layout.component.ts | 4 +++- src/systemjs.conf.js | 7 ++++++- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 63199bf..cfe208c 100644 --- a/package.json +++ b/package.json @@ -72,6 +72,7 @@ "gulp-useref": "~3.1.2", "jasmine-core": "~2.5.2", "jquery": "^3.2.1", + "jsonpath": "^0.2.11", "karma": "~1.5.0", "karma-coverage": "~1.1.1", "karma-ie-launcher": "^1.0.0", diff --git a/src/app/data/data.service.ts b/src/app/data/data.service.ts index 6e4625f..88ec34a 100644 --- a/src/app/data/data.service.ts +++ b/src/app/data/data.service.ts @@ -134,13 +134,13 @@ export class DataService { type: 'bar-chart', datamap: { 'labels': { - path: 'entry._id.CreateDate.$date', // Can be JSONPath? + path: '$[*]._id.CreateDate.$date', // Can be JSONPath? type: 'datestring', }, 'datasets': [ { label: 'Orders', - path: 'count' + path: '$[*].count' } ] } diff --git a/src/app/ui-toolbox/widget-layout/widget-layout.component.ts b/src/app/ui-toolbox/widget-layout/widget-layout.component.ts index 0936945..affff86 100644 --- a/src/app/ui-toolbox/widget-layout/widget-layout.component.ts +++ b/src/app/ui-toolbox/widget-layout/widget-layout.component.ts @@ -2,6 +2,7 @@ import { Component, OnInit, ViewChild, Type } from '@angular/core'; import { BarChartComponent, WidgetComponent } from '../index'; import { DataService } from '../../data/index'; import { UiRegistryService } from '../ui-registry.service'; +import * as jsonpath from 'jsonpath'; @Component({ moduleId: module.id, @@ -27,7 +28,8 @@ export class WidgetLayoutComponent implements OnInit { if (result) { // Need to parse this crap here let res: any[] = result; - console.log(res); + let resolve = jsonpath.query(res, '$[*].count'); + console.log(resolve); for (let entry of res) { barChartLabels.push(new Date(entry._id.CreateDate.$date).toDateString()); jobCountArray.push(entry.count); diff --git a/src/systemjs.conf.js b/src/systemjs.conf.js index 1c3aa6f..c45f1d5 100644 --- a/src/systemjs.conf.js +++ b/src/systemjs.conf.js @@ -38,6 +38,10 @@ 'primeng' : { main: 'primeng.js', defaultExtension: 'js' + }, + 'jsonpath' :{ + main: 'jsonpath.js', + defaultExtension: 'js' } }; @@ -49,7 +53,8 @@ 'angular2-jwt', 'angular2-letter-avatar', 'chart.js', - 'primeng' + 'primeng', + 'jsonpath' ]; // Add package entries for packages that expose barrels using index.js