From c302d59067b0f42a22d383871f8f69f72998fd1a Mon Sep 17 00:00:00 2001 From: Bjarne Fyrstenborg Date: Wed, 2 Oct 2019 23:21:43 +0200 Subject: [PATCH] Add method to get grouped parameter editors --- .../src/common/resources/macro.resource.js | 7 +++++++ src/Umbraco.Web/Editors/MacrosController.cs | 17 +++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/Umbraco.Web.UI.Client/src/common/resources/macro.resource.js b/src/Umbraco.Web.UI.Client/src/common/resources/macro.resource.js index 73a1651b5e6f..fd7c6c9af9ec 100644 --- a/src/Umbraco.Web.UI.Client/src/common/resources/macro.resource.js +++ b/src/Umbraco.Web.UI.Client/src/common/resources/macro.resource.js @@ -105,6 +105,13 @@ function macroResource($q, $http, umbRequestHelper) { ); }, + getGroupedParameterEditors: function () { + return umbRequestHelper.resourcePromise( + $http.get(umbRequestHelper.getApiUrl("macroApiBaseUrl", "GetGroupedParameterEditors"), + "Failed to get parameter editors") + ); + }, + getById: function(id) { return umbRequestHelper.resourcePromise( $http.get(umbRequestHelper.getApiUrl("macroApiBaseUrl", "GetById", { "id": id }), "Failed to get macro") diff --git a/src/Umbraco.Web/Editors/MacrosController.cs b/src/Umbraco.Web/Editors/MacrosController.cs index 429e8b619065..26b59b9aa923 100644 --- a/src/Umbraco.Web/Editors/MacrosController.cs +++ b/src/Umbraco.Web/Editors/MacrosController.cs @@ -229,6 +229,23 @@ public HttpResponseMessage GetParameterEditors() return this.Request.CreateResponse(HttpStatusCode.OK, Current.ParameterEditors); } + /// + /// Gets the available parameter editors grouped by their group. + /// + /// + /// The . + /// + public HttpResponseMessage GetGroupedParameterEditors() + { + var parameterEditors = Current.ParameterEditors.ToArray(); + + var grouped = parameterEditors + .GroupBy(x => x.Group.IsNullOrWhiteSpace() ? "" : x.Group.ToLower()) + .ToDictionary(group => group.Key, group => group.OrderBy(d => d.Name).AsEnumerable()); + + return this.Request.CreateResponse(HttpStatusCode.OK, grouped); + } + /// /// Returns a error response and optionally logs it ///