From a737810c50c07333fd56769de7b754dc684e08ca Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Mon, 3 Jul 2017 21:57:55 +0100 Subject: [PATCH] Add reformat button to JSONata test data editor --- editor/js/ui/editor.js | 13 ++++++++++++- editor/templates/index.mst | 7 +++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/editor/js/ui/editor.js b/editor/js/ui/editor.js index 7d353c506..dd7102b3a 100644 --- a/editor/js/ui/editor.js +++ b/editor/js/ui/editor.js @@ -1943,6 +1943,17 @@ RED.editor = (function() { } }); + $("#node-input-example-reformat").click(function(evt) { + evt.preventDefault(); + var v = testDataEditor.getValue()||""; + try { + v = JSON.stringify(JSON.parse(v),null,4); + } catch(err) { + // TODO: do an optimistic auto-format + } + testDataEditor.getSession().setValue(v||"",-1); + }); + testExpression(); }, close: function() { @@ -2009,7 +2020,7 @@ RED.editor = (function() { mode:"ace/mode/json" }); expressionEditor.getSession().setValue(value||"",-1); - $("#node-input-expression-reformat").click(function(evt) { + $("#node-input-json-reformat").click(function(evt) { evt.preventDefault(); var v = expressionEditor.getValue()||""; try { diff --git a/editor/templates/index.mst b/editor/templates/index.mst index ebf26947f..21c5a6376 100644 --- a/editor/templates/index.mst +++ b/editor/templates/index.mst @@ -188,7 +188,10 @@
- + + + +
@@ -200,7 +203,7 @@