diff --git a/src/Umbraco.Web.UI.Client/src/views/propertyeditors/contentpicker/contentpicker.controller.js b/src/Umbraco.Web.UI.Client/src/views/propertyeditors/contentpicker/contentpicker.controller.js index a56af3b4ae..27df035914 100644 --- a/src/Umbraco.Web.UI.Client/src/views/propertyeditors/contentpicker/contentpicker.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/propertyeditors/contentpicker/contentpicker.controller.js @@ -17,21 +17,11 @@ function contentPickerController($scope, entityResource, editorState, iconHelper $scope.$watch(function () { //return the joined Ids as a string to watch return _.map($scope.renderModel, function (i) { - if ($scope.model.config.idType === "udi") { - return i.udi; - } - else { - return i.id; - } + return $scope.model.config.idType === "udi" ? i.udi : i.id; }).join(); }, function (newVal) { var currIds = _.map($scope.renderModel, function (i) { - if ($scope.model.config.idType === "udi") { - return i.udi; - } - else { - return i.id; - } + return $scope.model.config.idType === "udi" ? i.udi : i.id; }); $scope.model.value = trim(currIds.join(), ","); @@ -210,15 +200,12 @@ function contentPickerController($scope, entityResource, editorState, iconHelper $scope.add = function (item) { var currIds = _.map($scope.renderModel, function (i) { - if ($scope.model.config.idType === "udi") { - return i.udi; - } - else { - return i.id; - } + return $scope.model.config.idType === "udi" ? i.udi : i.id; }); - if (currIds.indexOf(item.id) < 0) { + var itemId = $scope.model.config.idType === "udi" ? item.udi : item.id; + + if (currIds.indexOf(itemId) < 0) { setEntityUrl(item); } }; @@ -242,12 +229,7 @@ function contentPickerController($scope, entityResource, editorState, iconHelper var unsubscribe = $scope.$on("formSubmitting", function (ev, args) { var currIds = _.map($scope.renderModel, function (i) { - if ($scope.model.config.idType === "udi") { - return i.udi; - } - else { - return i.id; - } + return $scope.model.config.idType === "udi" ? i.udi : i.id; }); $scope.model.value = trim(currIds.join(), ","); }); @@ -264,12 +246,7 @@ function contentPickerController($scope, entityResource, editorState, iconHelper _.each(modelIds, function (id, i) { var entity = _.find(data, function (d) { - if ($scope.model.config.idType === "udi") { - return d.udi == id; - } - else { - return d.id == id; - } + return $scope.model.config.idType === "udi" ? (d.udi == id) : (d.id == id); }); if (entity) { diff --git a/src/Umbraco.Web.UI.Client/src/views/propertyeditors/memberpicker/memberpicker.controller.js b/src/Umbraco.Web.UI.Client/src/views/propertyeditors/memberpicker/memberpicker.controller.js index 0029332f64..efa05ae882 100644 --- a/src/Umbraco.Web.UI.Client/src/views/propertyeditors/memberpicker/memberpicker.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/propertyeditors/memberpicker/memberpicker.controller.js @@ -68,12 +68,19 @@ function memberPickerController($scope, dialogService, entityResource, $log, ico $scope.add = function (item) { var currIds = _.map($scope.renderModel, function (i) { - return i.id; + if ($scope.model.config.idType === "udi") { + return i.udi; + } + else { + return i.id; + } }); - if (currIds.indexOf(item.id) < 0) { + var itemId = $scope.model.config.idType === "udi" ? item.udi : item.id; + + 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, udi: item.udi, icon: item.icon}); } }; @@ -83,7 +90,12 @@ function memberPickerController($scope, dialogService, entityResource, $log, ico var unsubscribe = $scope.$on("formSubmitting", function (ev, args) { var currIds = _.map($scope.renderModel, function (i) { - return i.id; + if ($scope.model.config.idType === "udi") { + return i.udi; + } + else { + return i.id; + } }); $scope.model.value = trim(currIds.join(), ","); }); @@ -99,7 +111,7 @@ function memberPickerController($scope, dialogService, entityResource, $log, ico _.each(data, function (item, i) { // set default icon if it's missing item.icon = (item.icon) ? iconHelper.convertFromLegacyIcon(item.icon) : "icon-user"; - $scope.renderModel.push({ name: item.name, id: item.id, icon: item.icon }); + $scope.renderModel.push({ name: item.name, id: item.id, udi: item.udi, icon: item.icon }); }); }); } diff --git a/src/Umbraco.Web/Models/Mapping/EntityModelMapper.cs b/src/Umbraco.Web/Models/Mapping/EntityModelMapper.cs index 361836e529..cd6b9b9f83 100644 --- a/src/Umbraco.Web/Models/Mapping/EntityModelMapper.cs +++ b/src/Umbraco.Web/Models/Mapping/EntityModelMapper.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using AutoMapper; using Examine; +using Examine.LuceneEngine.Providers; using Umbraco.Core; using Umbraco.Core.Models; using Umbraco.Core.Models.Mapping; @@ -94,21 +95,40 @@ namespace Umbraco.Web.Models.Mapping .ForMember(dto => dto.Trashed, expression => expression.Ignore()) .ForMember(x => x.AdditionalData, expression => expression.Ignore()) .AfterMap((result, basic) => - { + { + //get the icon if there is one basic.Icon = result.Fields.ContainsKey(UmbracoContentIndexer.IconFieldName) ? result.Fields[UmbracoContentIndexer.IconFieldName] : "icon-document"; basic.Name = result.Fields.ContainsKey("nodeName") ? result.Fields["nodeName"] : "[no name]"; - if (result.Fields.ContainsKey("__NodeKey")) + if (result.Fields.ContainsKey(UmbracoContentIndexer.NodeKeyFieldName)) { Guid key; - if (Guid.TryParse(result.Fields["__NodeKey"], out key)) + if (Guid.TryParse(result.Fields[UmbracoContentIndexer.NodeKeyFieldName], out key)) { basic.Key = key; + + //need to set the UDI + if (result.Fields.ContainsKey(LuceneIndexer.IndexTypeFieldName)) + { + switch (result.Fields[LuceneIndexer.IndexTypeFieldName]) + { + case IndexTypes.Member: + basic.Udi = new GuidUdi(Constants.UdiEntityType.Member, basic.Key); + break; + case IndexTypes.Content: + basic.Udi = new GuidUdi(Constants.UdiEntityType.Document, basic.Key); + break; + case IndexTypes.Media: + basic.Udi = new GuidUdi(Constants.UdiEntityType.Media, basic.Key); + break; + } + } } } + if (result.Fields.ContainsKey("parentID")) { int parentId; @@ -121,7 +141,7 @@ namespace Umbraco.Web.Models.Mapping basic.ParentId = -1; } } - basic.Path = result.Fields.ContainsKey("__Path") ? result.Fields["__Path"] : ""; + basic.Path = result.Fields.ContainsKey(UmbracoContentIndexer.IndexPathFieldName) ? result.Fields[UmbracoContentIndexer.IndexPathFieldName] : ""; if (result.Fields.ContainsKey(UmbracoContentIndexer.NodeTypeAliasFieldName)) { diff --git a/src/Umbraco.Web/PropertyEditors/MemberPickerPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/MemberPickerPropertyEditor.cs index 7314121e70..68f864e9b6 100644 --- a/src/Umbraco.Web/PropertyEditors/MemberPickerPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/MemberPickerPropertyEditor.cs @@ -13,10 +13,28 @@ namespace Umbraco.Web.PropertyEditors [PropertyEditor(Constants.PropertyEditors.MemberPickerAlias, "(Obsolete) Member Picker", PropertyEditorValueTypes.Integer, "memberpicker", Group = "People", Icon = "icon-user", IsDeprecated = true)] public class MemberPickerPropertyEditor : MemberPickerPropertyEditor2 { + public MemberPickerPropertyEditor() + { + InternalPreValues["idType"] = "int"; + } } [PropertyEditor(Constants.PropertyEditors.MemberPicker2Alias, "Member Picker", PropertyEditorValueTypes.String, "memberpicker", Group = "People", Icon = "icon-user")] public class MemberPickerPropertyEditor2 : PropertyEditor { + public MemberPickerPropertyEditor2() + { + InternalPreValues = new Dictionary + { + {"idType", "udi"} + }; + } + + internal IDictionary InternalPreValues; + public override IDictionary DefaultPreValues + { + get { return InternalPreValues; } + set { InternalPreValues = value; } + } } } diff --git a/src/UmbracoExamine/UmbracoContentIndexer.cs b/src/UmbracoExamine/UmbracoContentIndexer.cs index e7df641122..1798596668 100644 --- a/src/UmbracoExamine/UmbracoContentIndexer.cs +++ b/src/UmbracoExamine/UmbracoContentIndexer.cs @@ -183,6 +183,7 @@ namespace UmbracoExamine /// Used to store the path of a content object /// public const string IndexPathFieldName = "__Path"; + public const string NodeKeyFieldName = "__Key"; public const string NodeTypeAliasFieldName = "__NodeTypeAlias"; public const string IconFieldName = "__Icon"; @@ -726,18 +727,23 @@ namespace UmbracoExamine //ensure the special path and node type alias fields is added to the dictionary to be saved to file var path = e.Node.Attribute("path").Value; - if (!e.Fields.ContainsKey(IndexPathFieldName)) + if (e.Fields.ContainsKey(IndexPathFieldName) == false) e.Fields.Add(IndexPathFieldName, path); //this needs to support both schema's so get the nodeTypeAlias if it exists, otherwise the name var nodeTypeAlias = e.Node.Attribute("nodeTypeAlias") == null ? e.Node.Name.LocalName : e.Node.Attribute("nodeTypeAlias").Value; - if (!e.Fields.ContainsKey(NodeTypeAliasFieldName)) + if (e.Fields.ContainsKey(NodeTypeAliasFieldName) == false) e.Fields.Add(NodeTypeAliasFieldName, nodeTypeAlias); //add icon var icon = (string)e.Node.Attribute("icon"); - if (!e.Fields.ContainsKey(IconFieldName)) - e.Fields.Add(IconFieldName, icon); + if (e.Fields.ContainsKey(IconFieldName) == false) + e.Fields.Add(IconFieldName, icon); + + //add guid + var guid = (string)e.Node.Attribute("key"); + if (e.Fields.ContainsKey(NodeKeyFieldName) == false) + e.Fields.Add(NodeKeyFieldName, guid); } /// @@ -768,6 +774,12 @@ namespace UmbracoExamine //adds the special node type alias property to the index fields.Add(NodeTypeAliasFieldName, allValuesForIndexing[NodeTypeAliasFieldName]); + //guid + if (allValuesForIndexing[IconFieldName].IsNullOrWhiteSpace() == false) + { + fields.Add(NodeKeyFieldName, allValuesForIndexing[NodeKeyFieldName]); + } + //icon if (allValuesForIndexing[IconFieldName].IsNullOrWhiteSpace() == false) { diff --git a/src/UmbracoExamine/UmbracoMemberIndexer.cs b/src/UmbracoExamine/UmbracoMemberIndexer.cs index 2e48dff64e..94cbcb2135 100644 --- a/src/UmbracoExamine/UmbracoMemberIndexer.cs +++ b/src/UmbracoExamine/UmbracoMemberIndexer.cs @@ -231,20 +231,7 @@ namespace UmbracoExamine protected override XDocument GetXDocument(string xPath, string type) { throw new NotSupportedException(); - } - - protected override Dictionary GetSpecialFieldsToIndex(Dictionary allValuesForIndexing) - { - var fields = base.GetSpecialFieldsToIndex(allValuesForIndexing); - - //adds the special path property to the index - string valuesForIndexing; - if (allValuesForIndexing.TryGetValue("__key", out valuesForIndexing)) - fields.Add("__key", valuesForIndexing); - - return fields; - - } + } /// /// Add the special __key and _searchEmail fields @@ -256,8 +243,8 @@ namespace UmbracoExamine if (e.Node.Attribute("key") != null) { - if (e.Fields.ContainsKey("__key") == false) - e.Fields.Add("__key", e.Node.Attribute("key").Value); + if (e.Fields.ContainsKey(NodeKeyFieldName) == false) + e.Fields.Add(NodeKeyFieldName, e.Node.Attribute("key").Value); } if (e.Node.Attribute("email") != null)