diff --git a/src/js/Node.js b/src/js/Node.js index 188ec09..7c1d16b 100644 --- a/src/js/Node.js +++ b/src/js/Node.js @@ -3701,11 +3701,15 @@ Node.prototype._onChangeType = function (newType) { /** * Sort the child's of the node. Only applicable when the node has type 'object' * or 'array'. - * @param {String[]} path Path of the child value to be compared - * @param {String} direction Sorting direction. Available values: "asc", "desc" + * @param {String[] | string} path Path of the child value to be compared + * @param {String} direction Sorting direction. Available values: "asc", "desc" * @private */ Node.prototype.sort = function (path, direction) { + if (typeof path === 'string') { + path = util.parsePath(path); + } + if (!this._hasChilds()) { return; } @@ -4427,7 +4431,7 @@ Node.prototype.showSortModal = function () { function onSort (sortedBy) { var path = sortedBy.path; - var pathArray = (path === '.') ? [] : path.split('.').slice(1); + var pathArray = util.parsePath(path); node.sortedBy = sortedBy node.sort(pathArray, sortedBy.direction) diff --git a/src/js/showSortModal.js b/src/js/showSortModal.js index bf5c8d3..b5f5c4b 100644 --- a/src/js/showSortModal.js +++ b/src/js/showSortModal.js @@ -18,7 +18,7 @@ var util = require('./util'); function showSortModal (container, json, onSort, options) { var paths = Array.isArray(json) ? util.getChildPaths(json) - : ['.']; + : ['']; var selectedPath = options && options.path && util.contains(paths, options.path) ? options.path : paths[0] @@ -79,7 +79,7 @@ function showSortModal (container, json, onSort, options) { paths.forEach(function (path) { var option = document.createElement('option'); - option.text = path; + option.text = path || '.'; option.value = path; field.appendChild(option); }); diff --git a/src/js/showTransformModal.js b/src/js/showTransformModal.js index 156cdd8..6533479 100644 --- a/src/js/showTransformModal.js +++ b/src/js/showTransformModal.js @@ -137,7 +137,7 @@ function showTransformModal (container, json, onTransform) { }); var selectablePaths = util.getChildPaths(json, true).filter(function(path) { - return path !== '.'; + return path !== ''; }); if (selectablePaths.length > 0) { selectablePaths.forEach(function (path) { @@ -179,14 +179,11 @@ function showTransformModal (container, json, onTransform) { query.value = Array.isArray(value) ? '[*]' : '@'; function preprocessPath(path) { - if (path[0] === '.') { - return (path === '.') - ? '@' - : path.slice(1); - } - else { - return path; - } + return (path === '') + ? '@' + : (path[0] === '.') + ? path.slice(1) + : path; } function generateQueryFromWizard () { @@ -198,7 +195,7 @@ function showTransformModal (container, json, onTransform) { var exampleValue = util.get(value, examplePath) var value1 = typeof exampleValue === 'string' ? filterValue.value - : parseString(filterValue.value); + : util.parseString(filterValue.value); query.value = '[? ' + field1 + ' ' + diff --git a/src/js/util.js b/src/js/util.js index 8b70606..018ba5e 100644 --- a/src/js/util.js +++ b/src/js/util.js @@ -1202,7 +1202,7 @@ exports.getChildPaths = function (json, includeObjects) { var isValue = !Array.isArray(json) && !exports.isObject(json) if (isValue || includeObjects) { - pathsMap[rootPath || '.'] = true; + pathsMap[rootPath || ''] = true; } if (exports.isObject(json)) { @@ -1218,7 +1218,7 @@ exports.getChildPaths = function (json, includeObjects) { }); } else { - pathsMap['.'] = true; + pathsMap[''] = true; } return Object.keys(pathsMap).sort(); diff --git a/test/util.test.js b/test/util.test.js index d840f2d..6f5299b 100644 --- a/test/util.test.js +++ b/test/util.test.js @@ -274,7 +274,7 @@ describe('util', function () { ]; assert.deepStrictEqual(util.getChildPaths(json, true), [ - '.', + '', '.location', '.location.latitude', '.location.longitude', @@ -287,14 +287,14 @@ describe('util', function () { var json = [ 1, 2, 3 ]; assert.deepStrictEqual(util.getChildPaths(json), [ - '.' + '' ]) }); it('should extract all child paths of a non-array', function () { - assert.deepStrictEqual(util.getChildPaths({a: 2, b: {c: 3}}), ['.']) - assert.deepStrictEqual(util.getChildPaths('foo'), ['.']) - assert.deepStrictEqual(util.getChildPaths(123), ['.']) + assert.deepStrictEqual(util.getChildPaths({a: 2, b: {c: 3}}), ['']) + assert.deepStrictEqual(util.getChildPaths('foo'), ['']) + assert.deepStrictEqual(util.getChildPaths(123), ['']) }); })