diff --git a/src/Umbraco.Web.UI.Client/src/views/propertyeditors/umbraco/readonlyvalue/readonlyvalue.html b/src/Umbraco.Web.UI.Client/src/views/propertyeditors/umbraco/readonlyvalue/readonlyvalue.html new file mode 100644 index 0000000000..738adb1ff6 --- /dev/null +++ b/src/Umbraco.Web.UI.Client/src/views/propertyeditors/umbraco/readonlyvalue/readonlyvalue.html @@ -0,0 +1,3 @@ +

+ {{model.value|json}} +

\ No newline at end of file diff --git a/src/Umbraco.Web.UI/App_Plugins/MyPackage/Package.manifest b/src/Umbraco.Web.UI/App_Plugins/MyPackage/Package.manifest index 45ce06e8fc..745d7c7814 100644 --- a/src/Umbraco.Web.UI/App_Plugins/MyPackage/Package.manifest +++ b/src/Umbraco.Web.UI/App_Plugins/MyPackage/Package.manifest @@ -1,10 +1,10 @@ { - propertyEditors: [ + propertyEditors: [ { id: "30CA72BD-A349-4386-B935-FA532DF24B4B", name: "Rich Text Editor", editor: { - view: "~/umbraco/Views/propertyeditors/rte/rte.html" + view: "~/umbraco/Views/propertyeditors/umbraco/rte/editor.html" } }, { diff --git a/src/Umbraco.Web.UI/umbraco/Views/propertyeditors/rte/rte.html b/src/Umbraco.Web.UI/umbraco/Views/propertyeditors/rte/rte.html deleted file mode 100644 index 6234d73fe1..0000000000 --- a/src/Umbraco.Web.UI/umbraco/Views/propertyeditors/rte/rte.html +++ /dev/null @@ -1,3 +0,0 @@ -
- -
\ No newline at end of file diff --git a/src/Umbraco.Web/Models/Mapping/BaseContentModelMapper.cs b/src/Umbraco.Web/Models/Mapping/BaseContentModelMapper.cs new file mode 100644 index 0000000000..b716c39c4f --- /dev/null +++ b/src/Umbraco.Web/Models/Mapping/BaseContentModelMapper.cs @@ -0,0 +1,160 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Umbraco.Core; +using Umbraco.Core.Configuration; +using Umbraco.Core.Models; +using Umbraco.Core.PropertyEditors; +using Umbraco.Web.Models.ContentEditing; + +namespace Umbraco.Web.Models.Mapping +{ + internal class BaseContentModelMapper + { + protected ApplicationContext ApplicationContext { get; private set; } + protected ProfileModelMapper ProfileMapper { get; private set; } + + public BaseContentModelMapper(ApplicationContext applicationContext, ProfileModelMapper profileMapper) + { + ApplicationContext = applicationContext; + ProfileMapper = profileMapper; + } + + protected ContentItemDto ToContentItemDtoBase(IContentBase content) + { + return CreateContent(content, null, (propertyDto, originalProperty, propEditor) => + { + propertyDto.Alias = originalProperty.Alias; + propertyDto.Description = originalProperty.PropertyType.Description; + propertyDto.Label = originalProperty.PropertyType.Name; + propertyDto.DataType = ApplicationContext.Services.DataTypeService.GetDataTypeDefinitionById(originalProperty.PropertyType.DataTypeDefinitionId); + propertyDto.PropertyEditor = PropertyEditorResolver.Current.GetById(originalProperty.PropertyType.DataTypeId); + }); + } + + protected ContentItemBasic ToContentItemSimpleBase(IContentBase content) + { + return CreateContent, ContentPropertyBasic>(content, null, null); + } + + protected IList> GetTabs(IContentBase content) + { + var tabs = content.PropertyGroups.Select(propertyGroup => + { + //get the properties for the current tab + var propertiesForTab = content.GetPropertiesForGroup(propertyGroup).ToArray(); + + //convert the properties to ContentPropertyDisplay objects + var displayProperties = propertiesForTab + .Select(ToContentPropertyDisplay); + + //return the tab with the tab properties + return new Tab + { + Id = propertyGroup.Id, + Alias = propertyGroup.Name, + Label = propertyGroup.Name, + Properties = displayProperties + }; + }).ToList(); + + //now add the generic properties tab for any properties that don't belong to a tab + var orphanProperties = content.GetNonGroupedProperties(); + + //now add the generic properties tab + tabs.Add(new Tab + { + Id = 0, + Label = "Generic properties", + Alias = "Generic properties", + Properties = orphanProperties.Select(ToContentPropertyDisplay).ToArray() + }); + + return tabs; + } + + protected TContent CreateContent(IContentBase content, + Action contentCreatedCallback = null, + Action propertyCreatedCallback = null, + bool createProperties = true) + where TContent : ContentItemBasic, new() + where TContentProperty : ContentPropertyBasic, new() + { + var result = new TContent + { + Id = content.Id, + Owner = ProfileMapper.ToBasicUser(content.GetCreatorProfile()), + + ParentId = content.ParentId, + UpdateDate = content.UpdateDate, + CreateDate = content.CreateDate, + Name = content.Name + }; + if (createProperties) + result.Properties = content.Properties.Select(p => CreateProperty(p, propertyCreatedCallback)).ToArray(); + if (contentCreatedCallback != null) + contentCreatedCallback(result, content); + return result; + } + + protected ContentPropertyDisplay ToContentPropertyDisplay(Property property) + { + return CreateProperty(property, (display, originalProp, propEditor) => + { + //set the display properties after mapping + display.Alias = originalProp.Alias; + display.Description = originalProp.PropertyType.Description; + display.Label = property.PropertyType.Name; + display.Config = ApplicationContext.Services.DataTypeService.GetPreValuesByDataTypeId(property.PropertyType.DataTypeDefinitionId); + if (propEditor == null) + { + //if there is no property editor it means that it is a legacy data type + // we cannot support editing with that so we'll just render the readonly value view. + display.View = GlobalSettings.Path.EnsureEndsWith('/') + "views/propertyeditors/umbraco/readonlyvalue/readonlyvalue.html"; + } + + }); + } + + /// + /// Creates the property with the basic property values mapped + /// + /// + /// + /// + /// + protected static TContentProperty CreateProperty( + Property property, + Action callback = null) + where TContentProperty : ContentPropertyBasic, new() + { + var editor = PropertyEditorResolver.Current.GetById(property.PropertyType.DataTypeId); + if (editor == null) + { + //TODO: Remove this check as we shouldn't support this at all! + var legacyEditor = DataTypesResolver.Current.GetById(property.PropertyType.DataTypeId); + if (legacyEditor == null) + { + throw new NullReferenceException("The property editor with id " + property.PropertyType.DataTypeId + " does not exist"); + } + + var legacyResult = new TContentProperty + { + Id = property.Id, + Value = property.Value.ToString(), + Alias = property.Alias + }; + if (callback != null) callback(legacyResult, property, null); + return legacyResult; + } + var result = new TContentProperty + { + Id = property.Id, + Value = editor.ValueEditor.SerializeValue(property.Value), + Alias = property.Alias + }; + if (callback != null) callback(result, property, editor); + return result; + } + } +} \ No newline at end of file