Fixing totally broken merge

This commit is contained in:
perploug
2014-02-19 12:16:58 +01:00
parent 09b9056fb0
commit f8baf343bf
7 changed files with 96 additions and 92 deletions

View File

@@ -4,6 +4,8 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Umbraco.Core;
using Umbraco.Core.Configuration;
using Umbraco.Core.Logging;
using Umbraco.Core.Models;
@@ -13,16 +15,11 @@ namespace Umbraco.Web
{
internal static class ImageCropperBaseExtensions
{
internal static bool IsJson(this string input)
{
input = input.Trim();
return input.StartsWith("{") && input.EndsWith("}") || input.StartsWith("[") && input.EndsWith("]");
}
internal static ImageCropData GetImageCrop(this string json, string id)
{
var ic = new ImageCropData();
if (IsJson(json))
if (json.DetectIsJson())
{
try
{
@@ -37,7 +34,7 @@ namespace Umbraco.Web
internal static ImageCropDataSet SerializeToCropDataSet(this string json)
{
var imageCrops = new ImageCropDataSet();
if (IsJson(json))
if (json.DetectIsJson())
{
try
{
@@ -58,11 +55,12 @@ namespace Umbraco.Web
{
try
{
if (propertyAlias != null && publishedContent.HasProperty(propertyAlias)
&& publishedContent.HasValue(propertyAlias))
{
var propertyAliasValue = publishedContent.GetPropertyValue<string>(propertyAlias);
if (propertyAliasValue.IsJson() && propertyAliasValue.Length <= 2)
if (propertyAliasValue.DetectIsJson() && propertyAliasValue.Length <= 2)
{
return false;
}
@@ -78,7 +76,7 @@ namespace Umbraco.Web
if (cropsProperty != null && !string.IsNullOrEmpty(cropsProperty.Value.ToString()))
{
var propertyAliasValue = cropsProperty.Value.ToString();
if (propertyAliasValue.IsJson() && propertyAliasValue.Length <= 2)
if (propertyAliasValue.DetectIsJson() && propertyAliasValue.Length <= 2)
{
return false;
}
@@ -96,7 +94,7 @@ namespace Umbraco.Web
&& publishedContent.HasValue(propertyAlias))
{
var propertyAliasValue = publishedContent.GetPropertyValue<string>(propertyAlias);
if (propertyAliasValue.IsJson() && propertyAliasValue.Length <= 2)
if (propertyAliasValue.DetectIsJson() && propertyAliasValue.Length <= 2)
{
return false;
}
@@ -122,7 +120,7 @@ namespace Umbraco.Web
if (cropsProperty != null && !string.IsNullOrEmpty(cropsProperty.Value.ToString()))
{
var propertyAliasValue = cropsProperty.Value.ToString();
if (propertyAliasValue.IsJson() && propertyAliasValue.Length <= 2)
if (propertyAliasValue.DetectIsJson() && propertyAliasValue.Length <= 2)
{
return false;
}

View File

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Umbraco.Core;
using Umbraco.Core.Models;
using Umbraco.Web.PropertyEditors;
@@ -20,17 +21,14 @@ namespace Umbraco.Web
if (string.IsNullOrEmpty(property))
return string.Empty;
if (property.IsJson())
if (property.DetectIsJson())
{
var cropDataSet = property.SerializeToCropDataSet();
var currentCrop = cropDataSet.Crops.First(x => x.Alias ==cropAlias);
return cropDataSet.Src + currentCrop.ToUrl();
return cropDataSet.Src + cropDataSet.GetCropUrl(cropAlias);
}
else
{
//must be a string
var cropData = ImageCropperPropertyEditorHelper.GetCrop(mediaItem.ContentType.Alias, cropAlias);
return property + cropData.ToUrl();
return property;
}
}
@@ -75,18 +73,14 @@ namespace Umbraco.Web
var imageResizerUrl = new StringBuilder();
imageResizerUrl.Append(imageUrl);
if (!string.IsNullOrEmpty(imageCropperValue) && imageCropperValue.IsJson())
if (!string.IsNullOrEmpty(imageCropperValue) && imageCropperValue.DetectIsJson())
{
var allTheCrops = imageCropperValue.SerializeToCropDataSet();
if (allTheCrops != null && allTheCrops.Crops.Any())
{
var crop = cropAlias != null
? allTheCrops.Crops.First(x => x.Alias ==cropAlias)
: allTheCrops.Crops.First();
if (crop != null)
{
imageResizerUrl.Append(crop.ToUrl());
}
if(allTheCrops.HasCrop(cropAlias))
imageResizerUrl.Append(allTheCrops.GetCropUrl(cropAlias));
}
}
else

View File

@@ -18,6 +18,63 @@ namespace Umbraco.Web.Models
[DataMember(Name = "crops")]
public IEnumerable<ImageCropData> Crops { get; set; }
public string GetCropUrl(string alias)
{
var crop = Crops.FirstOrDefault(x => x.Alias == alias);
if(crop == null)
return null;
StringBuilder sb = new StringBuilder();
if (crop.Coordinates != null)
{
sb.Append("?crop=");
sb.Append(crop.Coordinates.X1).Append(",");
sb.Append(crop.Coordinates.Y1).Append(",");
sb.Append(crop.Coordinates.X2).Append(",");
sb.Append(crop.Coordinates.Y2);
sb.Append("&cropmode=percentage");
}
else
{
if (HasFocalPoint())
{
}
else
{
sb.Append("?anchor=center");
sb.Append("&mode=crop");
}
}
sb.Append("&width=").Append(crop.Width);
sb.Append("&height=").Append(crop.Height);
sb.Append("&rnd=").Append(DateTime.Now.Ticks);
return sb.ToString();
}
public bool HasFocalPoint()
{
return (FocalPoint != null && FocalPoint.Top != 0.5m && FocalPoint.Top != 0.5m);
}
public bool HasCrop(string alias)
{
return Crops.Any(x => x.Alias == alias);
}
public bool HasImage()
{
return string.IsNullOrEmpty(Src);
}
}
[DataContract(Name = "imageCropFocalPoint")]
@@ -64,31 +121,6 @@ namespace Umbraco.Web.Models
[DataMember(Name = "coordinates")]
public ImageCropCoordinates Coordinates { get; set; }
public string ToUrl()
{
StringBuilder sb = new StringBuilder();
if (Coordinates != null)
{
sb.Append("?crop=");
sb.Append(Coordinates.X1).Append(",");
sb.Append(Coordinates.Y1).Append(",");
sb.Append(Coordinates.X2).Append(",");
sb.Append(Coordinates.Y2);
sb.Append("&cropmode=percentage");
}
else
{
sb.Append("?anchor=center");
sb.Append("&mode=crop");
}
sb.Append("&width=").Append(Width);
sb.Append("&height=").Append(Height);
sb.Append("&rnd=").Append(DateTime.Now.Ticks);
return sb.ToString();
}
}
}

View File

@@ -78,7 +78,7 @@ namespace Umbraco.Web.PropertyEditors
//now we need to check if there is a value
if (p.Value is string && ((string) p.Value).IsNullOrWhiteSpace() == false)
{
if (!p.Value.ToString().IsJson())
if (!p.Value.ToString().DetectIsJson())
{
//there might be multiple, we can only process the first one!
var split = ((string)p.Value).Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

View File

@@ -1,39 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Umbraco.Core.Configuration;
namespace Umbraco.Web.PropertyEditors
{
internal class ImageCropperPropertyEditorHelper
{
internal static Umbraco.Web.Models.ImageCropData GetCrop(string mediaTypeAlias, string cropAlias){
return null;
/*var _crops = GetConfigurationForType(mediaTypeAlias);
if (_crops == null || _crops.Crops == null)
return null;
return _crops.Crops[cropAlias];*/
}
//this queries all crops configured
internal static Umbraco.Web.Models.ImageCropData GetCrop(string cropAlias)
{
/*
foreach (var typeCrops in UmbracoConfig.For.UmbracoSettings().Content.ImageCrops.Crops)
{
var cropSize = typeCrops.CropSizes.FirstOrDefault(x => x.Alias == cropAlias);
if(cropSize != null)
return new Models.ImageCropData() { Alias = cropSize.Alias, Height = cropSize.Height, Width = cropSize.Width };
}*/
return null;
}
}
}

View File

@@ -6,6 +6,8 @@ using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Umbraco.Core;
using Umbraco.Core.Configuration;
using Umbraco.Core.IO;
using Umbraco.Core.Media;
@@ -118,6 +120,24 @@ namespace Umbraco.Web.PropertyEditors
return editorValue.Value.ToString();
}
public override string ConvertDbToString(Property property, PropertyType propertyType, Core.Services.IDataTypeService dataTypeService)
{
if(property.Value == null || string.IsNullOrEmpty(property.Value.ToString()))
return null;
//if we dont have a json structure, we will get it from the property type
var val = property.Value.ToString();
if (val.DetectIsJson())
return val;
var config = dataTypeService.GetPreValuesByDataTypeId(propertyType.DataTypeDefinitionId).FirstOrDefault();
var crops = !string.IsNullOrEmpty(config) ? config : "[]";
var newVal = "{src: '" + val + "', crops: " + crops + "}";
return newVal;
}
}

View File

@@ -347,7 +347,6 @@
<Compile Include="PropertyEditors\EmailAddressPropertyEditor.cs" />
<Compile Include="ImageCropperBaseExtensions.cs" />
<Compile Include="PropertyEditors\ImageCropperPropertyEditor.cs" />
<Compile Include="PropertyEditors\ImageCropperPropertyEditorHelper.cs" />
<Compile Include="PropertyEditors\ImageCropperPropertyValueEditor.cs" />
<Compile Include="PropertyEditors\ListViewPropertyEditor.cs" />
<Compile Include="PropertyEditors\MacroContainerPropertyEditor.cs" />