Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PagerOptions #12207

Merged
merged 8 commits into from
Aug 17, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/OrchardCore.Cms.Web/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@
// "CdnBaseUrl": "",
// "AppendVersion": true
//},
//"OrchardCore_Pager": {
// "PageSize": 10,
// "MaxPageSize": 100,
// "MaxPagedCount": 100
//},

// WARNING: AutoSetup section given as an example for Development only, for Production use "Environment Variables" instead
//"OrchardCore_AutoSetup": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
using OrchardCore.DisplayManagement;
using OrchardCore.DisplayManagement.ModelBinding;
using OrchardCore.DisplayManagement.Notify;
using OrchardCore.Settings;

namespace OrchardCore.AdminDashboard.Controllers
{
Expand All @@ -32,7 +31,6 @@ public class DashboardController : Controller
private readonly IContentManager _contentManager;
private readonly IContentItemDisplayManager _contentItemDisplayManager;
private readonly IContentDefinitionManager _contentDefinitionManager;
private readonly ISiteService _siteService;
private readonly IUpdateModelAccessor _updateModelAccessor;
private readonly INotifier _notifier;
private readonly IStringLocalizer S;
Expand All @@ -47,7 +45,6 @@ public DashboardController(
IContentManager contentManager,
IContentItemDisplayManager contentItemDisplayManager,
IContentDefinitionManager contentDefinitionManager,
ISiteService siteService,
IUpdateModelAccessor updateModelAccessor,
IShapeFactory shapeFactory,
INotifier notifier,
Expand All @@ -61,7 +58,6 @@ public DashboardController(
_contentManager = contentManager;
_contentItemDisplayManager = contentItemDisplayManager;
_contentDefinitionManager = contentDefinitionManager;
_siteService = siteService;
_updateModelAccessor = updateModelAccessor;
New = shapeFactory;
_notifier = notifier;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,37 +1,15 @@
using System;
using System.Threading.Tasks;
using OrchardCore.AdminDashboard.Models;
using OrchardCore.AdminDashboard.ViewModels;
using OrchardCore.ContentManagement;
using OrchardCore.ContentManagement.Display.ContentDisplay;
using OrchardCore.ContentManagement.Display.Models;
using OrchardCore.ContentManagement.Metadata;
using OrchardCore.DisplayManagement.ModelBinding;
using OrchardCore.DisplayManagement.Views;
using OrchardCore.Settings;

namespace OrchardCore.AdminDashboard.Drivers
{
public class DashboardPartDisplayDriver : ContentPartDisplayDriver<DashboardPart>
{
private readonly IContentDefinitionManager _contentDefinitionManager;
private readonly IContentManager _contentManager;
private readonly IServiceProvider _serviceProvider;
private readonly ISiteService _siteService;

public DashboardPartDisplayDriver(
IContentManager contentManager,
IContentDefinitionManager contentDefinitionManager,
IServiceProvider serviceProvider,
ISiteService siteService
)
{
_contentDefinitionManager = contentDefinitionManager;
_contentManager = contentManager;
_serviceProvider = serviceProvider;
_siteService = siteService;
}

public override Task<IDisplayResult> DisplayAsync(DashboardPart part, BuildPartDisplayContext context)
{
return Task.FromResult<IDisplayResult>(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.Localization;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using OrchardCore.Admin;
using OrchardCore.AdminMenu.Services;
using OrchardCore.AdminMenu.ViewModels;
using OrchardCore.DisplayManagement;
using OrchardCore.DisplayManagement.Notify;
using OrchardCore.Navigation;
using OrchardCore.Routing;
using OrchardCore.Settings;

namespace OrchardCore.AdminMenu.Controllers
{
Expand All @@ -25,7 +25,7 @@ public class MenuController : Controller
{
private readonly IAuthorizationService _authorizationService;
private readonly IAdminMenuService _adminMenuService;
private readonly ISiteService _siteService;
private readonly PagerOptions _pagerOptions;
private readonly INotifier _notifier;
private readonly IStringLocalizer S;
private readonly IHtmlLocalizer H;
Expand All @@ -35,7 +35,7 @@ public class MenuController : Controller
public MenuController(
IAuthorizationService authorizationService,
IAdminMenuService adminMenuService,
ISiteService siteService,
IOptions<PagerOptions> pagerOptions,
IShapeFactory shapeFactory,
INotifier notifier,
IStringLocalizer<MenuController> stringLocalizer,
Expand All @@ -44,7 +44,7 @@ public MenuController(
{
_authorizationService = authorizationService;
_adminMenuService = adminMenuService;
_siteService = siteService;
_pagerOptions = pagerOptions.Value;
New = shapeFactory;
_notifier = notifier;
S = stringLocalizer;
Expand All @@ -59,8 +59,7 @@ public async Task<IActionResult> List(ContentOptions options, PagerParameters pa
return Forbid();
}

var siteSettings = await _siteService.GetSiteSettingsAsync();
var pager = new Pager(pagerParameters, siteSettings.PageSize);
var pager = new Pager(pagerParameters, _pagerOptions.PageSize);

var adminMenuList = (await _adminMenuService.GetAdminMenuListAsync()).AdminMenu;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.Localization;
using Microsoft.Extensions.Options;
using OrchardCore.AuditTrail.Models;
using OrchardCore.AuditTrail.Services;
using OrchardCore.AuditTrail.ViewModels;
using OrchardCore.DisplayManagement;
using OrchardCore.DisplayManagement.ModelBinding;
using OrchardCore.Navigation;
using OrchardCore.Routing;
using OrchardCore.Settings;
using YesSql.Filters.Query;

namespace OrchardCore.AuditTrail.Controllers
{
public class AdminController : Controller
{
private readonly ISiteService _siteService;
private readonly PagerOptions _pagerOptions;
private readonly IShapeFactory _shapeFactory;
private readonly IAuditTrailManager _auditTrailManager;
private readonly IUpdateModelAccessor _updateModelAccessor;
Expand All @@ -30,7 +30,7 @@ public class AdminController : Controller
private readonly IStringLocalizer S;

public AdminController(
ISiteService siteService,
IOptions<PagerOptions> pagerOptions,
IShapeFactory shapeFactory,
IAuditTrailManager auditTrailManager,
IUpdateModelAccessor updateModelAccessor,
Expand All @@ -40,7 +40,7 @@ public AdminController(
IDisplayManager<AuditTrailIndexOptions> auditTrailOptionsDisplayManager,
IStringLocalizer<AdminController> stringLocalizer)
{
_siteService = siteService;
_pagerOptions = pagerOptions.Value;
_shapeFactory = shapeFactory;
_auditTrailManager = auditTrailManager;
_updateModelAccessor = updateModelAccessor;
Expand Down Expand Up @@ -76,8 +76,7 @@ public async Task<ActionResult> Index([ModelBinder(BinderType = typeof(AuditTrai
options.FilterResult.TryAddOrReplace(new CorrelationIdFilterNode(options.CorrelationId));
}

var siteSettings = await _siteService.GetSiteSettingsAsync();
var pager = new Pager(pagerParameters, siteSettings.PageSize);
var pager = new Pager(pagerParameters, _pagerOptions.PageSize);

// With the options populated we filter the query, allowing the filters to alter the options.
var result = await _auditTrailAdminListQueryService.QueryAsync(pager.Page, pager.PageSize, options);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Localization;
using Microsoft.Extensions.Options;
using OrchardCore.Admin;
using OrchardCore.BackgroundTasks.Services;
using OrchardCore.BackgroundTasks.ViewModels;
using OrchardCore.DisplayManagement;
using OrchardCore.Environment.Shell;
using OrchardCore.Navigation;
using OrchardCore.Settings;

namespace OrchardCore.BackgroundTasks.Controllers
{
Expand All @@ -22,7 +22,7 @@ public class BackgroundTaskController : Controller
private readonly IAuthorizationService _authorizationService;
private readonly IEnumerable<IBackgroundTask> _backgroundTasks;
private readonly BackgroundTaskManager _backgroundTaskManager;
private readonly ISiteService _siteService;
private readonly PagerOptions _pagerOptions;
private readonly IStringLocalizer S;
private readonly dynamic New;

Expand All @@ -32,15 +32,16 @@ public BackgroundTaskController(
IEnumerable<IBackgroundTask> backgroundTasks,
BackgroundTaskManager backgroundTaskManager,
IShapeFactory shapeFactory,
ISiteService siteService,
IOptions<PagerOptions> pagerOptions,
IStringLocalizer<BackgroundTaskController> stringLocalizer)
{
_tenant = shellSettings.Name;
_authorizationService = authorizationService;
_backgroundTasks = backgroundTasks;
_backgroundTaskManager = backgroundTaskManager;
_pagerOptions = pagerOptions.Value;

New = shapeFactory;
_siteService = siteService;
S = stringLocalizer;
}

Expand All @@ -51,8 +52,7 @@ public async Task<IActionResult> Index(PagerParameters pagerParameters)
return Forbid();
}

var siteSettings = await _siteService.GetSiteSettingsAsync();
var pager = new Pager(pagerParameters, siteSettings.PageSize);
var pager = new Pager(pagerParameters, _pagerOptions.PageSize);
var document = await _backgroundTaskManager.GetDocumentAsync();

var taskEntries = _backgroundTasks.Select(t =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.Localization;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using OrchardCore.ContentManagement;
using OrchardCore.ContentManagement.Display;
using OrchardCore.ContentManagement.Metadata;
Expand All @@ -24,7 +25,6 @@
using OrchardCore.Navigation;
using OrchardCore.Routing;
using OrchardCore.Security.Permissions;
using OrchardCore.Settings;
using YesSql;
using YesSql.Filters.Query;
using YesSql.Services;
Expand All @@ -35,8 +35,8 @@ public class AdminController : Controller
{
private readonly IContentManager _contentManager;
private readonly IContentDefinitionManager _contentDefinitionManager;
private readonly ISiteService _siteService;
private readonly YesSql.ISession _session;
private readonly PagerOptions _pagerOptions;
private readonly ISession _session;
private readonly IContentItemDisplayManager _contentItemDisplayManager;
private readonly INotifier _notifier;
private readonly IAuthorizationService _authorizationService;
Expand All @@ -54,9 +54,9 @@ public AdminController(
IContentManager contentManager,
IContentItemDisplayManager contentItemDisplayManager,
IContentDefinitionManager contentDefinitionManager,
ISiteService siteService,
IOptions<PagerOptions> pagerOptions,
INotifier notifier,
YesSql.ISession session,
ISession session,
IShapeFactory shapeFactory,
IDisplayManager<ContentOptionsViewModel> contentOptionsDisplayManager,
IContentsAdminListQueryService contentsAdminListQueryService,
Expand All @@ -69,7 +69,7 @@ public AdminController(
_notifier = notifier;
_contentItemDisplayManager = contentItemDisplayManager;
_session = session;
_siteService = siteService;
_pagerOptions = pagerOptions.Value;
_contentManager = contentManager;
_contentDefinitionManager = contentDefinitionManager;
_updateModelAccessor = updateModelAccessor;
Expand Down Expand Up @@ -99,8 +99,7 @@ public async Task<IActionResult> List(
return Forbid();
}

var siteSettings = await _siteService.GetSiteSettingsAsync();
var pager = new Pager(pagerParameters, siteSettings.PageSize);
var pager = new Pager(pagerParameters, _pagerOptions.PageSize);

// This is used by the AdminMenus so needs to be passed into the options.
if (!String.IsNullOrEmpty(contentTypeId))
Expand Down Expand Up @@ -240,13 +239,13 @@ public async Task<IActionResult> List(
options.RouteValues.TryAdd("q", options.FilterResult.ToString());

var routeData = new RouteData(options.RouteValues);
var maxPagedCount = siteSettings.MaxPagedCount;
if (maxPagedCount > 0 && pager.PageSize > maxPagedCount)

if (_pagerOptions.MaxPagedCount > 0 && pager.PageSize > _pagerOptions.MaxPagedCount)
{
pager.PageSize = maxPagedCount;
pager.PageSize = _pagerOptions.MaxPagedCount;
}

var pagerShape = (await New.Pager(pager)).TotalItemCount(maxPagedCount > 0 ? maxPagedCount : await query.CountAsync()).RouteData(routeData);
var pagerShape = (await New.Pager(pager)).TotalItemCount(_pagerOptions.MaxPagedCount > 0 ? _pagerOptions.MaxPagedCount : await query.CountAsync()).RouteData(routeData);

// Load items so that loading handlers are invoked.
var pageOfContentItems = await query.Skip(pager.GetStartIndex()).Take(pager.PageSize).ListAsync(_contentManager);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.Localization;
using Microsoft.Extensions.Options;
using OrchardCore.Admin;
using OrchardCore.Deployment.Remote.Services;
using OrchardCore.Deployment.Remote.ViewModels;
using OrchardCore.DisplayManagement;
using OrchardCore.DisplayManagement.Notify;
using OrchardCore.Navigation;
using OrchardCore.Routing;
using OrchardCore.Settings;

namespace OrchardCore.Deployment.Remote.Controllers
{
Expand All @@ -26,7 +26,7 @@ public class RemoteClientController : Controller
{
private readonly IDataProtector _dataProtector;
private readonly IAuthorizationService _authorizationService;
private readonly ISiteService _siteService;
private readonly PagerOptions _pagerOptions;
private readonly RemoteClientService _remoteClientService;
private readonly INotifier _notifier;
private readonly dynamic New;
Expand All @@ -37,15 +37,15 @@ public RemoteClientController(
IDataProtectionProvider dataProtectionProvider,
RemoteClientService remoteClientService,
IAuthorizationService authorizationService,
ISiteService siteService,
IOptions<PagerOptions> pagerOptions,
IShapeFactory shapeFactory,
IStringLocalizer<RemoteClientController> stringLocalizer,
IHtmlLocalizer<RemoteClientController> htmlLocalizer,
INotifier notifier
)
{
_authorizationService = authorizationService;
_siteService = siteService;
_pagerOptions = pagerOptions.Value;
New = shapeFactory;
S = stringLocalizer;
H = htmlLocalizer;
Expand All @@ -61,8 +61,7 @@ public async Task<IActionResult> Index(ContentOptions options, PagerParameters p
return Forbid();
}

var siteSettings = await _siteService.GetSiteSettingsAsync();
var pager = new Pager(pagerParameters, siteSettings.PageSize);
var pager = new Pager(pagerParameters, _pagerOptions.PageSize);

var remoteClients = (await _remoteClientService.GetRemoteClientListAsync()).RemoteClients;

Expand Down
Loading