diff --git a/CHANGELOG.md b/CHANGELOG.md
index 10567c7..b4bad57 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,11 +1,10 @@
# Change log
-All notable changes to this project will be documented in this file.
-This project adheres to [Semantic Versioning](http://semver.org/).
+All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/).
# 2.1.0
### Features
- * #45 - Feature Request : Querystring Parameters. Thanks to @mattbrailsford
+ * #45 - Feature Request: query string parameters. Thanks to @mattbrailsford
* No more "Could not find persisted pre-value for field (minNumberOfItems|maxNumberOfItems)" warnings in the Umbraco log
### Bugfixes
@@ -15,14 +14,14 @@ This project adheres to [Semantic Versioning](http://semver.org/).
# 2.0.1
### Bugfixes
- * #54 - Multi Url Picker cant add nodes
+ * #54 - Multi URL Picker can't add nodes
# 2.0.0
### Features
* Updated styling to match Umbraco v7.6
- * Added Udi support
- * New data types with `max number of items` set to 1 will return a single `Link` or `null`.
+ * Added UDI support
+ * New data types with `max number of items` set to 1 will return a single `Link` or `null`
Existing data types will continue to return `IEnumerable `
### Breaking
@@ -52,16 +51,16 @@ This project adheres to [Semantic Versioning](http://semver.org/).
# 1.2.0
### Features
- * #14 - Use url as name when Page Title is left empty
+ * #14 - Use URL as name when page title is left empty
# 1.1.0
### Features
- * #8 - Hide handle when only one item.
+ * #8 - Hide handle when only one item
### Bugfixes
- * #11 - Validation problem with min/max and external links.
+ * #11 - Validation problem with min/max and external links
* #13 - Gracefully handle when the recycling bin is chosen
# 1.0.0
@@ -73,7 +72,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
### Breaking
* Upgraded to Umbraco v7.1.2
- * Removed Pick multiple items field
+ * Removed 'Pick multiple items' field
# 0.2.0
### Features
diff --git a/README.md b/README.md
index 5bea8f2..c7b15c0 100644
--- a/README.md
+++ b/README.md
@@ -1,47 +1,51 @@
-# Multi Url Picker for Umbraco 7
+# Multi URL Picker for Umbraco 7
-[](https://www.nuget.org/packages/RJP.UmbracoMultiUrlPicker)
+[](https://www.nuget.org/packages/RJP.UmbracoMultiUrlPicker)
[](https://our.umbraco.org/projects/backoffice-extensions/multi-url-picker)
-Allows editors to pick and sort multiple urls, it uses Umbraco's link picker which supports internal and external links and media.
+Allows editors to pick and sort multiple URLs, it uses Umbraco's link picker which supports internal and external links and media.
## Installation
-Install the NuGet [package](https://www.nuget.org/packages/RJP.UmbracoMultiUrlPicker).
+Install the [NuGet package](https://www.nuget.org/packages/RJP.UmbracoMultiUrlPicker):
+
+```powershell
+PM> Install-Package RJP.UmbracoMultiUrlPicker
+```
or
-Install the [package](http://our.umbraco.org/projects/backoffice-extensions/multi-url-picker) from the Umbraco package repository.
+Install the [Umbraco package](http://our.umbraco.org/projects/backoffice-extensions/multi-url-picker) from the Umbraco package repository.
## Usage
-Add a new property to your document type and select the `Multi Url Picker` property editor in the `pickers` category.
+Add a new property to your document type and select the `Multi URL Picker` property editor in the `pickers` category.
-If you're using the models builder, you can access the property on your model e.g. `Model.Links` if your property alias is `links`.
+If you're using the Models Builder, you can access the property on your model as `IEnumerable ` (e.g. `Model.Links` if your property alias is `links`):
```csharp
@{ var links = Model.Links.ToList(); }
-
@if (links.Count > 0)
{
-
- @foreach (var item in links)
- {
- @item.Name
- }
+
+ @foreach (var link in links)
+ {
+ @link.Name
+ }
}
```
-If `Max number of items` is configured to 1
+Or, if `Maximum number of items` is configured to 1, as `Link`:
```csharp
-@if(Model.Link != null)
+@{ var link = Model.Link; }
+@if (link != null)
{
- @Model.Link.Name
+ @link.Name
}
-
```
## Changelog
-See the [changelog here](CHANGELOG.md)
+
+See the [changelog here](CHANGELOG.md).
diff --git a/RJP.MultiUrlPicker.sln b/RJP.MultiUrlPicker.sln
index 18641ee..572cd80 100644
--- a/RJP.MultiUrlPicker.sln
+++ b/RJP.MultiUrlPicker.sln
@@ -1,9 +1,9 @@
Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio 14
-VisualStudioVersion = 14.0.25420.1
+# Visual Studio 15
+VisualStudioVersion = 15.0.27428.2015
MinimumVisualStudioVersion = 10.0.40219.1
-Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Files", "Files", "{F960CEAB-2C15-4617-9BA9-68E8CEBD9920}"
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Documentation", "Documentation", "{F960CEAB-2C15-4617-9BA9-68E8CEBD9920}"
ProjectSection(SolutionItems) = preProject
CHANGELOG.md = CHANGELOG.md
LICENSE = LICENSE
@@ -12,6 +12,27 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Files", "Files", "{F960CEAB
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RJP.MultiUrlPicker", "src\RJP.MultiUrlPicker\RJP.MultiUrlPicker.csproj", "{2553C499-3593-43ED-95D6-39B03CC61ED1}"
EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "RJP.MultiUrlPicker.Web.UI", "RJP.MultiUrlPicker.Web.UI", "{261C0142-E82A-4B60-B8A9-3A78A6A66C81}"
+ ProjectSection(SolutionItems) = preProject
+ src\RJP.MultiUrlPicker.Web.UI\MultiUrlPicker.html = src\RJP.MultiUrlPicker.Web.UI\MultiUrlPicker.html
+ src\RJP.MultiUrlPicker.Web.UI\MultiUrlPicker.js = src\RJP.MultiUrlPicker.Web.UI\MultiUrlPicker.js
+ EndProjectSection
+EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Build", "Build", "{537BC621-7AE3-4BCB-976A-E4BCA95EBDD8}"
+ ProjectSection(SolutionItems) = preProject
+ build.cmd = build.cmd
+ build.fsx = build.fsx
+ build\nuspec\RJP.UmbracoMultiUrlPicker.nuspec = build\nuspec\RJP.UmbracoMultiUrlPicker.nuspec
+ build\version.txt = build\version.txt
+ EndProjectSection
+EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{93AF4399-1CA6-43DE-8632-C4D42745839D}"
+ ProjectSection(SolutionItems) = preProject
+ .editorconfig = .editorconfig
+ .gitattributes = .gitattributes
+ .gitignore = .gitignore
+ EndProjectSection
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -26,4 +47,7 @@ Global
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {CB76B347-638E-4CDF-903E-B532D7D50E21}
+ EndGlobalSection
EndGlobal
diff --git a/build/nuspec/RJP.UmbracoMultiUrlPicker.nuspec b/build/nuspec/RJP.UmbracoMultiUrlPicker.nuspec
index cc07fc1..7570a73 100644
--- a/build/nuspec/RJP.UmbracoMultiUrlPicker.nuspec
+++ b/build/nuspec/RJP.UmbracoMultiUrlPicker.nuspec
@@ -1,24 +1,24 @@
-
+
-
- RJP.UmbracoMultiUrlPicker
- $version$
- Umbraco Multi Url Picker
- Rasmus John Pedersen
- Rasmus John Pedersen
- https://github.com/rasmusjp/umbraco-multi-url-picker/raw/master/LICENSE
- https://github.com/rasmusjp/umbraco-multi-url-picker
- false
- Allows editors to pick and sort multiple urls, it uses Umbraco's link picker which supports internal and external links and media.
-
- Copyright 2014 Rasmus John Pedersen
- umbraco, urlpicker, multiurlpicker
-
-
-
+
+ RJP.UmbracoMultiUrlPicker
+ $version$
+ Umbraco Multi URL Picker
+ Rasmus John Pedersen
+ Rasmus John Pedersen
+ https://github.com/rasmusjp/umbraco-multi-url-picker/raw/master/LICENSE
+ https://github.com/rasmusjp/umbraco-multi-url-picker
+ false
+ Allows editors to pick and sort multiple URLs, it uses Umbraco's link picker which supports internal and external links and media.
+
+ Copyright 2014 Rasmus John Pedersen
+ umbraco, urlpicker, multiurlpicker
+
+
+
-
-
+
+
diff --git a/src/RJP.MultiUrlPicker.Web.UI/MultiUrlPicker.html b/src/RJP.MultiUrlPicker.Web.UI/MultiUrlPicker.html
index 54dd09d..5ef1e9f 100644
--- a/src/RJP.MultiUrlPicker.Web.UI/MultiUrlPicker.html
+++ b/src/RJP.MultiUrlPicker.Web.UI/MultiUrlPicker.html
@@ -1,4 +1,4 @@
-
+
@@ -17,7 +17,6 @@
Add
diff --git a/src/RJP.MultiUrlPicker.Web.UI/MultiUrlPicker.js b/src/RJP.MultiUrlPicker.Web.UI/MultiUrlPicker.js
index b7d2b44..336ee23 100644
--- a/src/RJP.MultiUrlPicker.Web.UI/MultiUrlPicker.js
+++ b/src/RJP.MultiUrlPicker.Web.UI/MultiUrlPicker.js
@@ -1,37 +1,37 @@
(function () {
- 'use strict'
+ 'use strict';
var MultiUrlPickerController = function ($scope, angularHelper, entityResource, iconHelper) {
- this.renderModel = []
+ this.renderModel = [];
if ($scope.preview) {
- return
+ return;
}
if (!Array.isArray($scope.model.value)) {
- $scope.model.value = []
+ $scope.model.value = [];
}
$scope.model.value.forEach(function (link) {
- link.icon = iconHelper.convertFromLegacyIcon(link.icon)
- this.renderModel.push(link)
- }.bind(this))
+ link.icon = iconHelper.convertFromLegacyIcon(link.icon);
+ this.renderModel.push(link);
+ }.bind(this));
$scope.$on('formSubmitting', function () {
- $scope.model.value = this.renderModel
- }.bind(this))
+ $scope.model.value = this.renderModel;
+ }.bind(this));
$scope.$watch(function () {
- return this.renderModel.length
+ return this.renderModel.length;
}.bind(this), function () {
if ($scope.model.config && $scope.model.config.minNumberOfItems) {
- $scope.multiUrlPickerForm.minCount.$setValidity('minCount', +$scope.model.config.minNumberOfItems <= this.renderModel.length)
+ $scope.multiUrlPickerForm.minCount.$setValidity('minCount', +$scope.model.config.minNumberOfItems <= this.renderModel.length);
}
if ($scope.model.config && $scope.model.config.maxNumberOfItems) {
- $scope.multiUrlPickerForm.maxCount.$setValidity('maxCount', +$scope.model.config.maxNumberOfItems >= this.renderModel.length)
+ $scope.multiUrlPickerForm.maxCount.$setValidity('maxCount', +$scope.model.config.maxNumberOfItems >= this.renderModel.length);
}
- this.sortableOptions.disabled = this.renderModel.length === 1
- }.bind(this))
+ this.sortableOptions.disabled = this.renderModel.length === 1;
+ }.bind(this));
this.sortableOptions = {
distance: 10,
@@ -39,15 +39,15 @@
scroll: true,
zIndex: 6000,
update: function () {
- angularHelper.getCurrentForm($scope).$setDirty()
+ angularHelper.getCurrentForm($scope).$setDirty();
}
- }
+ };
this.remove = function ($index) {
- this.renderModel.splice($index, 1)
+ this.renderModel.splice($index, 1);
- angularHelper.getCurrentForm($scope).$setDirty()
- }
+ angularHelper.getCurrentForm($scope).$setDirty();
+ };
this.openLinkPicker = function (link, $index) {
var target = link ? {
@@ -58,8 +58,7 @@
url: link.url,
querystring: link.querystring,
target: link.target
- } : null
-
+ } : null;
this.linkPickerOverlay = {
view: 'linkpicker',
@@ -70,18 +69,17 @@
if (model.target.url) {
if (link) {
if (link.isMedia && link.url === model.target.url) {
- // we can assume the existing media item is changed and no new file has been selected
- // so we don't need to update the id, udi and isMedia fields
+ // We can assume the existing media item is changed and no new file has been selected, so we don't need to update the id, udi and isMedia fields
} else {
- link.id = model.target.id
- link.udi = model.target.udi
- link.isMedia = model.target.isMedia
+ link.id = model.target.id;
+ link.udi = model.target.udi;
+ link.isMedia = model.target.isMedia;
}
- link.name = model.target.name || model.target.url
- link.target = model.target.target
- link.url = model.target.url
- link.querystring = model.target.querystring
+ link.name = model.target.name || model.target.url;
+ link.target = model.target.target;
+ link.url = model.target.url;
+ link.querystring = model.target.querystring;
} else {
link = {
id: model.target.id,
@@ -91,50 +89,49 @@
udi: model.target.udi,
url: model.target.url,
querystring: model.target.querystring
- }
- this.renderModel.push(link)
+ };
+ this.renderModel.push(link);
}
if (link.udi) {
- var entityType = link.isMedia ? 'media' : 'document'
+ var entityType = link.isMedia ? 'media' : 'document';
- entityResource.getById(link.udi, entityType)
- .then(function (data) {
- link.icon = iconHelper.convertFromLegacyIcon(data.icon)
- link.published = !(data.metaData && data.metaData.IsPublished === false && entityType === 'document')
- })
+ entityResource.getById(link.udi, entityType).then(function (data) {
+ link.icon = iconHelper.convertFromLegacyIcon(data.icon);
+ link.published = !(data.metaData && data.metaData.IsPublished === false && entityType === 'document');
+ });
} else {
- link.published = true
- link.icon = 'icon-link'
+ link.published = true;
+ link.icon = 'icon-link';
}
- angularHelper.getCurrentForm($scope).$setDirty()
+ angularHelper.getCurrentForm($scope).$setDirty();
}
- this.linkPickerOverlay.show = false
- this.linkPickerOverlay = null
+ this.linkPickerOverlay.show = false;
+ this.linkPickerOverlay = null;
}.bind(this)
- }
- }
- }
+ };
+ };
+ };
var mupHttpProvider = function ($httpProvider) {
$httpProvider.interceptors.push(function ($q) {
return {
response: function (response) {
if (response.config.url.indexOf('views/common/overlays/linkpicker/linkpicker.html') !== -1) {
- // Inject the querystring field
- var $markup = $(response.data)
- var $urlField = $markup.find('[label="@defaultdialogs_urlLinkPicker"]')
- $urlField.after(' ')
- response.data = $markup[0]
+ // Inject the query string field
+ var $markup = $(response.data);
+ var $urlField = $markup.find('[label="@defaultdialogs_urlLinkPicker"]');
+ $urlField.after(' ');
+ response.data = $markup[0];
}
- return response
+ return response;
}
- }
- })
- }
+ };
+ });
+ };
- angular.module('umbraco').controller('RJP.MultiUrlPickerController', MultiUrlPickerController)
+ angular.module('umbraco').controller('RJP.MultiUrlPickerController', MultiUrlPickerController);
angular.module("umbraco.services").config(['$httpProvider', mupHttpProvider]);
-})()
+})();
diff --git a/src/RJP.MultiUrlPicker/Information.cs b/src/RJP.MultiUrlPicker/Information.cs
index c8b98ba..3e2df27 100644
--- a/src/RJP.MultiUrlPicker/Information.cs
+++ b/src/RJP.MultiUrlPicker/Information.cs
@@ -1,4 +1,4 @@
-namespace RJP.MultiUrlPicker
+namespace RJP.MultiUrlPicker
{
using System;
using System.Reflection;
@@ -12,12 +12,6 @@ static Information()
_version = new Lazy(() => Assembly.GetExecutingAssembly().GetName().Version);
}
- public static Version Version
- {
- get
- {
- return _version.Value;
- }
- }
+ public static Version Version => _version.Value;
}
}
diff --git a/src/RJP.MultiUrlPicker/Models/Link.cs b/src/RJP.MultiUrlPicker/Models/Link.cs
index dbcf02f..74071ad 100644
--- a/src/RJP.MultiUrlPicker/Models/Link.cs
+++ b/src/RJP.MultiUrlPicker/Models/Link.cs
@@ -1,16 +1,16 @@
-namespace RJP.MultiUrlPicker.Models
+namespace RJP.MultiUrlPicker.Models
{
using System;
-
using Newtonsoft.Json.Linq;
-
- using Umbraco.Core.Models;
using Umbraco.Core;
-
+ using Umbraco.Core.Models;
+ using Umbraco.Core.Models.PublishedContent;
using Umbraco.Web;
using Umbraco.Web.Extensions;
- using Umbraco.Core.Models.PublishedContent;
+ ///
+ /// Represents a link.
+ ///
public class Link
{
private readonly JToken _linkItem;
@@ -38,7 +38,7 @@ private IPublishedContent PublishedContent
}
}
- [Obsolete("Use Udi instead")]
+ [Obsolete("Use Udi instead.")]
public int? Id
{
get
@@ -179,7 +179,7 @@ private void InitPublishedContent()
{
var helper = new UmbracoHelper(UmbracoContext.Current);
- // there were no Udi so let's try the legacy way
+ // There is no Udi, so let's try the legacy way
_id = _linkItem.Value("id");
if (_id.HasValue)
@@ -207,18 +207,14 @@ private void SetUdi()
Guid? key = _content.GetKey();
if (key == Guid.Empty)
{
- // if the key is Guid.Empty the model might be created by the ModelsBuilder,
- // if so it, by default, derives from PublishedContentModel.
- // By calling UnWrap() we get the original content, which probably implements
- // IPublishedContentWithKey, so we can get the key
+ // If the key is Guid.Empty, the model might be created by the ModelsBuilder, if so it (by default) derives from PublishedContentModel.
+ // By calling UnWrap() we get the original content, which probably implements IPublishedContentWithKey, so we can get the key.
key = (_content as PublishedContentWrapped)?.Unwrap().GetKey();
}
if (key.HasValue && key != Guid.Empty)
{
- string udiType = _content.ItemType == PublishedItemType.Media ?
- Constants.UdiEntityType.Media :
- Constants.UdiEntityType.Document;
+ string udiType = _content.ItemType == PublishedItemType.Media ? Constants.UdiEntityType.Media : Constants.UdiEntityType.Document;
_udi = Udi.Create(udiType, key.Value);
}
diff --git a/src/RJP.MultiUrlPicker/Models/LinkDisplay.cs b/src/RJP.MultiUrlPicker/Models/LinkDisplay.cs
index 25533e2..5597144 100644
--- a/src/RJP.MultiUrlPicker/Models/LinkDisplay.cs
+++ b/src/RJP.MultiUrlPicker/Models/LinkDisplay.cs
@@ -1,9 +1,11 @@
-namespace RJP.MultiUrlPicker.Models
+namespace RJP.MultiUrlPicker.Models
{
using System.Runtime.Serialization;
-
using Umbraco.Core;
+ ///
+ /// Represents a link for displaying in the editor.
+ ///
[DataContract]
internal class LinkDisplay
{
diff --git a/src/RJP.MultiUrlPicker/Models/LinkDto.cs b/src/RJP.MultiUrlPicker/Models/LinkDto.cs
index 9eaef7c..bde8070 100644
--- a/src/RJP.MultiUrlPicker/Models/LinkDto.cs
+++ b/src/RJP.MultiUrlPicker/Models/LinkDto.cs
@@ -1,9 +1,11 @@
-namespace RJP.MultiUrlPicker.Models
+namespace RJP.MultiUrlPicker.Models
{
using System.Runtime.Serialization;
-
using Umbraco.Core;
+ ///
+ /// Represents a link for saving in the database.
+ ///
[DataContract]
internal class LinkDto
{
diff --git a/src/RJP.MultiUrlPicker/Models/LinkType.cs b/src/RJP.MultiUrlPicker/Models/LinkType.cs
index 7b00650..8cf85e9 100644
--- a/src/RJP.MultiUrlPicker/Models/LinkType.cs
+++ b/src/RJP.MultiUrlPicker/Models/LinkType.cs
@@ -1,4 +1,4 @@
-namespace RJP.MultiUrlPicker.Models
+namespace RJP.MultiUrlPicker.Models
{
public enum LinkType
{
@@ -6,4 +6,4 @@ public enum LinkType
Media,
External
}
-}
\ No newline at end of file
+}
diff --git a/src/RJP.MultiUrlPicker/Models/MultiUrls.cs b/src/RJP.MultiUrlPicker/Models/MultiUrls.cs
index 976d577..35c3d0c 100644
--- a/src/RJP.MultiUrlPicker/Models/MultiUrls.cs
+++ b/src/RJP.MultiUrlPicker/Models/MultiUrls.cs
@@ -1,34 +1,21 @@
-namespace RJP.MultiUrlPicker.Models
+namespace RJP.MultiUrlPicker.Models
{
using System;
+ using System.Collections;
using System.Collections.Generic;
using System.Linq;
-
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
-
using Umbraco.Core.Logging;
- [Obsolete("Use IEnumerable instead")]
+ [Obsolete("Use IEnumerable instead.")]
public class MultiUrls : IEnumerable
{
- private readonly string _propertyData;
- private readonly List _multiUrls = new List ();
-
- internal MultiUrls()
- {
- }
-
- internal MultiUrls(JArray propertyData)
- {
- _propertyData = propertyData.ToString();
-
- Initialize(propertyData);
- }
+ private readonly List _multiUrls = new List ();
public MultiUrls(string propertyData)
{
- _propertyData = propertyData;
+ PropertyData = propertyData;
if (!string.IsNullOrEmpty(propertyData))
{
@@ -37,35 +24,22 @@ public MultiUrls(string propertyData)
}
}
- private void Initialize(JArray data)
- {
- foreach (var item in data)
- {
- var newLink = new Link(item);
- if (!newLink.Deleted)
- {
- _multiUrls.Add(new Link(item));
- }
- else
- {
- LogHelper.Warn(
- string.Format("MultiUrlPicker value converter skipped a link as the node has been upublished/deleted (Id: {0}), ", newLink.Id));
- }
- }
- }
+ internal MultiUrls()
+ { }
- public string PropertyData
+ internal MultiUrls(JArray propertyData)
{
- get
- {
- return _propertyData;
- }
+ PropertyData = propertyData.ToString();
+
+ Initialize(propertyData);
}
+ public string PropertyData { get; }
+
// Although this method seems unnecessary it makes .Any() available in Dynamics
public bool Any()
{
- return Enumerable.Any(this);
+ return Enumerable.Any(this);
}
public IEnumerator GetEnumerator()
@@ -73,9 +47,25 @@ public IEnumerator GetEnumerator()
return _multiUrls.GetEnumerator();
}
- System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
+ IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
+
+ private void Initialize(JArray data)
+ {
+ foreach (var item in data)
+ {
+ var newLink = new Link(item);
+ if (!newLink.Deleted)
+ {
+ _multiUrls.Add(new Link(item));
+ }
+ else
+ {
+ LogHelper.Warn("MultiUrlPicker value converter skipped a link as the node has been upublished/deleted (Id: {0}).", () => newLink.Id);
+ }
+ }
+ }
}
}
diff --git a/src/RJP.MultiUrlPicker/MultiUrlPickerPropertyEditor.cs b/src/RJP.MultiUrlPicker/MultiUrlPickerPropertyEditor.cs
index ee55b28..aff9c6a 100644
--- a/src/RJP.MultiUrlPicker/MultiUrlPickerPropertyEditor.cs
+++ b/src/RJP.MultiUrlPicker/MultiUrlPickerPropertyEditor.cs
@@ -3,11 +3,9 @@ namespace RJP.MultiUrlPicker
using System;
using System.Collections.Generic;
using System.Linq;
-
using ClientDependency.Core;
-
+ using Models;
using Newtonsoft.Json;
-
using Umbraco.Core;
using Umbraco.Core.Logging;
using Umbraco.Core.Models;
@@ -17,22 +15,15 @@ namespace RJP.MultiUrlPicker
using Umbraco.Core.Services;
using Umbraco.Web;
using Umbraco.Web.PropertyEditors;
-
- using Models;
-
using Constants = Umbraco.Core.Constants;
+ [PropertyEditor("RJP.MultiUrlPicker", "Multi URL Picker", PropertyEditorValueTypes.Json, "~/App_Plugins/RJP.MultiUrlPicker/MultiUrlPicker.html", Group = "pickers", Icon = "icon-link", IsParameterEditor = true)]
[PropertyEditorAsset(ClientDependencyType.Javascript, "~/App_Plugins/RJP.MultiUrlPicker/MultiUrlPicker.js")]
- [PropertyEditor("RJP.MultiUrlPicker", "Multi Url Picker", "JSON",
- "~/App_Plugins/RJP.MultiUrlPicker/MultiUrlPicker.html",
- Group ="pickers", Icon = "icon-link", IsParameterEditor = true)]
public class MultiUrlPickerPropertyEditor : PropertyEditor
{
- private IDictionary _defaultPreValues;
-
public MultiUrlPickerPropertyEditor()
{
- _defaultPreValues = new Dictionary
+ this.DefaultPreValues = new Dictionary
{
{"minNumberOfItems", null},
{"maxNumberOfItems", null},
@@ -40,12 +31,6 @@ public MultiUrlPickerPropertyEditor()
};
}
- public override IDictionary DefaultPreValues
- {
- get { return _defaultPreValues; }
- set { _defaultPreValues = value; }
- }
-
protected override PreValueEditor CreatePreValueEditor()
{
return new MultiUrlPickerPreValueEditor();
@@ -58,19 +43,19 @@ protected override PropertyValueEditor CreateValueEditor()
private class MultiUrlPickerPreValueEditor : PreValueEditor
{
- [PreValueField("minNumberOfItems", "Min number of items", "number")]
+ [PreValueField("minNumberOfItems", "Minimum number of items.", "number")]
public int? MinNumberOfItems { get; set; }
- [PreValueField("maxNumberOfItems", "Max number of items", "number")]
+ [PreValueField("maxNumberOfItems", "Maximum number of items.", "number")]
public int? MaxNumberOfItems { get; set; }
- [PreValueField("version", "Multi Url Picker version", "hidden", HideLabel = true)]
+ [PreValueField("version", "Multi URL Picker version", "hidden", HideLabel = true)]
public string Version { get; set; }
public override IDictionary ConvertDbToEditor(IDictionary defaultPreVals, PreValueCollection persistedPreVals)
{
- // if there isn't a version stored set it to 0 for backwards compatibility
- if(!persistedPreVals.PreValuesAsDictionary.ContainsKey("version"))
+ // If there isn't a version stored, set it to 0 for backwards compatibility
+ if (!persistedPreVals.PreValuesAsDictionary.ContainsKey("version"))
{
persistedPreVals.PreValuesAsDictionary["version"] = new PreValue("0");
}
@@ -81,15 +66,14 @@ public override IDictionary ConvertDbToEditor(IDictionary();
}
@@ -101,52 +85,36 @@ public override object ConvertDbToEditor(Property property, PropertyType propert
IContentTypeService contentTypeService = services.ContentTypeService;
var links = JsonConvert.DeserializeObject>(value);
-
- var documentLinks = links.FindAll(link =>
- link.Id.HasValue && false == link.IsMedia.GetValueOrDefault() ||
- link.Udi != null && link.Udi.EntityType == Constants.UdiEntityType.Document
- );
-
- var mediaLinks = links.FindAll(link =>
- link.Id.HasValue && true == link.IsMedia.GetValueOrDefault() ||
- link.Udi != null && link.Udi.EntityType == Constants.UdiEntityType.Media
- );
+ var documentLinks = links.FindAll(link => (link.Id.HasValue && !link.IsMedia.GetValueOrDefault()) || link.Udi?.EntityType == Constants.UdiEntityType.Document);
+ var mediaLinks = links.FindAll(link => (link.Id.HasValue && link.IsMedia.GetValueOrDefault()) || link.Udi?.EntityType == Constants.UdiEntityType.Media);
List entities = new List();
if (documentLinks.Count > 0)
{
- if(documentLinks[0].Id.HasValue)
+ if (documentLinks[0].Id.HasValue)
{
- entities.AddRange(
- entityService.GetAll(UmbracoObjectTypes.Document, documentLinks.Select(link => link.Id.Value).ToArray())
- );
+ entities.AddRange(entityService.GetAll(UmbracoObjectTypes.Document, documentLinks.Select(link => link.Id.Value).ToArray()));
}
else
{
- entities.AddRange(
- entityService.GetAll(UmbracoObjectTypes.Document, documentLinks.Select(link => link.Udi.Guid).ToArray())
- );
+ entities.AddRange(entityService.GetAll(UmbracoObjectTypes.Document, documentLinks.Select(link => link.Udi.Guid).ToArray()));
}
}
- if(mediaLinks.Count > 0)
+ if (mediaLinks.Count > 0)
{
if (mediaLinks[0].Id.HasValue)
{
- entities.AddRange(
- entityService.GetAll(UmbracoObjectTypes.Media, mediaLinks.Select(link => link.Id.Value).ToArray())
- );
+ entities.AddRange(entityService.GetAll(UmbracoObjectTypes.Media, mediaLinks.Select(link => link.Id.Value).ToArray()));
}
else
{
- entities.AddRange(
- entityService.GetAll(UmbracoObjectTypes.Media, mediaLinks.Select(link => link.Udi.Guid).ToArray())
- );
+ entities.AddRange(entityService.GetAll(UmbracoObjectTypes.Media, mediaLinks.Select(link => link.Udi.Guid).ToArray()));
}
}
var result = new List();
- foreach(LinkDto dto in links)
+ foreach (LinkDto dto in links)
{
if (dto.Id.HasValue || dto.Udi != null)
{
@@ -156,27 +124,21 @@ public override object ConvertDbToEditor(Property property, PropertyType propert
continue;
}
- string entityType = Equals(entity.AdditionalData["NodeObjectTypeId"], Constants.ObjectTypes.MediaGuid) ?
- Constants.UdiEntityType.Media :
- Constants.UdiEntityType.Document;
-
- var udi = new GuidUdi(entityType, entity.Key);
-
string contentTypeAlias = entity.AdditionalData["ContentTypeAlias"] as string;
- string icon;
- bool isMedia = false;
- bool published = Equals(entity.AdditionalData["IsPublished"], true);
- string url = dto.Url;
-
- if(string.IsNullOrEmpty(contentTypeAlias))
+ if (string.IsNullOrEmpty(contentTypeAlias))
{
continue;
}
+ string entityType = Equals(entity.AdditionalData["NodeObjectTypeId"], Constants.ObjectTypes.MediaGuid) ? Constants.UdiEntityType.Media : Constants.UdiEntityType.Document;
+
+ var udi = new GuidUdi(entityType, entity.Key);
+
+ string icon, url = dto.Url;
+ bool isMedia = false, published = Equals(entity.AdditionalData["IsPublished"], true);
if (udi.EntityType == Constants.UdiEntityType.Document)
{
IContentType contentType = contentTypeService.GetContentType(contentTypeAlias);
-
if (contentType == null)
{
continue;
@@ -192,7 +154,6 @@ public override object ConvertDbToEditor(Property property, PropertyType propert
else
{
IMediaType mediaType = contentTypeService.GetMediaType(contentTypeAlias);
-
if (mediaType == null)
{
continue;
@@ -234,9 +195,10 @@ public override object ConvertDbToEditor(Property property, PropertyType propert
});
}
}
+
return result;
}
- catch(Exception ex)
+ catch (Exception ex)
{
ApplicationContext.Current.ProfilingLogger.Logger.Error("Error getting links", ex);
}
@@ -247,7 +209,6 @@ public override object ConvertDbToEditor(Property property, PropertyType propert
public override object ConvertEditorToDb(ContentPropertyData editorValue, object currentValue)
{
string value = editorValue.Value?.ToString();
-
if (string.IsNullOrEmpty(value))
{
return string.Empty;
@@ -255,25 +216,25 @@ public override object ConvertEditorToDb(ContentPropertyData editorValue, object
try
{
- return JsonConvert.SerializeObject(
- from link in JsonConvert.DeserializeObject>(value)
- select new LinkDto
- {
- Name = link.Name,
- Target = link.Target,
- Udi = link.Udi,
- Url = link.Udi == null ? link.Url : null, // only save the url for external links
- Querystring = link.Querystring
- },
- new JsonSerializerSettings
- {
- NullValueHandling = NullValueHandling.Ignore
- });
+ var links = JsonConvert.DeserializeObject>(value).Select(link => new LinkDto
+ {
+ Name = link.Name,
+ Target = link.Target,
+ Udi = link.Udi,
+ Url = link.Udi == null ? link.Url : null, // Only save the URL for external links
+ Querystring = link.Querystring
+ });
+
+ return JsonConvert.SerializeObject(links, new JsonSerializerSettings()
+ {
+ NullValueHandling = NullValueHandling.Ignore
+ });
}
catch (Exception ex)
{
ApplicationContext.Current.ProfilingLogger.Logger.Error("Error saving links", ex);
}
+
return base.ConvertEditorToDb(editorValue, currentValue);
}
}
diff --git a/src/RJP.MultiUrlPicker/MultiUrlPickerValueConverter.cs b/src/RJP.MultiUrlPicker/MultiUrlPickerValueConverter.cs
index afe7724..05899b3 100644
--- a/src/RJP.MultiUrlPicker/MultiUrlPickerValueConverter.cs
+++ b/src/RJP.MultiUrlPicker/MultiUrlPickerValueConverter.cs
@@ -1,35 +1,30 @@
-using Umbraco.Core.Logging;
-using Umbraco.Core.PropertyEditors.ValueConverters;
-
namespace RJP.MultiUrlPicker
{
using System;
- using System.Linq;
using System.Collections.Generic;
-
+ using System.Linq;
+ using Models;
using Newtonsoft.Json.Linq;
-
using Umbraco.Core;
+ using Umbraco.Core.Logging;
using Umbraco.Core.Models;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Core.PropertyEditors;
using Umbraco.Core.Services;
- using Models;
-
public class MultiUrlPickerValueConverter : PropertyValueConverterBase, IPropertyValueConverterMeta
{
private readonly IDataTypeService _dataTypeService;
+ public MultiUrlPickerValueConverter()
+ : this(ApplicationContext.Current.Services.DataTypeService)
+ { }
+
public MultiUrlPickerValueConverter(IDataTypeService dataTypeService)
{
_dataTypeService = dataTypeService;
}
- public MultiUrlPickerValueConverter() : this(ApplicationContext.Current.Services.DataTypeService)
- {
- }
-
public override bool IsConverter(PublishedPropertyType propertyType)
{
return propertyType.PropertyEditorAlias.Equals("RJP.MultiUrlPicker");
@@ -37,22 +32,24 @@ public override bool IsConverter(PublishedPropertyType propertyType)
public override object ConvertDataToSource(PublishedPropertyType propertyType, object source, bool preview)
{
- if (string.IsNullOrWhiteSpace(source?.ToString()))
+ var sourceStr = source?.ToString();
+ if (string.IsNullOrWhiteSpace(sourceStr))
{
return null;
}
- if (source.ToString().Trim().StartsWith("["))
+ if (sourceStr.Trim().StartsWith("["))
{
try
{
- return JArray.Parse(source.ToString());
+ return JArray.Parse(sourceStr);
}
catch (Exception ex)
{
LogHelper.Error("Error parsing JSON", ex);
}
}
+
return null;
}
@@ -65,14 +62,16 @@ public override object ConvertSourceToObject(PublishedPropertyType propertyType,
}
var urls = new MultiUrls((JArray)source);
- if(isMultiple)
+ if (isMultiple)
{
- if(maxNumberOfItems > 0)
+ if (maxNumberOfItems > 0)
{
return urls.Take(maxNumberOfItems);
}
+
return urls;
}
+
return urls.FirstOrDefault();
}
@@ -82,6 +81,7 @@ public Type GetPropertyValueType(PublishedPropertyType propertyType)
{
return typeof(IEnumerable );
}
+
return typeof(Link);
}
@@ -101,20 +101,15 @@ public PropertyCacheLevel GetPropertyCacheLevel(PublishedPropertyType propertyTy
private bool IsMultipleDataType(int dataTypeId, out int maxNumberOfItems)
{
- IDictionary preValues = _dataTypeService
- .GetPreValuesCollectionByDataTypeId(dataTypeId)
- .PreValuesAsDictionary;
+ var preValues = _dataTypeService.GetPreValuesCollectionByDataTypeId(dataTypeId).FormatAsDictionary();
if (preValues.TryGetValue("maxNumberOfItems", out PreValue maxNumberOfItemsPreValue) &&
int.TryParse(maxNumberOfItemsPreValue.Value, out maxNumberOfItems))
{
- PreValue versionPreValue;
- Version version;
- // for backwards compatibility, always return true if version
- // is less than 2.0.0
- if (preValues.TryGetValue("version", out versionPreValue) &&
- Version.TryParse(versionPreValue.Value, out version)
- && version >= new Version(2, 0, 0))
+ // For backwards compatibility, always return true if version is less than 2.0.0
+ if (preValues.TryGetValue("version", out PreValue versionPreValue) &&
+ Version.TryParse(versionPreValue.Value, out Version version) &&
+ version >= new Version(2, 0, 0))
{
return maxNumberOfItems != 1;
}
diff --git a/src/RJP.MultiUrlPicker/Properties/AssemblyInfo.cs b/src/RJP.MultiUrlPicker/Properties/AssemblyInfo.cs
index 4d25dfc..29ff299 100644
--- a/src/RJP.MultiUrlPicker/Properties/AssemblyInfo.cs
+++ b/src/RJP.MultiUrlPicker/Properties/AssemblyInfo.cs
@@ -1,18 +1,13 @@
-using System.Reflection;
-using System.Runtime.CompilerServices;
+using System.Reflection;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("RJP.MultiUrlPicker")]
-[assembly: AssemblyDescription("")]
-[assembly: AssemblyConfiguration("")]
-[assembly: AssemblyCompany("")]
+[assembly: AssemblyDescription("Multi URL Picker for Umbraco 7")]
[assembly: AssemblyProduct("RJP.MultiUrlPicker")]
-[assembly: AssemblyCopyright("Copyright © 2014")]
-[assembly: AssemblyTrademark("")]
-[assembly: AssemblyCulture("")]
+[assembly: AssemblyCopyright("Copyright © 2014 Rasmus John Pedersen")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from