U4-7695 Media items are not updated when a new crop is added to Image Cropper
This commit is contained in:
@@ -12,6 +12,9 @@ using Umbraco.Core.Models.PublishedContent;
|
||||
|
||||
namespace Umbraco.Core.PropertyEditors.ValueConverters
|
||||
{
|
||||
/// <summary>
|
||||
/// This ensures that the grid config is merged in with the front-end value
|
||||
/// </summary>
|
||||
[DefaultPropertyValueConverter(typeof(JsonValueConverter))] //this shadows the JsonValueConverter
|
||||
[PropertyValueType(typeof(JToken))]
|
||||
[PropertyValueCache(PropertyCacheValue.All, PropertyCacheLevel.Content)]
|
||||
@@ -90,7 +93,7 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.Error<JsonValueConverter>("Could not parse the string " + sourceString + " to a json object", ex);
|
||||
LogHelper.Error<GridValueConverter>("Could not parse the string " + sourceString + " to a json object", ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
using System;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Models.PublishedContent;
|
||||
|
||||
namespace Umbraco.Core.PropertyEditors.ValueConverters
|
||||
{
|
||||
/// <summary>
|
||||
/// This ensures that the cropper config (pre-values/crops) are merged in with the front-end value.
|
||||
/// </summary>
|
||||
[DefaultPropertyValueConverter(typeof (JsonValueConverter))] //this shadows the JsonValueConverter
|
||||
[PropertyValueType(typeof (JToken))]
|
||||
[PropertyValueCache(PropertyCacheValue.All, PropertyCacheLevel.Content)]
|
||||
public class ImageCropperValueConverter : JsonValueConverter
|
||||
{
|
||||
public override bool IsConverter(PublishedPropertyType propertyType)
|
||||
{
|
||||
return propertyType.PropertyEditorAlias.InvariantEquals(Constants.PropertyEditors.ImageCropperAlias);
|
||||
}
|
||||
|
||||
public override object ConvertDataToSource(PublishedPropertyType propertyType, object source, bool preview)
|
||||
{
|
||||
if (source == null) return null;
|
||||
var sourceString = source.ToString();
|
||||
|
||||
if (sourceString.DetectIsJson())
|
||||
{
|
||||
JObject obj;
|
||||
try
|
||||
{
|
||||
obj = JsonConvert.DeserializeObject<JObject>(sourceString);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.Error<ImageCropperValueConverter>("Could not parse the string " + sourceString + " to a json object", ex);
|
||||
return sourceString;
|
||||
}
|
||||
|
||||
//need to lookup the pre-values for this data type
|
||||
//TODO: Change all singleton access to use ctor injection in v8!!!
|
||||
var dt = ApplicationContext.Current.Services.DataTypeService.GetPreValuesCollectionByDataTypeId(propertyType.DataTypeId);
|
||||
|
||||
if (dt != null && dt.IsDictionaryBased && dt.PreValuesAsDictionary.ContainsKey("crops"))
|
||||
{
|
||||
var cropsString = dt.PreValuesAsDictionary["crops"].Value;
|
||||
JArray crops;
|
||||
try
|
||||
{
|
||||
crops = JsonConvert.DeserializeObject<JArray>(cropsString);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.Error<ImageCropperValueConverter>("Could not parse the string " + cropsString + " to a json object", ex);
|
||||
return sourceString;
|
||||
}
|
||||
obj["crops"] = crops;
|
||||
}
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
//it's not json, just return the string
|
||||
return sourceString;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -488,6 +488,7 @@
|
||||
<Compile Include="PropertyEditors\DecimalValidator.cs" />
|
||||
<Compile Include="PropertyEditors\ValueConverters\GridValueConverter.cs" />
|
||||
<Compile Include="PropertyEditors\ValueConverters\DecimalValueConverter.cs" />
|
||||
<Compile Include="PropertyEditors\ValueConverters\ImageCropperValueConverter.cs" />
|
||||
<Compile Include="Publishing\UnPublishedStatusType.cs" />
|
||||
<Compile Include="Publishing\UnPublishStatus.cs" />
|
||||
<Compile Include="Security\BackOfficeClaimsIdentityFactory.cs" />
|
||||
|
||||
@@ -580,11 +580,11 @@ angular.module("umbraco")
|
||||
|
||||
|
||||
// *********************************************
|
||||
// INITIALISATION
|
||||
// Initialization
|
||||
// these methods are called from ng-init on the template
|
||||
// so we can controll their first load data
|
||||
//
|
||||
// intialisation sets non-saved data like percentage sizing, allowed editors and
|
||||
// intialization sets non-saved data like percentage sizing, allowed editors and
|
||||
// other data that should all be pre-fixed with $ to strip it out on save
|
||||
// *********************************************
|
||||
|
||||
|
||||
@@ -119,6 +119,10 @@
|
||||
|
||||
if (mediaItem.HasProperty(propertyAlias) && mediaItem.HasValue(propertyAlias))
|
||||
{
|
||||
//TODO: We should change this, the default value is JObject now, this means we are ToString() ing the value,
|
||||
// then re-deserializing it back to json and then to a strongly typed model.
|
||||
// With a tiny bit of work we can make this more efficient since it's already a JObject.
|
||||
|
||||
imageCropperValue = mediaItem.GetPropertyValue<string>(propertyAlias);
|
||||
|
||||
// get the raw value (this will be json)
|
||||
|
||||
Reference in New Issue
Block a user