From 3454e5ac7788e259ae2791aa0226f31e5eb0d25b Mon Sep 17 00:00:00 2001 From: Josh Date: Wed, 18 May 2016 09:09:57 +1200 Subject: [PATCH] Flows lib honours flowFilePretty setting (#837) * Flow lib now adheres to pretty flow file, ui also adheres to this as well * added settings mock object in flows_spec get api test * reverted api changes, fixed parse of flow only * try spell flows correctly --- editor/js/ui/clipboard.js | 7 ++++++- red/api/info.js | 4 ++++ red/runtime/storage/localfilesystem.js | 3 +++ test/red/api/flows_spec.js | 1 + 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/editor/js/ui/clipboard.js b/editor/js/ui/clipboard.js index b27c529c8..c78176017 100644 --- a/editor/js/ui/clipboard.js +++ b/editor/js/ui/clipboard.js @@ -119,8 +119,13 @@ RED.clipboard = (function() { var selection = RED.view.selection(); if (selection.nodes) { var nns = RED.nodes.createExportableNodeSet(selection.nodes); + if (RED.settings.flowFilePretty) { + nns = JSON.stringify(nns,null,4); + } else { + nns = JSON.stringify(nns); + } $("#clipboard-export") - .val(JSON.stringify(nns)) + .val(nns) .focus(function() { var textarea = $(this); textarea.select(); diff --git a/red/api/info.js b/red/api/info.js index a9f79a0d4..462868735 100644 --- a/red/api/info.js +++ b/red/api/info.js @@ -37,6 +37,10 @@ module.exports = { safeSettings.paletteCategories = settings.paletteCategories; } + if (settings.flowFilePretty) { + safeSettings.flowFilePretty = settings.flowFilePretty; + } + res.json(safeSettings); } } diff --git a/red/runtime/storage/localfilesystem.js b/red/runtime/storage/localfilesystem.js index 1ba46adeb..b783756b0 100644 --- a/red/runtime/storage/localfilesystem.js +++ b/red/runtime/storage/localfilesystem.js @@ -390,6 +390,9 @@ var localfilesystem = { headers += "// "+i+": "+meta[i]+"\n"; } } + if (type === "flows" && settings.flowFilePretty) { + body = JSON.stringify(JSON.parse(body),null,4); + } return promiseDir(fspath.dirname(fn)).then(function () { writeFile(fn,headers+body); }); diff --git a/test/red/api/flows_spec.js b/test/red/api/flows_spec.js index 970a0ea83..0ec10171c 100644 --- a/test/red/api/flows_spec.js +++ b/test/red/api/flows_spec.js @@ -36,6 +36,7 @@ describe("flows api", function() { it('returns flow', function(done) { flows.init({ + settings: {}, log:{warn:function(){},_:function(){},audit:function(){}}, nodes:{ getFlows: function() { return [1,2,3]; }