Skip to content

Commit

Permalink
Added support for selecting multiple images
Browse files Browse the repository at this point in the history
  • Loading branch information
abjerner committed Nov 18, 2020
1 parent c19ffd1 commit 9d12d04
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,9 @@ public class ImagePickerConfiguration : MediaPickerConfiguration {
[ConfigurationField("model", "Model", "textstring", Description = "Specify the .NET type to be used as model. Default is ImagePickerImage.")]
public string Model { get; set; }

public Type ModelType
{
public Type ModelType {


get
{
get {

if (_type == null && string.IsNullOrWhiteSpace(Model) == false) {
_type = Type.GetType(Model);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@ namespace Skybrud.ImagePicker.PropertyEditors {

public class ImagePickerConfigurationEditor : ConfigurationEditor<ImagePickerConfiguration> {

public ImagePickerConfigurationEditor() {
Field("StartNodeId").Config = new Dictionary<string, object> {
{ "multiPicker", false },
{ "onlyImages", true },
{ "disableFolderSelect", true },
{ "idType", "udi" }
};
public override IDictionary<string, object> ToValueEditor(object configuration) {

var d = base.ToValueEditor(configuration);

d["idType"] = "udi";

return d;

}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Skybrud.Essentials.Collections.Extensions;
using Skybrud.ImagePicker.Models;
using Umbraco.Core;
using Umbraco.Core.Composing;
Expand Down Expand Up @@ -39,7 +40,7 @@ public override object ConvertIntermediateToObject(IPublishedElement owner, IPub
var isMultiple = IsMultipleDataType(propertyType.DataType);

var udis = inter as Udi[] ?? new Udi[0];
var mediaItems = new List<ImagePickerImage>();
var mediaItems = new List<object>();

if (inter == null) return isMultiple ? mediaItems : null;

Expand All @@ -49,12 +50,12 @@ public override object ConvertIntermediateToObject(IPublishedElement owner, IPub
if (udi is GuidUdi guidUdi) {
IPublishedContent media = _publishedSnapshotAccessor.PublishedSnapshot.Media.GetById(guidUdi.Guid);
if (media != null) {
return type == null ? new ImagePickerImage(media) : Current.Factory.CreateInstance(type, media);
mediaItems.Add(type == null ? new ImagePickerImage(media) : Current.Factory.CreateInstance(type, media));
}
}
}

return isMultiple ? mediaItems : (object) mediaItems.FirstOrDefault();
return isMultiple ? mediaItems.Cast(type) : mediaItems.FirstOrDefault();

}

Expand All @@ -72,13 +73,12 @@ public override Type GetPropertyValueType(IPublishedPropertyType propertyType) {

Type type = propertyType.DataType.ConfigurationAs<ImagePickerConfiguration>()?.ModelType ?? typeof(ImagePickerImage);

return isMultiple ? typeof(IEnumerable).MakeGenericType(type) : type;
return isMultiple ? typeof(IEnumerable<>).MakeGenericType(type) : type;

}

private bool IsMultipleDataType(PublishedDataType dataType) {
if (!(dataType.Configuration is Dictionary<string, object> config)) return false;
return config.TryGetValue("multiPicker", out object isMultiPicker) && isMultiPicker?.ToString() == "True";
return dataType.ConfigurationAs<ImagePickerConfiguration>()?.Multiple ?? false;
}

}
Expand Down
1 change: 1 addition & 0 deletions src/Skybrud.ImagePicker/Skybrud.ImagePicker.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Skybrud.Essentials" Version="1.1.25" />
<PackageReference Include="Skybrud.Umbraco.Elements" Version="1.0.0-alpha011">
<ExcludeAssets>contentFiles</ExcludeAssets>
</PackageReference>
Expand Down

0 comments on commit 9d12d04

Please sign in to comment.