DataType refactoring
This commit is contained in:
@@ -15,11 +15,5 @@ namespace Umbraco.Web.Models.ContentEditing
|
||||
public string Description { get; set; }
|
||||
public bool IsRequired { get; set; }
|
||||
public string ValidationRegExp { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The current pre-values for this property
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
internal PreValueCollection PreValues { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,44 +1,43 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace Umbraco.Web.Models.ContentEditing
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines a pre value editable field for a data type
|
||||
/// </summary>
|
||||
[DataContract(Name = "preValue", Namespace = "")]
|
||||
public class PreValueFieldDisplay : PreValueFieldSave
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// The name to display for this pre-value field
|
||||
/// </summary>
|
||||
[DataMember(Name = "label", IsRequired = true)]
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The description to display for this pre-value field
|
||||
/// </summary>
|
||||
[DataMember(Name = "description")]
|
||||
public string Description { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Specifies whether to hide the label for the pre-value
|
||||
/// </summary>
|
||||
[DataMember(Name = "hideLabel")]
|
||||
public bool HideLabel { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The view to render for the field
|
||||
/// </summary>
|
||||
[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; }
|
||||
|
||||
}
|
||||
}
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace Umbraco.Web.Models.ContentEditing
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a datatype configuration field model for editing.
|
||||
/// </summary>
|
||||
[DataContract(Name = "preValue", Namespace = "")]
|
||||
public class DataTypeConfigurationFieldDisplay : DataTypeConfigurationFieldSave
|
||||
{
|
||||
/// <summary>
|
||||
/// The name to display for this pre-value field
|
||||
/// </summary>
|
||||
[DataMember(Name = "label", IsRequired = true)]
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The description to display for this pre-value field
|
||||
/// </summary>
|
||||
[DataMember(Name = "description")]
|
||||
public string Description { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Specifies whether to hide the label for the pre-value
|
||||
/// </summary>
|
||||
[DataMember(Name = "hideLabel")]
|
||||
public bool HideLabel { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The view to render for the field
|
||||
/// </summary>
|
||||
[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; }
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,23 +1,23 @@
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace Umbraco.Web.Models.ContentEditing
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines a pre value editable field for a data type
|
||||
/// </summary>
|
||||
[DataContract(Name = "preValue", Namespace = "")]
|
||||
public class PreValueFieldSave
|
||||
{
|
||||
/// <summary>
|
||||
/// The key to store the pre-value against
|
||||
/// </summary>
|
||||
[DataMember(Name = "key", IsRequired = true)]
|
||||
public string Key { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The value stored for the pre-value field
|
||||
/// </summary>
|
||||
[DataMember(Name = "value", IsRequired = true)]
|
||||
public object Value { get; set; }
|
||||
}
|
||||
}
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace Umbraco.Web.Models.ContentEditing
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a datatype configuration field model for editing.
|
||||
/// </summary>
|
||||
[DataContract(Name = "preValue", Namespace = "")]
|
||||
public class DataTypeConfigurationFieldSave
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the configuration field key.
|
||||
/// </summary>
|
||||
[DataMember(Name = "key", IsRequired = true)]
|
||||
public string Key { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the configuration field value.
|
||||
/// </summary>
|
||||
[DataMember(Name = "value", IsRequired = true)]
|
||||
public object Value { get; set; } // fixme - what's a value?
|
||||
}
|
||||
}
|
||||
@@ -27,7 +27,7 @@ namespace Umbraco.Web.Models.ContentEditing
|
||||
public IEnumerable<PropertyEditorBasic> AvailableEditors { get; set; }
|
||||
|
||||
[DataMember(Name = "preValues")]
|
||||
public IEnumerable<PreValueFieldDisplay> PreValues { get; set; }
|
||||
public IEnumerable<DataTypeConfigurationFieldDisplay> PreValues { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// This is used to add custom localized messages/strings to the response for the app to use for localized UI purposes.
|
||||
|
||||
@@ -8,34 +8,43 @@ using Umbraco.Core.PropertyEditors;
|
||||
|
||||
namespace Umbraco.Web.Models.ContentEditing
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a datatype model for editing.
|
||||
/// </summary>
|
||||
[DataContract(Name = "dataType", Namespace = "")]
|
||||
public class DataTypeSave : EntityBasic
|
||||
{
|
||||
/// <summary>
|
||||
/// The action to perform when saving this data type
|
||||
/// Gets or sets the action to perform.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// If either of the Publish actions are specified an exception will be thrown.
|
||||
/// Some values (publish) are illegal here.
|
||||
/// </remarks>
|
||||
[DataMember(Name = "action", IsRequired = true)]
|
||||
[Required]
|
||||
public ContentSaveAction Action { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the datatype editor.
|
||||
/// </summary>
|
||||
[DataMember(Name = "selectedEditor", IsRequired = true)]
|
||||
[Required]
|
||||
public string SelectedEditor { get; set; }
|
||||
|
||||
[DataMember(Name = "preValues")]
|
||||
public IEnumerable<PreValueFieldSave> PreValues { get; set; }
|
||||
public string EditorAlias { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The real persisted data type
|
||||
/// Gets or sets the datatype configuration fields.
|
||||
/// </summary>
|
||||
[DataMember(Name = "preValues")]
|
||||
public IEnumerable<DataTypeConfigurationFieldSave> ConfigurationFields { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the persisted data type.
|
||||
/// </summary>
|
||||
[IgnoreDataMember]
|
||||
internal IDataType PersistedDataType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The PropertyEditor assigned
|
||||
/// Gets or sets the property editor.
|
||||
/// </summary>
|
||||
[IgnoreDataMember]
|
||||
internal PropertyEditor PropertyEditor { get; set; }
|
||||
|
||||
@@ -123,7 +123,7 @@ namespace Umbraco.Web.Models.Mapping
|
||||
Alias = $"{Constants.PropertyEditors.InternalGenericPropertiesPrefix}doctype",
|
||||
Label = localizedText.Localize("content/documentType"),
|
||||
Value = localizedText.UmbracoDictionaryTranslate(display.ContentTypeName),
|
||||
View = Current.PropertyEditors[Constants.PropertyEditors.NoEditAlias].ValueEditor.View
|
||||
View = Current.PropertyEditors[Constants.PropertyEditors.Aliases.NoEdit].ValueEditor.View
|
||||
},
|
||||
new ContentPropertyDisplay
|
||||
{
|
||||
@@ -131,7 +131,7 @@ namespace Umbraco.Web.Models.Mapping
|
||||
Label = localizedText.Localize("content/releaseDate"),
|
||||
Value = display.ReleaseDate?.ToIsoString(),
|
||||
//Not editible for people without publish permission (U4-287)
|
||||
View = display.AllowedActions.Contains(ActionPublish.Instance.Letter.ToString(CultureInfo.InvariantCulture)) ? "datepicker" : Current.PropertyEditors[Constants.PropertyEditors.NoEditAlias].ValueEditor.View,
|
||||
View = display.AllowedActions.Contains(ActionPublish.Instance.Letter.ToString(CultureInfo.InvariantCulture)) ? "datepicker" : Current.PropertyEditors[Constants.PropertyEditors.Aliases.NoEdit].ValueEditor.View,
|
||||
Config = new Dictionary<string, object>
|
||||
{
|
||||
{"offsetTime", "1"}
|
||||
@@ -144,7 +144,7 @@ namespace Umbraco.Web.Models.Mapping
|
||||
Label = localizedText.Localize("content/unpublishDate"),
|
||||
Value = display.ExpireDate.HasValue ? display.ExpireDate.Value.ToIsoString() : null,
|
||||
//Not editible for people without publish permission (U4-287)
|
||||
View = display.AllowedActions.Contains(ActionPublish.Instance.Letter.ToString(CultureInfo.InvariantCulture)) ? "datepicker" : Current.PropertyEditors[Constants.PropertyEditors.NoEditAlias].ValueEditor.View,
|
||||
View = display.AllowedActions.Contains(ActionPublish.Instance.Letter.ToString(CultureInfo.InvariantCulture)) ? "datepicker" : Current.PropertyEditors[Constants.PropertyEditors.Aliases.NoEdit].ValueEditor.View,
|
||||
Config = new Dictionary<string, object>
|
||||
{
|
||||
{"offsetTime", "1"}
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace Umbraco.Web.Models.Mapping
|
||||
"No property editor found, converting to a Label",
|
||||
new NullReferenceException("The property editor with alias " + property.PropertyType.PropertyEditorAlias + " does not exist"));
|
||||
|
||||
editor = Current.PropertyEditors[Constants.PropertyEditors.NoEditAlias];
|
||||
editor = Current.PropertyEditors[Constants.PropertyEditors.Aliases.NoEdit];
|
||||
}
|
||||
var result = new TDestination
|
||||
{
|
||||
|
||||
@@ -23,11 +23,11 @@ namespace Umbraco.Web.Models.Mapping
|
||||
var display = base.Convert(originalProp, dest, context);
|
||||
|
||||
var dataTypeService = DataTypeService.Value;
|
||||
var preVals = dataTypeService.GetPreValuesCollectionByDataTypeId(originalProp.PropertyType.DataTypeDefinitionId);
|
||||
var config = dataTypeService.GetDataType(originalProp.PropertyType.DataTypeDefinitionId).Configuration;
|
||||
|
||||
//configure the editor for display with the pre-values
|
||||
var valEditor = display.PropertyEditor.ValueEditor;
|
||||
valEditor.ConfigureForDisplay(preVals);
|
||||
valEditor.ConfigureForDisplay(config);
|
||||
|
||||
//set the display properties after mapping
|
||||
display.Alias = originalProp.Alias;
|
||||
|
||||
@@ -25,10 +25,7 @@ namespace Umbraco.Web.Models.Mapping
|
||||
propertyDto.ValidationRegExp = originalProperty.PropertyType.ValidationRegExp;
|
||||
propertyDto.Description = originalProperty.PropertyType.Description;
|
||||
propertyDto.Label = originalProperty.PropertyType.Name;
|
||||
|
||||
//TODO: We should be able to look both of these up at the same time!
|
||||
propertyDto.DataType = dataTypeService.GetDataType(originalProperty.PropertyType.DataTypeDefinitionId);
|
||||
propertyDto.PreValues = dataTypeService.GetPreValuesCollectionByDataTypeId(originalProperty.PropertyType.DataTypeDefinitionId);
|
||||
|
||||
return propertyDto;
|
||||
}
|
||||
|
||||
@@ -1,76 +1,80 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using AutoMapper;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.PropertyEditors;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Web.Composing;
|
||||
using Umbraco.Web.Models.ContentEditing;
|
||||
|
||||
namespace Umbraco.Web.Models.Mapping
|
||||
{
|
||||
internal class PreValueDisplayResolver
|
||||
{
|
||||
private readonly Lazy<IDataTypeService> _dataTypeService;
|
||||
|
||||
public PreValueDisplayResolver(Lazy<IDataTypeService> dataTypeService)
|
||||
{
|
||||
_dataTypeService = dataTypeService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Maps pre-values in the dictionary to the values for the fields
|
||||
/// </summary>
|
||||
/// <param name="fields"></param>
|
||||
/// <param name="preValues"></param>
|
||||
internal static void MapPreValueValuesToPreValueFields(PreValueFieldDisplay[] fields, IDictionary<string, object> preValues)
|
||||
{
|
||||
if (fields == null) throw new ArgumentNullException("fields");
|
||||
if (preValues == null) throw new ArgumentNullException("preValues");
|
||||
//now we need to wire up the pre-values values with the actual fields defined
|
||||
foreach (var field in fields)
|
||||
{
|
||||
var found = preValues.Any(x => x.Key.InvariantEquals(field.Key));
|
||||
if (found == false)
|
||||
{
|
||||
Current.Logger.Warn<PreValueDisplayResolver>("Could not find persisted pre-value for field " + field.Key);
|
||||
continue;
|
||||
}
|
||||
field.Value = preValues.Single(x => x.Key.InvariantEquals(field.Key)).Value;
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<PreValueFieldDisplay> Resolve(IDataType source)
|
||||
{
|
||||
PropertyEditor propEd = null;
|
||||
if (source.EditorAlias.IsNullOrWhiteSpace() == false)
|
||||
{
|
||||
propEd = Current.PropertyEditors[source.EditorAlias];
|
||||
if (propEd == null)
|
||||
{
|
||||
throw new InvalidOperationException("Could not find property editor with alias " + source.EditorAlias);
|
||||
}
|
||||
}
|
||||
|
||||
//set up the defaults
|
||||
var dataTypeService = _dataTypeService.Value;
|
||||
var preVals = dataTypeService.GetPreValuesCollectionByDataTypeId(source.Id);
|
||||
IDictionary<string, object> dictionaryVals = preVals.FormatAsDictionary().ToDictionary(x => x.Key, x => (object)x.Value);
|
||||
var result = Enumerable.Empty<PreValueFieldDisplay>().ToArray();
|
||||
|
||||
//if we have a prop editor, then format the pre-values based on it and create it's fields.
|
||||
if (propEd != null)
|
||||
{
|
||||
result = propEd.PreValueEditor.Fields.Select(Mapper.Map<PreValueFieldDisplay>).ToArray();
|
||||
dictionaryVals = propEd.PreValueEditor.ConvertDbToEditor(propEd.DefaultPreValues, preVals);
|
||||
}
|
||||
|
||||
MapPreValueValuesToPreValueFields(result, dictionaryVals);
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using AutoMapper;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.PropertyEditors;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Web.Composing;
|
||||
using Umbraco.Web.Models.ContentEditing;
|
||||
|
||||
namespace Umbraco.Web.Models.Mapping
|
||||
{
|
||||
internal class DataTypeConfigurationFieldDisplayResolver
|
||||
{
|
||||
private readonly IDataTypeService _dataTypeService;
|
||||
|
||||
public DataTypeConfigurationFieldDisplayResolver(IDataTypeService dataTypeService)
|
||||
{
|
||||
_dataTypeService = dataTypeService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Maps pre-values in the dictionary to the values for the fields
|
||||
/// </summary>
|
||||
internal static void MapPreValueValuesToPreValueFields(DataTypeConfigurationFieldDisplay[] fields, IDataTypeConfiguration configuration)
|
||||
{
|
||||
if (fields == null) throw new ArgumentNullException(nameof(fields));
|
||||
if (configuration == null) throw new ArgumentNullException(nameof(configuration));
|
||||
|
||||
var preValues = configuration.ToDictionary();
|
||||
|
||||
//now we need to wire up the pre-values values with the actual fields defined
|
||||
foreach (var field in fields)
|
||||
{
|
||||
// fixme - how can we do this with configuration?
|
||||
// we need the configuration to be able to be returned as Dictionary<string, object> in order to be edited!
|
||||
|
||||
var found = preValues.Any(x => x.Key.InvariantEquals(field.Key));
|
||||
if (found == false)
|
||||
{
|
||||
Current.Logger.Warn<DataTypeConfigurationFieldDisplayResolver>("Could not find persisted pre-value for field " + field.Key);
|
||||
continue;
|
||||
}
|
||||
field.Value = preValues.Single(x => x.Key.InvariantEquals(field.Key)).Value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a set of configuration fields for a data type.
|
||||
/// </summary>
|
||||
public IEnumerable<DataTypeConfigurationFieldDisplay> Resolve(IDataType dataType)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(dataType.EditorAlias) || !Current.PropertyEditors.TryGet(dataType.EditorAlias, out var editor))
|
||||
throw new InvalidOperationException($"Could not find a property editor with alias \"{dataType.EditorAlias}\".");
|
||||
|
||||
var configuration = dataType.Configuration;
|
||||
var fields = editor.PreValueEditor.Fields.Select(Mapper.Map<DataTypeConfigurationFieldDisplay>).ToArray();
|
||||
var wtf = editor.PreValueEditor.ConvertDbToEditor(editor.DefaultPreValues, configuration); // but wtf?
|
||||
|
||||
//set up the defaults
|
||||
var dataTypeService = _dataTypeService.Value;
|
||||
var preVals = dataTypeService.GetPreValuesCollectionByDataTypeId(dataType.Id);
|
||||
IDictionary<string, object> dictionaryVals = preVals.FormatAsDictionary().ToDictionary(x => x.Key, x => (object)x.Value);
|
||||
var result = Enumerable.Empty<DataTypeConfigurationFieldDisplay>().ToArray();
|
||||
|
||||
//if we have a prop editor, then format the pre-values based on it and create it's fields.
|
||||
if (propEd != null)
|
||||
{
|
||||
result = propEd.PreValueEditor.Fields.Select(Mapper.Map<DataTypeConfigurationFieldDisplay>).ToArray();
|
||||
dictionaryVals = propEd.PreValueEditor.ConvertDbToEditor(propEd.DefaultPreValues, preVals);
|
||||
}
|
||||
|
||||
MapPreValueValuesToPreValueFields(result, dictionaryVals);
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,23 +13,21 @@ using Umbraco.Web.Models.ContentEditing;
|
||||
namespace Umbraco.Web.Models.Mapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Configure's model mappings for Data types
|
||||
/// Configures model mappings for datatypes.
|
||||
/// </summary>
|
||||
internal class DataTypeMapperProfile : Profile
|
||||
{
|
||||
public DataTypeMapperProfile(IDataTypeService dataTypeService)
|
||||
{
|
||||
var lazyDataTypeService = new Lazy<IDataTypeService>(() => dataTypeService);
|
||||
|
||||
// create, capture, cache
|
||||
var availablePropertyEditorsResolver = new AvailablePropertyEditorsResolver(UmbracoConfig.For.UmbracoSettings().Content);
|
||||
var preValueDisplayResolver = new PreValueDisplayResolver(lazyDataTypeService);
|
||||
var preValueDisplayResolver = new DataTypeConfigurationFieldDisplayResolver(dataTypeService);
|
||||
var databaseTypeResolver = new DatabaseTypeResolver();
|
||||
|
||||
CreateMap<PropertyEditor, PropertyEditorBasic>();
|
||||
|
||||
//just maps the standard properties, does not map the value!
|
||||
CreateMap<PreValueField, PreValueFieldDisplay>()
|
||||
// map the standard properties, not the values
|
||||
CreateMap<DataTypeConfigurationField, DataTypeConfigurationFieldDisplay>()
|
||||
.ForMember(dest => dest.Value, opt => opt.Ignore());
|
||||
|
||||
var systemIds = new[]
|
||||
@@ -59,8 +57,7 @@ namespace Umbraco.Web.Models.Mapping
|
||||
.ForMember(dest => dest.IsSystemDataType, opt => opt.MapFrom(src => systemIds.Contains(src.Id)))
|
||||
.AfterMap((src, dest) =>
|
||||
{
|
||||
var editor = Current.PropertyEditors[src.EditorAlias];
|
||||
if (editor != null)
|
||||
if (Current.PropertyEditors.TryGet(src.EditorAlias, out var editor))
|
||||
{
|
||||
dest.Alias = editor.Alias;
|
||||
dest.Group = editor.Group;
|
||||
@@ -81,8 +78,7 @@ namespace Umbraco.Web.Models.Mapping
|
||||
.ForMember(dest => dest.IsSystemDataType, opt => opt.MapFrom(src => systemIds.Contains(src.Id)))
|
||||
.AfterMap((src, dest) =>
|
||||
{
|
||||
var editor = Current.PropertyEditors[src.EditorAlias];
|
||||
if (editor != null)
|
||||
if (Current.PropertyEditors.TryGet(src.EditorAlias, out var editor))
|
||||
{
|
||||
dest.Group = editor.Group;
|
||||
dest.Icon = editor.Icon;
|
||||
@@ -90,33 +86,31 @@ namespace Umbraco.Web.Models.Mapping
|
||||
});
|
||||
|
||||
//gets a list of PreValueFieldDisplay objects from the data type definition
|
||||
CreateMap<IDataType, IEnumerable<PreValueFieldDisplay>>()
|
||||
CreateMap<IDataType, IEnumerable<DataTypeConfigurationFieldDisplay>>()
|
||||
.ConvertUsing(src => preValueDisplayResolver.Resolve(src));
|
||||
|
||||
CreateMap<DataTypeSave, IDataType>()
|
||||
.ConstructUsing(src => new DataType(src.SelectedEditor) {CreateDate = DateTime.Now})
|
||||
.ConstructUsing(src => new DataType(src.EditorAlias) {CreateDate = DateTime.Now})
|
||||
.IgnoreEntityCommonProperties()
|
||||
.ForMember(dest => dest.Id, opt => opt.MapFrom(src => Convert.ToInt32(src.Id)))
|
||||
//we have to ignore the Key otherwise this will reset the UniqueId field which should never change!
|
||||
// http://issues.umbraco.org/issue/U4-3911
|
||||
.ForMember(dest => dest.Key, opt => opt.Ignore())
|
||||
.ForMember(dest => dest.Key, opt => opt.Ignore()) // ignore key, else resets UniqueId - U4-3911
|
||||
.ForMember(dest => dest.Path, opt => opt.Ignore())
|
||||
.ForMember(dest => dest.EditorAlias, opt => opt.MapFrom(src => src.SelectedEditor))
|
||||
.ForMember(dest => dest.EditorAlias, opt => opt.MapFrom(src => src.EditorAlias))
|
||||
.ForMember(dest => dest.DatabaseType, opt => opt.ResolveUsing(src => databaseTypeResolver.Resolve(src)))
|
||||
.ForMember(dest => dest.CreatorId, opt => opt.Ignore())
|
||||
.ForMember(dest => dest.Level, opt => opt.Ignore())
|
||||
.ForMember(dest => dest.SortOrder, opt => opt.Ignore());
|
||||
|
||||
//Converts a property editor to a new list of pre-value fields - used when creating a new data type or changing a data type with new pre-vals
|
||||
CreateMap<PropertyEditor, IEnumerable<PreValueFieldDisplay>>()
|
||||
CreateMap<PropertyEditor, IEnumerable<DataTypeConfigurationFieldDisplay>>()
|
||||
.ConvertUsing(src =>
|
||||
{
|
||||
//this is a new data type, so just return the field editors, there are no values yet
|
||||
var defaultVals = src.DefaultPreValues;
|
||||
var fields = src.PreValueEditor.Fields.Select(Mapper.Map<PreValueFieldDisplay>).ToArray();
|
||||
var fields = src.PreValueEditor.Fields.Select(Mapper.Map<DataTypeConfigurationFieldDisplay>).ToArray();
|
||||
if (defaultVals != null)
|
||||
{
|
||||
PreValueDisplayResolver.MapPreValueValuesToPreValueFields(fields, defaultVals);
|
||||
DataTypeConfigurationFieldDisplayResolver.MapPreValueValuesToPreValueFields(fields, defaultVals);
|
||||
}
|
||||
return fields;
|
||||
});
|
||||
|
||||
@@ -12,10 +12,10 @@ namespace Umbraco.Web.Models.Mapping
|
||||
{
|
||||
public DataTypeDatabaseType Resolve(DataTypeSave source)
|
||||
{
|
||||
var propertyEditor = Current.PropertyEditors[source.SelectedEditor];
|
||||
var propertyEditor = Current.PropertyEditors[source.EditorAlias];
|
||||
if (propertyEditor == null)
|
||||
{
|
||||
throw new InvalidOperationException("Could not find property editor with id " + source.SelectedEditor);
|
||||
throw new InvalidOperationException("Could not find property editor with id " + source.EditorAlias);
|
||||
}
|
||||
return propertyEditor.ValueEditor.GetDatabaseType();
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ namespace Umbraco.Web.Models.Mapping
|
||||
if (paramEditor == null)
|
||||
{
|
||||
//we'll just map this to a text box
|
||||
paramEditor = Current.ParameterEditors[Constants.PropertyEditors.TextboxAlias];
|
||||
paramEditor = Current.ParameterEditors[Constants.PropertyEditors.Aliases.Textbox];
|
||||
Current.Logger.Warn<MacroMapperProfile>("Could not resolve a parameter editor with alias " + property.EditorAlias + ", a textbox will be rendered in it's place");
|
||||
}
|
||||
|
||||
|
||||
@@ -93,7 +93,7 @@ namespace Umbraco.Web.Models.Mapping
|
||||
Alias = string.Format("{0}doctype", Constants.PropertyEditors.InternalGenericPropertiesPrefix),
|
||||
Label = localizedText.Localize("content/mediatype"),
|
||||
Value = localizedText.UmbracoDictionaryTranslate(display.ContentTypeName),
|
||||
View = Current.PropertyEditors[Constants.PropertyEditors.NoEditAlias].ValueEditor.View
|
||||
View = Current.PropertyEditors[Constants.PropertyEditors.Aliases.NoEdit].ValueEditor.View
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -179,7 +179,7 @@ namespace Umbraco.Web.Models.Mapping
|
||||
Alias = string.Format("{0}doctype", Constants.PropertyEditors.InternalGenericPropertiesPrefix),
|
||||
Label = localizedText.Localize("content/membertype"),
|
||||
Value = localizedText.UmbracoDictionaryTranslate(display.ContentTypeName),
|
||||
View = Current.PropertyEditors[Constants.PropertyEditors.NoEditAlias].ValueEditor.View
|
||||
View = Current.PropertyEditors[Constants.PropertyEditors.Aliases.NoEdit].ValueEditor.View
|
||||
},
|
||||
GetLoginProperty(memberService, member, display, localizedText),
|
||||
new ContentPropertyDisplay
|
||||
|
||||
@@ -199,7 +199,7 @@ namespace Umbraco.Web.Models.Mapping
|
||||
foreach (var p in properties.Where(x => x.DataTypeDefinitionId != 0).OrderBy(x => x.SortOrder))
|
||||
{
|
||||
var propertyEditor = _propertyEditors[p.PropertyEditorAlias];
|
||||
var preValues = _dataTypeService.GetPreValuesCollectionByDataTypeId(p.DataTypeDefinitionId);
|
||||
var configuration = _dataTypeService.GetDataType(p.DataTypeDefinitionId).Configuration;
|
||||
|
||||
if (propertyEditor == null)
|
||||
throw new InvalidOperationException("No property editor could be resolved with the alias: " + p.PropertyEditorAlias + ", ensure all packages are installed correctly.");
|
||||
@@ -213,7 +213,7 @@ namespace Umbraco.Web.Models.Mapping
|
||||
Validation = new PropertyTypeValidation {Mandatory = p.Mandatory, Pattern = p.ValidationRegExp},
|
||||
Label = p.Name,
|
||||
View = propertyEditor.ValueEditor.View,
|
||||
Config = propertyEditor.PreValueEditor.ConvertDbToEditor(propertyEditor.DefaultPreValues, preValues),
|
||||
Config = propertyEditor.PreValueEditor.ConvertDbToEditor(propertyEditor.DefaultPreValues, configuration),
|
||||
//Value = "",
|
||||
GroupId = groupId,
|
||||
Inherited = inherited,
|
||||
|
||||
@@ -57,7 +57,7 @@ namespace Umbraco.Web.Models.Mapping
|
||||
//store the current props to append to the newly inserted ones
|
||||
var currProps = genericProps.Properties.ToArray();
|
||||
|
||||
var labelEditor = Current.PropertyEditors[Constants.PropertyEditors.NoEditAlias].ValueEditor.View;
|
||||
var labelEditor = Current.PropertyEditors[Constants.PropertyEditors.Aliases.NoEdit].ValueEditor.View;
|
||||
|
||||
var contentProps = new List<ContentPropertyDisplay>
|
||||
{
|
||||
@@ -148,8 +148,6 @@ namespace Umbraco.Web.Models.Mapping
|
||||
throw new InvalidOperationException("No list view data type was found for this document type, ensure that the default list view data types exists and/or that your custom list view data type exists");
|
||||
}
|
||||
|
||||
var preVals = dataTypeService.GetPreValuesCollectionByDataTypeId(dt.Id);
|
||||
|
||||
var editor = Current.PropertyEditors[dt.EditorAlias];
|
||||
if (editor == null)
|
||||
{
|
||||
@@ -164,7 +162,7 @@ namespace Umbraco.Web.Models.Mapping
|
||||
IsActive = true
|
||||
};
|
||||
|
||||
var listViewConfig = editor.PreValueEditor.ConvertDbToEditor(editor.DefaultPreValues, preVals);
|
||||
var listViewConfig = editor.PreValueEditor.ConvertDbToEditor(editor.DefaultPreValues, dt.Configuration);
|
||||
//add the entity type to the config
|
||||
listViewConfig["entityType"] = entityType;
|
||||
|
||||
|
||||
@@ -62,10 +62,10 @@ namespace Umbraco.Web.Models
|
||||
// want to return the normal URL and the cropper stores data as json
|
||||
switch (propType.EditorAlias)
|
||||
{
|
||||
case Constants.PropertyEditors.UploadFieldAlias:
|
||||
case Constants.PropertyEditors.Aliases.UploadField:
|
||||
_url = prop.GetValue().ToString();
|
||||
break;
|
||||
case Constants.PropertyEditors.ImageCropperAlias:
|
||||
case Constants.PropertyEditors.Aliases.ImageCropper:
|
||||
//get the url from the json format
|
||||
|
||||
var stronglyTyped = prop.GetValue() as ImageCropDataSet;
|
||||
|
||||
Reference in New Issue
Block a user