Updates new UDI pickers that have start nodes for pre-values to also store UDIs for their prevalues, this has a knock on effect in that we need to be able to inject some server side config for pre-value editors (otherwise we'd have to make diff udi prevalue editors but that isn't very re-usable), so have implemented that and then updated all of the logic to deal with the udi idType.

This commit is contained in:
Shannon
2017-02-08 16:15:27 +11:00
parent 846ac573cc
commit a20cc60c10
14 changed files with 274 additions and 72 deletions

View File

@@ -15,6 +15,7 @@ namespace Umbraco.Core.PropertyEditors
public PreValueField()
{
Validators = new List<IPropertyValidator>();
Config = new Dictionary<string, object>();
//check for an attribute and fill the values
var att = GetType().GetCustomAttribute<PreValueFieldAttribute>(false);
@@ -79,5 +80,11 @@ namespace Umbraco.Core.PropertyEditors
/// </summary>
[JsonProperty("validation", ItemConverterType = typeof(ManifestValidatorConverter))]
public List<IPropertyValidator> Validators { get; private set; }
/// <summary>
/// This allows for custom configuration to be injected into the pre-value editor
/// </summary>
[JsonProperty("config")]
public IDictionary<string, object> Config { get; set; }
}
}

View File

@@ -27,7 +27,8 @@ function DataTypeEditController($scope, $routeParams, $location, appState, navig
description: preVals[i].description,
label: preVals[i].label,
view: preVals[i].view,
value: preVals[i].value
value: preVals[i].value,
config: preVals[i].config,
});
}
}

View File

@@ -13,9 +13,15 @@ function mediaPickerController($scope, dialogService, entityResource, $log, icon
multiPicker: false,
entityType: "Media",
section: "media",
treeAlias: "media"
treeAlias: "media",
idType: "int"
};
//combine the dialogOptions with any values returned from the server
if ($scope.model.config) {
angular.extend(dialogOptions, $scope.model.config);
}
$scope.openContentPicker = function() {
$scope.contentPickerOverlay = dialogOptions;
$scope.contentPickerOverlay.view = "treePicker";
@@ -53,18 +59,21 @@ function mediaPickerController($scope, dialogService, entityResource, $log, icon
};
$scope.add = function (item) {
var itemId = dialogOptions.idType === "udi" ? item.udi : item.id;
var currIds = _.map($scope.renderModel, function (i) {
return i.id;
return dialogOptions.idType === "udi" ? i.udi : i.id;
});
if (currIds.indexOf(item.id) < 0) {
if (currIds.indexOf(itemId) < 0) {
item.icon = iconHelper.convertFromLegacyIcon(item.icon);
$scope.renderModel.push({name: item.name, id: item.id, icon: item.icon});
$scope.renderModel.push({ name: item.name, id: item.id, icon: item.icon, udi: item.udi });
}
};
var unsubscribe = $scope.$on("formSubmitting", function (ev, args) {
var currIds = _.map($scope.renderModel, function (i) {
return i.id;
return dialogOptions.idType === "udi" ? i.udi : i.id;
});
$scope.model.value = trim(currIds.join(), ",");
});
@@ -79,7 +88,7 @@ function mediaPickerController($scope, dialogService, entityResource, $log, icon
entityResource.getByIds(modelIds, dialogOptions.entityType).then(function (data) {
_.each(data, function (item, i) {
item.icon = iconHelper.convertFromLegacyIcon(item.icon);
$scope.renderModel.push({ name: item.name, id: item.id, icon: item.icon });
$scope.renderModel.push({ name: item.name, id: item.id, icon: item.icon, udi: item.udi });
});
});

View File

@@ -12,26 +12,29 @@ angular.module('umbraco')
multiPicker: false,
entityType: "Document",
type: "content",
treeAlias: "content"
};
treeAlias: "content",
idType: "int"
};
//combine the config with any values returned from the server
if ($scope.model.config) {
angular.extend(config, $scope.model.config);
}
if($scope.model.value){
$scope.ids = $scope.model.value.split(',');
entityResource.getByIds($scope.ids, config.entityType).then(function (data) {
_.each(data, function (item, i) {
item.icon = iconHelper.convertFromLegacyIcon(item.icon);
$scope.renderModel.push({name: item.name, id: item.id, icon: item.icon});
});
$scope.renderModel.push({ name: item.name, id: item.id, icon: item.icon, udi: item.udi });
});
});
}
$scope.openContentPicker = function() {
$scope.treePickerOverlay = {};
$scope.treePickerOverlay.section = config.type;
$scope.treePickerOverlay.treeAlias = config.treeAlias;
$scope.treePickerOverlay.multiPicker = config.multiPicker;
$scope.treePickerOverlay = config;
$scope.treePickerOverlay.view = "treePicker";
$scope.treePickerOverlay.show = true;
$scope.treePickerOverlay.show = true;
$scope.treePickerOverlay.submit = function(model) {
@@ -64,12 +67,15 @@ angular.module('umbraco')
$scope.ids = [];
};
$scope.add =function(item){
if($scope.ids.indexOf(item.id) < 0){
$scope.add = function (item) {
var itemId = config.idType === "udi" ? item.udi : item.id;
if ($scope.ids.indexOf(itemId) < 0){
item.icon = iconHelper.convertFromLegacyIcon(item.icon);
$scope.ids.push(item.id);
$scope.renderModel.push({name: item.name, id: item.id, icon: item.icon});
$scope.ids.push(itemId);
$scope.renderModel.push({name: item.name, id: item.id, icon: item.icon, udi: item.udi});
$scope.model.value = trim($scope.ids.join(), ",");
}
};

View File

@@ -12,7 +12,12 @@ angular.module('umbraco')
$scope.model.value = {
type: "content"
};
}
}
if (!$scope.model.config) {
$scope.model.config = {
idType: "int"
};
}
if($scope.model.value.id && $scope.model.value.type !== "member"){
var ent = "Document";
@@ -29,7 +34,8 @@ angular.module('umbraco')
$scope.openContentPicker =function(){
$scope.treePickerOverlay = {
view: "treepicker",
view: "treepicker",
idType: $scope.model.config.idType,
section: $scope.model.value.type,
treeAlias: $scope.model.value.type,
multiPicker: false,
@@ -67,6 +73,6 @@ angular.module('umbraco')
$scope.clear();
item.icon = iconHelper.convertFromLegacyIcon(item.icon);
$scope.node = item;
$scope.model.value.id = item.id;
$scope.model.value.id = $scope.model.config.idType === "udi" ? item.udi : item.id;
}
});

View File

@@ -58,7 +58,7 @@ function contentPickerController($scope, entityResource, editorState, iconHelper
startNode: {
query: "",
type: "content",
id: $scope.model.config.startNodeId ? $scope.model.config.startNodeId : -1 // get start node for simple Content Picker
id: $scope.model.config.startNodeId ? $scope.model.config.startNodeId : -1 // get start node for simple Content Picker
}
};
@@ -105,10 +105,11 @@ function contentPickerController($scope, entityResource, editorState, iconHelper
$scope.clear();
$scope.add(data);
}
angularHelper.getCurrentForm($scope).$setDirty();
angularHelper.getCurrentForm($scope).$setDirty();
},
treeAlias: $scope.model.config.startNode.type,
section: $scope.model.config.startNode.type
section: $scope.model.config.startNode.type,
idType: "int"
};
//since most of the pre-value config's are used in the dialog options (i.e. maxNumber, minNumber, etc...) we'll merge the
@@ -147,9 +148,10 @@ function contentPickerController($scope, entityResource, editorState, iconHelper
if ($scope.model.config.startNode.query) {
var rootId = $routeParams.id;
entityResource.getByQuery($scope.model.config.startNode.query, rootId, "Document").then(function (ent) {
dialogOptions.startNodeId = ent.id;
dialogOptions.startNodeId = $scope.model.config.idType === "udi" ? ent.udi : ent.id;
});
} else {
}
else {
dialogOptions.startNodeId = $scope.model.config.startNode.id;
}

View File

@@ -59,7 +59,7 @@ namespace Umbraco.Web.Editors
public void Initialize(HttpControllerSettings controllerSettings, HttpControllerDescriptor controllerDescriptor)
{
controllerSettings.Services.Replace(typeof(IHttpActionSelector), new ParameterSwapControllerActionSelector(
new ParameterSwapControllerActionSelector.ParameterSwapInfo("GetChildren", "id", typeof(int), typeof(Guid), typeof(string))));
new ParameterSwapControllerActionSelector.ParameterSwapInfo("GetChildren", "id", typeof(int), typeof(Guid), typeof(Udi), typeof(string))));
}
}
@@ -187,6 +187,7 @@ namespace Umbraco.Web.Editors
.Select(Mapper.Map<IMedia, ContentItemBasic<ContentPropertyBasic, IMedia>>);
}
#region GetChildren
/// <summary>
/// Returns the child media objects - using the entity INT id
/// </summary>
@@ -244,7 +245,7 @@ namespace Umbraco.Web.Editors
Direction orderDirection = Direction.Ascending,
bool orderBySystemField = true,
string filter = "")
{
{
var entity = Services.EntityService.GetByKey(id);
if (entity != null)
{
@@ -253,6 +254,39 @@ namespace Umbraco.Web.Editors
throw new HttpResponseException(HttpStatusCode.NotFound);
}
/// <summary>
/// Returns the child media objects - using the entity UDI id
/// </summary>
/// <param name="id"></param>
/// <param name="pageNumber"></param>
/// <param name="pageSize"></param>
/// <param name="orderBy"></param>
/// <param name="orderDirection"></param>
/// <param name="orderBySystemField"></param>
/// <param name="filter"></param>
/// <returns></returns>
[FilterAllowedOutgoingMedia(typeof(IEnumerable<ContentItemBasic<ContentPropertyBasic, IMedia>>), "Items")]
public PagedResult<ContentItemBasic<ContentPropertyBasic, IMedia>> GetChildren(Udi id,
int pageNumber = 0,
int pageSize = 0,
string orderBy = "SortOrder",
Direction orderDirection = Direction.Ascending,
bool orderBySystemField = true,
string filter = "")
{
var guidUdi = id as GuidUdi;
if (guidUdi != null)
{
var entity = Services.EntityService.GetByKey(guidUdi.Guid);
if (entity != null)
{
return GetChildren(entity.Id, pageNumber, pageSize, orderBy, orderDirection, orderBySystemField, filter);
}
}
throw new HttpResponseException(HttpStatusCode.NotFound);
}
[Obsolete("Do not use this method, use either the overload with INT or GUID instead, this will be removed in future versions")]
[EditorBrowsable(EditorBrowsableState.Never)]
[UmbracoTreeAuthorize(Constants.Trees.MediaTypes, Constants.Trees.Media)]
@@ -275,7 +309,8 @@ namespace Umbraco.Web.Editors
}
throw new HttpResponseException(HttpStatusCode.NotFound);
}
}
#endregion
/// <summary>
/// Moves an item to the recycle bin, if it is already there then it will permanently delete it

View File

@@ -40,7 +40,7 @@ namespace Umbraco.Web.Editors
public void Initialize(HttpControllerSettings controllerSettings, HttpControllerDescriptor controllerDescriptor)
{
controllerSettings.Services.Replace(typeof(IHttpActionSelector), new ParameterSwapControllerActionSelector(
new ParameterSwapControllerActionSelector.ParameterSwapInfo("GetAllowedChildren", "contentId", typeof(int), typeof(Guid), typeof(string))));
new ParameterSwapControllerActionSelector.ParameterSwapInfo("GetAllowedChildren", "contentId", typeof(int), typeof(Guid), typeof(Udi), typeof(string))));
}
}
@@ -187,6 +187,7 @@ namespace Umbraco.Web.Editors
}
#region GetAllowedChildren
/// <summary>
/// Returns the allowed child content type objects for the content item id passed in - based on an INT id
/// </summary>
@@ -247,10 +248,30 @@ namespace Umbraco.Web.Editors
throw new HttpResponseException(HttpStatusCode.NotFound);
}
[Obsolete("Do not use this method, use either the overload with INT or GUID instead, this will be removed in future versions")]
/// <summary>
/// Returns the allowed child content type objects for the content item id passed in - based on a UDI id
/// </summary>
/// <param name="contentId"></param>
[UmbracoTreeAuthorize(Constants.Trees.MediaTypes, Constants.Trees.Media)]
public IEnumerable<ContentTypeBasic> GetAllowedChildren(Udi contentId)
{
var guidUdi = contentId as GuidUdi;
if (guidUdi != null)
{
var entity = ApplicationContext.Services.EntityService.GetByKey(guidUdi.Guid);
if (entity != null)
{
return GetAllowedChildren(entity.Id);
}
}
throw new HttpResponseException(HttpStatusCode.NotFound);
}
[Obsolete("Do not use this method, use either the overload with INT, GUID or UDI instead, this will be removed in future versions")]
[EditorBrowsable(EditorBrowsableState.Never)]
[UmbracoTreeAuthorize(Constants.Trees.MediaTypes, Constants.Trees.Media)]
[UmbracoTreeAuthorize(Constants.Trees.MediaTypes, Constants.Trees.Media)]
public IEnumerable<ContentTypeBasic> GetAllowedChildren(string contentId)
{
foreach (var type in new[] { typeof(int), typeof(Guid) })
@@ -260,11 +281,12 @@ namespace Umbraco.Web.Editors
{
//oooh magic! will auto select the right overload
return GetAllowedChildren((dynamic)parsed.Result);
}
}
}
throw new HttpResponseException(HttpStatusCode.NotFound);
}
}
#endregion
/// <summary>
/// Move the media type

View File

@@ -1,4 +1,5 @@
using System.Runtime.Serialization;
using System.Collections.Generic;
using System.Runtime.Serialization;
namespace Umbraco.Web.Models.ContentEditing
{
@@ -33,5 +34,11 @@ namespace Umbraco.Web.Models.ContentEditing
[DataMember(Name = "view", IsRequired = true)]
public string View { get; set; }
/// <summary>
/// This allows for custom configuration to be injected into the pre-value editor
/// </summary>
[DataMember(Name = "config")]
public IDictionary<string, object> Config { get; set; }
}
}

View File

@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Umbraco.Core;
using Umbraco.Core.PropertyEditors;
@@ -16,7 +17,18 @@ namespace Umbraco.Web.PropertyEditors
public ContentPickerPropertyEditor()
{
InternalPreValues["idType"] = "int";
}
}
/// <summary>
/// overridden to change the pre-value picker to use INT ids
/// </summary>
/// <returns></returns>
protected override PreValueEditor CreatePreValueEditor()
{
var preValEditor = base.CreatePreValueEditor();
preValEditor.Fields.Single(x => x.Key == "startNodeId").Config["idType"] = "int";
return preValEditor;
}
}
/// <summary>
@@ -52,12 +64,27 @@ namespace Umbraco.Web.PropertyEditors
internal class ContentPickerPreValueEditor : PreValueEditor
{
[PreValueField("showOpenButton", "Show open button (this feature is in preview!)", "boolean", Description = " Opens the node in a dialog")]
public string ShowOpenButton { get; set; }
[PreValueField("startNodeId", "Start node", "treepicker")]
public int StartNodeId { get; set; }
public ContentPickerPreValueEditor()
{
//create the fields
Fields.Add(new PreValueField()
{
Key = "showOpenButton",
View = "boolean",
Name = "Show open button (this feature is in preview!)",
Description = "Opens the node in a dialog"
});
Fields.Add(new PreValueField()
{
Key = "startNodeId",
View = "treepicker",
Name = "Start node",
Config = new Dictionary<string, object>
{
{"idType", "udi"}
}
});
}
}
}
}

View File

@@ -67,17 +67,40 @@ namespace Umbraco.Web.PropertyEditors
internal class MediaPickerPreValueEditor : PreValueEditor
{
[PreValueField("multiPicker", "Pick multiple items", "boolean")]
public bool MultiPicker { get; set; }
[PreValueField("onlyImages", "Pick only images", "boolean", Description = "Only let the editor choose images from media.")]
public bool OnlyImages { get; set; }
[PreValueField("disableFolderSelect", "Disable folder select", "boolean", Description = "Do not allow folders to be picked.")]
public bool DisableFolderSelect { get; set; }
[PreValueField("startNodeId", "Start node", "mediapicker")]
public int StartNodeId { get; set; }
public MediaPickerPreValueEditor()
{
//create the fields
Fields.Add(new PreValueField()
{
Key = "multiPicker",
View = "boolean",
Name = "Pick multiple items"
});
Fields.Add(new PreValueField()
{
Key = "onlyImages",
View = "boolean",
Name = "Pick only images",
Description = "Only let the editor choose images from media."
});
Fields.Add(new PreValueField()
{
Key = "disableFolderSelect",
View = "boolean",
Name = "Disable folder select",
Description = "Do not allow folders to be picked."
});
Fields.Add(new PreValueField()
{
Key = "startNodeId",
View = "mediapicker",
Name = "Start node",
Config = new Dictionary<string, object>
{
{"idType", "udi"}
}
});
}
}
}
}

View File

@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Umbraco.Core;
using Umbraco.Core.Models;
using Umbraco.Core.PropertyEditors;
@@ -14,6 +15,17 @@ namespace Umbraco.Web.PropertyEditors
{
InternalPreValues["idType"] = "int";
}
/// <summary>
/// overridden to change the pre-value picker to use INT ids
/// </summary>
/// <returns></returns>
protected override PreValueEditor CreatePreValueEditor()
{
var preValEditor = base.CreatePreValueEditor();
preValEditor.Fields.Single(x => x.Key == "startNode").Config["idType"] = "int";
return preValEditor;
}
}
[PropertyEditor(Constants.PropertyEditors.MultiNodeTreePicker2Alias, "Multinode Treepicker", PropertyEditorValueTypes.Text, "contentpicker", Group="pickers", Icon="icon-page-add")]
@@ -45,20 +57,46 @@ namespace Umbraco.Web.PropertyEditors
internal class MultiNodePickerPreValueEditor : PreValueEditor
{
[PreValueField("startNode", "Node type", "treesource")]
public string StartNode { get; set; }
[PreValueField("filter", "Allow items of type", "textstring", Description = "Separate with comma")]
public string Filter { get; set; }
[PreValueField("minNumber", "Minimum number of items", "number")]
public string MinNumber { get; set; }
[PreValueField("maxNumber", "Maximum number of items", "number")]
public string MaxNumber { get; set; }
[PreValueField("showOpenButton", "Show open button (this feature is in preview!)", "boolean", Description = " Opens the node in a dialog")]
public string ShowOpenButton { get; set; }
public MultiNodePickerPreValueEditor()
{
//create the fields
Fields.Add(new PreValueField()
{
Key = "startNode",
View = "treesource",
Name = "Node type",
Config = new Dictionary<string, object>
{
{"idType", "udi"}
}
});
Fields.Add(new PreValueField()
{
Key = "filter",
View = "textstring",
Name = "Allow items of type",
Description = "Separate with comma"
});
Fields.Add(new PreValueField()
{
Key = "minNumber",
View = "number",
Name = "Minimum number of items"
});
Fields.Add(new PreValueField()
{
Key = "maxNumber",
View = "number",
Name = "Maximum number of items"
});
Fields.Add(new PreValueField()
{
Key = "showOpenButton",
View = "boolean",
Name = "Show open button (this feature is in preview!)",
Description = "Opens the node in a dialog"
});
}
/// <summary>
/// This ensures the multiPicker pre-val is set based on the maxNumber of nodes set

View File

@@ -1,4 +1,5 @@
using System;
using System.Linq;
using Umbraco.Core;
using Umbraco.Core.PropertyEditors;
@@ -12,6 +13,17 @@ namespace Umbraco.Web.PropertyEditors
{
//clear the pre-values so it defaults to a multiple picker.
InternalPreValues.Clear();
}
/// <summary>
/// overridden to change the pre-value picker to use INT ids
/// </summary>
/// <returns></returns>
protected override PreValueEditor CreatePreValueEditor()
{
var preValEditor = base.CreatePreValueEditor();
preValEditor.Fields.Single(x => x.Key == "startNodeId").Config["idType"] = "int";
return preValEditor;
}
}
}

View File

@@ -300,24 +300,31 @@ namespace Umbraco.Web.Trees
}
/// <summary>
/// Get an entity via an id that can be either an integer or a Guid
/// Get an entity via an id that can be either an integer, Guid or UDI
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
internal IUmbracoEntity GetEntityFromId(string id)
{
IUmbracoEntity entity;
Guid idGuid = Guid.Empty;
int idInt;
Udi idUdi;
if (Guid.TryParse(id, out idGuid))
{
entity = Services.EntityService.GetByKey(idGuid, UmbracoObjectType);
}
else if (int.TryParse(id, out idInt))
{
entity = Services.EntityService.Get(idInt, UmbracoObjectType);
}
else if (Udi.TryParse(id, out idUdi))
{
var guidUdi = idUdi as GuidUdi;
entity = guidUdi != null ? Services.EntityService.GetByKey(guidUdi.Guid, UmbracoObjectType) : null;
}
else
{
return null;