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 678e8547d5..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 @@ -114,28 +114,17 @@ function dataTypeResource($q, $http, umbDataFormatter, umbRequestHelper) { "GetAll")), "Failed to retrieve data"); }, - - getAllUserConfigured: function () { - + + getGroupedDataTypes: function () { return umbRequestHelper.resourcePromise( $http.get( umbRequestHelper.getApiUrl( "dataTypeApiBaseUrl", - "GetAllUserConfigured")), + "GetGroupedDataTypes")), "Failed to retrieve data"); }, - getAllUserPropertyEditors: function () { - - return umbRequestHelper.resourcePromise( - $http.get( - umbRequestHelper.getApiUrl( - "dataTypeApiBaseUrl", - "GetAllUserPropertyEditors")), - "Failed to retrieve data"); - }, - - getAllTypesAndEditors : function(){ + getGroupedPropertyEditors : function(){ return umbRequestHelper.resourcePromise( $http.get( umbRequestHelper.getApiUrl( diff --git a/src/Umbraco.Web.UI.Client/src/views/common/overlays/contenttypeeditor/editorpicker/editorpicker.controller.js b/src/Umbraco.Web.UI.Client/src/views/common/overlays/contenttypeeditor/editorpicker/editorpicker.controller.js index 90dc6a2e4e..5b2dbbb26d 100644 --- a/src/Umbraco.Web.UI.Client/src/views/common/overlays/contenttypeeditor/editorpicker/editorpicker.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/common/overlays/contenttypeeditor/editorpicker/editorpicker.controller.js @@ -21,14 +21,14 @@ { active: true, id: 1, - label: "Default", + label: "Available Editors", alias: "Default", typesAndEditors: [] }, { active: false, id: 2, - label: "Reuse", + label: "Re-use", alias: "Reuse", userConfigured: [] } @@ -38,17 +38,18 @@ vm.showDetailsOverlay = showDetailsOverlay; vm.hideDetailsOverlay = hideDetailsOverlay; vm.pickEditor = pickEditor; + vm.pickDataType = pickDataType; function activate() { - getAllUserConfiguredDataTypes(); - getAllTypesAndEditors(); + getGroupedDataTypes(); + getGroupedPropertyEditors(); } - function getAllTypesAndEditors() { + function getGroupedPropertyEditors() { - dataTypeResource.getAllTypesAndEditors().then(function(data){ + dataTypeResource.getGroupedPropertyEditors().then(function(data){ vm.tabs[0].typesAndEditors = data; vm.tabsLoaded = vm.tabsLoaded + 1; checkIfTabContentIsLoaded(); @@ -56,9 +57,9 @@ } - function getAllUserConfiguredDataTypes() { + function getGroupedDataTypes() { - dataTypeResource.getAllUserConfigured().then(function(data){ + dataTypeResource.getGroupedDataTypes().then(function (data) { vm.tabs[1].userConfigured = data; vm.tabsLoaded = vm.tabsLoaded + 1; checkIfTabContentIsLoaded(); @@ -93,58 +94,51 @@ function pickEditor(editor) { - if(editor.id === null) { + var parentId = -1; - // add scaffold in data type root - var parentId = -1; + dataTypeResource.getScaffold(parentId).then(function(dataType) { - dataTypeResource.getScaffold(parentId).then(function(dataType) { + // set alias + dataType.selectedEditor = editor.alias; - // set alias - dataType.selectedEditor = editor.alias; + // set name + var nameArray = []; - // set name - var nameArray = []; + if($scope.model.contentTypeName) { + nameArray.push($scope.model.contentTypeName); + } - if($scope.model.contentTypeName) { - nameArray.push($scope.model.contentTypeName); - } + if($scope.model.property.label) { + nameArray.push($scope.model.property.label); + } - if($scope.model.property.label) { - nameArray.push($scope.model.property.label); - } + if(editor.name) { + nameArray.push(editor.name); + } - if(editor.name) { - nameArray.push(editor.name); - } + // make name + dataType.name = nameArray.join(" - "); - // make name - dataType.name = nameArray.join(" - "); + // get pre values + dataTypeResource.getPreValues(dataType.selectedEditor).then(function(preValues) { - // get pre values - dataTypeResource.getPreValues(dataType.selectedEditor).then(function(preValues) { + dataType.preValues = preValues; - dataType.preValues = preValues; - - openEditorSettingsOverlay(dataType, true); - - }); + openEditorSettingsOverlay(dataType, true); }); - } else { + }); - dataTypeResource.getById(editor.id).then(function(dataType) { + } - contentTypeResource.getPropertyTypeScaffold(dataType.id).then(function(propertyType) { + function pickDataType(selectedDataType) { - submitOverlay(dataType, propertyType, false); - - }); - - }); - - } + dataTypeResource.getById(selectedDataType.id).then(function(dataType) { + contentTypeResource.getPropertyTypeScaffold(dataType.id).then(function(propertyType) { + submitOverlay(dataType, propertyType, false); + }); + }); } diff --git a/src/Umbraco.Web.UI.Client/src/views/common/overlays/contenttypeeditor/editorpicker/editorpicker.html b/src/Umbraco.Web.UI.Client/src/views/common/overlays/contenttypeeditor/editorpicker/editorpicker.html index a09101a54f..671d9083c4 100644 --- a/src/Umbraco.Web.UI.Client/src/views/common/overlays/contenttypeeditor/editorpicker/editorpicker.html +++ b/src/Umbraco.Web.UI.Client/src/views/common/overlays/contenttypeeditor/editorpicker/editorpicker.html @@ -42,15 +42,25 @@
-
Your configurations
- + +
+ +
+
{{key}}
+ + + +
+ +
+
diff --git a/src/Umbraco.Web/Editors/DataTypeController.cs b/src/Umbraco.Web/Editors/DataTypeController.cs index 1336166c2c..c2d7ec37d2 100644 --- a/src/Umbraco.Web/Editors/DataTypeController.cs +++ b/src/Umbraco.Web/Editors/DataTypeController.cs @@ -286,31 +286,7 @@ namespace Umbraco.Web.Editors } /// - /// Gets the content json for all data types added by the user - /// - /// - /// - /// Permission is granted to this method if the user has access to any of these sections: Content, media, settings, developer, members - /// - [UmbracoApplicationAuthorize( - Constants.Applications.Content, Constants.Applications.Media, Constants.Applications.Members, - Constants.Applications.Settings, Constants.Applications.Developer)] - public IEnumerable GetAllUserConfigured() - { - //find all user configured for re-reference - return Services.DataTypeService - .GetAllDataTypeDefinitions() - //TODO: This is pretty nasty :( - .Where(x => x.Id > 1045) - .Select(Mapper.Map).Where(x => x.IsSystemDataType == false); - - //find all custom editors added by non-core manifests - - //find the rest - } - - /// - /// Gets the content json for all user added property editors + /// Returns all data types grouped by their property editor group /// /// /// @@ -319,17 +295,29 @@ namespace Umbraco.Web.Editors [UmbracoTreeAuthorize( Constants.Applications.Content, Constants.Applications.Media, Constants.Applications.Members, Constants.Applications.Settings, Constants.Applications.Developer)] - public IEnumerable GetAllUserPropertyEditors() + public IDictionary> GetGroupedDataTypes() { - return PropertyEditorResolver.Current.PropertyEditors - .OrderBy(x => x.Name) - .Where(x => x.ValueEditor.View.IndexOf("app_plugins", StringComparison.InvariantCultureIgnoreCase) >= 0) - .Select(Mapper.Map); + var dataTypes = Services.DataTypeService + .GetAllDataTypeDefinitions() + .Select(Mapper.Map); + + var propertyEditors = PropertyEditorResolver.Current.PropertyEditors.ToArray(); + + foreach (var dataType in dataTypes) + { + var propertyEditor = propertyEditors.Single(x => x.Alias == dataType.Alias); + dataType.HasPrevalues = propertyEditor.PreValueEditor.Fields.Any(); ; + } + + 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 configured data types and all potential data types that could exist based on unused property editors grouped - /// by their property editor defined group. + /// Returns all property editors grouped /// /// /// @@ -340,44 +328,20 @@ namespace Umbraco.Web.Editors Constants.Applications.Settings, Constants.Applications.Developer)] public IDictionary> GetGroupedPropertyEditors() { - var datadefs = Services.DataTypeService - .GetAllDataTypeDefinitions() - .ToArray(); - var datatypes = new List(); - - //this is a very specific map - if a property editor does not have prevalue - and there is a datatype already using this type, return that. - //also, we exclude all the system listviews from the 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; }