Skip to content

Commit 770f4dd

Browse files
authored
Merge pull request #476 from leekelleher/dev/v5.x
Preparing v5.2.0 release
2 parents 9cd5f10 + deb1a40 commit 770f4dd

File tree

13 files changed

+79
-57
lines changed

13 files changed

+79
-57
lines changed

VERSION

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

src/Umbraco.Community.Contentment/DataEditors/DataPicker/DataPickerApiController.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,21 @@ array1[0] is JObject item1 &&
6666
return NotFound($"Unable to locate data source for data type: '{dataTypeKey}'");
6767
}
6868

69+
[Obsolete("Please call the `Search` endpoint using a POST method.")]
6970
[HttpGet]
70-
#pragma warning disable IDE0060 // Remove unused parameter
7171
public async Task<IActionResult> Search(string id, Guid dataTypeKey, int pageNumber = 1, int pageSize = 12, string query = "")
72+
=> await Search(id, dataTypeKey, pageNumber, pageSize, query, []);
73+
74+
[HttpPost]
75+
#pragma warning disable IDE0060 // Remove unused parameter
76+
public async Task<IActionResult> Search(string id, Guid dataTypeKey, int pageNumber = 1, int pageSize = 12, string query = "", [FromBody] string[]? values = null)
7277
#pragma warning restore IDE0060 // Remove unused parameter
7378
{
7479
if (_lookup.TryGetValue(dataTypeKey, out var cached) == true)
7580
{
76-
var results = await cached.Item1.SearchAsync(cached.Item2, pageNumber, pageSize, HttpUtility.UrlDecode(query));
81+
var results = cached.Item1 is IDataPickerSource2 source2
82+
? await source2.SearchAsync(cached.Item2, pageNumber, pageSize, HttpUtility.UrlDecode(query), values ?? [])
83+
: await cached.Item1.SearchAsync(cached.Item2, pageNumber, pageSize, HttpUtility.UrlDecode(query));
7784

7885
return Ok(results);
7986
}
@@ -92,7 +99,9 @@ tmp1 is JArray array1 &&
9299

93100
_ = _lookup.TryAdd(dataTypeKey, (source1, config1));
94101

95-
var results = await source1.SearchAsync(config1, pageNumber, pageSize, HttpUtility.UrlDecode(query));
102+
var results = source1 is IDataPickerSource2 source2
103+
? await source2.SearchAsync(config1, pageNumber, pageSize, HttpUtility.UrlDecode(query), values ?? [])
104+
: await source1.SearchAsync(config1, pageNumber, pageSize, HttpUtility.UrlDecode(query));
96105

97106
return Ok(results);
98107
}

src/Umbraco.Community.Contentment/DataEditors/DataPicker/IDataPickerSource.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright © 2023 Lee Kelleher.
1+
/* Copyright © 2023 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/. */
@@ -11,6 +11,18 @@ public interface IDataPickerSource : IContentmentEditorItem
1111
{
1212
Task<IEnumerable<DataListItem>> GetItemsAsync(Dictionary<string, object> config, IEnumerable<string> values);
1313

14+
[Obsolete("Use `SearchAsync` with the additional `values` parameter instead. This method will be removed in Contentment 7.0.")]
1415
Task<PagedResult<DataListItem>> SearchAsync(Dictionary<string, object> config, int pageNumber = 1, int pageSize = 12, string query = "");
1516
}
17+
18+
// NOTE: Added as a separate interface, so not to break binary backwards-compatibility. [LK]
19+
public interface IDataPickerSource2 : IDataPickerSource
20+
{
21+
Task<PagedResult<DataListItem>> SearchAsync(
22+
Dictionary<string, object> config,
23+
int pageNumber = 1,
24+
int pageSize = 12,
25+
string query = "",
26+
IEnumerable<string>? values = null);
27+
}
1628
}

src/Umbraco.Community.Contentment/DataEditors/DataPicker/data-picker.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@
66
angular.module("umbraco").controller("Umbraco.Community.Contentment.DataEditors.DataPicker.Controller", [
77
"$scope",
88
"$http",
9+
"$routeParams",
910
"editorService",
1011
"editorState",
1112
"localizationService",
1213
"overlayService",
1314
"umbRequestHelper",
1415
"Umbraco.Community.Contentment.Services.DevMode",
15-
function ($scope, $http, editorService, editorState, localizationService, overlayService, umbRequestHelper, devModeService) {
16+
function ($scope, $http, $routeParams, editorService, editorState, localizationService, overlayService, umbRequestHelper, devModeService) {
1617

1718
if ($scope.model.hasOwnProperty("contentTypeId")) {
1819
// NOTE: This will prevents the editor attempting to load whilst in the Content Type Editor's property preview panel.
@@ -127,7 +128,9 @@ angular.module("umbraco").controller("Umbraco.Community.Contentment.DataEditors.
127128
enableMultiple: config.maxItems !== 1,
128129
hideSearch: Object.toBoolean(config.hideSearch),
129130
listType: config.displayMode,
131+
maxItems: config.maxItems === 0 ? config.maxItems : config.maxItems - $scope.model.value.length,
130132
pageSize: config.pageSize,
133+
selectedItems: $scope.model.value,
131134
},
132135
submit: function (selection) {
133136

@@ -167,7 +170,11 @@ angular.module("umbraco").controller("Umbraco.Community.Contentment.DataEditors.
167170
vm.loading = true;
168171
umbRequestHelper.resourcePromise(
169172
$http.post("backoffice/Contentment/DataPickerApi/GetItems?id=" + config.currentPageId, $scope.model.value, {
170-
params: { dataTypeKey: $scope.model.dataTypeKey }
173+
params: {
174+
dataTypeKey: $scope.model.dataTypeKey,
175+
culture: $routeParams.cculture ?? $routeParams.mculture,
176+
segment: $routeParams.csegment
177+
}
171178
}),
172179
"Failed to retrieve item data.")
173180
.then(function (data) {

src/Umbraco.Community.Contentment/DataEditors/DataPicker/data-picker.overlay.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@
3030

3131
<umb-load-indicator ng-show="vm.loading === true"></umb-load-indicator>
3232

33+
<div ng-if="vm.enableMultiple === true && vm.selectionCount > 0 && vm.maxItems > 0 && vm.selectionCount > vm.maxItems" class="alert alert-danger">
34+
<span>Too many items selected, please unselect <strong>{{vm.selectionCount - vm.maxItems}}</strong> {{vm.selectionCount - vm.maxItems === 1 ? 'item' : 'items'}}.</span>
35+
</div>
36+
3337
<div class="umb-block-card-grid" ng-if="vm.listType === 'cards'" ng-show="vm.loading === false && vm.items.length !== 0">
3438
<div class="umb-block-card"
3539
ng-repeat="item in vm.items"

src/Umbraco.Community.Contentment/DataEditors/DataPicker/data-picker.overlay.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
angular.module("umbraco").controller("Umbraco.Community.Contentment.Overlays.DataPicker.Controller", [
77
"$scope",
88
"$http",
9+
"$routeParams",
910
"umbRequestHelper",
10-
function ($scope, $http, umbRequestHelper) {
11+
function ($scope, $http, $routeParams, umbRequestHelper) {
1112

1213
//console.log("data-picker.overlay", $scope.model);
1314

@@ -18,7 +19,9 @@ angular.module("umbraco").controller("Umbraco.Community.Contentment.Overlays.Dat
1819
enableMultiple: false,
1920
hideSearch: false,
2021
listType: "cards",
22+
maxItems: 0,
2123
pageSize: 12,
24+
selectedItems: [],
2225
};
2326
var config = Object.assign({}, defaultConfig, $scope.model.config);
2427

@@ -31,12 +34,15 @@ angular.module("umbraco").controller("Umbraco.Community.Contentment.Overlays.Dat
3134
vm.enableMultiple = config.enableMultiple;
3235
vm.hideSearch = config.hideSearch;
3336
vm.listType = config.listType;
37+
vm.maxItems = config.maxItems;
3438

3539
vm.loading = true;
40+
3641
vm.items = [];
3742

3843
vm.allowSubmit = false;
3944
vm.selection = {};
45+
vm.selectionCount = 0;
4046

4147
vm.searchOptions = {
4248
dataTypeKey: config.dataTypeKey,
@@ -64,13 +70,15 @@ angular.module("umbraco").controller("Umbraco.Community.Contentment.Overlays.Dat
6470
vm.loading = true;
6571

6672
umbRequestHelper.resourcePromise(
67-
$http.get("backoffice/Contentment/DataPickerApi/Search", {
73+
$http.post("backoffice/Contentment/DataPickerApi/Search", config.selectedItems, {
6874
params: {
6975
id: config.currentPageId,
7076
dataTypeKey: vm.searchOptions.dataTypeKey,
7177
pageNumber: vm.searchOptions.pageNumber,
7278
pageSize: vm.searchOptions.pageSize,
73-
query: encodeURIComponent(vm.searchOptions.query)
79+
query: encodeURIComponent(vm.searchOptions.query),
80+
culture: $routeParams.cculture ?? $routeParams.mculture,
81+
segment: $routeParams.csegment
7482
}
7583
}),
7684
"Failed to retrieve search data.")
@@ -117,11 +125,13 @@ angular.module("umbraco").controller("Umbraco.Community.Contentment.Overlays.Dat
117125

118126
if (vm.selection.hasOwnProperty(item.value) === false) {
119127
vm.selection[item.value] = item;
128+
vm.selectionCount++;
120129
} else {
121130
delete vm.selection[item.value];
131+
vm.selectionCount--;
122132
}
123133

124-
vm.allowSubmit = true;
134+
vm.allowSubmit = vm.selectionCount > 0 && (config.maxItems === 0 || vm.selectionCount <= config.maxItems);
125135

126136
} else {
127137

src/Umbraco.Community.Contentment/DataEditors/IconPicker/icon-picker.css

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,12 @@
1-
/* Copyright © 2019 Lee Kelleher.
1+
/* Copyright © 2019 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/. */
55

6-
.contentment .lk-icon-picker-small {
7-
border: 1px dashed #d8d7d9;
8-
color: #d8d7d9;
9-
display: inline-block;
10-
height: 20px;
11-
padding: 5px 0;
12-
text-align: center;
13-
width: 30px;
6+
.contentment .umb-panel-header-icon .label-add {
7+
font-size: 10px;
148
}
159

16-
.contentment .lk-icon-picker-small:focus,
17-
.contentment .lk-icon-picker-small:hover {
18-
border-color: #2152a3;
19-
color: #2152a3;
20-
text-decoration: none;
21-
}
22-
23-
.contentment .lk-icon-picker-small i.color-black {
24-
color: #000;
25-
}
26-
2710
.contentment .umb-mediapicker .umb-sortable-thumbnails__wrapper > .icon {
2811
font-size: 50px;
2912
}

src/Umbraco.Community.Contentment/DataEditors/IconPicker/icon-picker.html

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- Copyright © 2013-present Umbraco.
1+
<!-- Copyright © 2013-present Umbraco.
22
- This Source Code has been derived from Umbraco CMS.
33
- https://github.com/umbraco/Umbraco-CMS/blob/release-8.1.0/src/Umbraco.Web.UI.Client/src/views/propertyeditors/mediapicker/mediapicker.html
44
- https://github.com/umbraco/Umbraco-CMS/blob/release-8.17.0/src/Umbraco.Web.UI.Client/src/views/propertyeditors/listview/icon.prevalues.html
@@ -33,10 +33,13 @@
3333
</ul>
3434
</div>
3535
</div>
36-
<button ng-if="vm.size === 'small'" type="button" class="btn-reset umb-panel-header-icon" ng-click="vm.pick()" ng-class="{'-placeholder': !model.value }" title="{{model.value}}">
37-
<umb-icon icon="{{model.value}}" class="icon" ng-if="model.value"></umb-icon>
38-
<span class="umb-panel-header-icon-text" ng-if="!model.value">
39-
<localize key="settings_addIcon">Add icon</localize>
40-
</span>
41-
</button>
36+
<div ng-if="vm.size === 'small'" class="flex">
37+
<button type="button" class="btn-reset umb-panel-header-icon" ng-click="vm.pick()" ng-class="{'-placeholder': !model.value }" title="{{model.value}}">
38+
<umb-icon icon="{{model.value}}" class="icon" ng-if="model.value"></umb-icon>
39+
<span class="label-add" ng-if="!model.value">
40+
<localize key="settings_addIcon">Add icon</localize>
41+
</span>
42+
</button>
43+
<button ng-if="model.value" aria-label="Remove" type="button" class="btn-reset umb-button--xxs" ng-click="vm.remove()">Clear selection</button>
44+
</div>
4245
</div>

src/Umbraco.Community.Contentment/DataEditors/IconPicker/icon-picker.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright © 2019 Lee Kelleher.
1+
/* Copyright © 2019 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/. */

src/Umbraco.Community.Contentment/DataEditors/ItemPicker/item-picker.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- Copyright © 2019 Lee Kelleher.
1+
<!-- Copyright © 2019 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/. -->
@@ -15,6 +15,7 @@
1515
on-add="vm.add"
1616
on-edit="vm.edit"
1717
on-remove="vm.remove"
18-
on-sort="vm.sort">
18+
on-sort="vm.sort"
19+
property-actions="vm.propertyActions">
1920
</contentment-items-editor>
2021
</div>

0 commit comments

Comments
 (0)