Skip to content

Commit 97c2083

Browse files
committed
Updates
1 parent d6c43a7 commit 97c2083

File tree

5 files changed

+59
-36
lines changed

5 files changed

+59
-36
lines changed

AutoBlockList/Controllers/AutoBlockListApiController.cs

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using Umbraco.Extensions;
33
using AutoBlockList.Dtos;
44
using AutoBlockList.Services;
5+
using Umbraco.Cms.Core.Cache;
56
using Umbraco.Cms.Core.Models;
67
using AutoBlockList.Constants;
78
using Microsoft.AspNetCore.Mvc;
@@ -23,22 +24,24 @@ namespace AutoBlockList.Controllers
2324
public class AutoBlockListApiController : UmbracoApiController
2425
{
2526
private const string _checkLogs = "Check logs for futher details";
26-
private readonly IContentService _contentService;
27+
private readonly IAppPolicyCache _runtimeCache;
28+
private readonly IContentService _contentService;
2729
private readonly IDataTypeService _dataTypeService;
2830
private readonly ILogger<AutoBlockListApiController> _logger;
2931
private readonly IContentTypeService _contentTypeService;
3032
private readonly ILocalizationService _localizationService;
3133
private readonly IAutoBlockListService _autoBlockListService;
3234

33-
public AutoBlockListApiController(
34-
IContentService contentService,
35+
public AutoBlockListApiController(AppCaches appCaches,
36+
IContentService contentService,
3537
IDataTypeService dataTypeService,
3638
ILogger<AutoBlockListApiController> logger,
3739
IContentTypeService contentTypeService,
3840
ILocalizationService localizationService,
3941
IAutoBlockListService autoBlockListService)
4042
{
4143
_logger = logger;
44+
_runtimeCache = appCaches.RuntimeCache;
4245
_contentService = contentService;
4346
_dataTypeService = dataTypeService;
4447
_contentTypeService = contentTypeService;
@@ -79,17 +82,24 @@ public IEnumerable<CustomContentTypeReferences> GetAllNCContentTypes()
7982
[HttpGet]
8083
public PagedResult<AutoBlockListContent> GetAllContentWithNC(int page)
8184
{
82-
83-
var contentTypeIds = GetAllNCContentTypes().Select(x => x.Id).ToArray();
84-
var items = _contentService.GetPagedOfTypes(contentTypeIds, page, 10, out long totalRecords, null, null);
8585

86-
var result = new PagedResult<AutoBlockListContent>(totalRecords, page, 10);
86+
var contentTypeIds = _runtimeCache.GetCacheItem("AutoBlockListContentTypes", () =>
87+
{
88+
return GetAllNCContentTypes();
89+
})?.Select(x => x.Id).ToArray();
90+
91+
var items = _contentService.GetPagedOfTypes(contentTypeIds, page, 50, out long totalRecords, null, null);
92+
93+
var result = new PagedResult<AutoBlockListContent>(totalRecords, page, 50);
8794
result.Items = items.Select(x => new AutoBlockListContent()
8895
{
8996
ContentType = x.ContentType,
9097
Name = x.Name,
98+
Id = x.Id
9199
});
92100

101+
items.FirstOrDefault().GetPropertiesByEditor(PropertyEditors.Aliases.NestedContent).FirstOrDefault();
102+
93103
return result;
94104
}
95105

@@ -98,9 +108,9 @@ public PagedResult<AutoBlockListContent> GetAllContentWithNC(int page)
98108

99109
public IEnumerable<CustomDisplayDataType> GetDataTypesInContentType(Guid key)
100110
{
101-
var contentType = _contentTypeService.Get(key);
111+
var contentType = _contentTypeService.Get(key);
102112
if (contentType == null)
103-
return null;
113+
return new List<CustomDisplayDataType>();
104114

105115
return _autoBlockListService.GetDataTypesInContentType(contentType);
106116
}

AutoBlockList/Dtos/AutoBlockListContent.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ namespace AutoBlockList.Dtos
55
{
66
public class AutoBlockListContent
77
{
8-
[DataMember]
8+
[DataMember]
9+
public int Id { get; set; }
10+
11+
[DataMember]
912
public string? Name { get; set; }
1013

1114
[DataMember]

AutoBlockList/Services/AutoBlockListService.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using Umbraco.Cms.Core;
33
using Umbraco.Extensions;
44
using AutoBlockList.Dtos;
5-
using AutoBlockList.Dtos;
65
using Umbraco.Cms.Core.Models;
76
using AutoBlockList.Constants;
87
using Umbraco.Cms.Core.Strings;
@@ -12,8 +11,6 @@
1211
using Umbraco.Cms.Core.PropertyEditors;
1312
using static Umbraco.Cms.Core.Constants;
1413
using DataType = Umbraco.Cms.Core.Models.DataType;
15-
using ObjectTypes = Umbraco.Cms.Core.Models.ObjectTypes;
16-
using Umbraco.Cms.Infrastructure.PublishedCache.DataSource;
1714
using static Umbraco.Cms.Core.PropertyEditors.BlockListConfiguration;
1815

1916
namespace AutoBlockList.Services
@@ -62,8 +59,8 @@ public AutoBlockListService(IDataTypeService dataTypeService,
6259
{
6360
ValidationLimit = new NumberRange()
6461
{
65-
Max = ncConfig.MaxItems,
66-
Min = ncConfig.MinItems
62+
Max = ncConfig?.MaxItems,
63+
Min = ncConfig?.MinItems
6764
},
6865
},
6966
};
@@ -94,7 +91,7 @@ public IEnumerable<CustomDisplayDataType> GetAllNCDataTypes()
9491
{
9592
Id = dataType.Id,
9693
Name = dataType.Name,
97-
Icon = dataType.Editor.Icon,
94+
Icon = dataType.Editor?.Icon,
9895
MatchingBLId = _dataTypeService.GetDataType(string.Format(GetNameFormatting(), dataType.Name))?.Id
9996
});
10097

@@ -225,7 +222,7 @@ public IEnumerable<CustomDisplayDataType> GetDataTypesInContentType(IContentType
225222
dataTypes.Add(new CustomDisplayDataType()
226223
{
227224
Id = dataType.Id,
228-
Icon = dataType.Editor.Icon,
225+
Icon = dataType.Editor?.Icon,
229226
Name = dataType.Name,
230227
});
231228
}

AutoBlockList/wwwroot/backoffice/autoBlockList/overview.controller.js

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
angular.module("umbraco").controller("autoBlockList.overview.controller", function (
2-
$q,
32
$http,
43
editorService,
5-
overlayService,
6-
notificationsService) {
4+
overlayService) {
75

86
var vm = this;
97
vm.loading = true;
@@ -27,40 +25,49 @@ angular.module("umbraco").controller("autoBlockList.overview.controller", functi
2725
}
2826
};
2927

28+
vm.toggleSelectAll = function () {
29+
vm.pagedContent.items.forEach(function (e) {
30+
if (vm.selectedContent.indexOf(e.id) === -1) {
31+
vm.selectedContent.push(e.id);
32+
}
33+
});
34+
};
35+
3036
vm.clearSelection = function () {
3137
vm.selectedContent = [];
3238
};
3339

3440
$http.get("/umbraco/backoffice/api/AutoBlockListApi/GetAllContentWithNC?page=0").then(function (response) {
3541
vm.loading = false;
36-
3742
vm.pagedContent = response.data;
38-
43+
vm.pagedContent.pageNumber += 1;
44+
console.log(response)
3945
});
4046

4147
vm.paginator = function (page) {
48+
vm.loadingTable = true;
4249
$http.get("/umbraco/backoffice/api/AutoBlockListApi/GetAllContentWithNC?page=" + page).then(function (response) {
4350
vm.pagedContent = response.data;
44-
51+
vm.loadingTable = false;
4552
});
46-
}
53+
};
4754

4855
vm.nextPage = function () {
4956
vm.paginator(vm.pagedContent.pageNumber += 1);
50-
}
57+
};
5158

5259
vm.prevPage = function () {
53-
vm.paginator(vm.pagedContent.pageNumber);
54-
}
60+
vm.paginator(vm.pagedContent.pageNumber -= 1);
61+
};
5562

5663
vm.goToPage = function (pageNumber) {
5764
vm.paginator(pageNumber);
58-
}
65+
};
5966

6067
vm.convertContent = function (content) {
6168

6269
var confirmOptions = {
63-
title: "Confirm '" + content.name + "' convert",
70+
title: "Confirm '" + vm.selectedContent.length + "' convert",
6471
view: "/App_Plugins/AutoBlockList/components/overlays/confirm.html",
6572
submit: function () {
6673
var options = {

AutoBlockList/wwwroot/backoffice/autoBlockList/overview.html

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,17 @@
1717
<umb-box-header title="Content" description="Converts all nested content data types to block lists and adds them to the contents document type. It also converts the content to make it work with block list."></umb-box-header>
1818

1919
<umb-box-content>
20-
<div>
21-
<div class="umb-table">
20+
<div class="relative">
21+
<umb-load-indicator ng-if="vm.loadingTable"></umb-load-indicator>
22+
23+
<div class="umb-table" ng-if="!vm.loadingTable">
2224
<div class="umb-table-head">
2325
<div class="umb-table-row">
24-
<div class="umb-table-cell"></div>
26+
<div class="umb-table-cell">
27+
<button type="button" class="umb-table__action" ng-click="vm.toggleSelectAll()">
28+
<i class="icon-check umb-checkmark umb-checkmark--xs umb-outline" checked="checked" size="xs"></i>
29+
</button>
30+
</div>
2531
<div class="umb-table-cell umb-table__name not-fixed"><localize key="general_name">Name</localize></div>
2632
<div class="umb-table-cell umb-table-cell--nano"><localize key="general_open" style="visibility:hidden;">Open</localize></div>
2733
<div class="umb-table-cell"><localize key="general_open" style="visibility:hidden;">Open</localize></div>
@@ -57,7 +63,7 @@
5763
label="Clear selection">
5864
</umb-button>
5965

60-
{{vm.selectedContent.length}} of {{vm.content.length}} selected
66+
{{vm.selectedContent.length}} of {{vm.pagedContent.totalItems}} selected
6167
</div>
6268

6369
<div>
@@ -70,14 +76,14 @@
7076
</umb-button>
7177
</div>
7278
</div>
73-
79+
</div>
7480
<umb-pagination page-number="vm.pagedContent.pageNumber"
75-
total-pages="vm.pagedContent.totalPages"
81+
total-pages="vm.pagedContent.totalPages - 1"
7682
on-next="vm.nextPage"
7783
on-prev="vm.prevPage"
7884
on-go-to-page="vm.goToPage">
7985
</umb-pagination>
80-
</div>
86+
8187
</umb-box-content>
8288
</umb-box>
8389
</div>

0 commit comments

Comments
 (0)