Fixed some build problems, replaces all calls to the legacy/obsolete data type factory to the DataTypesResolver and removes test for DataTypeFactoryTests.
Updates data type editor to show legacy data types at the bottom and the new Property editors at the top. Updated the data type editor to use the new api so that we can test assigning Belle property editors to data types (pre-values have not been converted though). #U4-2289
This commit is contained in:
@@ -170,7 +170,7 @@ namespace Umbraco.Core.Models
|
||||
public Guid ControlId
|
||||
{
|
||||
get { return _controlId; }
|
||||
private set
|
||||
set
|
||||
{
|
||||
SetPropertyValueAndDetectChanges(o =>
|
||||
{
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace Umbraco.Core.Models
|
||||
/// <summary>
|
||||
/// Id of the DataType control
|
||||
/// </summary>
|
||||
Guid ControlId { get; }
|
||||
Guid ControlId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or Sets the DatabaseType for which the DataType's value is saved as
|
||||
|
||||
@@ -1,109 +0,0 @@
|
||||
using System;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.ObjectResolution;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
using umbraco.cms.businesslogic.datatype;
|
||||
using umbraco.interfaces;
|
||||
using System.Linq;
|
||||
|
||||
namespace Umbraco.Tests
|
||||
{
|
||||
|
||||
[TestFixture]
|
||||
public class DataTypeFactoryTests
|
||||
{
|
||||
[SetUp]
|
||||
public void Initialize()
|
||||
{
|
||||
TestHelper.SetupLog4NetForTests();
|
||||
|
||||
//this ensures its reset
|
||||
PluginManager.Current = new PluginManager(false);
|
||||
|
||||
//for testing, we'll specify which assemblies are scanned for the PluginTypeResolver
|
||||
PluginManager.Current.AssembliesToScan = new[]
|
||||
{
|
||||
this.GetType().Assembly
|
||||
};
|
||||
|
||||
DataTypesResolver.Current = new DataTypesResolver(
|
||||
() => PluginManager.Current.ResolveDataTypes());
|
||||
|
||||
Resolution.Freeze();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
DataTypesResolver.Reset();
|
||||
PluginManager.Current = null;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Get_All_Instances()
|
||||
{
|
||||
var factory = new umbraco.cms.businesslogic.datatype.controls.Factory();
|
||||
Assert.AreEqual(2, factory.GetAll().Count());
|
||||
}
|
||||
|
||||
#region Classes for tests
|
||||
public class DataType1 : AbstractDataEditor
|
||||
{
|
||||
public override Guid Id
|
||||
{
|
||||
get { return new Guid("FBAEA49B-F704-44FE-B725-6C8FE0767CF2"); }
|
||||
}
|
||||
|
||||
public override string DataTypeName
|
||||
{
|
||||
get { return "DataType1"; }
|
||||
}
|
||||
|
||||
public override IDataEditor DataEditor
|
||||
{
|
||||
get { throw new NotImplementedException(); }
|
||||
}
|
||||
|
||||
public override IDataPrevalue PrevalueEditor
|
||||
{
|
||||
get { throw new NotImplementedException(); }
|
||||
}
|
||||
|
||||
public override IData Data
|
||||
{
|
||||
get { throw new NotImplementedException(); }
|
||||
}
|
||||
}
|
||||
|
||||
public class DataType2 : AbstractDataEditor
|
||||
{
|
||||
public override Guid Id
|
||||
{
|
||||
get { return new Guid("3F58099B-96AC-415E-B3F9-BA273F51E681"); }
|
||||
}
|
||||
|
||||
public override string DataTypeName
|
||||
{
|
||||
get { return "DataType2"; }
|
||||
}
|
||||
|
||||
public override IDataEditor DataEditor
|
||||
{
|
||||
get { throw new NotImplementedException(); }
|
||||
}
|
||||
|
||||
public override IDataPrevalue PrevalueEditor
|
||||
{
|
||||
get { throw new NotImplementedException(); }
|
||||
}
|
||||
|
||||
public override IData Data
|
||||
{
|
||||
get { throw new NotImplementedException(); }
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
@@ -165,8 +165,10 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
unitOfWork.Commit();
|
||||
|
||||
// Act
|
||||
var newId = Guid.NewGuid();
|
||||
var definition = repository.Get(dataTypeDefinition.Id);
|
||||
definition.Name = "AgeDataType Updated";
|
||||
definition.ControlId = newId;
|
||||
repository.AddOrUpdate(definition);
|
||||
unitOfWork.Commit();
|
||||
|
||||
@@ -175,6 +177,7 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
// Assert
|
||||
Assert.That(definitionUpdated, Is.Not.Null);
|
||||
Assert.That(definitionUpdated.Name, Is.EqualTo("AgeDataType Updated"));
|
||||
Assert.That(definitionUpdated.ControlId, Is.EqualTo(newId));
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
||||
@@ -296,7 +296,6 @@
|
||||
<Compile Include="PublishedContent\DynamicNodeTests.cs" />
|
||||
<Compile Include="ObjectExtensionsTests.cs" />
|
||||
<Compile Include="PublishedCache\PublishedContentCacheTests.cs" />
|
||||
<Compile Include="DataTypeFactoryTests.cs" />
|
||||
<Compile Include="Resolvers\LazyManyObjectResolverTests.cs" />
|
||||
<Compile Include="Resolvers\ManyResolverTests.cs" />
|
||||
<Compile Include="Resolvers\SingleResolverTests.cs" />
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using System.Web.Mvc;
|
||||
|
||||
namespace Umbraco.Belle.App_Plugins.MyPackage.Controllers
|
||||
namespace Umbraco.Web.UI.App_Plugins.MyPackage.Controllers
|
||||
{
|
||||
|
||||
public class ServerSidePropertyEditorsController : Controller
|
||||
|
||||
@@ -12,19 +12,20 @@ namespace Umbraco.Web.UI.App_Plugins.MyPackage.PropertyEditors
|
||||
/// </summary>
|
||||
internal class PostcodeValidator : ValidatorBase
|
||||
{
|
||||
public override IEnumerable<ValidationResult> Validate(object value, string preValues, PropertyEditor editor)
|
||||
|
||||
public override IEnumerable<ValidationResult> Validate(string value, string preValues, PropertyEditor editor)
|
||||
{
|
||||
var stringVal = value.ToString();
|
||||
var stringVal = value;
|
||||
|
||||
if (preValues.IsNullOrWhiteSpace()) yield break;
|
||||
var asJson = JObject.Parse(preValues);
|
||||
if (asJson["country"] == null) yield break;
|
||||
|
||||
|
||||
if (asJson["country"].ToString() == "Australia")
|
||||
{
|
||||
if (!Regex.IsMatch(stringVal, "^\\d{4}$"))
|
||||
if (Regex.IsMatch(stringVal, "^\\d{4}$") == false)
|
||||
{
|
||||
yield return new ValidationResult("Australian postcodes must be a 4 digit number",
|
||||
yield return new ValidationResult("Australian postcodes must be a 4 digit number",
|
||||
new[]
|
||||
{
|
||||
//we only store a single value for this editor so the 'member' or 'field'
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using System.Web.Routing;
|
||||
using Umbraco.Core.PropertyEditors;
|
||||
|
||||
namespace Umbraco.Web.UI.App_Plugins.MyPackage.PropertyEditors
|
||||
{
|
||||
|
||||
@@ -1,14 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using System.Web.Routing;
|
||||
using Umbraco.Belle.System;
|
||||
using Umbraco.Core;
|
||||
using umbraco.businesslogic;
|
||||
using Umbraco.Web.UI.JavaScript;
|
||||
|
||||
namespace Umbraco.Belle.App_Plugins.MyPackage.System
|
||||
namespace Umbraco.Web.UI.App_Plugins.MyPackage.System
|
||||
{
|
||||
public class MyStartupHandler : ApplicationEventHandler
|
||||
{
|
||||
|
||||
@@ -1,11 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Web;
|
||||
using System.Text;
|
||||
using umbraco.cms.presentation.Trees;
|
||||
|
||||
namespace Umbraco.Belle.App_Plugins.MyPackage.Trees
|
||||
namespace Umbraco.Web.UI.App_Plugins.MyPackage.Trees
|
||||
{
|
||||
public class LegacyTestTree : BaseTree
|
||||
{
|
||||
|
||||
@@ -1,9 +1,16 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Web.UI;
|
||||
using System.Web.UI.WebControls;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.PropertyEditors;
|
||||
using umbraco.cms.presentation.Trees;
|
||||
using umbraco.IO;
|
||||
using umbraco.interfaces;
|
||||
|
||||
namespace umbraco.cms.presentation.developer
|
||||
{
|
||||
@@ -15,68 +22,78 @@ namespace umbraco.cms.presentation.developer
|
||||
|
||||
}
|
||||
protected ImageButton save;
|
||||
private cms.businesslogic.datatype.DataTypeDefinition dt;
|
||||
cms.businesslogic.datatype.controls.Factory f;
|
||||
|
||||
private int _id = 0;
|
||||
private interfaces.IDataPrevalue _prevalue;
|
||||
private IDataPrevalue _prevalue;
|
||||
private IDataTypeDefinition _dataTypeDefinition;
|
||||
|
||||
protected void Page_Load(object sender, System.EventArgs e)
|
||||
protected void Page_Load(object sender, EventArgs e)
|
||||
{
|
||||
pp_name.Text = ui.Text("name");
|
||||
pp_renderControl.Text = ui.Text("renderControl");
|
||||
pane_settings.Text = ui.Text("settings");
|
||||
pp_guid.Text = ui.Text("guid");
|
||||
|
||||
|
||||
_id = int.Parse(Request.QueryString["id"]);
|
||||
dt = cms.businesslogic.datatype.DataTypeDefinition.GetDataTypeDefinition(_id);
|
||||
|
||||
|
||||
f = new cms.businesslogic.datatype.controls.Factory();
|
||||
|
||||
if (!IsPostBack)
|
||||
_dataTypeDefinition = ApplicationContext.Services.DataTypeService.GetDataTypeDefinitionById(_id);
|
||||
|
||||
if (IsPostBack == false)
|
||||
{
|
||||
txtName.Text = dt.Text;
|
||||
txtName.Text = _dataTypeDefinition.Name;
|
||||
|
||||
SortedList datatypes = new SortedList();
|
||||
//get the legacy data types
|
||||
var datatypes = DataTypesResolver.Current.DataTypes
|
||||
.ToDictionary(df => df.Id, df => "(legacy) " + df.DataTypeName);
|
||||
|
||||
foreach (interfaces.IDataType df in f.GetAll())
|
||||
datatypes.Add(df.DataTypeName + "|" + Guid.NewGuid().ToString(), df.Id);
|
||||
//get the new property editors
|
||||
var propEditors = PropertyEditorResolver.Current.PropertyEditors
|
||||
.ToDictionary(pe => pe.Id, pe => pe.Name);
|
||||
|
||||
IDictionaryEnumerator ide = datatypes.GetEnumerator();
|
||||
|
||||
string datatTypeId = dt.DataType != null ? dt.DataType.Id.ToString() : String.Empty;
|
||||
while (ide.MoveNext())
|
||||
//join the lists
|
||||
var combined = propEditors.Concat(datatypes);
|
||||
|
||||
foreach (var item in combined)
|
||||
{
|
||||
ListItem li = new ListItem();
|
||||
li.Text = ide.Key.ToString().Substring(0, ide.Key.ToString().IndexOf("|"));
|
||||
li.Value = ide.Value.ToString();
|
||||
var li = new ListItem
|
||||
{
|
||||
|
||||
Text = item.Value,
|
||||
Value = item.Key.ToString()
|
||||
};
|
||||
|
||||
if (_dataTypeDefinition.ControlId != default(Guid) && li.Value == _dataTypeDefinition.ControlId.ToString())
|
||||
{
|
||||
li.Selected = true;
|
||||
}
|
||||
|
||||
if (!String.IsNullOrEmpty(datatTypeId) && li.Value.ToString() == datatTypeId) li.Selected = true;
|
||||
ddlRenderControl.Items.Add(li);
|
||||
}
|
||||
}
|
||||
|
||||
ClientTools
|
||||
.SetActiveTreeType(TreeDefinitionCollection.Instance.FindTree<loadDataTypes>().Tree.Alias)
|
||||
.SyncTree("-1,init," + _id.ToString(), false);
|
||||
.SyncTree("-1,init," + _id.ToString(CultureInfo.InvariantCulture), false);
|
||||
|
||||
}
|
||||
|
||||
if (dt.DataType != null)
|
||||
litGuid.Text = dt.DataType.Id.ToString();
|
||||
Panel1.Text = umbraco.ui.Text("edit") + " datatype: " + dt.Text;
|
||||
insertPrevalueEditor();
|
||||
if (_dataTypeDefinition.ControlId != default(Guid))
|
||||
{
|
||||
litGuid.Text = _dataTypeDefinition.ControlId.ToString();
|
||||
}
|
||||
|
||||
Panel1.Text = ui.Text("edit") + " datatype: " + _dataTypeDefinition.Name;
|
||||
InsertPrevalueEditor();
|
||||
}
|
||||
|
||||
private void insertPrevalueEditor()
|
||||
private void InsertPrevalueEditor()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (ddlRenderControl.SelectedIndex >= 0)
|
||||
{
|
||||
interfaces.IDataType o = f.DataType(new Guid(ddlRenderControl.SelectedValue));
|
||||
var o = DataTypesResolver.Current.GetById(new Guid(ddlRenderControl.SelectedValue));
|
||||
|
||||
o.DataTypeDefinitionId = dt.Id;
|
||||
o.DataTypeDefinitionId = _dataTypeDefinition.Id;
|
||||
_prevalue = o.PrevalueEditor;
|
||||
|
||||
if (o.PrevalueEditor.Editor != null)
|
||||
@@ -97,44 +114,26 @@ namespace umbraco.cms.presentation.developer
|
||||
if (_prevalue != null)
|
||||
_prevalue.Save();
|
||||
|
||||
dt.Text = txtName.Text;
|
||||
_dataTypeDefinition.ControlId = new Guid(ddlRenderControl.SelectedValue);
|
||||
_dataTypeDefinition.Name = txtName.Text;
|
||||
|
||||
dt.DataType = f.DataType(new Guid(ddlRenderControl.SelectedValue));
|
||||
dt.Save();
|
||||
ApplicationContext.Services.DataTypeService.Save(_dataTypeDefinition, UmbracoUser.Id);
|
||||
|
||||
ClientTools.ShowSpeechBubble(speechBubbleIcon.save, ui.Text("speechBubbles", "dataTypeSaved", null), "");
|
||||
|
||||
ClientTools.SyncTree(dt.Path, true);
|
||||
ClientTools.SyncTree("-1,init," + _id.ToString(CultureInfo.InvariantCulture), true);
|
||||
}
|
||||
|
||||
|
||||
#region Web Form Designer generated code
|
||||
|
||||
|
||||
override protected void OnInit(EventArgs e)
|
||||
{
|
||||
save = Panel1.Menu.NewImageButton();
|
||||
save.ID = "save";
|
||||
save.Click += new System.Web.UI.ImageClickEventHandler(save_click);
|
||||
save.Click += save_click;
|
||||
save.ImageUrl = SystemDirectories.Umbraco + "/images/editor/save.gif";
|
||||
|
||||
Panel1.hasMenu = true;
|
||||
|
||||
//
|
||||
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
|
||||
//
|
||||
InitializeComponent();
|
||||
base.OnInit(e);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,7 +128,7 @@ namespace umbraco.cms.presentation
|
||||
|
||||
private void UpdateMediaFileLinksLiteral()
|
||||
{
|
||||
var uploadField = new Factory().GetNewObject(new Guid(Constants.PropertyEditors.UploadField));
|
||||
var uploadField = DataTypesResolver.Current.GetById(new Guid(Constants.PropertyEditors.UploadField));
|
||||
|
||||
// always clear, incase the upload file was removed
|
||||
this._mediaFileLinksLiteral.Text = string.Empty;
|
||||
|
||||
@@ -568,7 +568,7 @@ namespace umbraco.cms.businesslogic
|
||||
// Remove all files
|
||||
|
||||
var fs = FileSystemProviderManager.Current.GetFileSystemProvider<MediaFileSystem>();
|
||||
var uploadField = new Factory().GetNewObject(new Guid(Constants.PropertyEditors.UploadField));
|
||||
var uploadField = DataTypesResolver.Current.GetById(new Guid(Constants.PropertyEditors.UploadField));
|
||||
|
||||
foreach (Property p in GenericProperties)
|
||||
{
|
||||
|
||||
@@ -55,9 +55,8 @@ namespace umbraco.cms.businesslogic.datatype
|
||||
{
|
||||
if (_controlId == Guid.Empty)
|
||||
return null;
|
||||
|
||||
controls.Factory factory = new controls.Factory();
|
||||
var dt = factory.DataType(_controlId);
|
||||
|
||||
var dt = DataTypesResolver.Current.GetById(_controlId);
|
||||
|
||||
if (dt != null)
|
||||
dt.DataTypeDefinitionId = Id;
|
||||
@@ -157,16 +156,12 @@ namespace umbraco.cms.businesslogic.datatype
|
||||
|
||||
|
||||
//Make sure that the dtd is not already present
|
||||
if (!CMSNode.IsNode(new Guid(_def)))
|
||||
if (IsNode(new Guid(_def)) == false)
|
||||
{
|
||||
BusinessLogic.User u = BusinessLogic.User.GetCurrent();
|
||||
var u = BusinessLogic.User.GetCurrent() ?? BusinessLogic.User.GetUser(0);
|
||||
|
||||
if (u == null)
|
||||
u = BusinessLogic.User.GetUser(0);
|
||||
|
||||
var f = new controls.Factory();
|
||||
DataTypeDefinition dtd = MakeNew(u, _name, new Guid(_def));
|
||||
var dataType = f.DataType(new Guid(_id));
|
||||
var dtd = MakeNew(u, _name, new Guid(_def));
|
||||
var dataType = DataTypesResolver.Current.GetById(new Guid(_id));
|
||||
if (dataType == null)
|
||||
throw new NullReferenceException("Could not resolve a data type with id " + _id);
|
||||
|
||||
@@ -238,17 +233,16 @@ namespace umbraco.cms.businesslogic.datatype
|
||||
public static DataTypeDefinition MakeNew(BusinessLogic.User u, string Text, Guid UniqueId)
|
||||
{
|
||||
|
||||
int newId = CMSNode.MakeNew(-1, _objectType, u.Id, 1, Text, UniqueId).Id;
|
||||
cms.businesslogic.datatype.controls.Factory f = new cms.businesslogic.datatype.controls.Factory();
|
||||
var newId = MakeNew(-1, _objectType, u.Id, 1, Text, UniqueId).Id;
|
||||
|
||||
// initial control id changed to empty to ensure that it'll always work no matter if 3rd party configurators fail
|
||||
// ref: http://umbraco.codeplex.com/workitem/29788
|
||||
Guid FirstcontrolId = Guid.Empty;
|
||||
var firstcontrolId = Guid.Empty;
|
||||
|
||||
SqlHelper.ExecuteNonQuery("Insert into cmsDataType (nodeId, controlId, dbType) values (" + newId.ToString() + ",@controlId,'Ntext')",
|
||||
SqlHelper.CreateParameter("@controlId", FirstcontrolId));
|
||||
SqlHelper.CreateParameter("@controlId", firstcontrolId));
|
||||
|
||||
DataTypeDefinition dtd = new DataTypeDefinition(newId);
|
||||
var dtd = new DataTypeDefinition(newId);
|
||||
dtd.OnNew(EventArgs.Empty);
|
||||
|
||||
return dtd;
|
||||
|
||||
@@ -3,12 +3,7 @@ using Umbraco.Core;
|
||||
|
||||
namespace umbraco.editorControls.mediapicker
|
||||
{
|
||||
//TODO: Properly rename this for a major release
|
||||
public class MediaPickerDataType : MemberPickerDataType
|
||||
{ }
|
||||
|
||||
[Obsolete("Renamed to MediaPickerDataType because.. that is what it was all along")]
|
||||
public class MemberPickerDataType : cms.businesslogic.datatype.BaseDataType, interfaces.IDataType
|
||||
public class MediaPickerDataType : cms.businesslogic.datatype.BaseDataType, interfaces.IDataType
|
||||
{
|
||||
private interfaces.IDataEditor _editor;
|
||||
private interfaces.IData _baseData;
|
||||
@@ -25,13 +20,13 @@ namespace umbraco.editorControls.mediapicker
|
||||
}
|
||||
|
||||
|
||||
public override Guid Id
|
||||
{
|
||||
get
|
||||
{
|
||||
return new Guid(Constants.PropertyEditors.MediaPicker);
|
||||
}
|
||||
}
|
||||
public override Guid Id
|
||||
{
|
||||
get
|
||||
{
|
||||
return new Guid(Constants.PropertyEditors.MediaPicker);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public override string DataTypeName
|
||||
|
||||
Reference in New Issue
Block a user