mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-09-23 21:13:35 +08:00
Roughing in Containers module
Container/containable editor templates appear Container id settable via drop list ContainerPathConstraint of higher priority providing list view --HG-- branch : dev
This commit is contained in:
@@ -1,11 +1,57 @@
|
||||
using System.Web.Mvc;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Web.Mvc;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.ContentManagement.Aspects;
|
||||
using Orchard.Core.Common.Models;
|
||||
using Orchard.Core.Routable.Models;
|
||||
using Orchard.DisplayManagement;
|
||||
using Orchard.Themes;
|
||||
|
||||
namespace Orchard.Core.Containers.Controllers {
|
||||
public class ItemController: Controller {
|
||||
public class ItemController : Controller {
|
||||
private readonly IContentManager _contentManager;
|
||||
private readonly IContainersPathConstraint _containersPathConstraint;
|
||||
|
||||
public ItemController(IContentManager contentManager, IContainersPathConstraint containersPathConstraint, IShapeFactory shapeFactory) {
|
||||
_contentManager = contentManager;
|
||||
_containersPathConstraint = containersPathConstraint;
|
||||
New = shapeFactory;
|
||||
}
|
||||
|
||||
dynamic New { get; set; }
|
||||
|
||||
[Themed]
|
||||
public ActionResult Display(string path, int? page) {
|
||||
return View();
|
||||
public ActionResult Display(string path, int? page) {
|
||||
var matchedPath = _containersPathConstraint.FindPath(path);
|
||||
if (string.IsNullOrEmpty(matchedPath)) {
|
||||
throw new ApplicationException("404 - should not have passed path constraint");
|
||||
}
|
||||
|
||||
var hits = _contentManager
|
||||
.Query<RoutePart, RoutePartRecord>(VersionOptions.Published)
|
||||
.Where(r => r.Path == matchedPath)
|
||||
.Slice(0, 2);
|
||||
|
||||
if (hits.Count() == 0) {
|
||||
throw new ApplicationException("404 - should not have passed path constraint");
|
||||
}
|
||||
|
||||
if (hits.Count() != 1) {
|
||||
throw new ApplicationException("Ambiguous content");
|
||||
}
|
||||
|
||||
var containerId = hits.Single().Id;
|
||||
var items = _contentManager
|
||||
.Query<ContentPart<CommonPartRecord>, CommonPartRecord>(VersionOptions.Published)
|
||||
.Where(x => x.Container.Id == containerId)
|
||||
.List();
|
||||
|
||||
var itemDisplays = items.Select(item => _contentManager.BuildDisplay(item, "Summary"));
|
||||
var list = New.List();
|
||||
list.AddRange(itemDisplays);
|
||||
|
||||
return View(list);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user