Skip to content

Commit 9cd5f10

Browse files
authored
Merge pull request #463 from leekelleher/dev/v5.x
Preparing v5.1.1 release
2 parents f70b4bc + deccbc4 commit 9cd5f10

File tree

12 files changed

+56
-32
lines changed

12 files changed

+56
-32
lines changed

.github/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ I reserve the right to address bug reports or feature requests **in my own time*
105105
**Any feedback is welcome and appreciated.** Please keep in mind, I am not your personal support developer.
106106

107107
If you are really stuck, do remember that the Umbraco community is amongst the friendliest on our planet, learn to embrace it.
108-
Ask for help on the [Our Umbraco support forum](https://our.umbraco.com/), or the [Community Discord Server](https://community.umbraco.com/get-involved/community-discord-server/), I am sure someone can help you there.
108+
Ask for help on the [Umbraco support forum](https://forum.umbraco.com/), I am sure someone can help you there.
109109

110110

111111
### Contributions, collaborations, rules of engagement

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
5.1.0
1+
5.1.1

src/Umbraco.Community.Contentment/DataEditors/Buttons/buttons.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ angular.module("umbraco").controller("Umbraco.Community.Contentment.DataEditors.
112112
vm.items.forEach(x => {
113113

114114
if (vm.multiple === false) {
115-
x.selected = x.value === item.value;
115+
x.selected = item.selected && x.value === item.value;
116116
}
117117

118118
if (x.selected) {

src/Umbraco.Community.Contentment/DataEditors/ContentBlocks/content-blocks.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ angular.module("umbraco").controller("Umbraco.Community.Contentment.DataEditors.
224224
config.elementTypeScaffoldCache[elementType.alias] = scaffold;
225225
}
226226

227+
scaffold.key = item.key;
227228
scaffold.name = name;
228229
scaffold.variants[0].name = name;
229230

src/Umbraco.Community.Contentment/DataEditors/ContentBlocks/content-blocks.overlay.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,7 @@ angular.module("umbraco").controller("Umbraco.Community.Contentment.Overlays.Con
4646
vm.items = config.elementTypes;
4747
vm.selectedElementType = null;
4848

49-
// NOTE: Corrected `retriveDataOfType` typo, but kept backwards-compatibility for v8.17.x.
50-
// ref: https://github.com/umbraco/Umbraco-CMS/pull/11027
51-
vm.clipboardItems = typeof clipboardService.retrieveDataOfType === "function"
52-
? clipboardService.retrieveDataOfType("elementType", config.elementTypes.map(item => item.alias))
53-
: clipboardService.retriveDataOfType("elementType", config.elementTypes.map(item => item.alias));
49+
vm.clipboardItems = clipboardService.retrieveDataOfType("elementType", config.elementTypes.map(item => item.alias));
5450

5551
if (config.elementTypes.length > 1 || vm.clipboardItems.length > 0) {
5652

src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/ExamineDataListSource.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
using Examine;
77
using Examine.Search;
8+
using Umbraco.Cms.Core;
89
using Umbraco.Cms.Core.IO;
910
using Umbraco.Cms.Core.Models;
1011
using Umbraco.Cms.Core.PropertyEditors;
@@ -197,6 +198,15 @@ private PagedResult<DataListItem> GetExamineResults(
197198
luceneQuery = string.Format(luceneQuery, udi.Result);
198199
}
199200
}
201+
else if (_contentmentContentContext is IContentmentContentContext2 ctx2)
202+
{
203+
var contentKey = ctx2.GetCurrentContentId<Guid?>(out _);
204+
if (contentKey.HasValue == true)
205+
{
206+
var udi = new GuidUdi(UmbConstants.UdiEntityType.Document, contentKey.Value);
207+
luceneQuery = string.Format(luceneQuery, udi);
208+
}
209+
}
200210
}
201211

202212
var nameField = config.GetValueAs("nameField", _defaultNameField);

src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoMembersDataListSource.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,9 @@ public Task<PagedResult<DataListItem>> SearchAsync(Dictionary<string, object> co
124124

125125
if (items?.Any() == true)
126126
{
127-
var offset = pageIndex * pageSize;
128127
var results = new PagedResult<DataListItem>(totalRecords, pageNumber, pageSize)
129128
{
130-
Items = items
131-
.Skip(offset)
132-
.Take(pageSize)
133-
.Select(ToDataListItem)
129+
Items = items.Select(ToDataListItem)
134130
};
135131

136132
return Task.FromResult(results);

src/Umbraco.Community.Contentment/DataEditors/TemplatedList/templated-list.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ angular.module("umbraco").controller("Umbraco.Community.Contentment.DataEditors.
102102
vm.items.forEach(x => {
103103

104104
if (vm.multiple === false) {
105-
x.selected = x.value === item.value;
105+
x.selected = item.selected && x.value === item.value;
106106
}
107107

108108
if (x.selected) {

src/Umbraco.Community.Contentment/Services/ContentmentContentContext.cs

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55

66
using Microsoft.AspNetCore.Http;
77
using Newtonsoft.Json;
8+
using Umbraco.Cms.Core;
89
using Umbraco.Cms.Core.Models.PublishedContent;
910
using Umbraco.Cms.Core.Web;
1011
using Umbraco.Extensions;
1112

1213
namespace Umbraco.Community.Contentment.Services
1314
{
14-
public sealed class ContentmentContentContext : IContentmentContentContext
15+
public sealed class ContentmentContentContext : IContentmentContentContext2
1516
{
1617
private readonly IHttpContextAccessor _httpContextAccessor;
1718
private readonly IRequestAccessor _requestAccessor;
@@ -27,40 +28,43 @@ public ContentmentContentContext(
2728
_umbracoContextAccessor = umbracoContextAccessor;
2829
}
2930

30-
public int? GetCurrentContentId(out bool isParent)
31+
public T? GetCurrentContentId<T>(out bool isParent)
3132
{
3233
isParent = false;
3334

34-
if (_umbracoContextAccessor.TryGetUmbracoContext(out var umbracoContext) == true)
35+
if (_umbracoContextAccessor.TryGetUmbracoContext(out var umbracoContext) == true &&
36+
umbracoContext.PublishedRequest?.PublishedContent is not null)
3537
{
36-
if (umbracoContext.PublishedRequest?.PublishedContent != null)
38+
var attempt = umbracoContext.PublishedRequest.PublishedContent.Id.TryConvertTo<T>();
39+
if (attempt.Success)
3740
{
38-
isParent = false;
39-
return umbracoContext.PublishedRequest.PublishedContent.Id;
41+
return attempt.Result;
4042
}
4143
}
4244

4345
// NOTE: First we check for "id" (if on a content page), then "parentId" (if editing an element).
44-
if (int.TryParse(_requestAccessor.GetRequestValue("id"), out var currentId) == true)
46+
var attempt1 = _requestAccessor.GetRequestValue("id")?.TryConvertTo<T>() ?? Attempt.Fail<T>();
47+
if (attempt1.Success)
4548
{
46-
return currentId;
49+
return attempt1.Result;
4750
}
48-
else if (int.TryParse(_requestAccessor.GetRequestValue("parentId"), out var parentId) == true)
51+
52+
var attempt2 = _requestAccessor.GetRequestValue("parentId")?.TryConvertTo<T>() ?? Attempt.Fail<T>();
53+
if (attempt2.Success)
4954
{
5055
isParent = true;
51-
52-
return parentId;
56+
return attempt2.Result;
5357
}
5458

5559
var json = _httpContextAccessor.HttpContext?.Request.GetRawBodyStringAsync().GetAwaiter().GetResult();
5660
if (string.IsNullOrWhiteSpace(json) == false)
5761
{
58-
var obj = JsonConvert.DeserializeAnonymousType(json, new { id = 0, parentId = 0 });
59-
if (obj?.id > 0)
62+
var obj = JsonConvert.DeserializeAnonymousType(json, new { id = default(T), parentId = default(T) });
63+
if (obj is not null && obj.id is not null)
6064
{
6165
return obj.id;
6266
}
63-
else if (obj?.parentId > 0)
67+
else if (obj is not null && obj.parentId is not null)
6468
{
6569
isParent = true;
6670
return obj.parentId;
@@ -70,6 +74,8 @@ public ContentmentContentContext(
7074
return default;
7175
}
7276

77+
public int? GetCurrentContentId(out bool isParent) => GetCurrentContentId<int>(out isParent);
78+
7379
public IPublishedContent? GetCurrentContent(out bool isParent)
7480
{
7581
isParent = false;
@@ -81,12 +87,21 @@ public ContentmentContentContext(
8187
return umbracoContext.PublishedRequest.PublishedContent;
8288
}
8389

84-
var currentContentId = GetCurrentContentId(out isParent);
90+
// NOTE: First we check for an integer ID.
91+
var currentContentId = GetCurrentContentId<int?>(out isParent);
8592

8693
if (currentContentId.HasValue == true)
8794
{
8895
return umbracoContext.Content?.GetById(true, currentContentId.Value);
8996
}
97+
98+
// NOTE: Next we check for a GUID ID.
99+
var currentContentKey = GetCurrentContentId<Guid?>(out isParent);
100+
101+
if (currentContentKey.HasValue == true)
102+
{
103+
return umbracoContext.Content?.GetById(true, currentContentKey.Value);
104+
}
90105
}
91106

92107
return default;

src/Umbraco.Community.Contentment/Services/IContentmentContentContext.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright © 2022 Lee Kelleher.
1+
/* Copyright © 2022 Lee Kelleher.
22
* This Source Code Form is subject to the terms of the Mozilla Public
33
* License, v. 2.0. If a copy of the MPL was not distributed with this
44
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
@@ -13,4 +13,10 @@ public interface IContentmentContentContext
1313

1414
IPublishedContent? GetCurrentContent(out bool isParent);
1515
}
16+
17+
// NOTE: Added as a separate interface, so not to break binary backwards-compatibility. [LK]
18+
public interface IContentmentContentContext2 : IContentmentContentContext
19+
{
20+
T? GetCurrentContentId<T>(out bool isParent);
21+
}
1622
}

0 commit comments

Comments
 (0)