From dfebc4b78d1b0dc6b4e3b65e94817cd6a874f929 Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Mon, 22 Jan 2018 23:04:05 +0000 Subject: [PATCH] Migrate deploy confirmations to notifications --- editor/js/ui/deploy.js | 276 +++++++++++------------ editor/js/ui/notifications.js | 16 ++ editor/sass/diff.scss | 48 ++-- editor/templates/index.mst | 25 -- red/api/editor/locales/en-US/editor.json | 3 +- 5 files changed, 176 insertions(+), 192 deletions(-) diff --git a/editor/js/ui/deploy.js b/editor/js/ui/deploy.js index b967f4db8..63305d2c2 100644 --- a/editor/js/ui/deploy.js +++ b/editor/js/ui/deploy.js @@ -97,113 +97,6 @@ RED.deploy = (function() { RED.actions.add("core:deploy-flows",save); - $( "#node-dialog-confirm-deploy" ).dialog({ - title: RED._('deploy.confirm.button.confirm'), - modal: true, - autoOpen: false, - width: 550, - height: "auto", - buttons: [ - { - text: RED._("common.label.cancel"), - click: function() { - $( this ).dialog( "close" ); - } - }, - { - id: "node-dialog-confirm-deploy-review", - text: RED._("deploy.confirm.button.review"), - class: "primary disabled", - click: function() { - if (!$("#node-dialog-confirm-deploy-review").hasClass('disabled')) { - RED.diff.showRemoteDiff(); - $( this ).dialog( "close" ); - } - } - }, - { - id: "node-dialog-confirm-deploy-merge", - text: RED._("deploy.confirm.button.merge"), - class: "primary disabled", - click: function() { - RED.diff.mergeDiff(currentDiff); - $( this ).dialog( "close" ); - } - }, - { - id: "node-dialog-confirm-deploy-deploy", - text: RED._("deploy.confirm.button.confirm"), - class: "primary", - click: function() { - - var ignoreChecked = $( "#node-dialog-confirm-deploy-hide" ).prop("checked"); - if (ignoreChecked) { - ignoreDeployWarnings[$( "#node-dialog-confirm-deploy-type" ).val()] = true; - } - save(true,/conflict/.test($("#node-dialog-confirm-deploy-type" ).val())); - $( this ).dialog( "close" ); - } - }, - { - id: "node-dialog-confirm-deploy-overwrite", - text: RED._("deploy.confirm.button.overwrite"), - class: "primary", - click: function() { - save(true,/conflict/.test($("#node-dialog-confirm-deploy-type" ).val())); - $( this ).dialog( "close" ); - } - } - ], - create: function() { - $("#node-dialog-confirm-deploy").parent().find("div.ui-dialog-buttonpane") - .prepend('
'+ - ' '+ - ''+ - ''+ - '
'); - }, - open: function() { - var deployType = $("#node-dialog-confirm-deploy-type" ).val(); - if (/conflict/.test(deployType)) { - $( "#node-dialog-confirm-deploy" ).dialog('option','title', RED._('deploy.confirm.button.review')); - $("#node-dialog-confirm-deploy-deploy").hide(); - $("#node-dialog-confirm-deploy-review").addClass('disabled').show(); - $("#node-dialog-confirm-deploy-merge").addClass('disabled').show(); - $("#node-dialog-confirm-deploy-overwrite").toggle(deployType === "deploy-conflict"); - currentDiff = null; - $("#node-dialog-confirm-deploy-conflict-checking").show(); - $("#node-dialog-confirm-deploy-conflict-auto-merge").hide(); - $("#node-dialog-confirm-deploy-conflict-manual-merge").hide(); - - var now = Date.now(); - RED.diff.getRemoteDiff(function(diff) { - var ellapsed = Math.max(1000 - (Date.now()-now), 0); - currentDiff = diff; - setTimeout(function() { - $("#node-dialog-confirm-deploy-conflict-checking").hide(); - var d = Object.keys(diff.conflicts); - if (d.length === 0) { - $("#node-dialog-confirm-deploy-conflict-auto-merge").show(); - $("#node-dialog-confirm-deploy-merge").removeClass('disabled') - } else { - $("#node-dialog-confirm-deploy-conflict-manual-merge").show(); - } - $("#node-dialog-confirm-deploy-review").removeClass('disabled') - },ellapsed); - }) - - - $("#node-dialog-confirm-deploy-hide").parent().hide(); - } else { - $( "#node-dialog-confirm-deploy" ).dialog('option','title', RED._('deploy.confirm.button.confirm')); - $("#node-dialog-confirm-deploy-deploy").show(); - $("#node-dialog-confirm-deploy-overwrite").hide(); - $("#node-dialog-confirm-deploy-review").hide(); - $("#node-dialog-confirm-deploy-merge").hide(); - $("#node-dialog-confirm-deploy-hide").parent().show(); - } - } - }); RED.events.on('nodes:change',function(state) { if (state.dirty) { @@ -224,8 +117,9 @@ RED.deploy = (function() { if (currentRev === null || deployInflight || currentRev === msg.revision) { return; } - var message = $('
').text(RED._('deploy.confirm.backgroundUpdate')); + var message = $('

').text(RED._('deploy.confirm.backgroundUpdate')); activeNotifyMessage = RED.notify(message,{ + modal: true, fixed: true, buttons: [ { @@ -276,14 +170,93 @@ RED.deploy = (function() { } function resolveConflict(currentNodes, activeDeploy) { - $( "#node-dialog-confirm-deploy-config" ).hide(); - $( "#node-dialog-confirm-deploy-unknown" ).hide(); - $( "#node-dialog-confirm-deploy-unused" ).hide(); - $( "#node-dialog-confirm-deploy-conflict" ).show(); - $( "#node-dialog-confirm-deploy-type" ).val(activeDeploy?"deploy-conflict":"background-conflict"); - $( "#node-dialog-confirm-deploy" ).dialog( "open" ); - } + var message = $('

'); + $('

').appendTo(message); + var conflictCheck = $('
'+ + '
'+ + '
').appendTo(message); + var conflictAutoMerge = $('
'+ + '
'+ + '
').hide().appendTo(message); + var conflictManualMerge = $('
'+ + '
'+ + '
').hide().appendTo(message); + message.i18n(); + currentDiff = null; + var buttons = [ + { + text: RED._("common.label.cancel"), + click: function() { + conflictNotification.close(); + } + }, + { + id: "node-dialog-confirm-deploy-review", + text: RED._("deploy.confirm.button.review"), + class: "primary disabled", + click: function() { + if (!$("#node-dialog-confirm-deploy-review").hasClass('disabled')) { + RED.diff.showRemoteDiff(); + conflictNotification.close(); + } + } + }, + { + id: "node-dialog-confirm-deploy-merge", + text: RED._("deploy.confirm.button.merge"), + class: "primary disabled", + click: function() { + if (!$("#node-dialog-confirm-deploy-merge").hasClass('disabled')) { + RED.diff.mergeDiff(currentDiff); + conflictNotification.close(); + } + } + } + ]; + if (activeDeploy) { + buttons.push({ + id: "node-dialog-confirm-deploy-overwrite", + text: RED._("deploy.confirm.button.overwrite"), + class: "primary", + click: function() { + save(true,activeDeploy); + conflictNotification.close(); + } + }) + } + var conflictNotification = RED.notify(message,{ + modal: true, + fixed: true, + width: 600, + buttons: buttons + }); + + var now = Date.now(); + RED.diff.getRemoteDiff(function(diff) { + var ellapsed = Math.max(1000 - (Date.now()-now), 0); + currentDiff = diff; + setTimeout(function() { + conflictCheck.hide(); + var d = Object.keys(diff.conflicts); + if (d.length === 0) { + conflictAutoMerge.show(); + $("#node-dialog-confirm-deploy-merge").removeClass('disabled') + } else { + conflictManualMerge.show(); + } + $("#node-dialog-confirm-deploy-review").removeClass('disabled') + },ellapsed); + }) + } + function cropList(list) { + if (list.length > 5) { + var remainder = list.length - 5; + list = list.slice(0,5); + list.push(RED._("deploy.confirm.plusNMore",{count:remainder})); + } + return list; + } function save(skipValidation,force) { if (!$("#btn-deploy").hasClass("disabled")) { if (!RED.user.hasPermission("flows.write")) { @@ -319,39 +292,62 @@ RED.deploy = (function() { } }); - $( "#node-dialog-confirm-deploy-config" ).hide(); - $( "#node-dialog-confirm-deploy-unknown" ).hide(); - $( "#node-dialog-confirm-deploy-unused" ).hide(); - $( "#node-dialog-confirm-deploy-conflict" ).hide(); - var showWarning = false; - + var notificationMessage; + var notificationButtons = []; + var notification; if (hasUnknown && !ignoreDeployWarnings.unknown) { showWarning = true; - $( "#node-dialog-confirm-deploy-type" ).val("unknown"); - $( "#node-dialog-confirm-deploy-unknown" ).show(); - $( "#node-dialog-confirm-deploy-unknown-list" ) - .html("
  • "+unknownNodes.join("
  • ")+"
  • "); + notificationMessage = "

    "+RED._('deploy.confirm.unknown')+"

    "+ + '
    • '+cropList(unknownNodes).join("
    • ")+"

    "+ + RED._('deploy.confirm.confirm')+ + "

    "; + + notificationButtons= [ + { + id: "node-dialog-confirm-deploy-deploy", + text: RED._("deploy.confirm.button.confirm"), + class: "primary", + click: function() { + save(true); + notification.close(); + } + } + ]; } else if (hasInvalid && !ignoreDeployWarnings.invalid) { showWarning = true; - $( "#node-dialog-confirm-deploy-type" ).val("invalid"); - $( "#node-dialog-confirm-deploy-config" ).show(); invalidNodes.sort(sortNodeInfo); - $( "#node-dialog-confirm-deploy-invalid-list" ) - .html("
  • "+invalidNodes.map(function(A) { return (A.tab?"["+A.tab+"] ":"")+A.label+" ("+A.type+")"}).join("
  • ")+"
  • "); - } else if (hasUnusedConfig && !ignoreDeployWarnings.unusedConfig) { - // showWarning = true; - // $( "#node-dialog-confirm-deploy-type" ).val("unusedConfig"); - // $( "#node-dialog-confirm-deploy-unused" ).show(); - // - // unusedConfigNodes.sort(sortNodeInfo); - // $( "#node-dialog-confirm-deploy-unused-list" ) - // .html("
  • "+unusedConfigNodes.map(function(A) { return (A.tab?"["+A.tab+"] ":"")+A.label+" ("+A.type+")"}).join("
  • ")+"
  • "); + notificationMessage = "

    "+RED._('deploy.confirm.improperlyConfigured')+"

    "+ + '
    • '+cropList(invalidNodes.map(function(A) { return (A.tab?"["+A.tab+"] ":"")+A.label+" ("+A.type+")"})).join("
    • ")+"

    "+ + RED._('deploy.confirm.confirm')+ + "

    "; + notificationButtons= [ + { + id: "node-dialog-confirm-deploy-deploy", + text: RED._("deploy.confirm.button.confirm"), + class: "primary", + click: function() { + save(true); + notification.close(); + } + } + ]; } if (showWarning) { - $( "#node-dialog-confirm-deploy-hide" ).prop("checked",false); - $( "#node-dialog-confirm-deploy" ).dialog( "open" ); + notificationButtons.unshift( + { + text: RED._("common.label.cancel"), + click: function() { + notification.close(); + } + } + ); + notification = RED.notify(notificationMessage,{ + modal: true, + fixed: true, + buttons:notificationButtons + }); return; } } @@ -391,7 +387,7 @@ RED.deploy = (function() { '

    '+RED._("deploy.successfulDeploy")+'

    '+ '

    '+RED._("deploy.unusedConfigNodes")+' '+RED._("deploy.unusedConfigNodesLink")+'

    ',"success",false,6000); } else { - RED.notify(RED._("deploy.successfulDeploy"),"success"); + RED.notify('

    '+RED._("deploy.successfulDeploy")+'

    ',"success"); } RED.nodes.eachNode(function(node) { if (node.changed) { diff --git a/editor/js/ui/notifications.js b/editor/js/ui/notifications.js index bee1e9e10..a9e1f387b 100644 --- a/editor/js/ui/notifications.js +++ b/editor/js/ui/notifications.js @@ -74,6 +74,16 @@ RED.notifications = (function() { if (type) { n.className = "notification notification-"+type; } + if (options.width) { + var parentWidth = $("#notifications").width(); + if (options.width > parentWidth) { + var margin = -(options.width-parentWidth)/2; + $(n).css({ + width: options.width+"px", + marginLeft: margin+"px" + }) + } + } n.style.display = "none"; if (typeof msg === "string") { n.innerHTML = msg; @@ -84,6 +94,9 @@ RED.notifications = (function() { var buttonSet = $('
    ').appendTo(n) options.buttons.forEach(function(buttonDef) { var b = $('