mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-26 03:40:56 +08:00
Removing Containers ItemController, moving logic to driver, fixes #2724
This commit is contained in:
@@ -1,66 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Web.Mvc;
|
|
||||||
using System.Web.Routing;
|
|
||||||
using Orchard.ContentManagement;
|
|
||||||
using Orchard.Core.Common.Models;
|
|
||||||
using Orchard.Core.Containers.Extensions;
|
|
||||||
using Orchard.Core.Containers.Models;
|
|
||||||
using Orchard.Core.Contents;
|
|
||||||
using Orchard.Core.Feeds;
|
|
||||||
using Orchard.DisplayManagement;
|
|
||||||
using Orchard.Mvc;
|
|
||||||
using Orchard.Themes;
|
|
||||||
using Orchard.UI.Navigation;
|
|
||||||
using Orchard.Settings;
|
|
||||||
using Orchard.Localization;
|
|
||||||
|
|
||||||
namespace Orchard.Core.Containers.Controllers {
|
|
||||||
|
|
||||||
public class ItemController : Controller {
|
|
||||||
private readonly IContentManager _contentManager;
|
|
||||||
private readonly ISiteService _siteService;
|
|
||||||
private readonly IFeedManager _feedManager;
|
|
||||||
|
|
||||||
public ItemController(
|
|
||||||
IContentManager contentManager,
|
|
||||||
IShapeFactory shapeFactory,
|
|
||||||
ISiteService siteService,
|
|
||||||
IFeedManager feedManager,
|
|
||||||
IOrchardServices services) {
|
|
||||||
|
|
||||||
_contentManager = contentManager;
|
|
||||||
_siteService = siteService;
|
|
||||||
_feedManager = feedManager;
|
|
||||||
Shape = shapeFactory;
|
|
||||||
Services = services;
|
|
||||||
T = NullLocalizer.Instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
dynamic Shape { get; set; }
|
|
||||||
public IOrchardServices Services { get; private set; }
|
|
||||||
|
|
||||||
public Localizer T { get; set; }
|
|
||||||
[Themed]
|
|
||||||
public ActionResult Display(int id, PagerParameters pagerParameters) {
|
|
||||||
var container = _contentManager
|
|
||||||
.Get(id, VersionOptions.Published)
|
|
||||||
.As<ContainerPart>();
|
|
||||||
|
|
||||||
if (container == null) {
|
|
||||||
return HttpNotFound(T("Container not found").Text);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!Services.Authorizer.Authorize(Permissions.ViewContent, container, T("Cannot view content"))) {
|
|
||||||
return new HttpUnauthorizedResult();
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: (PH) Find a way to apply PagerParameters via a driver so we can lose this controller
|
|
||||||
container.PagerParameters = pagerParameters;
|
|
||||||
var model = _contentManager.BuildDisplay(container);
|
|
||||||
|
|
||||||
return new ShapeResult(this, model);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
using System.Collections.Generic;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Xml;
|
using System.Xml;
|
||||||
using Orchard.ContentManagement;
|
using Orchard.ContentManagement;
|
||||||
@@ -27,8 +28,8 @@ namespace Orchard.Core.Containers.Drivers {
|
|||||||
private readonly IContainerService _containerService;
|
private readonly IContainerService _containerService;
|
||||||
|
|
||||||
public ContainerPartDriver(
|
public ContainerPartDriver(
|
||||||
IContentDefinitionManager contentDefinitionManager,
|
IContentDefinitionManager contentDefinitionManager,
|
||||||
IOrchardServices orchardServices,
|
IOrchardServices orchardServices,
|
||||||
ISiteService siteService,
|
ISiteService siteService,
|
||||||
IFeedManager feedManager, IContainerService containerService) {
|
IFeedManager feedManager, IContainerService containerService) {
|
||||||
_contentDefinitionManager = contentDefinitionManager;
|
_contentDefinitionManager = contentDefinitionManager;
|
||||||
@@ -47,7 +48,7 @@ namespace Orchard.Core.Containers.Drivers {
|
|||||||
if (!part.ItemsShown)
|
if (!part.ItemsShown)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
return ContentShape("Parts_Container_Contained", () => {
|
return ContentShape("Parts_Container_Contained", () => {
|
||||||
var container = part.ContentItem;
|
var container = part.ContentItem;
|
||||||
var query = _contentManager
|
var query = _contentManager
|
||||||
.Query(VersionOptions.Published)
|
.Query(VersionOptions.Published)
|
||||||
@@ -55,13 +56,26 @@ namespace Orchard.Core.Containers.Drivers {
|
|||||||
.Join<ContainablePartRecord>().OrderByDescending(x => x.Position);
|
.Join<ContainablePartRecord>().OrderByDescending(x => x.Position);
|
||||||
|
|
||||||
var metadata = container.ContentManager.GetItemMetadata(container);
|
var metadata = container.ContentManager.GetItemMetadata(container);
|
||||||
if (metadata!=null)
|
if (metadata != null) {
|
||||||
_feedManager.Register(metadata.DisplayText, "rss", new RouteValueDictionary { { "containerid", container.Id } });
|
_feedManager.Register(metadata.DisplayText, "rss", new RouteValueDictionary {{"containerid", container.Id}});
|
||||||
|
}
|
||||||
|
|
||||||
var pager = new Pager(_siteService.GetSiteSettings(), part.PagerParameters);
|
// Retrieving pager parameters.
|
||||||
pager.PageSize = part.PagerParameters.PageSize != null && part.Paginated
|
var queryString = _orchardServices.WorkContext.HttpContext.Request.QueryString;
|
||||||
? pager.PageSize
|
|
||||||
: part.PageSize;
|
var page = 0;
|
||||||
|
// Don't try to page if not necessary.
|
||||||
|
if (part.Paginated && queryString["page"] != null) {
|
||||||
|
Int32.TryParse(queryString["page"], out page);
|
||||||
|
}
|
||||||
|
|
||||||
|
var pageSize = part.PageSize;
|
||||||
|
// If the container is paginated and pageSize is provided in the query string then retrieve it.
|
||||||
|
if (part.Paginated && queryString["pageSize"] != null) {
|
||||||
|
Int32.TryParse(queryString["pageSize"], out pageSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
var pager = new Pager(_siteService.GetSiteSettings(), page, pageSize);
|
||||||
|
|
||||||
var pagerShape = shapeHelper.Pager(pager).TotalItemCount(query.Count());
|
var pagerShape = shapeHelper.Pager(pager).TotalItemCount(query.Count());
|
||||||
var startIndex = part.Paginated ? pager.GetStartIndex() : 0;
|
var startIndex = part.Paginated ? pager.GetStartIndex() : 0;
|
||||||
@@ -88,7 +102,7 @@ namespace Orchard.Core.Containers.Drivers {
|
|||||||
|
|
||||||
protected override DriverResult Editor(ContainerPart part, IUpdateModel updater, dynamic shapeHelper) {
|
protected override DriverResult Editor(ContainerPart part, IUpdateModel updater, dynamic shapeHelper) {
|
||||||
return ContentShape("Parts_Container_Edit", () => {
|
return ContentShape("Parts_Container_Edit", () => {
|
||||||
if(!part.ContainerSettings.DisplayContainerEditor) {
|
if (!part.ContainerSettings.DisplayContainerEditor) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,7 +121,7 @@ namespace Orchard.Core.Containers.Drivers {
|
|||||||
EnablePositioning = part.Record.EnablePositioning,
|
EnablePositioning = part.Record.EnablePositioning,
|
||||||
OverrideEnablePositioning = part.ContainerSettings.EnablePositioning == null
|
OverrideEnablePositioning = part.ContainerSettings.EnablePositioning == null
|
||||||
};
|
};
|
||||||
|
|
||||||
if (updater != null) {
|
if (updater != null) {
|
||||||
if (updater.TryUpdateModel(model, "Container", null, new[] { "OverrideEnablePositioning" })) {
|
if (updater.TryUpdateModel(model, "Container", null, new[] { "OverrideEnablePositioning" })) {
|
||||||
part.AdminMenuPosition = model.AdminMenuPosition;
|
part.AdminMenuPosition = model.AdminMenuPosition;
|
||||||
@@ -127,7 +141,7 @@ namespace Orchard.Core.Containers.Drivers {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return shapeHelper.EditorTemplate(TemplateName: "Container", Model: model, Prefix: "Container");
|
return shapeHelper.EditorTemplate(TemplateName: "Container", Model: model, Prefix: "Container");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ using Orchard.Core.Containers.Models;
|
|||||||
using Orchard.Core.Containers.Services;
|
using Orchard.Core.Containers.Services;
|
||||||
using Orchard.Core.Containers.Settings;
|
using Orchard.Core.Containers.Settings;
|
||||||
using Orchard.Data;
|
using Orchard.Data;
|
||||||
using System.Web.Routing;
|
|
||||||
|
|
||||||
namespace Orchard.Core.Containers.Handlers {
|
namespace Orchard.Core.Containers.Handlers {
|
||||||
public class ContainerPartHandler : ContentHandler {
|
public class ContainerPartHandler : ContentHandler {
|
||||||
@@ -35,14 +34,6 @@ namespace Orchard.Core.Containers.Handlers {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
OnGetContentItemMetadata<ContainerPart>((context, part) => {
|
|
||||||
context.Metadata.DisplayRouteValues = new RouteValueDictionary {
|
|
||||||
{"Area", "Containers"},
|
|
||||||
{"Controller", "Item"},
|
|
||||||
{"Action", "Display"},
|
|
||||||
{"id", context.ContentItem.Id}
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
OnActivated<ContainerPart>((context, part) => {
|
OnActivated<ContainerPart>((context, part) => {
|
||||||
part.ContainerSettingsField.Loader(() => part.Settings.GetModel<ContainerTypePartSettings>());
|
part.ContainerSettingsField.Loader(() => part.Settings.GetModel<ContainerTypePartSettings>());
|
||||||
|
|||||||
@@ -71,12 +71,6 @@ namespace Orchard.Core.Containers.Models {
|
|||||||
get { return Record.ItemCount; }
|
get { return Record.ItemCount; }
|
||||||
set { Record.ItemCount = value; }
|
set { Record.ItemCount = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public PagerParameters PagerParameters { get; set; }
|
|
||||||
|
|
||||||
public ContainerPart() {
|
|
||||||
PagerParameters = new PagerParameters();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ContainerPartRecord : ContentPartRecord {
|
public class ContainerPartRecord : ContentPartRecord {
|
||||||
|
|||||||
@@ -119,7 +119,6 @@
|
|||||||
<Compile Include="Common\ViewModels\DateTimeEditor.cs" />
|
<Compile Include="Common\ViewModels\DateTimeEditor.cs" />
|
||||||
<Compile Include="Common\ViewModels\TextFieldDriverViewModel.cs" />
|
<Compile Include="Common\ViewModels\TextFieldDriverViewModel.cs" />
|
||||||
<Compile Include="Common\ViewModels\TextFieldSettingsEventsViewModel.cs" />
|
<Compile Include="Common\ViewModels\TextFieldSettingsEventsViewModel.cs" />
|
||||||
<Compile Include="Containers\Controllers\ItemController.cs" />
|
|
||||||
<Compile Include="Containers\Drivers\ContainablePartDriver.cs" />
|
<Compile Include="Containers\Drivers\ContainablePartDriver.cs" />
|
||||||
<Compile Include="Containers\Drivers\ContainerPartDriver.cs" />
|
<Compile Include="Containers\Drivers\ContainerPartDriver.cs" />
|
||||||
<Compile Include="Common\Migrations.cs" />
|
<Compile Include="Common\Migrations.cs" />
|
||||||
|
|||||||
Reference in New Issue
Block a user