From 404fc40127180ff157189e50ecd245d3a735395c Mon Sep 17 00:00:00 2001 From: Marc Goodson Date: Sun, 15 Oct 2017 10:28:16 +0100 Subject: [PATCH 1/2] Skips the Macro Selection stage if only one macro exists, and it has parameters to be entered --- .../macropicker/macropicker.controller.js | 26 ++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/views/common/overlays/macropicker/macropicker.controller.js b/src/Umbraco.Web.UI.Client/src/views/common/overlays/macropicker/macropicker.controller.js index 69f9851926..3915282876 100644 --- a/src/Umbraco.Web.UI.Client/src/views/common/overlays/macropicker/macropicker.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/common/overlays/macropicker/macropicker.controller.js @@ -17,14 +17,17 @@ function MacroPickerController($scope, entityResource, macroResource, umbPropEdi $scope.model.selectedMacro = macro; if ($scope.wizardStep === "macroSelect") { - editParams(); + editParams(true); } else { $scope.model.submit($scope.model); } }; /** changes the view to edit the params of the selected macro */ - function editParams() { + /** if there is pnly one macro, and it has parameters - editor can skip selecting the Macro **/ + function editParams(insertIfNoParameters) { + //whether to insert the macro in the rich text editor when editParams is called and there are no parameters see U4-10537 + insertIfNoParameters = (typeof insertIfNoParameters !== 'undefined') ? insertIfNoParameters : true; //get the macro params if there are any macroResource.getMacroParameters($scope.model.selectedMacro.id) .then(function (data) { @@ -34,7 +37,11 @@ function MacroPickerController($scope, entityResource, macroResource, umbPropEdi //go to next page if there are params otherwise we can just exit if (!angular.isArray(data) || data.length === 0) { - $scope.model.submit($scope.model); + if (insertIfNoParameters) { + $scope.model.submit($scope.model); + } else { + $scope.wizardStep = 'macroSelect'; + } } else { @@ -113,12 +120,19 @@ function MacroPickerController($scope, entityResource, macroResource, umbPropEdi if (found) { //select the macro and go to next screen $scope.model.selectedMacro = found; - editParams(); + editParams(true); return; } } - //we don't have a pre-selected macro so ensure the correct step is set - $scope.wizardStep = "macroSelect"; + //if there is only one macro in the site and it has parameters, let's not make the editor choose it from a selection of one macro (unless there are no parameters - then weirdly it's a better experience to make that selection) + if ($scope.macros.length == 1) { + $scope.model.selectedMacro = $scope.macros[0]; + editParams(false); + } + else { + //we don't have a pre-selected macro so ensure the correct step is set + $scope.wizardStep = 'macroSelect'; + } }); From 0752ef06b120373ea0fea214acebf4f53a262fe0 Mon Sep 17 00:00:00 2001 From: Marc Goodson Date: Sun, 15 Oct 2017 10:36:26 +0100 Subject: [PATCH 2/2] Enables the editor to skip the macro selection stage, when there is only one Macro and it has parameters (is this a controller still used? ) --- .../common/dialogs/insertmacro.controller.js | 29 ++++++++++++++----- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/views/common/dialogs/insertmacro.controller.js b/src/Umbraco.Web.UI.Client/src/views/common/dialogs/insertmacro.controller.js index dbb86e87ec..1fd870b42d 100644 --- a/src/Umbraco.Web.UI.Client/src/views/common/dialogs/insertmacro.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/common/dialogs/insertmacro.controller.js @@ -10,16 +10,22 @@ function InsertMacroController($scope, entityResource, macroResource, umbPropEditorHelper, macroService, formHelper) { /** changes the view to edit the params of the selected macro */ - function editParams() { + /** if there is pnly one macro, and it has parameters - editor can skip selecting the Macro **/ + function editParams(insertIfNoParameters) { + //whether to insert the macro in the rich text editor when editParams is called and there are no parameters see U4-10537 + insertIfNoParameters = (typeof insertIfNoParameters !== 'undefined') ? insertIfNoParameters : true; //get the macro params if there are any macroResource.getMacroParameters($scope.selectedMacro.id) .then(function (data) { //go to next page if there are params otherwise we can just exit if (!angular.isArray(data) || data.length === 0) { - //we can just exist! - submitForm(); - + //we can just exist! + if (insertIfNoParameters) { + submitForm(); + } else { + $scope.wizardStep = 'macroSelect'; + } } else { $scope.wizardStep = "paramSelect"; $scope.macroParams = data; @@ -117,7 +123,7 @@ function InsertMacroController($scope, entityResource, macroResource, umbPropEdi formHelper.resetForm({ scope: $scope }); if ($scope.wizardStep === "macroSelect") { - editParams(); + editParams(true); } else { submitForm(); @@ -155,12 +161,19 @@ function InsertMacroController($scope, entityResource, macroResource, umbPropEdi if (found) { //select the macro and go to next screen $scope.selectedMacro = found; - editParams(); + editParams(true); return; } } - //we don't have a pre-selected macro so ensure the correct step is set - $scope.wizardStep = "macroSelect"; + //if there is only one macro in the site and it has parameters, let's not make the editor choose it from a selection of one macro (unless there are no parameters - then weirdly it's a better experience to make that selection) + if ($scope.macros.length == 1) { + $scope.selectedMacro = $scope.macros[0]; + editParams(false); + } + else { + //we don't have a pre-selected macro so ensure the correct step is set + $scope.wizardStep = 'macroSelect'; + } });