Skip to content

Commit

Permalink
1/2 data mapper - only map the value on the way back in #185
Browse files Browse the repository at this point in the history
The value can be exported as is - but internally inside umbraco the value is actualy the ID of the property (which can change per site) so we dont map out but we do map in
  • Loading branch information
KevinJump committed Sep 4, 2018
1 parent 599e8cc commit a7b18dd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
7 changes: 3 additions & 4 deletions Jumoo.uSync.Core/Config/uSyncCore.Config
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,12 @@
<uSyncContentMapping Alias="Umbraco.DropdownlistPublishingKeys" Mapping="DataTypeKeys" />
<uSyncContentMapping Alias="Umbraco.DropdownlistMultiplePublishKeys" Mapping="DataTypeKeys" />

<!--
<uSyncContentMapping Alias="Umbraco.DropDownList" Mapping="DataType" />
<uSyncContentMapping Alias="Umbraco.DropDown" Mapping="DataType" />
<uSyncContentMapping Alias="Umbraco.DropDownMultiple" Mapping="DataType" />
<uSyncContentMapping Alias="Umbraco.CheckBoxList" Mapping="DataType" />
-->
<uSyncContentMapping Alias="Umbraco.CheckBoxList" Mapping="DataType" />
<uSyncContentMapping Alias="Umbraco.DropDown.Flexible" Mapping="DataType"/>

<uSyncContentMapping Alias="Umbraco.Grid" Mapping="Custom" CustomMappingType="Jumoo.uSync.Core.Mappers.GridMapper,Jumoo.uSync.Core"/>

<!-- grid mappers : value of control.editor.alias
Expand Down
29 changes: 17 additions & 12 deletions Jumoo.uSync.Core/Mappers/ContentDataTypeMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public class ContentDataTypeMapper : IContentMapper
/// </summary>
public string GetExportValue(int dataTypeDefinitionId, string value)
{
return value;
/*
if (string.IsNullOrWhiteSpace(value))
return value;
Expand Down Expand Up @@ -53,40 +55,43 @@ public string GetExportValue(int dataTypeDefinitionId, string value)
}
return value;
*/
}

public string GetImportValue(int dataTypeDefinitionId, string content)
{
LogHelper.Debug<ContentDataTypeMapper>("Mapping a datatype: {0} {1}", () => dataTypeDefinitionId, () => content);
if (string.IsNullOrWhiteSpace(content))
return content;

var prevalues =
ApplicationContext.Current.Services.DataTypeService.GetPreValuesCollectionByDataTypeId(dataTypeDefinitionId)
.PreValuesAsDictionary;
ApplicationContext.Current.Services.DataTypeService.GetPreValuesCollectionByDataTypeId(dataTypeDefinitionId).PreValuesAsDictionary;

if (prevalues != null && prevalues.Count > 0)
{
var importValue = "";

var values = content.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
var importValue = "";

foreach(var alias in values)
foreach (var val in values)
{
string preValue = prevalues.Where(kvp => kvp.Key == alias)
.Select(kvp => kvp.Value.Id.ToString())
.SingleOrDefault();
// ? needs to be set to the key value .
int inValue = prevalues.Where(kvp => kvp.Value.Value == val)
.Select(kvp => kvp.Value.Id)
.SingleOrDefault();

if (!String.IsNullOrWhiteSpace(preValue))
if (inValue >= 0)
{
importValue = string.Format("{0}{1},", importValue, preValue);
importValue += inValue + ",";
}
else
{
importValue = string.Format("{0}{1},", alias, preValue);
importValue += val + ",";
}
}
LogHelper.Debug<ContentDataTypeMapper>("Setting value {0} to {1}", () => content, () => importValue.Trim(","));

return importValue.Trim(",");
}

return content;
}
}
Expand Down

0 comments on commit a7b18dd

Please sign in to comment.