From 7695ffdac67bbed03fd2398cb2bdc2bbf3845acf Mon Sep 17 00:00:00 2001 From: David Pickett Date: Mon, 13 Jun 2016 10:04:27 -1000 Subject: [PATCH] Add checkbox setting for JSON-Dictionary to have the key:value of the first column be included in the dictionary object (in addition to the value being used as the key for the whole row) --- index.html | 3 +++ js/Controller.js | 2 ++ js/DataGridRenderer.js | 10 +++++++--- js/converter.js | 4 +++- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/index.html b/index.html index af128d7..0b7799b 100644 --- a/index.html +++ b/index.html @@ -49,6 +49,9 @@

Settings

Indent with:

+

+ +

diff --git a/js/Controller.js b/js/Controller.js index 8146ca8..c5ef790 100644 --- a/js/Controller.js +++ b/js/Controller.js @@ -32,6 +32,8 @@ $(document).ready(function(){ _gaq.push(['_trackEvent', 'Settings',evt.currentTarget.id ]); }; + d.includeKeyInDictionary = $('#includeKeyInDictionary').attr('checked'); + d.includeWhiteSpace = $('#includeWhiteSpaceCB').attr('checked'); if (d.includeWhiteSpace) { diff --git a/js/DataGridRenderer.js b/js/DataGridRenderer.js index 1af1a44..0ea9e23 100755 --- a/js/DataGridRenderer.js +++ b/js/DataGridRenderer.js @@ -226,13 +226,17 @@ var DataGridRenderer = { //--------------------------------------- // JSON Dictionary //--------------------------------------- - jsonDict: function(dataGrid, headerNames, headerTypes, indent, newLine) { + jsonDict: function(dataGrid, headerNames, headerTypes, indent, newLine, includeKeyInDictionary) { //inits... var commentLine = "//"; var commentLineEnd = ""; var outputText = ""; var numRows = dataGrid.length; var numColumns = headerNames.length; + var initialJ = 1; + if (includeKeyInDictionary) { + initialJ = 0; + } //begin render loop outputText += "{" + newLine; @@ -242,8 +246,8 @@ var DataGridRenderer = { outputText += _fmtVal(i, 1, dataGrid); } else { outputText += '{ '; - for (var j = 1; j < numColumns; j++) { - if (j > 1) outputText += ', '; + for (var j = initialJ; j < numColumns; j++) { + if (j > initialJ) outputText += ', '; outputText += '"' + headerNames[j] + '"' + ":" + _fmtVal(i, j, dataGrid); } outputText += '}'; diff --git a/js/converter.js b/js/converter.js index e9c3820..c60683b 100755 --- a/js/converter.js +++ b/js/converter.js @@ -60,6 +60,8 @@ function DataConverter(nodeId) { this.includeWhiteSpace = true; this.useTabsForIndent = false; + this.includeKeyInDictionary = false; + } //--------------------------------------- @@ -160,7 +162,7 @@ DataConverter.prototype.convert = function() { var headerTypes = parseOutput.headerTypes; var errors = parseOutput.errors; - this.outputText = DataGridRenderer[this.outputDataType](dataGrid, headerNames, headerTypes, this.indent, this.newLine); + this.outputText = DataGridRenderer[this.outputDataType](dataGrid, headerNames, headerTypes, this.indent, this.newLine, this.includeKeyInDictionary); this.outputTextArea.val(errors + this.outputText);