Merge pull request #9421 from umbraco/netcore/feature/property-editors-migration-from-infrastructure

Netcore: Migration of Property Editor classes from Umbraco.Infrastructure to Core
This commit is contained in:
Bjarke Berg
2020-11-23 10:06:43 +01:00
committed by GitHub
22 changed files with 73 additions and 80 deletions

View File

@@ -2,10 +2,9 @@
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using Umbraco.Core.PropertyEditors;
using Umbraco.Core.Serialization;
namespace Umbraco.Core
namespace Umbraco.Core.PropertyEditors
{
/// <summary>
/// Represents a data type configuration editor.

View File

@@ -25,7 +25,7 @@ namespace Umbraco.Core.PropertyEditors
//TODO: We will need to change this once we support tracking via variants/segments
// for now, we are tracking values from ALL variants
foreach(var propertyVal in p.Values)
foreach (var propertyVal in p.Values)
{
var val = propertyVal.EditedValue;
@@ -33,9 +33,9 @@ namespace Umbraco.Core.PropertyEditors
if (valueEditor is IDataValueReference reference)
{
var refs = reference.GetReferences(val);
foreach(var r in refs)
foreach (var r in refs)
trackedRelations.Add(r);
}
}
// Loop over collection that may be add to existing property editors
// implementation of GetReferences in IDataValueReference.
@@ -48,14 +48,11 @@ namespace Umbraco.Core.PropertyEditors
// in the dataeditor/property has referecnes to media/content items
if (item.IsForEditor(editor))
{
foreach(var r in item.GetDataValueReference().GetReferences(val))
foreach (var r in item.GetDataValueReference().GetReferences(val))
trackedRelations.Add(r);
}
}
}
}
return trackedRelations;

View File

@@ -1,5 +1,4 @@
using Umbraco.Core;
using Umbraco.Core.PropertyEditors;
using Umbraco.Core.PropertyEditors;
using Umbraco.Core.PropertyEditors.Validators;
namespace Umbraco.Web.PropertyEditors
@@ -7,7 +6,7 @@ namespace Umbraco.Web.PropertyEditors
/// <summary>
/// A custom pre-value editor class to deal with the legacy way that the pre-value data is stored.
/// </summary>
internal class DecimalConfigurationEditor : ConfigurationEditor
public class DecimalConfigurationEditor : ConfigurationEditor
{
public DecimalConfigurationEditor()
{

View File

@@ -13,6 +13,6 @@ namespace Umbraco.Core.PropertyEditors
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
IEnumerable<UmbracoEntityReference> GetReferences(object value);
IEnumerable<UmbracoEntityReference> GetReferences(object value);
}
}

View File

@@ -5,7 +5,7 @@
/// <summary>
/// Gets a value indicating whether the DataValueReference lookup supports a datatype (data editor).
/// </summary>
/// <param name="dataType">The datatype.</param>
/// <param name="dataEditor"></param>
/// <returns>A value indicating whether the converter supports a datatype.</returns>
bool IsForEditor(IDataEditor dataEditor);

View File

@@ -1,5 +1,4 @@
using Umbraco.Core;
using Umbraco.Core.PropertyEditors;
using Umbraco.Core.PropertyEditors;
using Umbraco.Core.PropertyEditors.Validators;
namespace Umbraco.Web.PropertyEditors
@@ -7,7 +6,7 @@ namespace Umbraco.Web.PropertyEditors
/// <summary>
/// A custom pre-value editor class to deal with the legacy way that the pre-value data is stored.
/// </summary>
internal class IntegerConfigurationEditor : ConfigurationEditor
public class IntegerConfigurationEditor : ConfigurationEditor
{
public IntegerConfigurationEditor()
{

View File

@@ -1,4 +1,4 @@
using Newtonsoft.Json;
using System.Runtime.Serialization;
using Umbraco.Core.PropertyEditors;
namespace Umbraco.Web.PropertyEditors
@@ -31,7 +31,7 @@ namespace Umbraco.Web.PropertyEditors
new Layout { Name = "grid", Icon = "icon-thumbnails-small", IsSystem = 1, Selected = true, Path = "views/propertyeditors/listview/layouts/grid/grid.html" }
};
IncludeProperties = new []
IncludeProperties = new[]
{
new Property { Alias = "sortOrder", Header = "Sort order", IsSystem = 1 },
new Property { Alias = "updateDate", Header = "Last edited", IsSystem = 1 },
@@ -41,7 +41,7 @@ namespace Umbraco.Web.PropertyEditors
[ConfigurationField("pageSize", "Page Size", "number", Description = "Number of items per page")]
public int PageSize { get; set; }
[ConfigurationField("orderBy", "Order By", "views/propertyeditors/listview/sortby.prevalues.html",
Description = "The default sort order for the list")]
public string OrderBy { get; set; }
@@ -69,54 +69,57 @@ namespace Umbraco.Web.PropertyEditors
[ConfigurationField("showContentFirst", "Show Content App First", "boolean", Description = "Enable this to show the content app by default instead of the list view app")]
public bool ShowContentFirst { get; set; }
[DataContract]
public class Property
{
[JsonProperty("alias")]
[DataMember(Name = "alias")]
public string Alias { get; set; }
[JsonProperty("header")]
[DataMember(Name = "header")]
public string Header { get; set; }
[JsonProperty("nameTemplate")]
[DataMember(Name = "nameTemplate")]
public string Template { get; set; }
[JsonProperty("isSystem")]
[DataMember(Name = "isSystem")]
public int IsSystem { get; set; } // TODO: bool
}
[DataContract]
public class Layout
{
[JsonProperty("name")]
[DataMember(Name = "name")]
public string Name { get; set; }
[JsonProperty("path")]
[DataMember(Name = "path")]
public string Path { get; set; }
[JsonProperty("icon")]
[DataMember(Name = "icon")]
public string Icon { get; set; }
[JsonProperty("isSystem")]
[DataMember(Name = "isSystem")]
public int IsSystem { get; set; } // TODO: bool
[JsonProperty("selected")]
[DataMember(Name = "selected")]
public bool Selected { get; set; }
}
[DataContract]
public class BulkActionPermissionSettings
{
[JsonProperty("allowBulkPublish")]
[DataMember(Name = "allowBulkPublish")]
public bool AllowBulkPublish { get; set; } = true;
[JsonProperty("allowBulkUnpublish")]
[DataMember(Name = "allowBulkUnpublish")]
public bool AllowBulkUnpublish { get; set; } = true;
[JsonProperty("allowBulkCopy")]
[DataMember(Name = "allowBulkCopy")]
public bool AllowBulkCopy { get; set; } = true;
[JsonProperty("allowBulkMove")]
[DataMember(Name = "allowBulkMove")]
public bool AllowBulkMove { get; set; } = true;
[JsonProperty("allowBulkDelete")]
[DataMember(Name = "allowBulkDelete")]
public bool AllowBulkDelete { get; set; } = true;
}
}

View File

@@ -1,5 +1,5 @@
using System.Collections.Generic;
using Umbraco.Core;
using Umbraco.Core.PropertyEditors;
namespace Umbraco.Web.PropertyEditors
{

View File

@@ -0,0 +1,21 @@
using System.Runtime.Serialization;
using Umbraco.Core;
namespace Umbraco.Web.PropertyEditors
{
/// <summary>
/// Represents the 'startNode' value for the <see cref="Umbraco.Web.PropertyEditors.MultiNodePickerConfiguration"/>
/// </summary>
[DataContract]
public class MultiNodePickerConfigurationTreeSource
{
[DataMember(Name = "type")]
public string ObjectType { get; set; }
[DataMember(Name = "query")]
public string StartNodeQuery { get; set; }
[DataMember(Name = "id")]
public Udi StartNodeId { get; set; }
}
}

View File

@@ -1,4 +1,4 @@
using Newtonsoft.Json;
using System.Runtime.Serialization;
using Umbraco.Core.PropertyEditors;
namespace Umbraco.Web.PropertyEditors
@@ -27,15 +27,17 @@ namespace Umbraco.Web.PropertyEditors
[ConfigurationField("hideLabel", "Hide Label", "boolean", Description = "Hide the property label and let the item list span the full width of the editor window.")]
public bool HideLabel { get; set; }
[DataContract]
public class ContentType
{
[JsonProperty("ncAlias")]
[DataMember(Name = "ncAlias")]
public string Alias { get; set; }
[JsonProperty("ncTabAlias")]
[DataMember(Name = "ncTabAlias")]
public string TabAlias { get; set; }
[JsonProperty("nameTemplate")]
[DataMember(Name = "nameTemplate")]
public string Template { get; set; }
}
}

View File

@@ -1,5 +1,4 @@
using System.Collections.Generic;
using Umbraco.Core;
using Umbraco.Core.PropertyEditors;
namespace Umbraco.Web.PropertyEditors

View File

@@ -27,7 +27,7 @@ namespace Umbraco.Web.PropertyEditors.ValueConverters
=> propertyType.EditorAlias.Equals(Constants.PropertyEditors.Aliases.ContentPicker);
public override Type GetPropertyValueType(IPublishedPropertyType propertyType)
=> typeof (IPublishedContent);
=> typeof(IPublishedContent);
public override PropertyCacheLevel GetPropertyCacheLevel(IPublishedPropertyType propertyType)
=> PropertyCacheLevel.Elements;

View File

@@ -65,9 +65,9 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters
if (source is decimal sourceDecimal) return sourceDecimal;
if (source is string sourceDecimalString)
return decimal.TryParse(sourceDecimalString, NumberStyles.Any, CultureInfo.InvariantCulture, out var d) ? d : 0;
if (source is double sourceDouble)
return Convert.ToDecimal(sourceDouble);
return (decimal) 0;
if (source is double sourceDouble)
return Convert.ToDecimal(sourceDouble);
return (decimal)0;
case ValueTypes.Integer:
if (source is int sourceInt) return sourceInt;
if (source is string sourceIntString)
@@ -76,7 +76,7 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters
case ValueTypes.Bigint:
if (source is string sourceLongString)
return long.TryParse(sourceLongString, out var i) ? i : 0;
return (long) 0;
return (long)0;
default: // everything else is a string
return source?.ToString() ?? string.Empty;
}

View File

@@ -6,6 +6,7 @@ using Umbraco.Core;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Core.PropertyEditors;
using Umbraco.Web.PublishedCache;
namespace Umbraco.Web.PropertyEditors.ValueConverters
{
/// <summary>
@@ -67,7 +68,7 @@ namespace Umbraco.Web.PropertyEditors.ValueConverters
{
var isMultiple = IsMultipleDataType(propertyType.DataType);
var udis = (Udi[]) source;
var udis = (Udi[])source;
var mediaItems = new List<IPublishedContent>();
if (source == null) return isMultiple ? mediaItems : null;

View File

@@ -14,7 +14,7 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters
=> propertyType.EditorAlias == Constants.PropertyEditors.Aliases.TinyMce;
public override Type GetPropertyValueType(IPublishedPropertyType propertyType)
=> typeof (IHtmlEncodedString);
=> typeof(IHtmlEncodedString);
// PropertyCacheLevel.Content is ok here because that converter does not parse {locallink} nor executes macros
public override PropertyCacheLevel GetPropertyCacheLevel(IPublishedPropertyType propertyType)

View File

@@ -1,21 +0,0 @@
using Newtonsoft.Json;
using Umbraco.Core;
namespace Umbraco.Web.PropertyEditors
{
/// <summary>
/// Represents the 'startNode' value for the <see cref="MultiNodePickerConfiguration"/>
/// </summary>
[JsonObject]
public class MultiNodePickerConfigurationTreeSource
{
[JsonProperty("type")]
public string ObjectType {get;set;}
[JsonProperty("query")]
public string StartNodeQuery {get;set;}
[JsonProperty("id")]
public Udi StartNodeId {get;set;}
}
}

View File

@@ -250,7 +250,7 @@ namespace Umbraco.Web.BackOffice.Controllers
/// <param name="culture">The culture to fetch the URL for</param>
/// <returns>The URL or path to the item</returns>
[DetermineAmbiguousActionByPassingParameters]
public HttpResponseMessage GetUrl(Udi udi, string culture = "*")
public IActionResult GetUrl(Udi udi, string culture = "*")
{
var intId = _entityService.GetId(udi);
if (!intId.Success)
@@ -284,7 +284,7 @@ namespace Umbraco.Web.BackOffice.Controllers
/// We are not restricting this with security because there is no sensitive data
/// </remarks>
[DetermineAmbiguousActionByPassingParameters]
public HttpResponseMessage GetUrl(int id, UmbracoEntityTypes type, string culture = null)
public IActionResult GetUrl(int id, UmbracoEntityTypes type, string culture = null)
{
culture = culture ?? ClientCulture();
@@ -297,10 +297,7 @@ namespace Umbraco.Web.BackOffice.Controllers
{
returnUrl = foundUrl;
return new HttpResponseMessage(HttpStatusCode.OK)
{
Content = new StringContent(returnUrl)
};
return Ok(returnUrl);
}
}
@@ -314,10 +311,7 @@ namespace Umbraco.Web.BackOffice.Controllers
returnUrl = "/" + string.Join("/", ancestors.Select(x => x.Name));
return new HttpResponseMessage(HttpStatusCode.OK)
{
Content = new StringContent(returnUrl)
};
return Ok(returnUrl);
}

View File

@@ -157,7 +157,7 @@ namespace Umbraco.Web.BackOffice.Controllers
}
[HttpPost]
public HttpResponseMessage CreatePartialViewMacroWithFile(CreatePartialViewMacroWithFileModel model)
public IActionResult CreatePartialViewMacroWithFile(CreatePartialViewMacroWithFileModel model)
{
if (model == null) throw new ArgumentNullException("model");
if (string.IsNullOrWhiteSpace(model.Filename)) throw new ArgumentException("Filename cannot be null or whitespace", "model.Filename");
@@ -173,7 +173,7 @@ namespace Umbraco.Web.BackOffice.Controllers
};
_macroService.Save(macro); // may throw
return new HttpResponseMessage(HttpStatusCode.OK);
return Ok();
}
public class CreatePartialViewMacroWithFileModel