Add jsonPath

This commit is contained in:
Rashid Khan 2014-03-19 15:39:28 -07:00
parent 98a3773dab
commit 0b11291f59
4 changed files with 13 additions and 18 deletions

View file

@ -6,7 +6,8 @@
"globals": {
"define": true,
"require": true,
"console": true
"console": true,
"jsonPath": false
},
"camelcase": false,
@ -34,5 +35,6 @@
"maxlen": 140,
"-W084": true,
"maxerr": 10,
"scripturl": true
"scripturl": true,
"evil": true
}

View file

@ -36,7 +36,8 @@
"moment": "~2.5.1",
"require-css": "~0.1.2",
"angular-bootstrap": "~0.10.0",
"stacktrace.js": "https://github.com/stacktracejs/stacktrace.js.git#~0.6.0"
"stacktrace.js": "https://github.com/stacktracejs/stacktrace.js.git#~0.6.0",
"jsonpath": "*"
},
"devDependencies": {}
}

View file

@ -3,6 +3,7 @@ define(function (require) {
var _ = require('lodash');
var nextTick = require('utils/next_tick');
var $ = require('jquery');
var jsonpath = require('jsonpath');
require('directives/truncated');
require('directives/infinite_scroll');
@ -313,21 +314,8 @@ define(function (require) {
function _getValForField(row, field, untruncate) {
var val;
// is field name a path?
if (~field.indexOf('.')) {
var path = field.split('.');
// only check source for "paths"
var current = row._source;
var step;
while (step = path.shift() && current) {
// walk from the _source to the specified by the path
current = current[step];
}
val = current;
} else {
// simple, with a fallback to row
val = row._source[field] || row[field];
}
// Fall back to the root if not found in _source
val = jsonPath.eval(row, '$._source.' + field)[0] || row[field];
// undefined and null should just be an empty string
val = (val == null) ? '' : val;

View file

@ -18,6 +18,7 @@ require.config({
gridster: '../bower_components/gridster/dist/jquery.gridster',
stacktrace: '../bower_components/stacktrace.js/stacktrace',
modules: 'utils/modules',
jsonpath: '../bower_components/jsonpath/lib/jsonpath',
K4D3: '../bower_components/K4D3/k4.d3',
bower_components: '../bower_components'
},
@ -26,6 +27,9 @@ require.config({
deps: ['jquery'],
exports: 'angular'
},
jsonpath: {
exports: 'jsonPath'
},
gridster: ['jquery'],
'angular-route': ['angular'],
'angular-mocks': ['angular'],