Skip to content
This repository has been archived by the owner on Dec 13, 2021. It is now read-only.

Commit

Permalink
Merge pull request #8 from umco/develop
Browse files Browse the repository at this point in the history
Preparing v1.0.0 release
  • Loading branch information
leekelleher authored Jul 17, 2018
2 parents ec376fd + 1711cb4 commit 7e3ad47
Show file tree
Hide file tree
Showing 14 changed files with 220 additions and 90 deletions.
20 changes: 8 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

[![Build status](https://img.shields.io/appveyor/ci/UMCO/umbraco-property-list.svg)](https://ci.appveyor.com/project/UMCO/umbraco-property-list)
[![NuGet release](https://img.shields.io/nuget/v/Our.Umbraco.PropertyList.svg)](https://www.nuget.org/packages/Our.Umbraco.PropertyList)
[![Our Umbraco project page](https://img.shields.io/badge/our-umbraco-orange.svg)](https://our.umbraco.org/projects/backoffice-extensions/property-list)

Property List is a property editor for making repeatable lists of a datatype for Umbraco 7.6+

Expand All @@ -11,8 +12,13 @@ Property List is a property editor for making repeatable lists of a datatype for

> *Note:* Property List has been developed against **Umbraco v7.6.0** and will support that version and above.
Property List can be installed from either NuGet package repositories, or build manually from the source-code:
Property List can be installed from either Our Umbraco, NuGet package repositories, or build manually from the source-code:

#### Our Umbraco package repository

To install from Our Umbraco, please download the package from:

> <https://our.umbraco.org/projects/backoffice-extensions/property-list>
#### NuGet package repository

Expand Down Expand Up @@ -50,23 +56,13 @@ Anyone and everyone is welcome to contribute. Please take a moment to review the
* [Feature requests](CONTRIBUTING.md#features)
* [Pull requests](CONTRIBUTING.md#pull-requests)

### TODO

What's left to do?

- [ ] Deploy ValueConnector
- [ ] Pre Value Editor
- [ ] Add DataType dependency
- [ ] Value Editor
- [ ] Processing all list item DataTypes


---

## Contact

Have a question?

* [Property List Forum](https://our.umbraco.org/projects/backoffice-extensions/property-list/property-list-feedback) on Our Umbraco
* [Raise an issue](https://github.com/umco/umbraco-property-list/issues) on GitHub

## Dev Team
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ version: 1.0.0.{build}
# UMBRACO_PACKAGE_PRERELEASE_SUFFIX if a rtm release build this should be blank, otherwise if empty will default to alpha
# example UMBRACO_PACKAGE_PRERELEASE_SUFFIX=beta
init:
- set UMBRACO_PACKAGE_PRERELEASE_SUFFIX=beta2
- set UMBRACO_PACKAGE_PRERELEASE_SUFFIX=

cache:
- src\packages -> **\packages.config # preserve "packages" directory in the root of build folder but will reset it if packages.config is modified
Expand Down
4 changes: 4 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Property List
## Documentation

* [Property List - Developers Guide](developers-guide.md)
2 changes: 2 additions & 0 deletions docs/developers-guide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Property List - Developers Guide

11 changes: 6 additions & 5 deletions src/Our.Umbraco.PropertyList/Bootstrap.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Newtonsoft.Json;
using Our.Umbraco.PropertyList.ValueConverters;
using System;
using Newtonsoft.Json;
using Umbraco.Core;
using Umbraco.Core.Sync;
using Umbraco.Web.Cache;
Expand All @@ -17,15 +17,16 @@ protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplica
// NOTE: The properties for the JSON payload are available here: (Currently there isn't a public API to deserialize the payload)
// https://github.com/umbraco/Umbraco-CMS/blob/release-7.6.0/src/Umbraco.Web/Cache/DataTypeCacheRefresher.cs#L66-L70
// TODO: Once `DataTypeCacheRefresher.DeserializeFromJsonPayload` is public, we can deserialize correctly.
// TODO: Once Umbraco's `DataTypeCacheRefresher.DeserializeFromJsonPayload` is public, we can deserialize correctly.
// https://github.com/umbraco/Umbraco-CMS/blob/release-7.6.0/src/Umbraco.Web/Cache/DataTypeCacheRefresher.cs#L27
var payload = JsonConvert.DeserializeAnonymousType((string)e.MessageObject, new[] { new { Id = default(int) } });
var payload = JsonConvert.DeserializeAnonymousType((string)e.MessageObject, new[] { new { Id = default(int), UniqueId = Guid.Empty } });
if (payload == null)
return;
foreach (var item in payload)
{
PropertyListValueConverter.ClearDataTypeCache(item.Id);
PropertyEditors.PropertyListValidator.ClearDataTypeCache(item.UniqueId);
ValueConverters.PropertyListValueConverter.ClearDataTypeCache(item.Id);
}
};
}
Expand Down
15 changes: 1 addition & 14 deletions src/Our.Umbraco.PropertyList/Our.Umbraco.PropertyList.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -43,32 +43,18 @@
<HintPath>..\packages\UmbracoCms.Core.7.6.0\lib\net45\interfaces.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="log4net, Version=2.0.8.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
<HintPath>..\packages\UmbracoCms.Core.7.6.0\lib\net45\log4net.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="MiniProfiler, Version=2.1.0.0, Culture=neutral, PublicKeyToken=b44f9351044011a3, processorArchitecture=MSIL">
<HintPath>..\packages\MiniProfiler.2.1.0\lib\net40\MiniProfiler.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.10.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Core" />
<Reference Include="System.Web" />
<Reference Include="System.Web.Http, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.AspNet.WebApi.Core.5.2.3\lib\net45\System.Web.Http.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.AspNet.Mvc.5.2.3\lib\net45\System.Web.Mvc.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System.Xml.Linq" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<Reference Include="umbraco, Version=1.0.6331.7975, Culture=neutral, processorArchitecture=MSIL">
Expand All @@ -82,6 +68,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Bootstrap.cs" />
<Compile Include="PropertyListConstants.cs" />
<Compile Include="ValueConverters\PropertyListValueConverter.cs" />
<Compile Include="Models\PropertyListValue.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Umbraco.Core.IO;
using Umbraco.Core.PropertyEditors;
using static Our.Umbraco.PropertyList.PropertyListConstants;

namespace Our.Umbraco.PropertyList.PropertyEditors
{
Expand All @@ -11,7 +12,7 @@ public PropertyListPreValueEditor()
// In terms of inheritance, we'd like the "dataType" field to always be at the top.
Fields.Insert(0, new PreValueField
{
Key = "dataType",
Key = PreValueKeys.DataType,
Name = "Data Type",
View = IOHelper.ResolveUrl("~/App_Plugins/PropertyList/views/propertylist.datatypepicker.html"),
Description = "Select a data type."
Expand All @@ -22,21 +23,21 @@ public PropertyListPreValueEditor()
{
new PreValueField
{
Key = "minItems",
Key = PreValueKeys.MinItems,
Name = "Min Items",
View = "number",
Description = "Set the minimum number of items allowed."
},
new PreValueField
{
Key = "maxItems",
Key = PreValueKeys.MaxItems,
Name = "Max Items",
View = "number",
Description = "Set the maximum number of items allowed."
},
new PreValueField
{
Key = "hideLabel",
Key = PreValueKeys.HideLabel,
Name = "Hide Label",
View = "boolean",
Description = "Set whether to hide the editor label and have the list take up the full width of the editor window."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,14 @@
using ClientDependency.Core;
using Umbraco.Core.PropertyEditors;
using Umbraco.Web.PropertyEditors;
using static Our.Umbraco.PropertyList.PropertyListConstants;

namespace Our.Umbraco.PropertyList.PropertyEditors
{
[PropertyEditor(PropertyEditorAlias, PropertyEditorName, "JSON", PropertyEditorViewPath, Group = "Lists", Icon = "icon-bulleted-list", IsParameterEditor = false)]
[PropertyEditorAsset(ClientDependencyType.Javascript, "~/App_Plugins/PropertyList/js/propertylist.js")]
[PropertyEditor(PropertyEditorKeys.Alias, PropertyEditorKeys.Name, PropertyEditorValueTypes.Json, PropertyEditorKeys.ViewPath, Group = PropertyEditorKeys.Group, Icon = PropertyEditorKeys.Icon, IsParameterEditor = false)]
[PropertyEditorAsset(ClientDependencyType.Javascript, PropertyEditorKeys.JavaScriptPath)]
public class PropertyListPropertyEditor : PropertyEditor
{
public const string PropertyEditorAlias = "Our.Umbraco.PropertyList";
public const string PropertyEditorName = "Property List";
public const string PropertyEditorViewPath = "~/App_Plugins/PropertyList/Views/propertylist.html";

internal const string DefaultTextstringPropertyEditorGuid = "0cc0eba1-9960-42c9-bf9b-60e150b429ae"; // Guid for default Textstring

private IDictionary<string, object> _defaultPreValues;
public override IDictionary<string, object> DefaultPreValues
{
Expand All @@ -26,9 +21,10 @@ public PropertyListPropertyEditor()
{
_defaultPreValues = new Dictionary<string, object>
{
{ "dataType", DefaultTextstringPropertyEditorGuid },
{ "minItems", 0 },
{ "maxItems", 0 }
{ PreValueKeys.DataType, DataTypeGuids.DefaultTextstring },
{ PreValueKeys.MinItems, 0 },
{ PreValueKeys.MaxItems, 0 },
{ PreValueKeys.HideLabel, 0 }
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Umbraco.Core.PropertyEditors;
using Umbraco.Core.Services;
using Umbraco.Web.PropertyEditors;
using static Our.Umbraco.PropertyList.PropertyListConstants;

namespace Our.Umbraco.PropertyList.PropertyEditors
{
Expand All @@ -26,13 +27,9 @@ public override void ConfigureForDisplay(PreValueCollection preValues)
{
base.ConfigureForDisplay(preValues);

if (preValues.PreValuesAsDictionary.ContainsKey("hideLabel"))
if (preValues.PreValuesAsDictionary.ContainsKey(PreValueKeys.HideLabel))
{
var boolAttempt = preValues.PreValuesAsDictionary["hideLabel"].Value.TryConvertTo<bool>();
if (boolAttempt.Success)
{
HideLabel = boolAttempt.Result;
}
HideLabel = preValues.PreValuesAsDictionary[PreValueKeys.HideLabel].Value == "1";
}
}

Expand All @@ -48,7 +45,7 @@ public override object ConvertDbToEditor(Property property, PropertyType propert
if (propertyValue.DetectIsJson() == false)
{
var items = string.Join("', '", propertyValue.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries));
propertyValue = $"{{ dtd: '{PropertyListPropertyEditor.DefaultTextstringPropertyEditorGuid}', values: [ '{items}' ] }}";
propertyValue = $"{{ dtd: '{DataTypeGuids.DefaultTextstring}', values: [ '{items}' ] }}";
}

var model = JsonConvert.DeserializeObject<PropertyListValue>(propertyValue);
Expand All @@ -57,16 +54,19 @@ public override object ConvertDbToEditor(Property property, PropertyType propert

// Get the associated datatype definition
var dtd = dataTypeService.GetDataTypeDefinitionById(model.DataTypeGuid);
if (dtd == null)
return base.ConvertDbToEditor(property, propertyType, dataTypeService);

// Lookup the property editor
var propEditor = PropertyEditorResolver.Current.GetByAlias(dtd.PropertyEditorAlias);
var propType = new PropertyType(dtd);
if (propEditor == null)
return base.ConvertDbToEditor(property, propertyType, dataTypeService);

var propType = new PropertyType(dtd, propertyType.Alias);

for (var i = 0; i < model.Values.Count; i++)
{
var obj = model.Values[i];

var prop = new Property(propType, obj?.ToString());
var prop = new Property(propType, model.Values[i]);
var newValue = propEditor.ValueEditor.ConvertDbToEditor(prop, propType, dataTypeService);

model.Values[i] = (newValue == null) ? null : JToken.FromObject(newValue);
Expand All @@ -87,13 +87,18 @@ public override string ConvertDbToString(Property property, PropertyType propert
return base.ConvertDbToString(property, propertyType, dataTypeService);

var dtd = dataTypeService.GetDataTypeDefinitionById(model.DataTypeGuid);
if (dtd == null)
return base.ConvertDbToString(property, propertyType, dataTypeService);

var propEditor = PropertyEditorResolver.Current.GetByAlias(dtd.PropertyEditorAlias);
var propType = new PropertyType(dtd);
if (propEditor == null)
return base.ConvertDbToString(property, propertyType, dataTypeService);

var propType = new PropertyType(dtd, propertyType.Alias);

for (var i = 0; i < model.Values.Count; i++)
{
var obj = model.Values[i];
var prop = new Property(propType, obj?.ToString());
var prop = new Property(propType, model.Values[i]);
var newValue = propEditor.ValueEditor.ConvertDbToString(prop, propType, dataTypeService);

model.Values[i] = newValue;
Expand All @@ -113,13 +118,18 @@ public override XNode ConvertDbToXml(Property property, PropertyType propertyTyp
return base.ConvertDbToXml(property, propertyType, dataTypeService);

var dtd = dataTypeService.GetDataTypeDefinitionById(model.DataTypeGuid);
if (dtd == null)
return base.ConvertDbToXml(property, propertyType, dataTypeService);

var propEditor = PropertyEditorResolver.Current.GetByAlias(dtd.PropertyEditorAlias);
var propType = new PropertyType(dtd);
if (propEditor == null)
return base.ConvertDbToXml(property, propertyType, dataTypeService);

var propType = new PropertyType(dtd, propertyType.Alias);

for (var i = 0; i < model.Values.Count; i++)
{
var obj = model.Values[i];
var prop = new Property(propType, obj?.ToString());
var prop = new Property(propType, model.Values[i]);
var newValue = propEditor.ValueEditor.ConvertDbToXml(prop, propType, dataTypeService);
model.Values[i] = newValue;
}
Expand All @@ -140,9 +150,18 @@ public override object ConvertEditorToDb(ContentPropertyData editorValue, object
return base.ConvertEditorToDb(editorValue, currentValue);

var dataTypeService = ApplicationContext.Current.Services.DataTypeService;

var dtd = dataTypeService.GetDataTypeDefinitionById(model.DataTypeGuid);
if (dtd == null)
return base.ConvertEditorToDb(editorValue, currentValue);

var preValues = dataTypeService.GetPreValuesCollectionByDataTypeId(dtd.Id);
if (preValues == null)
return base.ConvertEditorToDb(editorValue, currentValue);

var propEditor = PropertyEditorResolver.Current.GetByAlias(dtd.PropertyEditorAlias);
if (propEditor == null)
return base.ConvertEditorToDb(editorValue, currentValue);

for (var i = 0; i < model.Values.Count; i++)
{
Expand Down
Loading

0 comments on commit 7e3ad47

Please sign in to comment.