Fixes property editors that have default pre-values for those prevalues to show up when creating a new data type, fixes: U4-3147 Create tag supported property editors - and adds the tag group to the pre-values for the tag property editor.

This commit is contained in:
Shannon
2013-10-29 18:17:10 +11:00
parent 37464e5f0f
commit d62aae0205
11 changed files with 238 additions and 55 deletions

View File

@@ -39,8 +39,7 @@ namespace Umbraco.Web.Models.Mapping
{
var resolver = new PreValueDisplayResolver(lazyDataTypeService);
return resolver.Convert(definition);
});
});
config.CreateMap<DataTypeSave, IDataTypeDefinition>()
.ConstructUsing(save => new DataTypeDefinition(-1, save.SelectedEditor) {CreateDate = DateTime.Now})
@@ -48,6 +47,20 @@ namespace Umbraco.Web.Models.Mapping
.ForMember(definition => definition.PropertyEditorAlias, expression => expression.MapFrom(save => save.SelectedEditor))
.ForMember(definition => definition.ParentId, expression => expression.MapFrom(save => -1))
.ForMember(definition => definition.DatabaseType, expression => expression.ResolveUsing<DatabaseTypeResolver>());
//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
config.CreateMap<PropertyEditor, IEnumerable<PreValueFieldDisplay>>()
.ConvertUsing(editor =>
{
//this is a new data type, so just return the field editors, there are no values yet
var defaultVals = editor.DefaultPreValues;
var fields = editor.PreValueEditor.Fields.Select(Mapper.Map<PreValueFieldDisplay>).ToArray();
if (defaultVals != null)
{
PreValueDisplayResolver.MapPreValueValuesToPreValueFields(fields, defaultVals, true);
}
return fields;
});
}
}
}

View File

@@ -20,6 +20,47 @@ namespace Umbraco.Web.Models.Mapping
_dataTypeService = dataTypeService;
}
/// <summary>
/// Maps pre-values in the dictionary to the values for the fields
/// </summary>
/// <param name="fields"></param>
/// <param name="preValues"></param>
/// <param name="isDictionaryBased"></param>
internal static void MapPreValueValuesToPreValueFields(PreValueFieldDisplay[] fields, IDictionary<string, object> preValues, bool isDictionaryBased)
{
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
var currentIndex = 0; //used if the collection is non-dictionary based.
foreach (var field in fields)
{
if (isDictionaryBased == false)
{
//we'll just need to wire up the values based on the order that the pre-values are stored
var found = preValues.Any(x => x.Key.InvariantEquals(currentIndex.ToInvariantString()));
if (found == false)
{
LogHelper.Warn<PreValueDisplayResolver>("Could not find persisted pre-value for index " + currentIndex);
continue;
}
field.Value = preValues.Single(x => x.Key.InvariantEquals(currentIndex.ToInvariantString())).Value.ToString();
currentIndex++;
}
else
{
var found = preValues.Any(x => x.Key.InvariantEquals(field.Key));
if (found == false)
{
LogHelper.Warn<PreValueDisplayResolver>("Could not find persisted pre-value for field " + field.Key);
continue;
}
field.Value = preValues.Single(x => x.Key.InvariantEquals(field.Key)).Value;
}
}
}
internal IEnumerable<PreValueFieldDisplay> Convert(IDataTypeDefinition source)
{
PropertyEditor propEd = null;
@@ -45,36 +86,7 @@ namespace Umbraco.Web.Models.Mapping
dictionaryVals = propEd.PreValueEditor.ConvertDbToEditor(propEd.DefaultPreValues, preVals);
}
var currentIndex = 0; //used if the collection is non-dictionary based.
//now we need to wire up the pre-values values with the actual fields defined
foreach (var field in result)
{
if (preVals.IsDictionaryBased == false)
{
//we'll just need to wire up the values based on the order that the pre-values are stored
var found = dictionaryVals.Any(x => x.Key.InvariantEquals(currentIndex.ToInvariantString()));
if (found == false)
{
LogHelper.Warn<PreValueDisplayResolver>("Could not find persisted pre-value for index " + currentIndex);
continue;
}
field.Value = dictionaryVals.Single(x => x.Key.InvariantEquals(currentIndex.ToInvariantString())).Value.ToString();
currentIndex++;
}
else
{
var found = dictionaryVals.Any(x => x.Key.InvariantEquals(field.Key));
if (found == false)
{
LogHelper.Warn<PreValueDisplayResolver>("Could not find persisted pre-value for field " + field.Key);
continue;
}
field.Value = dictionaryVals.Single(x => x.Key.InvariantEquals(field.Key)).Value;
}
}
MapPreValueValuesToPreValueFields(result, dictionaryVals, preVals.IsDictionaryBased);
return result;
}