Changes imagecropper to store config in its property data
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
<div class="umb-cropper umb-editor" ng-show="src">
|
||||
<div class="crop-container">
|
||||
<div class="viewport" ng-style="style()">
|
||||
<img src="{{src}}" ng-style="dimensions.image"/>
|
||||
<img ng-src="{{src}}" ng-style="dimensions.image"/>
|
||||
<div class="overlay" ng-style="dimensions.image"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<div class="umb-cropper-gravity">
|
||||
<div class="gravity-container">
|
||||
<div class="viewport">
|
||||
<img src="{{src}}" style="max-width: 100%; max-height: 100%" />
|
||||
<img ng-src="{{src}}" style="max-width: 100%; max-height: 100%" />
|
||||
|
||||
<div class="overlay" ng-style="style()">
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<div class="umb-crop-thumbnail-container"
|
||||
ng-style="{height: height, width: width, overflow: 'hidden', position: 'relative'}">
|
||||
<img src="{{src}}" ng-style="preview" class="noScale" />
|
||||
<img ng-src="{{src}}" ng-style="preview" class="noScale" />
|
||||
</div>
|
||||
@@ -0,0 +1,34 @@
|
||||
angular.module("umbraco").controller("Umbraco.PrevalueEditors.CropSizesController",
|
||||
function ($scope, $timeout) {
|
||||
|
||||
$scope.newItem = {};
|
||||
|
||||
if(!$scope.model.value){
|
||||
$scope.model.value = [];
|
||||
}
|
||||
|
||||
$scope.remove = function(item, evt) {
|
||||
evt.preventDefault();
|
||||
$scope.model.value = _.reject($scope.model.value, function (x) {
|
||||
return x.alias === item.alias;
|
||||
});
|
||||
};
|
||||
|
||||
$scope.add = function (evt) {
|
||||
|
||||
evt.preventDefault();
|
||||
|
||||
if ($scope.newItem) {
|
||||
var exists = _.find($scope.model.value, function(item){return $scope.newItem.alias === item.alias;});
|
||||
if (!exists){
|
||||
$scope.model.value.push($scope.newItem);
|
||||
$scope.newItem = {};
|
||||
$scope.hasError = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//there was an error, do the highlight (will be set back by the directive)
|
||||
$scope.hasError = true;
|
||||
};
|
||||
});
|
||||
@@ -0,0 +1,58 @@
|
||||
<div ng-controller="Umbraco.PrevalueEditors.CropSizesController" class="umb-editor umb-cropsizes">
|
||||
|
||||
<div class="control-group">
|
||||
<div class="row">
|
||||
<div class="span3">
|
||||
<label>Alias</label>
|
||||
<input name="newItem.alias" type="text"
|
||||
ng-model="newItem.alias" val-highlight="hasError" />
|
||||
</div>
|
||||
|
||||
<div class="span3">
|
||||
<label>Height</label>
|
||||
<input name="newItem.height" type="number"
|
||||
ng-model="newItem.height" val-highlight="hasError" />
|
||||
</div>
|
||||
|
||||
<div class="span3">
|
||||
<label>Width</label>
|
||||
<input name="newItem.width" type="number"
|
||||
ng-model="newItem.width" val-highlight="hasError" />
|
||||
</div>
|
||||
|
||||
<div class="span3">
|
||||
<button class="btn btn-small" ng-click="add($event)">Add</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="control-group">
|
||||
<div class="row" ng-repeat="item in model.value">
|
||||
<div class="span3">
|
||||
<label>Alias</label>
|
||||
<input name="newItem.alias" type="text"
|
||||
ng-model="item.alias"
|
||||
required val-highlight="hasError" />
|
||||
</div>
|
||||
|
||||
<div class="span3">
|
||||
<label>Height</label>
|
||||
<input name="newItem.height" type="number"
|
||||
ng-model="item.height"
|
||||
required val-highlight="hasError" />
|
||||
</div>
|
||||
|
||||
<div class="span3">
|
||||
<label>Width</label>
|
||||
<input name="newItem.width" type="number"
|
||||
ng-model="item.width"
|
||||
required val-highlight="hasError" />
|
||||
</div>
|
||||
|
||||
<div class="span3">
|
||||
<button class="btn btn-small btn-danger" ng-click="remove(item, $event)">Remove</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
@@ -182,11 +182,6 @@ namespace Umbraco.Web.Editors
|
||||
"rteApiBaseUrl", Url.GetUmbracoApiServiceBaseUrl<RichTextPreValueController>(
|
||||
controller => controller.GetConfiguration())
|
||||
},
|
||||
{
|
||||
"imageCropperApiBaseUrl", Url.GetUmbracoApiServiceBaseUrl<ImageCropperPreValueController>(
|
||||
controller => controller.GetConfiguration(string.Empty))
|
||||
},
|
||||
|
||||
{
|
||||
"stylesheetApiBaseUrl", Url.GetUmbracoApiServiceBaseUrl<StylesheetController>(
|
||||
controller => controller.GetAll())
|
||||
@@ -261,7 +256,7 @@ namespace Umbraco.Web.Editors
|
||||
: string.Format("{0}-{1}", UmbracoVersion.Current.ToString(3), UmbracoVersion.CurrentComment);
|
||||
|
||||
app.Add("version", version);
|
||||
|
||||
app.Add("cdf", ClientDependency.Core.Config.ClientDependencySettings.Instance.Version);
|
||||
return app;
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,6 @@ namespace Umbraco.Web
|
||||
return ic;
|
||||
}
|
||||
|
||||
|
||||
internal static ImageCropDataSet SerializeToCropDataSet(this string json)
|
||||
{
|
||||
var imageCrops = new ImageCropDataSet();
|
||||
@@ -44,9 +43,9 @@ namespace Umbraco.Web
|
||||
{
|
||||
imageCrops = JsonConvert.DeserializeObject<ImageCropDataSet>(json);
|
||||
}
|
||||
catch
|
||||
catch(Exception ex)
|
||||
{
|
||||
|
||||
var e = ex;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,8 +104,8 @@ namespace Umbraco.Web
|
||||
if (allTheCrops != null && allTheCrops.Crops.Any())
|
||||
{
|
||||
var crop = cropAlias != null
|
||||
? allTheCrops.Crops[cropAlias]
|
||||
: allTheCrops.Crops.First().Value;
|
||||
? allTheCrops.Crops.First(x => x.Alias ==cropAlias)
|
||||
: allTheCrops.Crops.First();
|
||||
if (crop != null)
|
||||
{
|
||||
return true;
|
||||
@@ -131,8 +130,8 @@ namespace Umbraco.Web
|
||||
if (allTheCrops != null && allTheCrops.Crops.Any())
|
||||
{
|
||||
var crop = cropAlias != null
|
||||
? allTheCrops.Crops[cropAlias]
|
||||
: allTheCrops.Crops.First().Value;
|
||||
? allTheCrops.Crops.First(x => x.Alias ==cropAlias)
|
||||
: allTheCrops.Crops.First();
|
||||
if (crop != null)
|
||||
{
|
||||
return true;
|
||||
|
||||
@@ -10,11 +10,7 @@ namespace Umbraco.Web
|
||||
{
|
||||
public static class ImageCropperTemplateExtensions
|
||||
{
|
||||
public static bool HasCrop(this IPublishedContent publishedContent, string propertyAlias, string cropAlias)
|
||||
{
|
||||
return ImageCropperPropertyEditorHelper.GetCrop(publishedContent.ContentType.Alias, cropAlias) != null;
|
||||
}
|
||||
|
||||
|
||||
//this only takes the crop json into account
|
||||
public static string Crop(this IPublishedContent mediaItem, string propertyAlias, string cropAlias)
|
||||
{
|
||||
@@ -26,7 +22,7 @@ namespace Umbraco.Web
|
||||
if (property.IsJson())
|
||||
{
|
||||
var cropDataSet = property.SerializeToCropDataSet();
|
||||
var currentCrop = cropDataSet.Crops[cropAlias];
|
||||
var currentCrop = cropDataSet.Crops.First(x => x.Alias ==cropAlias);
|
||||
return cropDataSet.Src + currentCrop.ToUrl();
|
||||
}
|
||||
else
|
||||
@@ -38,10 +34,7 @@ namespace Umbraco.Web
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public static string Crop(
|
||||
public static string Crop(
|
||||
this IPublishedContent mediaItem,
|
||||
int? width = null,
|
||||
int? height = null,
|
||||
@@ -72,7 +65,7 @@ namespace Umbraco.Web
|
||||
Mode? mode = null,
|
||||
Anchor? anchor = null,
|
||||
string imageCropperValue = null,
|
||||
string imageCropperCropId = null,
|
||||
string cropAlias = null,
|
||||
string furtherOptions = null,
|
||||
bool slimmage = false)
|
||||
{
|
||||
@@ -86,9 +79,9 @@ namespace Umbraco.Web
|
||||
var allTheCrops = imageCropperValue.SerializeToCropDataSet();
|
||||
if (allTheCrops != null && allTheCrops.Crops.Any())
|
||||
{
|
||||
var crop = imageCropperCropId != null
|
||||
? allTheCrops.Crops[imageCropperCropId]
|
||||
: allTheCrops.Crops.First().Value;
|
||||
var crop = cropAlias != null
|
||||
? allTheCrops.Crops.First(x => x.Alias ==cropAlias)
|
||||
: allTheCrops.Crops.First();
|
||||
if (crop != null)
|
||||
{
|
||||
imageResizerUrl.Append(crop.ToUrl());
|
||||
|
||||
@@ -21,6 +21,10 @@ namespace Umbraco.Web.Models.ContentEditing
|
||||
[Required(AllowEmptyStrings = false)]
|
||||
public string Alias { get; set; }
|
||||
|
||||
[DataMember(Name = "editor", IsRequired = false)]
|
||||
public string Editor { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Used internally during model mapping
|
||||
/// </summary>
|
||||
|
||||
@@ -13,17 +13,11 @@ namespace Umbraco.Web.Models
|
||||
[DataMember(Name="src")]
|
||||
public string Src { get; set;}
|
||||
|
||||
[DataMember(Name = "imagePropertyAlias")]
|
||||
public string ImagePropertyAlias { get; set; }
|
||||
|
||||
[DataMember(Name = "focalPointPropertyAlias")]
|
||||
public string FocalPointPropertyAlias { get; set; }
|
||||
|
||||
[DataMember(Name = "focalPoint")]
|
||||
public ImageCropFocalPoint FocalPoint { get; set; }
|
||||
|
||||
[DataMember(Name = "crops")]
|
||||
public IDictionary<string, ImageCropData> Crops { get; set; }
|
||||
public IEnumerable<ImageCropData> Crops { get; set; }
|
||||
}
|
||||
|
||||
[DataContract(Name = "imageCropFocalPoint")]
|
||||
@@ -59,8 +53,8 @@ namespace Umbraco.Web.Models
|
||||
[DataMember(Name = "alias")]
|
||||
public string Alias { get; set; }
|
||||
|
||||
[DataMember(Name = "name")]
|
||||
public string Name { get; set; }
|
||||
//[DataMember(Name = "name")]
|
||||
//public string Name { get; set; }
|
||||
|
||||
[DataMember(Name = "width")]
|
||||
public int Width { get; set; }
|
||||
|
||||
@@ -44,7 +44,8 @@ namespace Umbraco.Web.Models.Mapping
|
||||
Id = property.Id,
|
||||
Value = editor.ValueEditor.ConvertDbToEditor(property, property.PropertyType, DataTypeService.Value),
|
||||
Alias = property.Alias,
|
||||
PropertyEditor = editor
|
||||
PropertyEditor = editor,
|
||||
Editor = editor.Alias
|
||||
};
|
||||
|
||||
return result;
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Web.Editors;
|
||||
using Umbraco.Web.Mvc;
|
||||
|
||||
namespace Umbraco.Web.PropertyEditors
|
||||
{
|
||||
|
||||
public class ImageCropperPreValueController : UmbracoAuthorizedJsonController
|
||||
{
|
||||
//Returns the collection of allowed crops on a given media alias type
|
||||
public Models.ImageCropDataSet GetConfiguration(string mediaTypeAlias)
|
||||
{
|
||||
return ImageCropperPropertyEditorHelper.GetConfigurationForType(mediaTypeAlias);
|
||||
}
|
||||
|
||||
//Returns a specific crop on a media type
|
||||
public Models.ImageCropData GetCrop(string mediaTypeAlias, string cropAlias)
|
||||
{
|
||||
return ImageCropperPropertyEditorHelper.GetCrop(mediaTypeAlias, cropAlias);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -21,5 +21,34 @@ namespace Umbraco.Web.PropertyEditors
|
||||
var baseEditor = base.CreateValueEditor();
|
||||
return new ImageCropperPropertyValueEditor(baseEditor);
|
||||
}
|
||||
|
||||
protected override PreValueEditor CreatePreValueEditor()
|
||||
{
|
||||
return new ImageCropperPreValueEditor();
|
||||
}
|
||||
|
||||
|
||||
public ImageCropperPropertyEditor()
|
||||
{
|
||||
_internalPreValues = new Dictionary<string, object>
|
||||
{
|
||||
{"crops", "[]"},
|
||||
{"focalPoint", "{left: 0.5, top: 0.5}"},
|
||||
{"src", ""}
|
||||
};
|
||||
}
|
||||
|
||||
private IDictionary<string, object> _internalPreValues;
|
||||
public override IDictionary<string, object> DefaultPreValues
|
||||
{
|
||||
get { return _internalPreValues; }
|
||||
set { _internalPreValues = value; }
|
||||
}
|
||||
|
||||
internal class ImageCropperPreValueEditor : PreValueEditor
|
||||
{
|
||||
[PreValueField("crops", "Crop sizes", "cropsizes")]
|
||||
public string Crops { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,44 +9,29 @@ namespace Umbraco.Web.PropertyEditors
|
||||
{
|
||||
internal class ImageCropperPropertyEditorHelper
|
||||
{
|
||||
//Returns the collection of allowed crops on a given media alias type
|
||||
internal static Models.ImageCropDataSet GetConfigurationForType(string mediaTypeAlias)
|
||||
{
|
||||
var defaultModel = new Models.ImageCropDataSet();
|
||||
defaultModel.FocalPoint = new Models.ImageCropFocalPoint() { Left = 0.5M, Top = 0.5M };
|
||||
|
||||
var configuredCrops = UmbracoConfig.For.UmbracoSettings().Content.ImageCrops.Crops.FirstOrDefault(x => x.MediaTypeAlias == mediaTypeAlias);
|
||||
if (configuredCrops == null || !configuredCrops.CropSizes.Any())
|
||||
return defaultModel;
|
||||
|
||||
var crops = new Dictionary<string, Umbraco.Web.Models.ImageCropData>();
|
||||
foreach (var cropSize in configuredCrops.CropSizes)
|
||||
crops.Add(cropSize.Alias, new Models.ImageCropData() { Alias = cropSize.Alias, Height = cropSize.Height, Width = cropSize.Width });
|
||||
|
||||
|
||||
defaultModel.Crops = crops;
|
||||
return defaultModel;
|
||||
}
|
||||
|
||||
|
||||
internal static Umbraco.Web.Models.ImageCropData GetCrop(string mediaTypeAlias, string cropAlias){
|
||||
|
||||
var _crops = GetConfigurationForType(mediaTypeAlias);
|
||||
return null;
|
||||
|
||||
/*var _crops = GetConfigurationForType(mediaTypeAlias);
|
||||
|
||||
if (_crops == null || _crops.Crops == null)
|
||||
return null;
|
||||
|
||||
return _crops.Crops[cropAlias];
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ namespace Umbraco.Web.PropertyEditors
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Overrides the deserialize value so that we can save the file accordingly
|
||||
/// </summary>
|
||||
@@ -62,7 +63,7 @@ namespace Umbraco.Web.PropertyEditors
|
||||
|
||||
//compare old and new src path
|
||||
//if not alike, that means we have a new file, or delete the current one...
|
||||
if (oldFile != newFile)
|
||||
if (string.IsNullOrEmpty(newFile) || editorValue.AdditionalData.ContainsKey("files"))
|
||||
{
|
||||
var fs = FileSystemProviderManager.Current.GetFileSystemProvider<MediaFileSystem>();
|
||||
|
||||
@@ -118,4 +119,6 @@ namespace Umbraco.Web.PropertyEditors
|
||||
return editorValue.Value.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user