From 7396b014660905bc83966493f2f8ee80b88e81b4 Mon Sep 17 00:00:00 2001 From: Shannon Date: Fri, 20 Sep 2013 14:24:39 +1000 Subject: [PATCH] Got macro parameter editors inserting macros into the template editor for both webforms and mvc, created unit tests for macro syntax in macroservice. Removed the hard coded span8 for input elements for property editors - need to figure out a different way to set their width. --- .../lib/umbraco/LegacyUmbClientMgr.js | 4 +- .../src/common/services/dialog.service.js | 8 +- .../src/common/services/macro.service.js | 79 ++++++++++++++++ .../src/common/services/util.service.js | 35 ++++---- .../src/views/directives/umb-editor.html | 4 +- .../src/views/prevalueeditors/textarea.html | 2 +- .../contentpicker/contentpicker.html | 2 +- .../googlemaps/googlemaps.html | 2 +- .../src/views/propertyeditors/rte/rte.html | 2 +- .../src/views/propertyeditors/tags/tags.html | 2 +- .../propertyeditors/textarea/textarea.html | 2 +- .../propertyeditors/textbox/textbox.html | 2 +- .../views/templates/insertmacro.controller.js | 90 +++++++++++++++---- .../src/views/templates/insertmacro.html | 26 ++++-- .../common/services/macro-service.spec.js | 70 +++++++++++++++ .../umbraco_client/Editors/EditTemplate.js | 14 +-- .../umbraco_client/Editors/EditView.js | 20 +++-- .../Models/ContentEditing/EntityBasic.cs | 6 ++ .../Models/Mapping/MacroModelMapper.cs | 7 +- .../Mapping/ParameterEditorViewResolver.cs | 20 +++++ src/Umbraco.Web/Umbraco.Web.csproj | 1 + 21 files changed, 326 insertions(+), 72 deletions(-) create mode 100644 src/Umbraco.Web.UI.Client/src/common/services/macro.service.js create mode 100644 src/Umbraco.Web.UI.Client/test/unit/common/services/macro-service.spec.js create mode 100644 src/Umbraco.Web/Models/Mapping/ParameterEditorViewResolver.cs diff --git a/src/Umbraco.Web.UI.Client/lib/umbraco/LegacyUmbClientMgr.js b/src/Umbraco.Web.UI.Client/lib/umbraco/LegacyUmbClientMgr.js index 5ff0db913a..ab0458ed46 100644 --- a/src/Umbraco.Web.UI.Client/lib/umbraco/LegacyUmbClientMgr.js +++ b/src/Umbraco.Web.UI.Client/lib/umbraco/LegacyUmbClientMgr.js @@ -175,7 +175,7 @@ Umbraco.Sys.registerNamespace("Umbraco.Application"); }, /** This is used to launch an angular based modal window instead of the legacy window */ - openAngularModalWindow: function (options, onCloseCallback) { + openAngularModalWindow: function (options) { //get our angular navigation service var injector = getRootInjector(); @@ -249,8 +249,6 @@ Umbraco.Sys.registerNamespace("Umbraco.Application"); //instead of calling just the dialog service we funnel it through the global //event emitter getRootScope().$emit("closeDialogs", event); - - //dialogService.closeAll(rVal); } }, _debug: function(strMsg) { diff --git a/src/Umbraco.Web.UI.Client/src/common/services/dialog.service.js b/src/Umbraco.Web.UI.Client/src/common/services/dialog.service.js index af086eb608..5c370fcde1 100644 --- a/src/Umbraco.Web.UI.Client/src/common/services/dialog.service.js +++ b/src/Umbraco.Web.UI.Client/src/common/services/dialog.service.js @@ -38,8 +38,6 @@ angular.module('umbraco.services') for (var i = 0; i < dialogs.length; i++) { var dialog = dialogs[i]; dialog.close(args); - - //removeDialog(dialog, args); dialogs.splice(i, 1); } } @@ -266,10 +264,8 @@ angular.module('umbraco.services') */ close: function (dialog, args) { if(dialog){ - dialog.close(); - } - - //removeDialog(dialog, args); + dialog.close(args); + } }, /** diff --git a/src/Umbraco.Web.UI.Client/src/common/services/macro.service.js b/src/Umbraco.Web.UI.Client/src/common/services/macro.service.js new file mode 100644 index 0000000000..9a1f4b7483 --- /dev/null +++ b/src/Umbraco.Web.UI.Client/src/common/services/macro.service.js @@ -0,0 +1,79 @@ +/** + * @ngdoc service + * @name umbraco.services.macroService + * + * + * @description + * A service to return macro information such as generating syntax to insert a macro into an editor + */ +function macroService() { + + return { + + /** + * @ngdoc function + * @name generateWebFormsSyntax + * @methodOf umbraco.services.macroService + * @function + * + * @description + * generates the syntax for inserting a macro into a webforms templates + * + * @param {object} args an object containing the macro alias and it's parameter values + */ + generateWebFormsSyntax: function(args) { + + var macroString = '"; + + return macroString; + }, + + /** + * @ngdoc function + * @name generateMvcSyntax + * @methodOf umbraco.services.macroService + * @function + * + * @description + * generates the syntax for inserting a macro into an mvc template + * + * @param {object} args an object containing the macro alias and it's parameter values + */ + generateMvcSyntax: function (args) { + + var macroString = "@Umbraco.RenderMacro(\"" + args.macroAlias + "\""; + + if (args.macroParams && args.macroParams.length > 0) { + macroString += ", new {"; + for (var i = 0; i < args.macroParams.length; i++) { + + var keyVal = args.macroParams[i].alias + "=\"" + (args.macroParams[i].value ? args.macroParams[i].value : "") + "\""; + + macroString += keyVal; + + if (i < args.macroParams.length - 1) { + macroString += ", "; + } + } + macroString += "}"; + } + + macroString += ")"; + return macroString; + } + + }; + +} + +angular.module('umbraco.services').factory('macroService', macroService); \ No newline at end of file diff --git a/src/Umbraco.Web.UI.Client/src/common/services/util.service.js b/src/Umbraco.Web.UI.Client/src/common/services/util.service.js index fe70bf67c8..f3d9f1498a 100644 --- a/src/Umbraco.Web.UI.Client/src/common/services/util.service.js +++ b/src/Umbraco.Web.UI.Client/src/common/services/util.service.js @@ -28,41 +28,38 @@ angular.module('umbraco.services').factory('legacyJsLoader', legacyJsLoader); function umbPropEditorHelper() { return { /** - * @ngdoc function - * @name getImagePropertyValue - * @methodOf umbraco.services.umbPropertyEditorHelper - * @function - * - * @description - * Returns the correct view path for a property editor, it will detect if it is a full virtual path but if not then default to the internal umbraco one - * - * @param {string} input the view path currently stored for the property editor - */ - getViewPath: function (input, isPreValue) { + * @ngdoc function + * @name getImagePropertyValue + * @methodOf umbraco.services.umbPropertyEditorHelper + * @function + * + * @description + * Returns the correct view path for a property editor, it will detect if it is a full virtual path but if not then default to the internal umbraco one + * + * @param {string} input the view path currently stored for the property editor + */ + getViewPath: function(input, isPreValue) { var path = String(input); if (path.startsWith('/')) { //This is an absolute path, so just leave it return path; - } - else { - + } else { + if (path.indexOf("/") >= 0) { //This is a relative path, so just leave it return path; - } - else { + } else { if (!isPreValue) { //i.e. views/propertyeditors/fileupload/fileupload.html return "views/propertyeditors/" + path + "/" + path + ".html"; - } - else { + } else { //i.e. views/prevalueeditors/requiredfield.html return "views/prevalueeditors/" + path + ".html"; } } - + } } }; diff --git a/src/Umbraco.Web.UI.Client/src/views/directives/umb-editor.html b/src/Umbraco.Web.UI.Client/src/views/directives/umb-editor.html index 3cb344e6fe..cb7f084650 100644 --- a/src/Umbraco.Web.UI.Client/src/views/directives/umb-editor.html +++ b/src/Umbraco.Web.UI.Client/src/views/directives/umb-editor.html @@ -1,3 +1,3 @@ -
- +
+
\ No newline at end of file diff --git a/src/Umbraco.Web.UI.Client/src/views/prevalueeditors/textarea.html b/src/Umbraco.Web.UI.Client/src/views/prevalueeditors/textarea.html index 2321f3dd8d..ed4c1490d2 100644 --- a/src/Umbraco.Web.UI.Client/src/views/prevalueeditors/textarea.html +++ b/src/Umbraco.Web.UI.Client/src/views/prevalueeditors/textarea.html @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/src/Umbraco.Web.UI.Client/src/views/propertyeditors/contentpicker/contentpicker.html b/src/Umbraco.Web.UI.Client/src/views/propertyeditors/contentpicker/contentpicker.html index c07baa10f1..4b6d47b459 100644 --- a/src/Umbraco.Web.UI.Client/src/views/propertyeditors/contentpicker/contentpicker.html +++ b/src/Umbraco.Web.UI.Client/src/views/propertyeditors/contentpicker/contentpicker.html @@ -1,4 +1,4 @@ -
+