Skip to content

Commit

Permalink
Add method to get grouped parameter editors
Browse files Browse the repository at this point in the history
  • Loading branch information
Bjarne Fyrstenborg committed Oct 2, 2019
1 parent b4c6930 commit c302d59
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
17 changes: 17 additions & 0 deletions src/Umbraco.Web/Editors/MacrosController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,23 @@ public HttpResponseMessage GetParameterEditors()
return this.Request.CreateResponse(HttpStatusCode.OK, Current.ParameterEditors);
}

/// <summary>
/// Gets the available parameter editors grouped by their group.
/// </summary>
/// <returns>
/// The <see cref="HttpResponseMessage"/>.
/// </returns>
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);
}

/// <summary>
/// Returns a error response and optionally logs it
/// </summary>
Expand Down

0 comments on commit c302d59

Please sign in to comment.