From d915b280d463c99e58770e5f32b00bc6ecc0dc1a Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Mon, 19 Sep 2016 13:54:23 +0100 Subject: [PATCH] Add new options to export-nodes dialog --- editor/js/nodes.js | 9 +- editor/js/ui/clipboard.js | 145 +++++++++++++++++++++++++----- editor/sass/colors.scss | 6 +- editor/sass/editor.scss | 22 ++++- editor/sass/jquery.scss | 2 +- editor/sass/mixins.scss | 26 ++++-- red/api/locales/en-US/editor.json | 13 ++- 7 files changed, 182 insertions(+), 41 deletions(-) diff --git a/editor/js/nodes.js b/editor/js/nodes.js index 7507798b0..b2d8477b9 100644 --- a/editor/js/nodes.js +++ b/editor/js/nodes.js @@ -537,7 +537,10 @@ RED.nodes = (function() { } //TODO: rename this (createCompleteNodeSet) - function createCompleteNodeSet() { + function createCompleteNodeSet(exportCredentials) { + if (exportCredentials === undefined) { + exportCredentials = true; + } var nns = []; var i; for (i=0;i '+RED._("clipboard.nodes")+''+ - ''+ + exportNodesDialog = + '
'+ + ''+ + ''+ + ''+ + ''+ + ''+ + ''+ + '
'+ + '
'+ + ''+ '
'+ - '
'+ - RED._("clipboard.selectNodes")+ + '
'+ + ''+ + ''+ + ''+ + ''+ '
'; importNodesDialog = '
'+ @@ -103,6 +126,7 @@ RED.clipboard = (function() { $("#clipboard-dialog-ok").show(); $("#clipboard-dialog-cancel").show(); $("#clipboard-dialog-close").hide(); + $("#clipboard-dialog-copy").hide(); $("#clipboard-dialog-ok").button("disable"); $("#clipboard-import").keyup(validateImport); $("#clipboard-import").on('paste',function() { setTimeout(validateImport,10)}); @@ -113,29 +137,104 @@ RED.clipboard = (function() { function exportNodes() { dialogContainer.empty(); dialogContainer.append($(exportNodesDialog)); + dialogContainer.i18n(); + + $("#export-format-group > a").click(function(evt) { + evt.preventDefault(); + if ($(this).hasClass('disabled') || $(this).hasClass('selected')) { + return; + } + $(this).parent().children().removeClass('selected'); + $(this).addClass('selected'); + + var flow = $("#clipboard-export").val(); + if (flow.length > 0) { + var nodes = JSON.parse(flow); + + var format = $(this).attr('id'); + if (format === 'export-format-full') { + flow = JSON.stringify(nodes,null,4); + } else { + flow = JSON.stringify(nodes); + } + $("#clipboard-export").val(flow); + } + }); + $("#export-range-group > a").click(function(evt) { + evt.preventDefault(); + if ($(this).hasClass('disabled') || $(this).hasClass('selected')) { + return; + } + $(this).parent().children().removeClass('selected'); + $(this).addClass('selected'); + var type = $(this).attr('id'); + var flow = ""; + var nodes = null; + if (type === 'export-range-selected') { + var selection = RED.view.selection(); + nodes = RED.nodes.createExportableNodeSet(selection.nodes); + } else if (type === 'export-range-flow') { + var activeWorkspace = RED.workspaces.active(); + nodes = RED.nodes.filterNodes({z:activeWorkspace}); + var parentNode = RED.nodes.workspace(activeWorkspace)||RED.nodes.subflow(activeWorkspace); + nodes.unshift(parentNode); + nodes = RED.nodes.createExportableNodeSet(nodes); + } else if (type === 'export-range-full') { + nodes = RED.nodes.createCompleteNodeSet(false); + } + if (nodes !== null) { + if (RED.settings.flowFilePretty) { + flow = JSON.stringify(nodes,null,4); + } else { + flow = JSON.stringify(nodes); + } + } + if (flow.length > 0) { + $("#export-copy").removeClass('disabled'); + } else { + $("#export-copy").addClass('disabled'); + } + $("#clipboard-export").val(flow); + }) + $("#clipboard-dialog-ok").hide(); $("#clipboard-dialog-cancel").hide(); - $("#clipboard-dialog-close").show(); + $("#clipboard-dialog-copy").hide(); + $("#clipboard-dialog-close").hide(); 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(nns) - .focus(function() { - var textarea = $(this); - textarea.select(); - textarea.mouseup(function() { - textarea.unbind("mouseup"); - return false; - }) - }); - dialog.dialog("option","title",RED._("clipboard.exportNodes")).dialog( "open" ); + $("#export-range-selected").click(); + } else { + $("#export-range-selected").addClass('disabled').removeClass('selected'); + $("#export-range-flow").click(); } + if (RED.settings.flowFilePretty) { + $("#export-format-full").click(); + } else { + $("#export-format-mini").click(); + } + $("#clipboard-export") + .focus(function() { + var textarea = $(this); + textarea.select(); + textarea.mouseup(function() { + textarea.unbind("mouseup"); + return false; + }) + }); + dialog.dialog("option","title",RED._("clipboard.exportNodes")).dialog( "open" ); + + setTimeout(function() { + $("#clipboard-export").focus(); + if (!document.queryCommandEnabled("copy")) { + $("#clipboard-dialog-cancel").hide(); + $("#clipboard-dialog-close").show(); + } else { + $("#clipboard-dialog-cancel").show(); + $("#clipboard-dialog-copy").show(); + } + + },0); } function hideDropTarget() { diff --git a/editor/sass/colors.scss b/editor/sass/colors.scss index b2a691d99..576292fc7 100644 --- a/editor/sass/colors.scss +++ b/editor/sass/colors.scss @@ -43,13 +43,17 @@ $palette-header-background: #f3f3f3; $workspace-button-background: #fff; $workspace-button-background-hover: #ddd; $workspace-button-background-active: #efefef; -$workspace-button-color: #999; +$workspace-button-color: #888; $workspace-button-color-disabled: #ccc; $workspace-button-color-focus: #999; $workspace-button-color-hover: #666; $workspace-button-color-active: #666; $workspace-button-color-selected: #AAA; +$workspace-button-toggle-color: #999; +$workspace-button-toggle-color-selected: #888; +$workspace-button-toggle-color-disabled: #ddd; + $workspace-button-color-focus-outline: rgba(85,150,230,0.2); $typedInput-button-background: #efefef; diff --git a/editor/sass/editor.scss b/editor/sass/editor.scss index b0f20634f..2642e698f 100644 --- a/editor/sass/editor.scss +++ b/editor/sass/editor.scss @@ -76,16 +76,16 @@ font-size: 14px; padding: 6px 14px; margin-right: 8px; - color: $editor-button-color; + color: $editor-button-color !important; background: $editor-button-background; &.primary { border-color: $editor-button-background-primary; - color: $editor-button-color-primary; + color: $editor-button-color-primary !important; background: $editor-button-background-primary; &.disabled, &.ui-state-disabled { background: none; - color: $editor-button-color; + color: $editor-button-color !important; border-color: $form-input-border-color; } &:not(.disabled):not(.ui-button-disabled):hover { @@ -230,7 +230,12 @@ font-size: 13px; border-radius: 4px; padding: 0 10px; + &.toggle { + @include workspace-button-toggle; + } } + + .editor-button-small { height: 20px; line-height: 18px; @@ -239,6 +244,17 @@ padding: 0 5px; } +.dialog-form { + .button-group { + .editor-button { + &:first-child { + + } + } + } + +} + #node-config-dialog-scope-container { cursor: auto; float: right; diff --git a/editor/sass/jquery.scss b/editor/sass/jquery.scss index a57db8a04..67aa22ac7 100644 --- a/editor/sass/jquery.scss +++ b/editor/sass/jquery.scss @@ -92,7 +92,7 @@ &.primary { border-color: $editor-button-background-primary; - color: $editor-button-color-primary; + color: $editor-button-color-primary !important; background: $editor-button-background-primary; &:not(.disabled):hover { border-color: $editor-button-background-primary-hover; diff --git a/editor/sass/mixins.scss b/editor/sass/mixins.scss index 58bd7de1e..29a7997a0 100644 --- a/editor/sass/mixins.scss +++ b/editor/sass/mixins.scss @@ -40,39 +40,46 @@ @include disable-selection; box-sizing: border-box; display: inline-block; - color: $workspace-button-color; + color: $workspace-button-color !important; background: $workspace-button-background; border: 1px solid $form-input-border-color; text-align: center; margin:0; text-decoration: none; cursor:pointer; + &.disabled { cursor: default; - color: $workspace-button-color-disabled; + color: $workspace-button-color-disabled !important; } &:hover, &:focus { text-decoration: none; } &:not(.disabled):hover { - color: $workspace-button-color-hover; + color: $workspace-button-color-hover !important; background: $workspace-button-background-hover; } &:not(.disabled):focus { - color: $workspace-button-color-focus; + color: $workspace-button-color-focus !important; } &:not(.disabled):active { - color: $workspace-button-color-active; + color: $workspace-button-color-active !important; background: $workspace-button-background-active; text-decoration: none; } &.selected:not(.disabled) { - color: $workspace-button-color-selected; + color: $workspace-button-color-selected !important; background: $workspace-button-background-active; cursor: default; } .button-group &:not(:first-child) { border-left: none; + border-top-left-radius: 0; + border-bottom-left-radius: 0; + } + .button-group &:not(:last-child) { + border-top-right-radius: 0; + border-bottom-right-radius: 0; } &:focus { @@ -81,17 +88,20 @@ } @mixin workspace-button-toggle { @include workspace-button; - color: $workspace-button-color-selected; + color: $workspace-button-toggle-color !important; background:$workspace-button-background-active; transition: all 0.1s ease-in-out; margin-bottom: 1px; &.selected:not(.disabled) { - color: $workspace-button-color; + color: $workspace-button-toggle-color-selected !important; background: $workspace-button-background; border-bottom-width: 2px; border-bottom-color: $form-input-border-selected-color; margin-bottom: 0; } + &.disabled { + color: $workspace-button-toggle-color-disabled !important; + } } diff --git a/red/api/locales/en-US/editor.json b/red/api/locales/en-US/editor.json index 68eb72fa7..d6136cdb9 100644 --- a/red/api/locales/en-US/editor.json +++ b/red/api/locales/en-US/editor.json @@ -77,16 +77,25 @@ } }, "clipboard": { - "nodes": "Nodes:", + "nodes": "Nodes", "selectNodes": "Select the text above and copy to the clipboard.", "pasteNodes": "Paste nodes here", "importNodes": "Import nodes", "exportNodes": "Export nodes to clipboard", "importUnrecognised": "Imported unrecognised type:", "importUnrecognised_plural": "Imported unrecognised types:", + "nodesExported": "Nodes exported to clipboard", "nodeCopied": "__count__ node copied", "nodeCopied_plural": "__count__ nodes copied", - "invalidFlow": "Invalid flow: __message__" + "invalidFlow": "Invalid flow: __message__", + "export": { + "selected":"selected nodes", + "current":"current flow", + "all":"all flows", + "compact":"compact", + "formatted":"formatted", + "copy": "Export to clipboard" + } }, "deploy": { "deploy": "Deploy",