From 62db58110a49a160e00a8fadd8d79976979af18c Mon Sep 17 00:00:00 2001 From: Shannon Date: Thu, 17 Dec 2015 11:13:49 +0100 Subject: [PATCH] re-reverts GetGroupedPropertyEditors and adds GetGroupedDataTypes --- .../src/common/resources/datatype.resource.js | 9 +++ src/Umbraco.Web/Editors/DataTypeController.cs | 67 +++++++++++-------- 2 files changed, 48 insertions(+), 28 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/common/resources/datatype.resource.js b/src/Umbraco.Web.UI.Client/src/common/resources/datatype.resource.js index efa7cc4e84..7bc65c89a6 100644 --- a/src/Umbraco.Web.UI.Client/src/common/resources/datatype.resource.js +++ b/src/Umbraco.Web.UI.Client/src/common/resources/datatype.resource.js @@ -115,6 +115,15 @@ function dataTypeResource($q, $http, umbDataFormatter, umbRequestHelper) { "Failed to retrieve data"); }, + getGroupedDataTypes: function () { + return umbRequestHelper.resourcePromise( + $http.get( + umbRequestHelper.getApiUrl( + "dataTypeApiBaseUrl", + "GetGroupedDataTypes")), + "Failed to retrieve data"); + }, + getGroupedPropertyEditors : function(){ return umbRequestHelper.resourcePromise( $http.get( diff --git a/src/Umbraco.Web/Editors/DataTypeController.cs b/src/Umbraco.Web/Editors/DataTypeController.cs index d5d18f5c0d..252c739778 100644 --- a/src/Umbraco.Web/Editors/DataTypeController.cs +++ b/src/Umbraco.Web/Editors/DataTypeController.cs @@ -286,9 +286,41 @@ namespace Umbraco.Web.Editors } /// - /// Returns all Property Editors - if a Property Editor has no pre-values and a data type exists for this property editor than it's - /// configuration is returned instead of a non-configured property editor, this is because only one data type with this Property Editor should exist - /// (since it cannot be configured differently) + /// Returns all data types grouped by their property editor group + /// + /// + /// + /// Permission is granted to this method if the user has access to any of these sections: Content, media, settings, developer, members + /// + [UmbracoTreeAuthorize( + Constants.Applications.Content, Constants.Applications.Media, Constants.Applications.Members, + Constants.Applications.Settings, Constants.Applications.Developer)] + public IDictionary> GetGroupedDataTypes() + { + var datadefs = Services.DataTypeService + .GetAllDataTypeDefinitions(); + + var datatypes = new List(); + + var propertyEditors = PropertyEditorResolver.Current.PropertyEditors.ToArray(); + foreach (var datatype in datadefs) + { + var propertyEditor = propertyEditors.Single(x => x.Name == datatype.PropertyEditorAlias); + var hasPrevalues = propertyEditor.PreValueEditor.Fields.Any(); + var basic = Mapper.Map(propertyEditor); + basic.HasPrevalues = hasPrevalues; + datatypes.Add(basic); + } + + var grouped = datatypes + .GroupBy(x => x.Group.IsNullOrWhiteSpace() ? "" : x.Group.ToLower()) + .ToDictionary(group => group.Key, group => group.OrderBy(d => d.Name).AsEnumerable()); + + return grouped; + } + + /// + /// Returns all property editors grouped /// /// /// @@ -299,41 +331,20 @@ namespace Umbraco.Web.Editors Constants.Applications.Settings, Constants.Applications.Developer)] public IDictionary> GetGroupedPropertyEditors() { - var datadefs = Services.DataTypeService - .GetAllDataTypeDefinitions() - .ToArray(); - var datatypes = new List(); var propertyEditors = PropertyEditorResolver.Current.PropertyEditors; foreach (var propertyEditor in propertyEditors) { var hasPrevalues = propertyEditor.PreValueEditor.Fields.Any(); - - //check if a data type exists for this property editor - var dataDef = datadefs.FirstOrDefault(x => x.PropertyEditorAlias == propertyEditor.Alias); - - //if no prevalues and a datatype exists with this property editor - if (hasPrevalues == false && dataDef != null) - { - //exclude system list views - if (dataDef.Name.InvariantStartsWith(Constants.Conventions.DataTypes.ListViewPrefix) == false) - { - datatypes.Add(Mapper.Map(dataDef)); - } - } - else - { - //else, just add a clean property editor - var basic = Mapper.Map(propertyEditor); - basic.HasPrevalues = hasPrevalues; - datatypes.Add(basic); - } + var basic = Mapper.Map(propertyEditor); + basic.HasPrevalues = hasPrevalues; + datatypes.Add(basic); } var grouped = datatypes .GroupBy(x => x.Group.IsNullOrWhiteSpace() ? "" : x.Group.ToLower()) - .ToDictionary(group => group.Key, group => group.AsEnumerable()); + .ToDictionary(group => group.Key, group => group.OrderBy(d => d.Name).AsEnumerable()); return grouped; }