Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/multiple items in area #28

Open
wants to merge 16 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -196,3 +196,4 @@ node_modules/
/src/.idea/

src/Bento.Website/App_Data/cache/
src/Bento.Website/Umbraco.sdf
3 changes: 3 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ Bento Item setup is straight forward. Create a new DataType, either in the Data

You should now be able to add your Bento Item type to a Document Type and create a Bento Item.

### Bento Multi Item
As ```Bento Items``` above, but it allows more than one item to be created under it.

### Bento Stack
The Bento Stack is similar to the Bento Item setup except for a key difference that it requires Layouts. To setup a new stack either create a new Data Type in the Data Type section or during Document Type creation.

Expand Down
6 changes: 6 additions & 0 deletions src/Bento.Core/Bento.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,14 @@
<Compile Include="Composers\BentoComposer.cs" />
<Compile Include="Constants\BentoGridDataEditor.cs" />
<Compile Include="Constants\BentoItemDataEditor.cs" />
<Compile Include="Constants\BentoMultiItemDataEditor.cs" />
<Compile Include="Constants\BentoStackDataEditor.cs" />
<Compile Include="Constants\RelationTypes.cs" />
<Compile Include="ContentApps\RelationshipManager.cs" />
<Compile Include="DataEditors\BentoMultiItemConfiguration.cs" />
<Compile Include="DataEditors\BentoMultiItemConfigurationEditor.cs" />
<Compile Include="DataEditors\BentoMultiItemDataEditor.cs" />
<Compile Include="DataEditors\BentoMultiItemDataValueEditor.cs" />
<Compile Include="DataEditors\DataEditorConstants.cs" />
<Compile Include="Events\DatatypeServiceEvents.cs" />
<Compile Include="Extensions\ContentTypeServiceExtensions.cs" />
Expand Down Expand Up @@ -282,6 +287,7 @@
<Compile Include="Services\PluralizationServiceWrapper.cs" />
<Compile Include="Services\EmbeddedContentService.cs" />
<Compile Include="ValueConverters\BentoItemValueConverter.cs" />
<Compile Include="ValueConverters\BentoMultiItemValueConverter.cs" />
<Compile Include="ValueConverters\BentoStackValueConverter.cs" />
</ItemGroup>
<ItemGroup>
Expand Down
15 changes: 15 additions & 0 deletions src/Bento.Core/Constants/BentoMultiItemDataEditor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Bento.Core.Constants
{
public static class BentoMultiItemDataEditor
{
public const string EditorAlias = "bentomultiitem.editor";
public const string EditorName = "Bento Multi Item";
public const string Group = "Bento";
}
}
83 changes: 83 additions & 0 deletions src/Bento.Core/DataEditors/BentoMultiItemConfiguration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
using System.Reflection;
using Umbraco.Core.PropertyEditors;

namespace Bento.Core.DataEditors
{
public class BentoMultiItemConfiguration
{
[ConfigurationField(
"credits",
"Credits",
"/app_plugins/bento/prevalueeditors/bento.credits.html",
Description = "", HideLabel = true
)]
public string Credits
{
get { return DataEditorConstants.Credits; }
set { }
}


[ConfigurationField(
"libraryFolderDoctypeAlias",
"Library Folder content type",
"~/App_Plugins/Bento/Views/PreValueEditors/singlerequiredcontenttypepicker.html",
Description = "Select the library folder content type (this is where item folder types are created). This can be relative to the root node or the content root."
)]
public string LibraryFolderDoctypeAlias { get; set; }

[ConfigurationField(
"itemTypeFolderDoctypeAlias",
"Item Type Folder content type",
"~/App_Plugins/Bento/Views/PreValueEditors/singlerequiredcontenttypepicker.html",
Description = "Select the item folder folder content type (this is where items are created)."
)]
public string ItemTypeFolderDoctypeAlias { get; set; }

[ConfigurationField(
"itemDoctypeCompositionAlias",
"Item Doctype Composition content type",
"~/App_Plugins/Bento/Views/PreValueEditors/singlerequiredcontenttypepicker.html",
Description = "Select the item composition content type (this is used to identify the saved content as a Bento item)."
)]
public string ItemDoctypeCompositionAlias { get; set; }



[ConfigurationField(
"allowedDoctypeAliases",
"Allowed content types",
"~/App_Plugins/Bento/Views/PreValueEditors/contenttypepicker.html",
Description = "Optional. Select the content types the editor is allowed to use"
)]
public string AllowedDoctypeAliases { get; set; }

[ConfigurationField(
"allowedElementAliases",
"Allowed element types",
"~/App_Plugins/Bento/Views/PreValueEditors/contenttypepicker.html",
Description = "Optional. Select the element types the editor is allowed to embed"
)]
public string AllowedElementAliases { get; set; }

[ConfigurationField(
"minNumber",
"Minimum number of items allowed",
"number")]
public int MinNumber { get; set; }

[ConfigurationField(
"maxNumber",
"Maximum number of items allowed",
"number")]
public int MaxNumber { get; set; }

[ConfigurationField(
"hideLabel",
"Hide Label",
"boolean",
Description = "Select whether to hide the property label."
)]
public bool HideLabel { get; set; }
}
}
12 changes: 12 additions & 0 deletions src/Bento.Core/DataEditors/BentoMultiItemConfigurationEditor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Umbraco.Core.PropertyEditors;

namespace Bento.Core.DataEditors
{
public class BentoMultiItemConfigurationEditor : ConfigurationEditor<BentoMultiItemConfiguration>
{
public override object DefaultConfigurationObject
{
get;
} = new BentoMultiItemConfiguration();
}
}
24 changes: 24 additions & 0 deletions src/Bento.Core/DataEditors/BentoMultiItemDataEditor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using Umbraco.Core.Logging;
using Umbraco.Core.PropertyEditors;

namespace Bento.Core.DataEditors
{
[DataEditor(
Bento.Core.Constants.BentoMultiItemDataEditor.EditorAlias,
Bento.Core.Constants.BentoMultiItemDataEditor.EditorName,
"~/App_Plugins/Bento/bento.editor.html",
ValueType = "JSON",
Group = Bento.Core.Constants.BentoItemDataEditor.Group,
Icon = "icon-umb-contour",
HideLabel = false
)]
public class BentoMultiItemDataEditor : DataEditor
{
public BentoMultiItemDataEditor(ILogger logger) : base(logger)
{

}

protected override IConfigurationEditor CreateConfigurationEditor() => new BentoMultiItemConfigurationEditor();
}
}
9 changes: 9 additions & 0 deletions src/Bento.Core/DataEditors/BentoMultiItemDataValueEditor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using Umbraco.Core.PropertyEditors;

namespace Bento.Core.DataEditors
{
public class BentoMultiItemDataValueEditor : DataValueEditor
{

}
}
41 changes: 37 additions & 4 deletions src/Bento.Core/Events/ContentServiceEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
using Umbraco.Core.Services;
using Umbraco.Core.Services.Implement;
using BentoItemDataEditor = Bento.Core.Constants.BentoItemDataEditor;
using BentoMultiItemDataEditor = Bento.Core.Constants.BentoMultiItemDataEditor;
using BentoStackDataEditor = Bento.Core.Constants.BentoStackDataEditor;

namespace Bento.Core.Events
{
Expand Down Expand Up @@ -73,7 +75,7 @@ private static void ContentService_Saved(IContentService contentService, Content
{
List<string> editors = new List<string>
{
Umbraco.Core.Constants.PropertyEditors.Aliases.Grid,
//Umbraco.Core.Constants.PropertyEditors.Aliases.Grid,
BentoItemDataEditor.EditorAlias,
BentoStackDataEditor.EditorAlias
};
Expand Down Expand Up @@ -123,7 +125,7 @@ private static void ContentService_Saved(IContentService contentService, Content
continue;
}

var bentoContent = contentService.GetById(area.Id);
var bentoContent = contentService.GetById(area.Id.Value);

if (bentoContent == null)
{
Expand All @@ -135,7 +137,38 @@ private static void ContentService_Saved(IContentService contentService, Content
ProcessRelationship(contentService, bentoContent, content, bentoBlocksRelationType, config.ItemDoctypeCompositionAlias);
}
}
else
else if (contentProperty.PropertyType.PropertyEditorAlias == BentoMultiItemDataEditor.EditorAlias)
{
foreach (Property.PropertyValue value in contentProperty.Values)
{
if (value.PublishedValue == null)
{
break;
}

var area = JsonConvert.DeserializeObject<Area>(value.PublishedValue.ToString());

foreach (var areaItem in area.Contents)
{
if (areaItem.Id <= 0)
{
continue;
}

var bentoContent = contentService.GetById(areaItem.Id);

if (bentoContent == null)
{
continue;
}

BentoItemConfiguration config = (BentoItemConfiguration)editor.Configuration;

ProcessRelationship(contentService, bentoContent, content, bentoBlocksRelationType, config.ItemDoctypeCompositionAlias);
}
}
}
else if (contentProperty.PropertyType.PropertyEditorAlias == BentoStackDataEditor.EditorAlias)
{
foreach (Property.PropertyValue value in contentProperty.Values)
{
Expand All @@ -154,7 +187,7 @@ private static void ContentService_Saved(IContentService contentService, Content
IEnumerable<StackItem> items = JsonConvert.DeserializeObject<IEnumerable<StackItem>>(valueString, new StackItemConverter());

var itemList = items.Where(x => x.Areas != null && x.Areas.Any())
.SelectMany(stackItem => stackItem.Areas.Where(x => x.Id > 0), (stackItem, x) => contentService.GetById(x.Id))
.SelectMany(stackItem => stackItem.Areas.SelectMany(y => y.Contents).Where(x => x.Id > 0), (stackItem, x) => contentService.GetById(x.Id))
.Where(bentoContent => bentoContent != null)
.Distinct();

Expand Down
1 change: 0 additions & 1 deletion src/Bento.Core/Models/BentoStackItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ public class StackItem
[JsonProperty("alias")]
public String Alias { get; set; }


[JsonProperty("areas")]
public IEnumerable<Area> Areas { get; set; } = new List<Area>();

Expand Down
47 changes: 47 additions & 0 deletions src/Bento.Core/Models/Compartment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,53 @@
namespace Bento.Core.Models
{
public class Area
{
[JsonProperty("contents")]
public List<AreaItem> Contents { get; set; }

[JsonProperty("settings")]
public IDictionary<string, object> SettingsData { get; set; } = new Dictionary<string, object>();

[JsonIgnore]
public IPublishedElement Settings { get; set; }

/**
* Old "Single Item" Area setup (check if any of these are set, make key/id nullable, and then assume it is not Multi)
**/

[JsonConverter(typeof(NullToDefaultConverter<Guid>))]
[JsonProperty("key")]
public Guid? Key { get; set; }

[JsonProperty("id")]
public int? Id { get; set; }

[JsonProperty("alias")]
public string Alias { get; set; }

[JsonProperty("name")]
public string Name { get; set; }

[JsonProperty("contentData")]
public Dictionary<string, object> ContentData { get; set; }

[JsonIgnore]
public IPublishedElement Content { get; set; }


public void ResetContents()
{
Id = null;
Name = null;
Alias = null;
ContentData = null;
Key = null;
Content = null;
}
}


public class AreaItem
{
[JsonConverter(typeof(NullToDefaultConverter<Guid>))]
[JsonProperty("key")]
Expand Down
10 changes: 9 additions & 1 deletion src/Bento.Core/Models/Grid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,15 @@ public class GridArea

public class Control
{
[JsonProperty("editor")]
public Editor Editor { get; set; }
[JsonProperty("value")]
public object Value { get; set; }
}
}

public class Editor
{
[JsonProperty("alias")]
public string Alias { get; set; }
}
}
12 changes: 7 additions & 5 deletions src/Bento.Core/ValueConverters/BentoItemValueConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,18 @@ public object ConvertSourceToIntermediate(IPublishedElement owner, IPublishedPro
//had to move to this because someone broke DI for propertyValueConverts between 8.2 and 8.5
var embeddedContentService = Umbraco.Web.Composing.Current.Factory.GetInstance<IEmbeddedContentService>();


//This could be problematic to update to multiple items as it is meant to return single IPublishedElement
//And making it return either IPublishedElement or IEnumerable based on data could break existing views
//So for backwards compatibility we could create a new BentoMultipleItem DataType (with a min/max)

IPublishedElement content = null;
if (area.Key != Guid.Empty && area.ContentData == null)
if (area.Key.HasValue && area.Key != Guid.Empty && area.ContentData == null)
{
content = _publishedSnapshotAccessor.PublishedSnapshot.Content.GetById(area.Key);
content = _publishedSnapshotAccessor.PublishedSnapshot.Content.GetById(area.Key.Value);
}
else if (area.Id != 0 && area.ContentData == null)
else if (area.Id.HasValue && area.Id != 0 && area.ContentData == null)
{
content = _publishedSnapshotAccessor.PublishedSnapshot.Content.GetById(area.Id);
content = _publishedSnapshotAccessor.PublishedSnapshot.Content.GetById(area.Id.Value);
}
else if (area.ContentData != null)
{
Expand Down
Loading