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

Commit 2028d8a

Browse files
authored
Merge pull request #10 from umco/develop
Preparing v1.0.1 release
2 parents 7e3ad47 + 837ebe6 commit 2028d8a

File tree

7 files changed

+125
-3
lines changed

7 files changed

+125
-3
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

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

9+
![Property List Editor](docs/img/screenshots/property-list-property-editor-02.png)
10+
911
## Getting Started
1012

1113
### Installation
@@ -40,6 +42,11 @@ To clone it locally click the "Clone in Windows" button above or run the followi
4042
cd umbraco-property-list
4143
.\build.cmd
4244

45+
46+
### Documentation
47+
48+
For details on how to use the Property List package, please refer to our [Developers Guide](docs/developers-guide.md) documentation.
49+
4350
---
4451

4552
## Known Issues
@@ -70,6 +77,10 @@ Have a question?
7077
* [Lee Kelleher](https://github.com/leekelleher)
7178
* [Matt Brailsford](https://github.com/mattbrailsford)
7279

80+
If you enjoy using Property List on your commercial Umbraco projects, please do consider supporting our work on other open-source Umbraco packages.
81+
82+
<a href="https://www.patreon.com/bePatron?u=4312563"><img src="http://weareumco.com/img/umco_patreon.png?v=1" alt="Become a UMCO Patron!" height="60" /></a>
83+
7384
## License
7485

7586
Copyright &copy; 2017 UMCO, Our Umbraco and [other contributors](https://github.com/umco/umbraco-property-list/graphs/contributors)

appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
image: Visual Studio 2017
22

33
# version format
4-
version: 1.0.0.{build}
4+
version: 1.0.1.{build}
55

66
# UMBRACO_PACKAGE_PRERELEASE_SUFFIX if a rtm release build this should be blank, otherwise if empty will default to alpha
77
# example UMBRACO_PACKAGE_PRERELEASE_SUFFIX=beta

docs/developers-guide.md

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,95 @@
11
# Property List - Developers Guide
22

3+
### Contents
4+
5+
1. [Introduction](#introduction)
6+
2. [Getting Set Up](#getting-set-up)
7+
3. [Configuring Property List](#configuring-property-list)
8+
4. [Editing Property List](#editing-property-list)
9+
5. [Rendering Property List](#rendering-property-list)
10+
6. [Useful Links](#useful-links)
11+
12+
---
13+
14+
### Introduction
15+
16+
**Property List** is property editor for making repeatable lists for Umbraco 7.6+, similar to the default [**Multiple Textbox aka Repeatable textstrings**](https://our.umbraco.com/documentation/getting-started/backoffice/property-editors/built-in-property-editors/Multiple-Textbox) editor. However **Property List** has the ability to use any data-type to define the type of the list. By using data-types, we can use any property-editor to power the list, opening up to community property-editors, such as [**Styled Textbox**](https://our.umbraco.com/projects/backoffice-extensions/styled-textbox/).
17+
18+
---
19+
20+
### Getting Set Up
21+
22+
Before you get started, there are a number of things you will need:
23+
24+
1. Umbraco 7.6.0+
25+
2. The **Property List** package installed
26+
27+
---
28+
29+
### Configuring Property List
30+
31+
The **Property List** property editor is set-up/configured in the same way as any standard property editor, via the *Data Types* admin interface. To set-up your Property List property, create a new *Data Type* and select **Property List** from the list of available property editors.
32+
33+
You should then be presented with the **Property List** property editors prevalue editor as shown below.
34+
35+
![Property List - Prevalue Editor](img/screenshots/property-list-data-prevalues.png)
36+
37+
The prevalue editor allows you to configure the following properties.
38+
39+
| Member | Type | Description |
40+
|-----------------|---------|-------------|
41+
| Data Type | Picker | Select the data-type you wish to use for your **Property List**. By default, the **Textstring** will be pre-selected. |
42+
| Min Items | Integer | Sets the minimum number of items that should be allowed in the list. If greater than `0`, **Property List** will pre-populate your list with the minimum amount of allowed items and prevent deleting items below this level. Defaults to `0`.
43+
| Max Items | Integer | Sets the maximum number of items that should be allowed in the list. If greater than `0`, **Property List** will prevent new items being added to the list above this threshold. Defaults to `0`. |
44+
| Hide Label | Boolean | Enabling this will hide the property editors label and expand the **Property List** property editor to the full with of the editor window. |
45+
46+
Once your data-type has been configured, set-up a property on your page document-type using your new data-type and you are set to start editing.
47+
48+
---
49+
50+
### Editing Property List
51+
52+
When viewing a **Property List** editor for the first time, you'll be presented with a simple "Add item" button to get you started.
53+
54+
![Property List - Add Item](img/screenshots/property-list-property-editor-01.png)
55+
56+
Clicking the "Add item" button will add a new item in the list.
57+
58+
To reorder the list, click and drag the move icon up and down to place the items in the order you want.
59+
60+
![Property List - Add Item](img/screenshots/property-list-property-editor-02.png)
61+
62+
To remove an item from the list, click the trash can icon. If the minimum number of items is reached, then the trash can icon will disappear, this prevents going below the minimum allowed number of items.
63+
64+
---
65+
66+
### Rendering Property List
67+
68+
To render the stored value of your **Property List** property, a built-in value-converter is provided for you. By calling the `GetPropertyValue<T>` method with a generic type of `IEnumerable<string>` and the stored value will be returned as a list of `string` entity.
69+
70+
Please note, that the type of the `IEnumerable<T>` will depend on the data-type you have selected. The default **Textstring** will return a `string` object-type. If you select a different data-type, you will need to update the object-type (`T`) accordingly.
71+
72+
Example:
73+
74+
```csharp
75+
@inherits Umbraco.Web.Mvc.UmbracoViewPage
76+
@{
77+
var items = Model.GetPropertyValue<IEnumerable<string>>("myPropertyAlias");
78+
79+
<ul>
80+
@foreach(var item in items)
81+
{
82+
<li>@item</li>
83+
}
84+
</ul>
85+
}
86+
```
87+
88+
If you are using Umbraco's ModelsBuilder feature, then the underlying object-type will automatically be wired up for you. You don't need to worry about this part.
89+
90+
---
91+
92+
### Useful Links
93+
94+
* [Source Code](https://github.com/umco/umbraco-property-list)
95+
* [Our Umbraco Project Page](http://our.umbraco.org/projects/backoffice-extensions/property-list)
Loading
Loading
Loading

src/Our.Umbraco.PropertyList/ValueConverters/PropertyListValueConverter.cs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,16 @@ public class PropertyListValueConverter : PropertyValueConverterBase, IPropertyV
1919
{
2020
public override bool IsConverter(PublishedPropertyType propertyType)
2121
{
22-
return propertyType.PropertyEditorAlias.Equals(PropertyEditorKeys.Alias);
22+
return propertyType.PropertyEditorAlias.InvariantEquals(PropertyEditorKeys.Alias);
2323
}
2424

2525
public override object ConvertDataToSource(PublishedPropertyType propertyType, object source, bool preview)
2626
{
2727
var data = source?.ToString();
2828
if (string.IsNullOrWhiteSpace(data))
29+
{
2930
return null;
31+
}
3032

3133
var innerPropertyType = this.GetInnerPublishedPropertyType(propertyType);
3234

@@ -41,14 +43,18 @@ public override object ConvertDataToSource(PublishedPropertyType propertyType, o
4143
{
4244
var model = JsonConvert.DeserializeObject<PropertyListValue>(data);
4345
if (model != null)
46+
{
4447
items.AddRange(model.Values);
48+
}
4549
}
4650
else
4751
{
4852
// otherwise we assume it's XML
4953
var elements = XElement.Parse(data);
5054
if (elements != null && elements.HasElements)
55+
{
5156
items.AddRange(elements.XPathSelectElements("value").Select(x => x.Value));
57+
}
5258
}
5359

5460
var values = new List<object>();
@@ -79,14 +85,26 @@ public override object ConvertSourceToObject(PublishedPropertyType propertyType,
7985
}
8086
}
8187

82-
// Force result to right type
88+
// Ensure the result is of the correct type
8389
var targetType = innerPropertyType.ClrType;
8490
var result = Array.CreateInstance(targetType, objects.Count);
8591
for (var i = 0; i < objects.Count; i++)
8692
{
8793
var attempt = objects[i].TryConvertTo(targetType);
8894
if (attempt.Success)
95+
{
8996
result.SetValue(attempt.Result, i);
97+
}
98+
else
99+
{
100+
// NOTE: At this point `TryConvertTo` can't convert to the `targetType`.
101+
// This may be a case where the `targetType` is an interface.
102+
// We can attempt to cast it directly, as a last resort.
103+
if (targetType.IsInstanceOfType(objects[i]))
104+
{
105+
result.SetValue(objects[i], i);
106+
}
107+
}
90108
}
91109

92110
return result;

0 commit comments

Comments
 (0)