diff --git a/.github/ROADMAP.md b/.github/ROADMAP.md index 9e82ba9b..22298efa 100644 --- a/.github/ROADMAP.md +++ b/.github/ROADMAP.md @@ -119,10 +119,14 @@ Property Editors are: - [Data Picker](https://github.com/leekelleher/umbraco-contentment/pull/297) - Data List: [Umbraco Backoffice Sections](https://github.com/leekelleher/umbraco-contentment/commit/c8a2f0f8552b2ad3a778782f13c45cbb18aff88c) data-source. -### v4.6 +### [v4.6](https://github.com/leekelleher/umbraco-contentment/releases/tag/4.6.0) - A non-breaking-change minor release. Adds support for Umbraco v13, .NET 8.0. _(Whilst still supporting v8.17+, v9, v10, v11 and v12)._ +### [v4.7](https://github.com/leekelleher/umbraco-contentment/releases/tag/4.7.0) + +- Data Picker: [Data List source bridge](https://github.com/leekelleher/umbraco-contentment/pull/393) _(to enable all the built-in Data List sources within Data Picker)._ + ## v5 diff --git a/.gitignore b/.gitignore index 046994a6..cb5f299a 100644 --- a/.gitignore +++ b/.gitignore @@ -20,4 +20,5 @@ build/build-push-umb.ps1 src/packages/*/** src/Umbraco.Cms.*.x/* src/Umbraco.Community.Contentment/wwwroot/App_Plugins/Contentment/* +src/Umbraco.Community.Contentment.StaticAssets/* tools/*.exe diff --git a/VERSION b/VERSION index f4fa8fcb..1163055e 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -4.6.1 \ No newline at end of file +4.7.0 \ No newline at end of file diff --git a/build/readme-nuget-main.md b/build/readme-nuget-main.md index a6e71ccf..6927e9d6 100644 --- a/build/readme-nuget-main.md +++ b/build/readme-nuget-main.md @@ -8,6 +8,7 @@ The following property editors are available... - [Code Editor](https://github.com/leekelleher/umbraco-contentment/blob/develop/docs/editors/code-editor.md) - a code snippet editor, _(using the ACE library that is bundled with Umbraco)._ - [Content Blocks](https://github.com/leekelleher/umbraco-contentment/blob/develop/docs/editors/content-blocks.md) - a block editor, configurable using element types. - [Data List](https://github.com/leekelleher/umbraco-contentment/blob/develop/docs/editors/data-list.md) - an editor that combines a custom data source with a custom list editor. +- [Data Picker](https://github.com/leekelleher/umbraco-contentment/blob/develop/docs/editors/data-picker.md) - advanced picker editor to query a custom data source. - [Editor Notes](https://github.com/leekelleher/umbraco-contentment/blob/develop/docs/editors/editor-notes.md) - Similar to [Notes](https://github.com/leekelleher/umbraco-contentment/blob/develop/docs/editors/notes.md), with enhanced UI options. - [Icon Picker](https://github.com/leekelleher/umbraco-contentment/blob/develop/docs/editors/icon-picker.md) - an editor to select an icon (from the Umbraco icon library). - [Notes](https://github.com/leekelleher/umbraco-contentment/blob/develop/docs/editors/notes.md) - a read-only label to display rich-text instructional messages for content editors. diff --git a/src/Umbraco.Cms.10.x/uSync/v10/ContentTypes/testmiscpage.config b/src/Umbraco.Cms.10.x/uSync/v10/ContentTypes/testmiscpage.config index fb73e3b7..bbe9b194 100644 --- a/src/Umbraco.Cms.10.x/uSync/v10/ContentTypes/testmiscpage.config +++ b/src/Umbraco.Cms.10.x/uSync/v10/ContentTypes/testmiscpage.config @@ -39,6 +39,22 @@ false + + 45248546-4d6c-4418-92e9-855c3aac8328 + Data Picker - uCssClassName + dataPickerUCssClassName + d4b190f2-e2a6-470c-a39f-8e1ae14d521c + Umbraco.Community.Contentment.DataPicker + false + + + 20 + Data Picker + Nothing + + + false + a290a9de-0b71-49b7-9572-0bf541525469 Data Picker - Umbraco Content diff --git a/src/Umbraco.Cms.10.x/uSync/v10/DataTypes/ContentmentDataPickerWebUCssClassName.config b/src/Umbraco.Cms.10.x/uSync/v10/DataTypes/ContentmentDataPickerWebUCssClassName.config new file mode 100644 index 00000000..6f320781 --- /dev/null +++ b/src/Umbraco.Cms.10.x/uSync/v10/DataTypes/ContentmentDataPickerWebUCssClassName.config @@ -0,0 +1,35 @@ + + + + [Contentment] Data Picker - Web uCssClassName + Umbraco.Community.Contentment.DataPicker + Ntext + Test+Data+Picker + + + \ No newline at end of file diff --git a/src/Umbraco.Cms.13.x/uSync/v9/ContentTypes/testmiscpage.config b/src/Umbraco.Cms.13.x/uSync/v9/ContentTypes/testmiscpage.config index a13ce9a1..d743e6ab 100644 --- a/src/Umbraco.Cms.13.x/uSync/v9/ContentTypes/testmiscpage.config +++ b/src/Umbraco.Cms.13.x/uSync/v9/ContentTypes/testmiscpage.config @@ -39,6 +39,22 @@ false + + 2f56d9fd-2066-4905-9c2e-8e29c657fe10 + Data Picker - uCssClassName + dataPickerUCssClassName + 882e9021-789a-412c-ac26-9818df51c647 + Umbraco.Community.Contentment.DataPicker + false + + + 20 + Data Picker + Nothing + + + false + a290a9de-0b71-49b7-9572-0bf541525469 Data Picker - Umbraco Content diff --git a/src/Umbraco.Cms.13.x/uSync/v9/DataTypes/ContentmentDataPickerWebUCssClassName.config b/src/Umbraco.Cms.13.x/uSync/v9/DataTypes/ContentmentDataPickerWebUCssClassName.config new file mode 100644 index 00000000..ea482e31 --- /dev/null +++ b/src/Umbraco.Cms.13.x/uSync/v9/DataTypes/ContentmentDataPickerWebUCssClassName.config @@ -0,0 +1,35 @@ + + + + [Contentment] Data Picker - Web uCssClassName + Umbraco.Community.Contentment.DataPicker + Ntext + Test+Data+Picker + + + \ No newline at end of file diff --git a/src/Umbraco.Community.Contentment/DataEditors/ContentBlocks/ContentBlocksValueConverter.cs b/src/Umbraco.Community.Contentment/DataEditors/ContentBlocks/ContentBlocksValueConverter.cs index 6f206e9d..759641ad 100644 --- a/src/Umbraco.Community.Contentment/DataEditors/ContentBlocks/ContentBlocksValueConverter.cs +++ b/src/Umbraco.Community.Contentment/DataEditors/ContentBlocks/ContentBlocksValueConverter.cs @@ -5,7 +5,9 @@ using System; using System.Collections.Generic; +using System.Linq; using Newtonsoft.Json; +using Newtonsoft.Json.Linq; using Umbraco.Community.Contentment.Web.PublishedCache; #if NET472 using Umbraco.Core; @@ -51,6 +53,11 @@ public override object ConvertSourceToIntermediate(IPublishedElement owner, IPub return JsonConvert.DeserializeObject>(value); } + if (source is JArray array && array.Any() == true) + { + return array.ToObject>(); + } + return base.ConvertSourceToIntermediate(owner, propertyType, source, preview); } diff --git a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/DataListToDataPickerSourceBridge.cs b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/DataListToDataPickerSourceBridge.cs new file mode 100644 index 00000000..c3ce40d6 --- /dev/null +++ b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/DataListToDataPickerSourceBridge.cs @@ -0,0 +1,76 @@ +/* Copyright © 2024 Lee Kelleher. + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +#if NET472 +using Umbraco.Core; +using Umbraco.Core.Models; +using Umbraco.Core.PropertyEditors; +#else +using Umbraco.Cms.Core.Models; +using Umbraco.Cms.Core.PropertyEditors; +using Umbraco.Extensions; +#endif + +namespace Umbraco.Community.Contentment.DataEditors +{ + public abstract class DataListToDataPickerSourceBridge : IDataListSource, IDataPickerSource + { + public abstract string Name { get; } + + public abstract string Description { get; } + + public abstract string Icon { get; } + + public abstract string Group { get; } + + public abstract IEnumerable Fields { get; } + + public abstract Dictionary DefaultValues { get; } + + public abstract OverlaySize OverlaySize { get; } + + public abstract IEnumerable GetItems(Dictionary config); + + public virtual Task> GetItemsAsync(Dictionary config, IEnumerable values) + { + var items = GetItems(config); + + if (items?.Any() == true) + { + return Task.FromResult(items.Where(x => values.Contains(x.Value) == true)); + } + + return Task.FromResult(Enumerable.Empty()); + } + + public virtual Task> SearchAsync(Dictionary config, int pageNumber = 1, int pageSize = 12, string query = "") + { + var items = default(IEnumerable); + + if (string.IsNullOrWhiteSpace(query) == true) + { + items = GetItems(config); + } + else + { + items = GetItems(config)?.Where(x => x.Name?.InvariantContains(query) == true || x.Value?.InvariantStartsWith(query) == true); + } + + if (items?.Any() == true) + { + var offset = (pageNumber - 1) * pageSize; + return Task.FromResult(new PagedResult(items.Count(), pageNumber, pageSize) + { + Items = items.Skip(offset).Take(pageSize), + }); + } + + return Task.FromResult(new PagedResult(-1, pageNumber, pageSize)); + } + } +} diff --git a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/EnumDataListSource.cs b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/EnumDataListSource.cs index 6555c142..f8606217 100644 --- a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/EnumDataListSource.cs +++ b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/EnumDataListSource.cs @@ -28,7 +28,7 @@ namespace Umbraco.Community.Contentment.DataEditors { - public sealed class EnumDataListSource : IDataListSource, IDataSourceValueConverter, IContentmentListTemplateItem + public sealed class EnumDataListSource : DataListToDataPickerSourceBridge, IDataListSource, IDataSourceValueConverter, IContentmentListTemplateItem { private readonly ConcurrentDictionary, Dictionary)> _lookup; private readonly IIOHelper _ioHelper; @@ -56,23 +56,23 @@ public EnumDataListSource( _ioHelper = ioHelper; } - public string Name => ".NET Enumeration"; + public override string Name => ".NET Enumeration"; public string NameTemplate => default; - public string Description => "Select an enumeration from a .NET assembly as the data source."; + public override string Description => "Select an enumeration from a .NET assembly as the data source."; public string DescriptionTemplate => "{{ enumType[1] }}"; - public string Icon => "icon-indent"; + public override string Icon => "icon-indent"; - public string Group => Constants.Conventions.DataSourceGroups.DotNet; + public override string Group => Constants.Conventions.DataSourceGroups.DotNet; - public OverlaySize OverlaySize => OverlaySize.Small; + public override OverlaySize OverlaySize => OverlaySize.Small; - public Dictionary DefaultValues => default; + public override Dictionary DefaultValues => default; - public IEnumerable Fields => new[] + public override IEnumerable Fields => new[] { new ConfigurationField { @@ -134,7 +134,7 @@ public EnumDataListSource( return (items, values); } - public IEnumerable GetItems(Dictionary config) + public override IEnumerable GetItems(Dictionary config) { var type = GetValueType(config); diff --git a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/ExamineDataListSource.cs b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/ExamineDataListSource.cs index 0d5cc0ac..27f86b18 100644 --- a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/ExamineDataListSource.cs +++ b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/ExamineDataListSource.cs @@ -30,7 +30,7 @@ namespace Umbraco.Community.Contentment.DataEditors { - public sealed class ExamineDataListSource : IDataListSource + public sealed class ExamineDataListSource : DataListToDataPickerSourceBridge, IDataListSource { private readonly IContentmentContentContext _contentmentContentContext; @@ -102,17 +102,17 @@ public ExamineDataListSource( _shortStringHelper = shortStringHelper; } - public string Name => "Examine Query"; + public override string Name => "Examine Query"; - public string Description => "Populate the data source from an Examine query."; + public override string Description => "Populate the data source from an Examine query."; - public string Icon => "icon-search"; + public override string Icon => "icon-search"; - public string Group => Constants.Conventions.DataSourceGroups.Umbraco; + public override string Group => Constants.Conventions.DataSourceGroups.Umbraco; - public OverlaySize OverlaySize => OverlaySize.Small; + public override OverlaySize OverlaySize => OverlaySize.Small; - public IEnumerable Fields => new[] + public override IEnumerable Fields => new[] { new ConfigurationField { @@ -181,7 +181,7 @@ public ExamineDataListSource( }, }; - public Dictionary DefaultValues => new Dictionary + public override Dictionary DefaultValues => new Dictionary() { { "examineIndex", UmbConstants.UmbracoIndexes.ExternalIndexName }, { "luceneQuery", "+__IndexType:content" }, @@ -191,7 +191,7 @@ public ExamineDataListSource( { "descriptionField", string.Empty }, }; - public IEnumerable GetItems(Dictionary config) + public override IEnumerable GetItems(Dictionary config) { var examineIndex = config.GetValueAs("examineIndex", UmbConstants.UmbracoIndexes.ExternalIndexName); if (_examineManager.TryGetIndex(examineIndex, out var index) == true) diff --git a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/JsonDataListSource.cs b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/JsonDataListSource.cs index a930dc6f..884de77a 100644 --- a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/JsonDataListSource.cs +++ b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/JsonDataListSource.cs @@ -27,7 +27,7 @@ namespace Umbraco.Community.Contentment.DataEditors { - public sealed class JsonDataListSource : IDataListSource, IContentmentListTemplateItem + public sealed class JsonDataListSource : DataListToDataPickerSourceBridge, IDataListSource, IContentmentListTemplateItem { private readonly IWebHostEnvironment _webHostEnvironment; private readonly IIOHelper _ioHelper; @@ -53,21 +53,21 @@ public JsonDataListSource( _ioHelper = ioHelper; } - public string Name => "JSON Data"; + public override string Name => "JSON Data"; public string NameTemplate => default; - public string Description => "Configure JSON data to populate the data source."; + public override string Description => "Configure JSON data to populate the data source."; public string DescriptionTemplate => "{{ url }}"; - public string Icon => "icon-brackets"; + public override string Icon => "icon-brackets"; - public string Group => Constants.Conventions.DataSourceGroups.Data; + public override string Group => Constants.Conventions.DataSourceGroups.Data; - public OverlaySize OverlaySize => OverlaySize.Small; + public override OverlaySize OverlaySize => OverlaySize.Small; - public IEnumerable Fields => new[] + public override IEnumerable Fields => new[] { new NotesConfigurationField(_ioHelper, $@"
Do you need help with JSONPath expressions? @@ -120,7 +120,7 @@ public JsonDataListSource( }, }; - public Dictionary DefaultValues => new Dictionary + public override Dictionary DefaultValues => new Dictionary() { { "url", "https://leekelleher.com/umbraco/contentment/data.json" }, { "itemsJsonPath", "$[*]" }, @@ -130,7 +130,7 @@ public JsonDataListSource( { "descriptionJsonPath", "$.description" }, }; - public IEnumerable GetItems(Dictionary config) + public override IEnumerable GetItems(Dictionary config) { var url = config.GetValueAs("url", string.Empty); @@ -226,6 +226,7 @@ public IEnumerable GetItems(Dictionary config) catch (Exception ex) { #if NET472 + // Error finding items in the JSON. Please check the syntax of your JSONPath expressions. _logger.Error(ex, "Error finding items in the JSON. Please check the syntax of your JSONPath expressions."); #else _logger.LogError(ex, "Error finding items in the JSON. Please check the syntax of your JSONPath expressions."); diff --git a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/NumberRangeDataListSource.cs b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/NumberRangeDataListSource.cs index 1bf9cec0..a5ecd930 100644 --- a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/NumberRangeDataListSource.cs +++ b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/NumberRangeDataListSource.cs @@ -19,7 +19,7 @@ namespace Umbraco.Community.Contentment.DataEditors { - public sealed class NumberRangeDataListSource : IDataListSource, IDataSourceValueConverter + public sealed class NumberRangeDataListSource : DataListToDataPickerSourceBridge, IDataListSource, IDataSourceValueConverter { private readonly IIOHelper _ioHelper; @@ -28,15 +28,15 @@ public NumberRangeDataListSource(IIOHelper ioHelper) _ioHelper = ioHelper; } - public string Name => "Number Range"; + public override string Name => "Number Range"; - public string Description => "Generates a sequence of numbers within a specified range."; + public override string Description => "Generates a sequence of numbers within a specified range."; - public string Icon => "icon-fa fa-sort-numeric-asc"; + public override string Icon => "icon-fa fa-sort-numeric-asc"; - public string Group => Constants.Conventions.DataSourceGroups.Data; + public override string Group => Constants.Conventions.DataSourceGroups.Data; - public IEnumerable Fields => new[] + public override IEnumerable Fields => new[] { new ConfigurationField { @@ -90,7 +90,7 @@ public NumberRangeDataListSource(IIOHelper ioHelper) } }; - public Dictionary DefaultValues => new Dictionary + public override Dictionary DefaultValues => new Dictionary() { { "start", 1 }, { "end", 10 }, @@ -98,9 +98,9 @@ public NumberRangeDataListSource(IIOHelper ioHelper) { "decimals", 0 }, }; - public OverlaySize OverlaySize => OverlaySize.Small; + public override OverlaySize OverlaySize => OverlaySize.Small; - public IEnumerable GetItems(Dictionary config) + public override IEnumerable GetItems(Dictionary config) { var start = config.GetValueAs("start", defaultValue: default(double)); var end = config.GetValueAs("end", defaultValue: default(double)); diff --git a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/PhysicalFileSystemDataSource.cs b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/PhysicalFileSystemDataSource.cs index 4f549532..183456ed 100644 --- a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/PhysicalFileSystemDataSource.cs +++ b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/PhysicalFileSystemDataSource.cs @@ -26,7 +26,7 @@ namespace Umbraco.Community.Contentment.DataEditors { - public sealed class PhysicalFileSystemDataSource : IDataListSource, IContentmentListTemplateItem + public sealed class PhysicalFileSystemDataSource : DataListToDataPickerSourceBridge, IDataListSource, IContentmentListTemplateItem { private readonly IShortStringHelper _shortStringHelper; @@ -57,21 +57,21 @@ public PhysicalFileSystemDataSource( } #endif - public string Name => "File System"; + public override string Name => "File System"; public string NameTemplate => default; - public string Description => "Select paths from the physical file system as the data source."; + public override string Description => "Select paths from the physical file system as the data source."; public string DescriptionTemplate => "{{ path }}; {{ filter }}"; - public string Icon => "icon-folder-close"; + public override string Icon => "icon-folder-close"; - public string Group => Constants.Conventions.DataSourceGroups.Data; + public override string Group => Constants.Conventions.DataSourceGroups.Data; - public OverlaySize OverlaySize => OverlaySize.Small; + public override OverlaySize OverlaySize => OverlaySize.Small; - public IEnumerable Fields => new[] + public override IEnumerable Fields => new[] { new ConfigurationField { @@ -100,13 +100,13 @@ public PhysicalFileSystemDataSource( } }; - public Dictionary DefaultValues => new Dictionary + public override Dictionary DefaultValues => new Dictionary() { { "path", "~/css" }, { "filter", "*.css" }, }; - public IEnumerable GetItems(Dictionary config) + public override IEnumerable GetItems(Dictionary config) { var path = config.GetValueAs("path", string.Empty); var filter = config.GetValueAs("filter", string.Empty); diff --git a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/SqlDataListSource.cs b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/SqlDataListSource.cs index f62f967c..621f7bd1 100644 --- a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/SqlDataListSource.cs +++ b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/SqlDataListSource.cs @@ -8,11 +8,17 @@ * please see the .NET472, .NET5_0 or .NET6_0 code files. */ using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + #if NET472 +using Umbraco.Core; using Umbraco.Core.IO; +using Umbraco.Core.Models; using Umbraco.Core.PropertyEditors; using UmbConstants = Umbraco.Core.Constants; #else +using Umbraco.Cms.Core.Models; using Umbraco.Cms.Core.PropertyEditors; using Umbraco.Extensions; using UmbConstants = Umbraco.Cms.Core.Constants; @@ -20,7 +26,7 @@ namespace Umbraco.Community.Contentment.DataEditors { - public sealed partial class SqlDataListSource : IDataListSource + public sealed partial class SqlDataListSource : IDataListSource, IDataPickerSource { public string Name => "SQL Data"; @@ -74,10 +80,47 @@ public sealed partial class SqlDataListSource : IDataListSource }, }; - public Dictionary DefaultValues => new Dictionary + public Dictionary DefaultValues => new Dictionary() { { "query", $"SELECT\r\n\t[text],\r\n\t[uniqueId]\r\nFROM\r\n\t[umbracoNode]\r\nWHERE\r\n\t[nodeObjectType] = '{UmbConstants.ObjectTypes.Strings.Document}'\r\n\tAND\r\n\t[level] = 1\r\nORDER BY\r\n\t[sortOrder] ASC\r\n\r\n-- This is an example query that will select all the content nodes that are at level 1.\r\n;" }, { "connectionString", UmbConstants.System.UmbracoConnectionName } }; + + public Task> GetItemsAsync(Dictionary config, IEnumerable values) + { + var items = GetItems(config); + + if (items?.Any() == true) + { + return Task.FromResult(items.Where(x => values.Contains(x.Value) == true)); + } + + return Task.FromResult(Enumerable.Empty()); + } + + public Task> SearchAsync(Dictionary config, int pageNumber = 1, int pageSize = 12, string query = "") + { + var items = default(IEnumerable); + + if (string.IsNullOrWhiteSpace(query) == true) + { + items = GetItems(config); + } + else + { + items = GetItems(config)?.Where(x => x.Name?.InvariantContains(query) == true || x.Value?.InvariantStartsWith(query) == true); + } + + if (items?.Any() == true) + { + var offset = (pageNumber - 1) * pageSize; + return Task.FromResult(new PagedResult(items.Count(), pageNumber, pageSize) + { + Items = items.Skip(offset).Take(pageSize), + }); + } + + return Task.FromResult(new PagedResult(-1, pageNumber, pageSize)); + } } } diff --git a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/TextDelimitedDataListSource.cs b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/TextDelimitedDataListSource.cs index 9e9a651e..86d6fb88 100644 --- a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/TextDelimitedDataListSource.cs +++ b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/TextDelimitedDataListSource.cs @@ -24,7 +24,7 @@ namespace Umbraco.Community.Contentment.DataEditors { - public sealed class TextDelimitedDataListSource : IDataListSource, IContentmentListTemplateItem + public sealed class TextDelimitedDataListSource : DataListToDataPickerSourceBridge, IDataListSource, IContentmentListTemplateItem { private readonly IWebHostEnvironment _webHostEnvironment; private readonly IIOHelper _ioHelper; @@ -55,21 +55,21 @@ public TextDelimitedDataListSource( } #endif - public string Name => "Text Delimited Data"; + public override string Name => "Text Delimited Data"; public string NameTemplate => default; - public string Description => "Configure text-delimited data to populate the data source."; + public override string Description => "Configure text-delimited data to populate the data source."; public string DescriptionTemplate => "{{ url }}"; - public string Icon => "icon-fa fa-file-text-o"; + public override string Icon => "icon-fa fa-file-text-o"; - public string Group => Constants.Conventions.DataSourceGroups.Data; + public override string Group => Constants.Conventions.DataSourceGroups.Data; - public OverlaySize OverlaySize => OverlaySize.Small; + public override OverlaySize OverlaySize => OverlaySize.Small; - public IEnumerable Fields => new[] + public override IEnumerable Fields => new[] { new NotesConfigurationField(_ioHelper, @"
A note about using this data source. @@ -127,7 +127,7 @@ public TextDelimitedDataListSource( } }; - public Dictionary DefaultValues => new Dictionary + public override Dictionary DefaultValues => new Dictionary() { { "url", "https://leekelleher.com/umbraco/contentment/data.csv" }, { "delimiter", "," }, @@ -137,7 +137,7 @@ public TextDelimitedDataListSource( { "descriptionIndex", 3 }, }; - public IEnumerable GetItems(Dictionary config) + public override IEnumerable GetItems(Dictionary config) { var items = new List(); diff --git a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/TimeZoneDataListSource.cs b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/TimeZoneDataListSource.cs index a1884b6e..167cbdc6 100644 --- a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/TimeZoneDataListSource.cs +++ b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/TimeZoneDataListSource.cs @@ -65,7 +65,7 @@ public Task> SearchAsync(Dictionary co else { items = GetItems(config) - .Where(x => x.Name.InvariantContains(query) == true || x.Value.InvariantStartsWith(query) == true); + .Where(x => x.Name?.InvariantContains(query) == true || x.Value?.InvariantStartsWith(query) == true); } if (items?.Any() == true) diff --git a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoBackofficeSectionsDataSource.cs b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoBackofficeSectionsDataSource.cs index f719e0c1..0b59115b 100644 --- a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoBackofficeSectionsDataSource.cs +++ b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoBackofficeSectionsDataSource.cs @@ -19,7 +19,7 @@ namespace Umbraco.Community.Contentment.DataEditors { - public sealed class UmbracoBackofficeSectionsDataSource : IDataListSource, IDataSourceValueConverter + public sealed class UmbracoBackofficeSectionsDataSource : DataListToDataPickerSourceBridge, IDataListSource, IDataSourceValueConverter { private readonly ISectionService _sectionService; @@ -28,21 +28,21 @@ public UmbracoBackofficeSectionsDataSource(ISectionService sectionService) _sectionService = sectionService; } - public string Name => "Umbraco Backoffice Sections"; + public override string Name => "Umbraco Backoffice Sections"; - public string Description => "Use the backoffice sections to populate the data source."; + public override string Description => "Use the backoffice sections to populate the data source."; - public string Icon => "icon-section"; + public override string Icon => "icon-section"; - public string Group => Constants.Conventions.DataSourceGroups.Umbraco; + public override string Group => Constants.Conventions.DataSourceGroups.Umbraco; - public IEnumerable Fields => default; + public override IEnumerable Fields => Enumerable.Empty(); - public Dictionary DefaultValues => default; + public override Dictionary DefaultValues => default; - public OverlaySize OverlaySize => OverlaySize.Small; + public override OverlaySize OverlaySize => OverlaySize.Small; - public IEnumerable GetItems(Dictionary config) + public override IEnumerable GetItems(Dictionary config) { return _sectionService .GetSections() diff --git a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoContentPropertiesDataListSource.cs b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoContentPropertiesDataListSource.cs index 49fde0b2..121ddfa7 100644 --- a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoContentPropertiesDataListSource.cs +++ b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoContentPropertiesDataListSource.cs @@ -24,7 +24,7 @@ namespace Umbraco.Community.Contentment.DataEditors { - public sealed class UmbracoContentPropertiesDataListSource : IDataListSource + public sealed class UmbracoContentPropertiesDataListSource : DataListToDataPickerSourceBridge, IDataListSource { private readonly IContentTypeService _contentTypeService; private readonly Lazy _dataEditors; @@ -41,15 +41,15 @@ public UmbracoContentPropertiesDataListSource( _ioHelper = ioHelper; } - public string Name => "Umbraco Content Properties"; + public override string Name => "Umbraco Content Properties"; - public string Description => "Populate the data source using a Content Type's properties."; + public override string Description => "Populate the data source using a Content Type's properties."; - public string Icon => "icon-fa fa-tasks"; + public override string Icon => "icon-fa fa-tasks"; - public string Group => Constants.Conventions.DataSourceGroups.Umbraco; + public override string Group => Constants.Conventions.DataSourceGroups.Umbraco; - public IEnumerable Fields + public override IEnumerable Fields { get { @@ -99,11 +99,11 @@ public IEnumerable Fields } } - public Dictionary DefaultValues => default; + public override Dictionary DefaultValues => default; - public OverlaySize OverlaySize => OverlaySize.Small; + public override OverlaySize OverlaySize => OverlaySize.Small; - public IEnumerable GetItems(Dictionary config) + public override IEnumerable GetItems(Dictionary config) { if (config.TryGetValueAs("contentType", out JArray array) == true && array.Count > 0 && diff --git a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoContentPropertyValueDataListSource.cs b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoContentPropertyValueDataListSource.cs index 05f83773..5e0afa03 100644 --- a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoContentPropertyValueDataListSource.cs +++ b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoContentPropertyValueDataListSource.cs @@ -34,7 +34,7 @@ namespace Umbraco.Community.Contentment.DataEditors.DataList.DataSources { - public sealed class UmbracoContentPropertyValueDataListSource : IDataListSource + public sealed class UmbracoContentPropertyValueDataListSource : DataListToDataPickerSourceBridge, IDataListSource { private readonly ContentmentDataListItemPropertyValueConverterCollection _converters; private readonly IContentmentContentContext _contentmentContentContext; @@ -53,15 +53,15 @@ public UmbracoContentPropertyValueDataListSource( _umbracoContextAccessor = umbracoContextAccessor; } - public string Name => "Umbraco Content Property Values"; + public override string Name => "Umbraco Content Property Values"; - public string Description => "Use Umbraco content property values to populate a data source."; + public override string Description => "Use Umbraco content property values to populate a data source."; - public string Icon => "icon-umbraco"; + public override string Icon => "icon-umbraco"; - public OverlaySize OverlaySize => OverlaySize.Small; + public override OverlaySize OverlaySize => OverlaySize.Small; - public IEnumerable Fields => new ConfigurationField[] + public override IEnumerable Fields => new ConfigurationField[] { new ConfigurationField { @@ -79,11 +79,11 @@ public UmbracoContentPropertyValueDataListSource( }, }; - public Dictionary DefaultValues => default; + public override Dictionary DefaultValues => default; - public string Group => Constants.Conventions.DataSourceGroups.Umbraco; + public override string Group => Constants.Conventions.DataSourceGroups.Umbraco; - public IEnumerable GetItems(Dictionary config) + public override IEnumerable GetItems(Dictionary config) { var contentNode = config.GetValueAs("contentNode", string.Empty); var propertyAlias = config.GetValueAs("propertyAlias", string.Empty); diff --git a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoContentTypesDataListSource.cs b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoContentTypesDataListSource.cs index 2712ffae..aed9ff21 100644 --- a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoContentTypesDataListSource.cs +++ b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoContentTypesDataListSource.cs @@ -31,7 +31,7 @@ namespace Umbraco.Community.Contentment.DataEditors { - public sealed class UmbracoContentTypesDataListSource : IDataListSource, IDataSourceValueConverter + public sealed class UmbracoContentTypesDataListSource : DataListToDataPickerSourceBridge, IDataListSource, IDataSourceValueConverter { private readonly IContentTypeService _contentTypeService; private readonly IUmbracoContextAccessor _umbracoContextAccessor; @@ -59,17 +59,17 @@ public UmbracoContentTypesDataListSource( _ioHelper = ioHelper; } - public string Name => "Umbraco Content Types"; + public override string Name => "Umbraco Content Types"; - public string Description => "Populate the data source using Content Types."; + public override string Description => "Populate the data source using Content Types."; - public string Icon => UmbConstants.Icons.ContentType; + public override string Icon => UmbConstants.Icons.ContentType; - public string Group => Constants.Conventions.DataSourceGroups.Umbraco; + public override string Group => Constants.Conventions.DataSourceGroups.Umbraco; - public OverlaySize OverlaySize => OverlaySize.Small; + public override OverlaySize OverlaySize => OverlaySize.Small; - public IEnumerable Fields => new[] + public override IEnumerable Fields => new[] { new ConfigurationField { @@ -111,9 +111,9 @@ public UmbracoContentTypesDataListSource( }, }; - public Dictionary DefaultValues => default; + public override Dictionary DefaultValues => default; - public IEnumerable GetItems(Dictionary config) + public override IEnumerable GetItems(Dictionary config) { var types = config.GetValueAs("contentTypes", defaultValue: default(JArray))?.ToObject>(); diff --git a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoContentXPathDataListSource.cs b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoContentXPathDataListSource.cs index 8be99144..779e9137 100644 --- a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoContentXPathDataListSource.cs +++ b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoContentXPathDataListSource.cs @@ -26,7 +26,7 @@ namespace Umbraco.Community.Contentment.DataEditors { - public sealed class UmbracoContentXPathDataListSource : IDataListSource, IDataSourceValueConverter + public sealed class UmbracoContentXPathDataListSource : DataListToDataPickerSourceBridge, IDataListSource, IDataSourceValueConverter { private readonly IContentmentContentContext _contentmentContentContext; private readonly IUmbracoContextAccessor _umbracoContextAccessor; @@ -42,15 +42,15 @@ public UmbracoContentXPathDataListSource( _ioHelper = ioHelper; } - public string Name => "Umbraco Content by XPath"; + public override string Name => "Umbraco Content by XPath"; - public string Description => "Use an XPath query to select Umbraco content to use as the data source."; + public override string Description => "Use an XPath query to select Umbraco content to use as the data source."; - public string Icon => "icon-fa fa-file-code-o"; + public override string Icon => "icon-fa fa-file-code-o"; - public OverlaySize OverlaySize => OverlaySize.Small; + public override OverlaySize OverlaySize => OverlaySize.Small; - public IEnumerable Fields => new ConfigurationField[] + public override IEnumerable Fields => new ConfigurationField[] { new ConfigurationField { @@ -79,14 +79,14 @@ public UmbracoContentXPathDataListSource(
", true), }; - public Dictionary DefaultValues => new Dictionary + public override Dictionary DefaultValues => new Dictionary() { { "xpath", "/root/*[@level = 1]/*[@isDoc]" }, }; - public string Group => Constants.Conventions.DataSourceGroups.Umbraco; + public override string Group => Constants.Conventions.DataSourceGroups.Umbraco; - public IEnumerable GetItems(Dictionary config) + public override IEnumerable GetItems(Dictionary config) { var xpath = config.GetValueAs("xpath", string.Empty); diff --git a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoDictionaryDataListSource.cs b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoDictionaryDataListSource.cs index 1a5f5e9d..929e6776 100644 --- a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoDictionaryDataListSource.cs +++ b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoDictionaryDataListSource.cs @@ -24,7 +24,7 @@ namespace Umbraco.Community.Contentment.DataEditors { - public sealed class UmbracoDictionaryDataListSource : IDataListSource + public sealed class UmbracoDictionaryDataListSource : DataListToDataPickerSourceBridge, IDataListSource { private readonly ILocalizationService _localizationService; private readonly IIOHelper _ioHelper; @@ -37,15 +37,15 @@ public UmbracoDictionaryDataListSource( _ioHelper = ioHelper; } - public string Name => "Umbraco Dictionary Items"; + public override string Name => "Umbraco Dictionary Items"; - public string Description => "Select an Umbraco dictionary item to populate the data source with its child items."; + public override string Description => "Select an Umbraco dictionary item to populate the data source with its child items."; - public string Icon => "icon-book-alt"; + public override string Icon => "icon-book-alt"; - public string Group => Constants.Conventions.DataSourceGroups.Umbraco; + public override string Group => Constants.Conventions.DataSourceGroups.Umbraco; - public IEnumerable Fields => new[] + public override IEnumerable Fields => new[] { new ConfigurationField { @@ -60,11 +60,11 @@ public UmbracoDictionaryDataListSource( } }; - public Dictionary DefaultValues => default; + public override Dictionary DefaultValues => default; - public OverlaySize OverlaySize => OverlaySize.Small; + public override OverlaySize OverlaySize => OverlaySize.Small; - public IEnumerable GetItems(Dictionary config) + public override IEnumerable GetItems(Dictionary config) { if (config.TryGetValueAs("item", out JArray array) == true && array.Count > 0 && diff --git a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoEntityDataListSource.cs b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoEntityDataListSource.cs index 4e438e6d..c8123ffd 100644 --- a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoEntityDataListSource.cs +++ b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoEntityDataListSource.cs @@ -29,7 +29,7 @@ namespace Umbraco.Community.Contentment.DataEditors { - public sealed class UmbracoEntityDataListSource : IDataListSource, IDataSourceValueConverter + public sealed class UmbracoEntityDataListSource : DataListToDataPickerSourceBridge, IDataListSource, IDataSourceValueConverter { internal static Dictionary SupportedEntityTypes = new Dictionary { @@ -69,15 +69,15 @@ public UmbracoEntityDataListSource( _ioHelper = ioHelper; } - public string Name => "Umbraco Entities"; + public override string Name => "Umbraco Entities"; - public string Description => "Select an Umbraco entity type to populate the data source."; + public override string Description => "Select an Umbraco entity type to populate the data source."; - public string Icon => "icon-lab"; + public override string Icon => "icon-lab"; - public string Group => Constants.Conventions.DataSourceGroups.Umbraco; + public override string Group => Constants.Conventions.DataSourceGroups.Umbraco; - public IEnumerable Fields => new ConfigurationField[] + public override IEnumerable Fields => new ConfigurationField[] { new NotesConfigurationField(_ioHelper, @"
A note about supported Umbraco entity types. @@ -103,11 +103,11 @@ public UmbracoEntityDataListSource( } }; - public Dictionary DefaultValues => default; + public override Dictionary DefaultValues => default; - public OverlaySize OverlaySize => OverlaySize.Small; + public override OverlaySize OverlaySize => OverlaySize.Small; - public IEnumerable GetItems(Dictionary config) + public override IEnumerable GetItems(Dictionary config) { if (config.TryGetValueAs("entityType", out string entityType) == true && SupportedEntityTypes.TryGetValue(entityType, out var objectType) == true) { diff --git a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoFilesDataListSource.cs b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoFilesDataListSource.cs index d49550ca..8b798860 100644 --- a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoFilesDataListSource.cs +++ b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoFilesDataListSource.cs @@ -23,7 +23,7 @@ namespace Umbraco.Community.Contentment.DataEditors { - public sealed class UmbracoFilesDataListSource : IDataListSource + public sealed class UmbracoFilesDataListSource : DataListToDataPickerSourceBridge, IDataListSource { private static readonly Dictionary _icons = new Dictionary { @@ -45,17 +45,17 @@ public UmbracoFilesDataListSource( _textService = textService; } - public string Name => "Umbraco Files"; + public override string Name => "Umbraco Files"; - public string Description => "Use files defined in Umbraco, such as scripts or stylesheets."; + public override string Description => "Use files defined in Umbraco, such as scripts or stylesheets."; - public string Icon => "icon-notepad-alt"; + public override string Icon => "icon-notepad-alt"; - public string Group => Constants.Conventions.DataSourceGroups.Umbraco; + public override string Group => Constants.Conventions.DataSourceGroups.Umbraco; - public OverlaySize OverlaySize => OverlaySize.Small; + public override OverlaySize OverlaySize => OverlaySize.Small; - public IEnumerable Fields => new[] + public override IEnumerable Fields => new[] { new ConfigurationField { @@ -110,13 +110,13 @@ public UmbracoFilesDataListSource( }, }; - public Dictionary DefaultValues => new Dictionary + public override Dictionary DefaultValues => new Dictionary() { { "fileType", UmbConstants.UdiEntityType.Stylesheet }, { "valueType", "alias" }, }; - public IEnumerable GetItems(Dictionary config) + public override IEnumerable GetItems(Dictionary config) { var fileType = config.GetValueAs("fileType", defaultValue: UmbConstants.UdiEntityType.Stylesheet); var valueType = config.GetValueAs("valueType", defaultValue: "alias"); diff --git a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoImageCropDataListSource.cs b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoImageCropDataListSource.cs index 1d2f69da..b58e9bad 100644 --- a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoImageCropDataListSource.cs +++ b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoImageCropDataListSource.cs @@ -24,7 +24,7 @@ namespace Umbraco.Community.Contentment.DataEditors { - public sealed class UmbracoImageCropDataListSource : IDataListSource + public sealed class UmbracoImageCropDataListSource : DataListToDataPickerSourceBridge, IDataListSource { private readonly IDataTypeService _dataTypeService; private readonly IIOHelper _ioHelper; @@ -37,15 +37,15 @@ public UmbracoImageCropDataListSource( _ioHelper = ioHelper; } - public string Name => "Umbraco Image Crops"; + public override string Name => "Umbraco Image Crops"; - public string Description => "Select an Image Cropper data-type to use its defined crops to populate the data source."; + public override string Description => "Select an Image Cropper data-type to use its defined crops to populate the data source."; - public string Icon => "icon-crop"; + public override string Icon => "icon-crop"; - public string Group => Constants.Conventions.DataSourceGroups.Umbraco; + public override string Group => Constants.Conventions.DataSourceGroups.Umbraco; - public IEnumerable Fields + public override IEnumerable Fields { get { @@ -77,11 +77,11 @@ public IEnumerable Fields } } - public Dictionary DefaultValues => default; + public override Dictionary DefaultValues => default; - public OverlaySize OverlaySize => OverlaySize.Small; + public override OverlaySize OverlaySize => OverlaySize.Small; - public IEnumerable GetItems(Dictionary config) + public override IEnumerable GetItems(Dictionary config) { if (config.TryGetValue("imageCropper", out var obj) == true && obj is string str && diff --git a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoLanguagesDataListSource.cs b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoLanguagesDataListSource.cs index fad79aca..168ddb4a 100644 --- a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoLanguagesDataListSource.cs +++ b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoLanguagesDataListSource.cs @@ -17,7 +17,7 @@ namespace Umbraco.Community.Contentment.DataEditors { - public sealed class UmbracoLanguagesDataListSource : IDataListSource + public sealed class UmbracoLanguagesDataListSource : DataListToDataPickerSourceBridge, IDataListSource { private readonly ILocalizationService _localizationService; @@ -26,21 +26,21 @@ public UmbracoLanguagesDataListSource(ILocalizationService localizationService) _localizationService = localizationService; } - public string Name => "Umbraco Languages"; + public override string Name => "Umbraco Languages"; - public string Description => "Populate the data source with languages configured in Umbraco."; + public override string Description => "Populate the data source with languages configured in Umbraco."; - public string Icon => UmbConstants.Icons.Language; + public override string Icon => UmbConstants.Icons.Language; - public string Group => Constants.Conventions.DataSourceGroups.Umbraco; + public override string Group => Constants.Conventions.DataSourceGroups.Umbraco; - public IEnumerable Fields => default; + public override IEnumerable Fields => Enumerable.Empty(); - public Dictionary DefaultValues => default; + public override Dictionary DefaultValues => default; - public OverlaySize OverlaySize => OverlaySize.Small; + public override OverlaySize OverlaySize => OverlaySize.Small; - public IEnumerable GetItems(Dictionary config) + public override IEnumerable GetItems(Dictionary config) { return _localizationService .GetAllLanguages() diff --git a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoMemberGroupDataListSource.cs b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoMemberGroupDataListSource.cs index 05a5e910..63aabd0b 100644 --- a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoMemberGroupDataListSource.cs +++ b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoMemberGroupDataListSource.cs @@ -20,7 +20,7 @@ namespace Umbraco.Community.Contentment.DataEditors { - public sealed class UmbracoMemberGroupDataListSource : IDataListSource, IDataSourceValueConverter + public sealed class UmbracoMemberGroupDataListSource : DataListToDataPickerSourceBridge, IDataListSource, IDataSourceValueConverter { private readonly IMemberGroupService _memberGroupService; @@ -29,21 +29,21 @@ public UmbracoMemberGroupDataListSource(IMemberGroupService memberGroupService) _memberGroupService = memberGroupService; } - public string Name => "Umbraco Member Groups"; + public override string Name => "Umbraco Member Groups"; - public string Description => "Populate the data source with Umbraco member groups."; + public override string Description => "Populate the data source with Umbraco member groups."; - public string Icon => UmbConstants.Icons.MemberGroup; + public override string Icon => UmbConstants.Icons.MemberGroup; - public string Group => Constants.Conventions.DataSourceGroups.Umbraco; + public override string Group => Constants.Conventions.DataSourceGroups.Umbraco; - public IEnumerable Fields => default; + public override IEnumerable Fields => Enumerable.Empty(); - public Dictionary DefaultValues => default; + public override Dictionary DefaultValues => default; - public OverlaySize OverlaySize => OverlaySize.Small; + public override OverlaySize OverlaySize => OverlaySize.Small; - public IEnumerable GetItems(Dictionary config) + public override IEnumerable GetItems(Dictionary config) { return _memberGroupService .GetAll() diff --git a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoTagsDataListSource.cs b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoTagsDataListSource.cs index 01c32151..4b469807 100644 --- a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoTagsDataListSource.cs +++ b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoTagsDataListSource.cs @@ -20,7 +20,7 @@ namespace Umbraco.Community.Contentment.DataEditors { - public sealed class UmbracoTagsDataListSource : IDataListSource + public sealed class UmbracoTagsDataListSource : DataListToDataPickerSourceBridge, IDataListSource { #if NET472 private readonly Lazy _tagQuery; @@ -38,17 +38,17 @@ public UmbracoTagsDataListSource(IHttpContextAccessor httpContextAccessor) } #endif - public string Name => "Umbraco Tags"; + public override string Name => "Umbraco Tags"; - public string Description => "Populate the data source using already defined tags."; + public override string Description => "Populate the data source using already defined tags."; - public string Icon => "icon-tags"; + public override string Icon => "icon-tags"; - public string Group => Constants.Conventions.DataSourceGroups.Umbraco; + public override string Group => Constants.Conventions.DataSourceGroups.Umbraco; - public OverlaySize OverlaySize => OverlaySize.Small; + public override OverlaySize OverlaySize => OverlaySize.Small; - public IEnumerable Fields => new[] + public override IEnumerable Fields => new[] { new ConfigurationField { @@ -59,12 +59,12 @@ public UmbracoTagsDataListSource(IHttpContextAccessor httpContextAccessor) }, }; - public Dictionary DefaultValues => new Dictionary + public override Dictionary DefaultValues => new Dictionary() { { "tagGroup", "default" }, }; - public IEnumerable GetItems(Dictionary config) + public override IEnumerable GetItems(Dictionary config) { var tagGroup = config.GetValueAs("tagGroup", defaultValue: string.Empty); diff --git a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoTemplatesDataListSource.cs b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoTemplatesDataListSource.cs index 29d2edc7..ba77f268 100644 --- a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoTemplatesDataListSource.cs +++ b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoTemplatesDataListSource.cs @@ -25,7 +25,7 @@ namespace Umbraco.Community.Contentment.DataEditors { - public sealed class UmbracoTemplatesDataListSource : IDataListSource, IDataSourceValueConverter + public sealed class UmbracoTemplatesDataListSource : DataListToDataPickerSourceBridge, IDataListSource, IDataSourceValueConverter { private readonly IFileService _fileService; private readonly IIOHelper _ioHelper; @@ -38,17 +38,17 @@ public UmbracoTemplatesDataListSource( _ioHelper = ioHelper; } - public string Name => "Umbraco Templates"; + public override string Name => "Umbraco Templates"; - public string Description => "Populate the data source using defined view templates."; + public override string Description => "Populate the data source using defined view templates."; - public string Icon => UmbConstants.Icons.Template; + public override string Icon => UmbConstants.Icons.Template; - public string Group => Constants.Conventions.DataSourceGroups.Umbraco; + public override string Group => Constants.Conventions.DataSourceGroups.Umbraco; - public OverlaySize OverlaySize => OverlaySize.Small; + public override OverlaySize OverlaySize => OverlaySize.Small; - public IEnumerable Fields => new[] + public override IEnumerable Fields => new[] { new ConfigurationField { @@ -85,12 +85,12 @@ public UmbracoTemplatesDataListSource( }, }; - public Dictionary DefaultValues => new Dictionary + public override Dictionary DefaultValues => new Dictionary() { { "valueType", "udi" }, }; - public IEnumerable GetItems(Dictionary config) + public override IEnumerable GetItems(Dictionary config) { var valueType = config.GetValueAs("valueType", defaultValue: "udi"); diff --git a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoUserGroupDataListSource.cs b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoUserGroupDataListSource.cs index 84b739f5..30990400 100644 --- a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoUserGroupDataListSource.cs +++ b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoUserGroupDataListSource.cs @@ -20,7 +20,7 @@ namespace Umbraco.Community.Contentment.DataEditors { - public sealed class UmbracoUserGroupDataListSource : IDataListSource, IDataSourceValueConverter + public sealed class UmbracoUserGroupDataListSource : DataListToDataPickerSourceBridge, IDataListSource, IDataSourceValueConverter { private readonly IUserService _userService; @@ -29,21 +29,21 @@ public UmbracoUserGroupDataListSource(IUserService userService) _userService = userService; } - public string Name => "Umbraco User Groups"; + public override string Name => "Umbraco User Groups"; - public string Description => "Populate the data source with Umbraco user groups."; + public override string Description => "Populate the data source with Umbraco user groups."; - public string Icon => UmbConstants.Icons.UserGroup; + public override string Icon => UmbConstants.Icons.UserGroup; - public string Group => Constants.Conventions.DataSourceGroups.Umbraco; + public override string Group => Constants.Conventions.DataSourceGroups.Umbraco; - public IEnumerable Fields => default; + public override IEnumerable Fields => Enumerable.Empty(); - public Dictionary DefaultValues => default; + public override Dictionary DefaultValues => default; - public OverlaySize OverlaySize => OverlaySize.Small; + public override OverlaySize OverlaySize => OverlaySize.Small; - public IEnumerable GetItems(Dictionary config) + public override IEnumerable GetItems(Dictionary config) { return _userService .GetAllUserGroups() diff --git a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoUsersDataListSource.cs b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoUsersDataListSource.cs index 64e42700..37285a3a 100644 --- a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoUsersDataListSource.cs +++ b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoUsersDataListSource.cs @@ -25,7 +25,7 @@ namespace Umbraco.Community.Contentment.DataEditors { - public sealed class UmbracoUsersDataListSource : IDataListSource, IDataSourceValueConverter + public sealed class UmbracoUsersDataListSource : DataListToDataPickerSourceBridge, IDataListSource, IDataSourceValueConverter { private readonly IIOHelper _ioHelper; private readonly IUserService _userService; @@ -36,15 +36,15 @@ public UmbracoUsersDataListSource(IIOHelper ioHelper, IUserService userService) _userService = userService; } - public string Name => "Umbraco Users"; + public override string Name => "Umbraco Users"; - public string Description => "Use Umbraco users to populate the data source."; + public override string Description => "Use Umbraco users to populate the data source."; - public string Icon => UmbConstants.Icons.User; + public override string Icon => UmbConstants.Icons.User; - public string Group => Constants.Conventions.DataSourceGroups.Umbraco; + public override string Group => Constants.Conventions.DataSourceGroups.Umbraco; - public IEnumerable Fields + public override IEnumerable Fields { get { @@ -80,11 +80,11 @@ public IEnumerable Fields } } - public Dictionary DefaultValues => default; + public override Dictionary DefaultValues => default; - public OverlaySize OverlaySize => OverlaySize.Small; + public override OverlaySize OverlaySize => OverlaySize.Small; - public IEnumerable GetItems(Dictionary config) + public override IEnumerable GetItems(Dictionary config) { DataListItem mapUser(IUser user) { diff --git a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UserDefinedDataListSource.cs b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UserDefinedDataListSource.cs index 29c06355..fc28cf40 100644 --- a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UserDefinedDataListSource.cs +++ b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UserDefinedDataListSource.cs @@ -20,7 +20,7 @@ namespace Umbraco.Community.Contentment.DataEditors { - public sealed class UserDefinedDataListSource : IDataListSource, IContentmentListTemplateItem + public sealed class UserDefinedDataListSource : DataListToDataPickerSourceBridge, IDataListSource, IContentmentListTemplateItem { private readonly IIOHelper _ioHelper; @@ -29,19 +29,19 @@ public UserDefinedDataListSource(IIOHelper ioHelper) _ioHelper = ioHelper; } - public string Name => "User-defined List"; + public override string Name => "User-defined List"; public string NameTemplate => default; - public string Description => "Manually configure the items for the data source."; + public override string Description => "Manually configure the items for the data source."; public string DescriptionTemplate => "{{ items.length }} {{ items.length === 1 ? 'item' : 'items' }} defined."; - public string Icon => UmbConstants.Icons.DataType; + public override string Icon => UmbConstants.Icons.DataType; - public string Group => Constants.Conventions.DataSourceGroups.Data; + public override string Group => Constants.Conventions.DataSourceGroups.Data; - public IEnumerable Fields => new[] + public override IEnumerable Fields => new[] { new ConfigurationField { @@ -81,11 +81,11 @@ public UserDefinedDataListSource(IIOHelper ioHelper) } }; - public Dictionary DefaultValues => default; + public override Dictionary DefaultValues => default; - public OverlaySize OverlaySize => OverlaySize.Medium; + public override OverlaySize OverlaySize => OverlaySize.Medium; - public IEnumerable GetItems(Dictionary config) + public override IEnumerable GetItems(Dictionary config) { return config.TryGetValueAs("items", out JArray array) == true ? array.ToObject>().DistinctBy(x => x.Value) diff --git a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/XmlDataListSource.cs b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/XmlDataListSource.cs index f3952908..5197e62c 100644 --- a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/XmlDataListSource.cs +++ b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/XmlDataListSource.cs @@ -27,7 +27,7 @@ namespace Umbraco.Community.Contentment.DataEditors { - public sealed class XmlDataListSource : IDataListSource, IContentmentListTemplateItem + public sealed class XmlDataListSource : DataListToDataPickerSourceBridge, IDataListSource, IContentmentListTemplateItem { private readonly IWebHostEnvironment _webHostEnvironment; private readonly IIOHelper _ioHelper; @@ -58,21 +58,21 @@ public XmlDataListSource( } #endif - public string Name => "XML Data"; + public override string Name => "XML Data"; public string NameTemplate => default; - public string Description => "Configure XML data to populate the data source."; + public override string Description => "Configure XML data to populate the data source."; public string DescriptionTemplate => "{{ url }}"; - public string Icon => "icon-code"; + public override string Icon => "icon-code"; - public string Group => Constants.Conventions.DataSourceGroups.Data; + public override string Group => Constants.Conventions.DataSourceGroups.Data; - public OverlaySize OverlaySize => OverlaySize.Small; + public override OverlaySize OverlaySize => OverlaySize.Small; - public IEnumerable Fields => new ConfigurationField[] + public override IEnumerable Fields => new ConfigurationField[] { new ConfigurationField { @@ -126,7 +126,7 @@ public XmlDataListSource( }, }; - public Dictionary DefaultValues => new Dictionary + public override Dictionary DefaultValues => new Dictionary() { { "url", "https://leekelleher.com/umbraco/contentment/data.xml" }, { "itemsXPath", "/items/item" }, @@ -136,7 +136,7 @@ public XmlDataListSource( { "descriptionXPath", "@description" }, }; - public IEnumerable GetItems(Dictionary config) + public override IEnumerable GetItems(Dictionary config) { var url = config.GetValueAs("url", string.Empty); diff --git a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/XmlSitemapChangeFrequencyDataListSource.cs b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/XmlSitemapChangeFrequencyDataListSource.cs index 6c5cc68f..97fb1371 100644 --- a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/XmlSitemapChangeFrequencyDataListSource.cs +++ b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/XmlSitemapChangeFrequencyDataListSource.cs @@ -15,7 +15,7 @@ namespace Umbraco.Community.Contentment.DataEditors { - public sealed class XmlSitemapChangeFrequencyDataListSource : IDataListSource + public sealed class XmlSitemapChangeFrequencyDataListSource : DataListToDataPickerSourceBridge, IDataListSource { private readonly string[] _options; @@ -33,21 +33,21 @@ public XmlSitemapChangeFrequencyDataListSource() }; } - public string Name => "XML Sitemap: Change Frequency"; + public override string Name => "XML Sitemap: Change Frequency"; - public string Description => "Populate the data source using XML Sitemap change frequency values."; + public override string Description => "Populate the data source using XML Sitemap change frequency values."; - public string Icon => "icon-fa fa-signal"; + public override string Icon => "icon-fa fa-signal"; - public string Group => Constants.Conventions.DataSourceGroups.Web; + public override string Group => Constants.Conventions.DataSourceGroups.Web; - public IEnumerable Fields => default; + public override IEnumerable Fields => Enumerable.Empty(); - public Dictionary DefaultValues => default; + public override Dictionary DefaultValues => default; - public OverlaySize OverlaySize => OverlaySize.Small; + public override OverlaySize OverlaySize => OverlaySize.Small; - public IEnumerable GetItems(Dictionary config) + public override IEnumerable GetItems(Dictionary config) { return _options.Select(x => new DataListItem { Name = x.ToFirstUpperInvariant(), Value = x }); } diff --git a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/XmlSitemapPriorityDataListSource.cs b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/XmlSitemapPriorityDataListSource.cs index 1e32d5ba..9c75bf02 100644 --- a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/XmlSitemapPriorityDataListSource.cs +++ b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/XmlSitemapPriorityDataListSource.cs @@ -4,6 +4,7 @@ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ using System.Collections.Generic; +using System.Linq; #if NET472 using Umbraco.Core.PropertyEditors; #else @@ -12,23 +13,23 @@ namespace Umbraco.Community.Contentment.DataEditors { - public sealed class XmlSitemapPriorityDataListSource : IDataListSource + public sealed class XmlSitemapPriorityDataListSource : DataListToDataPickerSourceBridge, IDataListSource { - public string Name => "XML Sitemap: Priority"; + public override string Name => "XML Sitemap: Priority"; - public string Description => "Populate the data source using XML Sitemap priority values."; + public override string Description => "Populate the data source using XML Sitemap priority values."; - public string Icon => "icon-fa fa-exclamation-circle"; + public override string Icon => "icon-fa fa-exclamation-circle"; - public string Group => Constants.Conventions.DataSourceGroups.Web; + public override string Group => Constants.Conventions.DataSourceGroups.Web; - public IEnumerable Fields => default; + public override IEnumerable Fields => Enumerable.Empty(); - public Dictionary DefaultValues => default; + public override Dictionary DefaultValues => default; - public OverlaySize OverlaySize => OverlaySize.Small; + public override OverlaySize OverlaySize => OverlaySize.Small; - public IEnumerable GetItems(Dictionary config) + public override IEnumerable GetItems(Dictionary config) { for (var i = 0.0D; i <= 1.0D; i += 0.1D) { diff --git a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/uCssClassNameDataListSource.cs b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/uCssClassNameDataListSource.cs index b34c2020..9c315486 100644 --- a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/uCssClassNameDataListSource.cs +++ b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/uCssClassNameDataListSource.cs @@ -23,7 +23,7 @@ namespace Umbraco.Community.Contentment.DataEditors { - public class uCssClassNameDataListSource : IDataListSource + public class uCssClassNameDataListSource : DataListToDataPickerSourceBridge, IDataListSource { private readonly IWebHostEnvironment _webHostEnvironment; private readonly IIOHelper _ioHelper; @@ -36,15 +36,15 @@ public uCssClassNameDataListSource( _ioHelper = ioHelper; } - public string Name => "uCssClassName"; + public override string Name => "uCssClassName"; - public string Description => "A homage to @marcemarc's bingo-famous uCssClassNameDropdown package!"; + public override string Description => "A homage to @marcemarc's bingo-famous uCssClassNameDropdown package!"; - public string Icon => "icon-fa fa-css3"; + public override string Icon => "icon-fa fa-css3"; - public string Group => Constants.Conventions.DataSourceGroups.Web; + public override string Group => Constants.Conventions.DataSourceGroups.Web; - public IEnumerable Fields => new[] + public override IEnumerable Fields => new[] { new NotesConfigurationField(_ioHelper, @"
uCssClassName? What sort of a name is that? @@ -88,7 +88,7 @@ public uCssClassNameDataListSource( }, }; - public Dictionary DefaultValues => new Dictionary + public override Dictionary DefaultValues => new Dictionary() { { "cssPath", "~/umbraco/lib/font-awesome/css/font-awesome.min.css" }, { "cssRegex", "\\.fa-([^:]*?):before" }, @@ -96,9 +96,9 @@ public uCssClassNameDataListSource( { "iconPattern", "icon-fa fa-{0}" }, }; - public OverlaySize OverlaySize => OverlaySize.Small; + public override OverlaySize OverlaySize => OverlaySize.Small; - public IEnumerable GetItems(Dictionary config) + public override IEnumerable GetItems(Dictionary config) { var cssPath = config.GetValueAs("cssPath", string.Empty); var cssRegex = config.GetValueAs("cssRegex", string.Empty); diff --git a/src/Umbraco.Community.Contentment/DataEditors/DataPicker/DataPickerConfigurationEditor.cs b/src/Umbraco.Community.Contentment/DataEditors/DataPicker/DataPickerConfigurationEditor.cs index 8ce018c1..db021c24 100644 --- a/src/Umbraco.Community.Contentment/DataEditors/DataPicker/DataPickerConfigurationEditor.cs +++ b/src/Umbraco.Community.Contentment/DataEditors/DataPicker/DataPickerConfigurationEditor.cs @@ -73,6 +73,11 @@ public DataPickerConfigurationEditor( { Constants.Conventions.ConfigurationFieldAliases.AddButtonLabelKey, "contentment_configureDataSource" }, { Constants.Conventions.ConfigurationFieldAliases.Items, dataSources }, { EnableFilterConfigurationField.EnableFilter, dataSources.Count > 10 ? Constants.Values.True : Constants.Values.False }, + { "help", new { + @class = "alert alert-info", + title = "Do you need a custom data-source?", + notes = $@"

If one of the data-sources above does not fit your needs, you can extend Data Picker with your own custom data source.

+

To do this, read the documentation on extending with your own custom data source.

" } }, } }); @@ -118,6 +123,14 @@ public DataPickerConfigurationEditor( } }); + Fields.Add(new ConfigurationField + { + Key = "hideSearch", + Name = "Hide search box?", + Description = "Hide the search box in the overlay panel.", + View = "boolean", + }); + Fields.Add(new MaxItemsConfigurationField(ioHelper)); Fields.Add(new EnableDevModeConfigurationField()); } diff --git a/src/Umbraco.Community.Contentment/DataEditors/DataPicker/data-picker.js b/src/Umbraco.Community.Contentment/DataEditors/DataPicker/data-picker.js index 3c54642b..9fca19ba 100644 --- a/src/Umbraco.Community.Contentment/DataEditors/DataPicker/data-picker.js +++ b/src/Umbraco.Community.Contentment/DataEditors/DataPicker/data-picker.js @@ -1,4 +1,4 @@ -/* Copyright © 2023 Lee Kelleher. +/* Copyright © 2023 Lee Kelleher. * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ @@ -27,6 +27,7 @@ angular.module("umbraco").controller("Umbraco.Community.Contentment.DataEditors. defaultValue: [], displayMode: "cards", enableDevMode: 0, + hideSearch: 0, maxItems: 0, overlaySize: "medium", overlayView: "", @@ -113,6 +114,7 @@ angular.module("umbraco").controller("Umbraco.Community.Contentment.DataEditors. currentPageId: config.currentPageId, dataTypeKey: $scope.model.dataTypeKey, enableMultiple: config.maxItems !== 1, + hideSearch: Object.toBoolean(config.hideSearch), listType: config.displayMode, pageSize: config.pageSize, }, diff --git a/src/Umbraco.Community.Contentment/DataEditors/DataPicker/data-picker.overlay.html b/src/Umbraco.Community.Contentment/DataEditors/DataPicker/data-picker.overlay.html index 26373542..95e0eef6 100644 --- a/src/Umbraco.Community.Contentment/DataEditors/DataPicker/data-picker.overlay.html +++ b/src/Umbraco.Community.Contentment/DataEditors/DataPicker/data-picker.overlay.html @@ -1,4 +1,4 @@ - @@ -15,7 +15,7 @@ -
+