Skip to content

Commit

Permalink
Merge pull request #104 from leekelleher/dev/v1.4.2
Browse files Browse the repository at this point in the history
Preparing v1.4.2 release
  • Loading branch information
leekelleher authored Apr 28, 2021
2 parents 8e8343e + 9a8030a commit 4176ced
Show file tree
Hide file tree
Showing 28 changed files with 450 additions and 109 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.4.1
1.4.2
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ public static Composition UnlockContentment(this Composition composition)
// Data List - Data Sources
.Add<CountriesDataListSource>()
.Add<CurrenciesDataListSource>()
.Add<ExamineDataListSource>()
.Add<TimeZoneDataListSource>()
.Add<uCssClassNameDataListSource>()
.Add<UmbracoContentPropertiesDataListSource>()
.Add<UmbracoContentXPathDataListSource>()
.Add<UmbracoDictionaryDataListSource>()
.Add<UmbracoEntityDataListSource>()
.Add<UmbracoImageCropDataListSource>()
.Add<UmbracoMembersDataListSource>()
.Add<UmbracoMemberGroupDataListSource>()
.Add<UserDefinedDataListSource>()
;
Expand Down
5 changes: 5 additions & 0 deletions src/Umbraco.Community.Contentment/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ internal static partial class PropertyGroups
}
}

internal static partial class Icons
{
public const string ContentTemplate = "icon-blueprint";
}

internal static partial class Package
{
public const string Author = "Lee Kelleher";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ internal sealed class CodeEditorConfigurationEditor : ConfigurationEditor
internal const string Mode = "mode";
internal const string Theme = "theme";
internal const string UseWrapMode = "useWrapMode";
internal const string MinLines = "minLines";
internal const string MaxLines = "maxLines";

public CodeEditorConfigurationEditor()
: base()
Expand Down Expand Up @@ -131,11 +133,11 @@ public CodeEditorConfigurationEditor()
//Fields.Add("enableLiveAutocompletion", "enableLiveAutocompletion", "[A friendly description]", "boolean");// enableLiveAutocompletion: 0,
//Fields.Add("readonly", "readonly", "[A friendly description]", "boolean");// readonly: 0,

DefaultConfiguration.Add("minLines", 12);
Fields.Add("minLines", "Minimum lines", "Set the minimum number of lines that the editor will be. The default is 12 lines.", IOHelper.ResolveUrl(NumberInputDataEditor.DataEditorViewPath));
DefaultConfiguration.Add(MinLines, 12);
Fields.Add(MinLines, "Minimum lines", "Set the minimum number of lines that the editor will be. The default is 12 lines.", IOHelper.ResolveUrl(NumberInputDataEditor.DataEditorViewPath));

DefaultConfiguration.Add("maxLines", 30);
Fields.Add("maxLines", "Maximum lines", "Set the maximum number of lines that the editor can be. If left empty, the editor will not auto-scale.", IOHelper.ResolveUrl(NumberInputDataEditor.DataEditorViewPath));
DefaultConfiguration.Add(MaxLines, 30);
Fields.Add(MaxLines, "Maximum lines", "Set the maximum number of lines that the editor can be. If left empty, the editor will not auto-scale.", IOHelper.ResolveUrl(NumberInputDataEditor.DataEditorViewPath));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ angular.module("umbraco").controller("Umbraco.Community.Contentment.DataEditors.
config.allowEdit = {};
config.nameTemplates = {};
config.descriptionTemplates = {};
config.missingItem = {};

config.items.forEach(function (item) {
config.itemLookup[item.key] = item;
Expand All @@ -67,6 +68,12 @@ angular.module("umbraco").controller("Umbraco.Community.Contentment.DataEditors.
}
});

localizationService.localizeMany(["contentment_missingItemName", "contentment_missingItemDescription"]).then(function (data) {
config.missingItem["name"] = data[0];
config.missingItem["description"] = data[1];
config.missingItem["icon"] = "icon-alert";
});

vm.allowAdd = (config.maxItems === 0 || config.maxItems === "0") || $scope.model.value.length < config.maxItems;
vm.allowEdit = function (item, $index) { return config.allowEdit[item.key]; };
vm.allowRemove = Object.toBoolean(config.allowRemove);
Expand Down Expand Up @@ -178,7 +185,12 @@ angular.module("umbraco").controller("Umbraco.Community.Contentment.DataEditors.
function populate(item, $index, propertyName) {
var label = "";

if (propertyName === 'name' && config.nameTemplates.hasOwnProperty(item.key) === true) {
// check that the configuration editor exists, if not then return a default label.
if (config.itemLookup.hasOwnProperty(item.key) === false && config.missingItem) {
return config.missingItem[propertyName] || propertyName;
}

if (propertyName === "name" && config.nameTemplates.hasOwnProperty(item.key) === true) {
var expression = config.nameTemplates[item.key];
if (expression) {
item.value.$index = $index + 1;
Expand All @@ -187,7 +199,7 @@ angular.module("umbraco").controller("Umbraco.Community.Contentment.DataEditors.
}
}

if (propertyName === 'description' && config.descriptionTemplates.hasOwnProperty(item.key) === true) {
if (propertyName === "description" && config.descriptionTemplates.hasOwnProperty(item.key) === true) {
var expression = config.descriptionTemplates[item.key];
if (expression) {
item.value.$index = $index + 1;
Expand All @@ -212,6 +224,7 @@ angular.module("umbraco").controller("Umbraco.Community.Contentment.DataEditors.

$scope.model.value.splice($index, 1);

// TODO: [LK] Add the `maxItem` numeric code.
if ((config.maxItems === 0 || config.maxItems === "0") || $scope.model.value.length < config.maxItems) {
vm.allowAdd = true;
}
Expand All @@ -234,6 +247,7 @@ angular.module("umbraco").controller("Umbraco.Community.Contentment.DataEditors.
} else {
vm.allowAdd = true;
}
emit();
};

function setDirty() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
no-dirty-check />
</div>
<ul class="umb-actions umb-actions-child">
<li class="umb-action" ng-repeat="item in vm.items | orderBy:vm.orderBy | filter:vm.searchTerm">
<li class="umb-action" ng-repeat="item in vm.items | orderBy:vm.orderBy | filter:vm.searchTerm as results">
<button type="button" class="btn-reset umb-action-link" ng-click="vm.select(item)">
<i class="large icon" ng-class="item.icon"></i>
<span class="menu-label">
Expand All @@ -39,6 +39,9 @@
</span>
</button>
</li>
<li class="alert alert-danger" ng-if="results.length == 0">
<span>No items found for '<em ng-bind="vm.searchTerm"></em>'.</span>
</li>
</ul>
</umb-box-content>
</umb-box>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
<umb-box-content>

<ul class="umb-actions umb-actions-child" ng-show="vm.selectBlueprint === false">
<li class="umb-action" ng-repeat="item in vm.items | filter:vm.searchTerm">
<li class="umb-action" ng-repeat="item in vm.items | filter:vm.searchTerm as results">
<button type="button" class="btn-reset umb-action-link" ng-click="vm.select(item)">
<i class="large icon" ng-class="item.icon"></i>
<span class="menu-label">
Expand All @@ -50,6 +50,9 @@
</span>
</button>
</li>
<li class="alert alert-danger" ng-if="results.length == 0">
<span>No items found for '<em ng-bind="vm.searchTerm"></em>'.</span>
</li>
</ul>

<ul class="umb-actions umb-actions-child" ng-show="vm.selectBlueprint === true">
Expand Down Expand Up @@ -92,14 +95,17 @@
</umb-box-header>
<umb-box-content>
<ul class="umb-actions umb-actions-child">
<li class="umb-action" ng-repeat="item in vm.clipboardItems | orderBy:vm.orderBy | filter:vm.searchTerm">
<li class="umb-action" ng-repeat="item in vm.clipboardItems | orderBy:vm.orderBy | filter:vm.searchTerm as results">
<button class="btn-reset umb-action-link" ng-click="vm.paste(item)">
<i class="large icon" ng-class="item.icon"></i>
<span class="menu-label">
<span ng-bind="item.name"></span>
</span>
</button>
</li>
<li class="alert alert-danger" ng-if="results.length == 0">
<span>No items found for '<em ng-bind="vm.searchTerm"></em>'.</span>
</li>
</ul>
</umb-box-content>
</umb-box>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public EnumDataListSource(ILogger logger)
Key = "enumType",
Name = "Enumeration type",
Description = "Select the enumeration from an assembly type.",
View = IOHelper.ResolveUrl(CascadingDropdownListDataEditor.DataEditorViewPath),
View = CascadingDropdownListDataEditor.DataEditorViewPath,
Config = new Dictionary<string, object>
{
{ CascadingDropdownListDataEditor.APIs, new[]
Expand All @@ -65,15 +65,16 @@ public EnumDataListSource(ILogger logger)

public IEnumerable<DataListItem> GetItems(Dictionary<string, object> config)
{
var items = new List<DataListItem>();

var type = GetValueType(config);
if (type == null)
{
return items;
return Enumerable.Empty<DataListItem>();
}

var items = new List<DataListItem>();

var fields = type.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);

foreach (var field in fields)
{
var attr = field.GetCustomAttribute<DataListItemAttribute>(false);
Expand All @@ -83,6 +84,7 @@ public IEnumerable<DataListItem> GetItems(Dictionary<string, object> config)
}

var attr2 = field.GetCustomAttribute<DescriptionAttribute>(false);

items.Add(new DataListItem
{
Description = attr?.Description ?? attr2?.Description,
Expand All @@ -93,7 +95,7 @@ public IEnumerable<DataListItem> GetItems(Dictionary<string, object> config)
});
}

if (config.TryGetValueAs("sortAlphabetically", out string boolean) == true && boolean == "1")
if (config.TryGetValueAs("sortAlphabetically", out bool boolean) == true && boolean == true)
{
return items.OrderBy(x => x.Name, StringComparer.InvariantCultureIgnoreCase);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
/* Copyright © 2021 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 Examine;
using Examine.Search;
using Umbraco.Core;
using Umbraco.Core.IO;
using Umbraco.Core.PropertyEditors;
using UmbConstants = Umbraco.Core.Constants;

namespace Umbraco.Community.Contentment.DataEditors
{
[Core.Composing.HideFromTypeFinder]
public sealed class ExamineDataListSource : IDataListSource
{
private readonly IExamineManager _examineManager;

private const string _defaultNameField = "nodeName";
private const string _defaultValueField = "__Key";
private const string _defaultIconField = "__Icon";

public ExamineDataListSource(IExamineManager examineManager)
{
_examineManager = examineManager;
}

public string Name => "Examine Query";

public string Description => "Populate the data source from an Examine query.";

public string Icon => "icon-search";

public OverlaySize OverlaySize => OverlaySize.Small;

public IEnumerable<ConfigurationField> Fields => new[]
{
new ConfigurationField
{
Key = "examineIndex",
Name = "Examine Index",
Description = "Select the Examine index.",
View = DropdownListDataListEditor.DataEditorViewPath,
Config = new Dictionary<string, object>
{
{ DropdownListDataListEditor.AllowEmpty, Constants.Values.False },
{ Constants.Conventions.ConfigurationFieldAliases.Items, _examineManager.Indexes.OrderBy(x => x.Name).Select(x => new DataListItem { Name = x.Name.SplitPascalCasing(), Value = x.Name }) },
}
},
new NotesConfigurationField(@"<details class=""well well-small"">
<summary><strong>Do you need help with Lucene query?</strong></summary>
<div class=""mt3"">
<p>If you need assistance with Lucene query syntax, please refer to this resource on <a href=""https://our.umbraco.com/documentation/reference/searching/examine/overview-explanation#power-searching-with-raw-lucene-queries"" target=""_blank""><strong>our.umbraco.com</strong></a>.</p>
</div>
</details>", true),
new ConfigurationField
{
Key = "luceneQuery",
Name = "Lucene query",
Description = "Enter your raw Lucene expression to query Examine with.",
View = CodeEditorDataEditor.DataEditorViewPath,
Config = new Dictionary<string, object>
{
{ CodeEditorConfigurationEditor.Mode, "text" },
{ CodeEditorConfigurationEditor.MinLines, 1 },
{ CodeEditorConfigurationEditor.MaxLines, 5 },
}
},
new ConfigurationField
{
Key = "nameField",
Name = "Name Field",
Description = "Enter the field name to select the name from the Examine record.",
View = "textstring",
},
new ConfigurationField
{
Key = "valueField",
Name = "Value Field",
Description = "Enter the field name to select the value (key) from the Examine record.",
View = "textstring",
},
new ConfigurationField
{
Key = "iconField",
Name = "Icon Field",
Description = "<em>(optional)</em> Enter the field name to select the icon from the Examine record.",
View = "textstring",
},
new ConfigurationField
{
Key = "descriptionField",
Name = "Description Field",
Description = "<em>(optional)</em> Enter the field name to select the description from the Examine record.",
View = "textstring",
},
};

public Dictionary<string, object> DefaultValues => new Dictionary<string, object>
{
{ "examineIndex", UmbConstants.UmbracoIndexes.ExternalIndexName },
{ "luceneQuery", "+__IndexType:content" },
{ "nameField", _defaultNameField },
{ "valueField", _defaultValueField },
{ "iconField", _defaultIconField },
{ "descriptionField", string.Empty },
};

public IEnumerable<DataListItem> GetItems(Dictionary<string, object> config)
{
var examineIndex = config.GetValueAs("examineIndex", UmbConstants.UmbracoIndexes.ExternalIndexName);
if (_examineManager.TryGetIndex(examineIndex, out var index) == true)
{
var luceneQuery = config.GetValueAs("luceneQuery", string.Empty);
if (string.IsNullOrWhiteSpace(luceneQuery) == false)
{
var nameField = config.GetValueAs("nameField", _defaultNameField);
var valueField = config.GetValueAs("valueField", _defaultValueField);
var iconField = config.GetValueAs("iconField", _defaultIconField);
var descriptionField = config.GetValueAs("descriptionField", string.Empty);

var results = index
.GetSearcher()
.CreateQuery()
.NativeQuery(luceneQuery)
// NOTE: For any `OrderBy` complaints, refer to: https://github.com/Shazwazza/Examine/issues/126
.OrderBy(new SortableField(nameField, SortType.String))
.Execute();

if (results?.TotalItemCount > 0)
{
return results.Select(x => new DataListItem
{
Name = x.Values.ContainsKey(nameField) == true ? x.Values[nameField] : x.Values[_defaultNameField],
Value = x.Values.ContainsKey(valueField) == true ? x.Values[valueField] : x.Values[_defaultValueField],
Icon = x.Values.ContainsKey(iconField) == true ? x.Values[iconField] : x.Values[_defaultIconField],
Description = x.Values.ContainsKey(descriptionField) == true ? x.Values[descriptionField] : null,
});
}
}
}

return Enumerable.Empty<DataListItem>();
}
}
}
Loading

0 comments on commit 4176ced

Please sign in to comment.