Added container scoping to the admin content item list

--HG--
branch : dev
This commit is contained in:
Nathan Heskew
2010-07-16 16:37:12 -07:00
parent 416ca95395
commit 95f2eee912
5 changed files with 49 additions and 1 deletions

View File

@@ -7,6 +7,8 @@ using System.Web.Routing;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Aspects;
using Orchard.ContentManagement.MetaData;
using Orchard.ContentManagement.Records;
using Orchard.Core.Common.Models;
using Orchard.Core.Contents.ViewModels;
using Orchard.Data;
using Orchard.Localization;
@@ -43,6 +45,9 @@ namespace Orchard.Core.Contents.Controllers {
public ILogger Logger { get; set; }
public ActionResult List(ListContentsViewModel model) {
if (model.ContainerId != null && _contentManager.GetLatest((int)model.ContainerId) == null)
return new NotFoundResult();
const int pageSize = 20;
var skip = (Math.Max(model.Page ?? 0, 1) - 1) * pageSize;
@@ -59,6 +64,9 @@ namespace Orchard.Core.Contents.Controllers {
query = query.ForType(model.TypeName);
}
if (model.ContainerId != null)
query = query.Join<CommonRecord>().Where(cr => cr.Container.Id == model.ContainerId);
var contentItems = query.Slice(skip, pageSize);
model.Entries = contentItems.Select(BuildEntry).ToList();

View File

@@ -0,0 +1,38 @@
using System.Collections.Generic;
using System.Web.Mvc;
using System.Web.Routing;
using Orchard.Mvc.Routes;
namespace Orchard.Core.Contents {
public class Routes : IRouteProvider {
#region IRouteProvider Members
public void GetRoutes(ICollection<RouteDescriptor> routes) {
foreach (RouteDescriptor routeDescriptor in GetRoutes()) {
routes.Add(routeDescriptor);
}
}
public IEnumerable<RouteDescriptor> GetRoutes() {
return new[] {
new RouteDescriptor {
Priority = 5,
Route = new Route(
"Admin/Contents/List/{id}/InContainer/{containerId}",
new RouteValueDictionary {
{"area", "Contents"},
{"controller", "Admin"},
{"action", "List"}
},
new RouteValueDictionary(),
new RouteValueDictionary {
{"area", "Contents"}
},
new MvcRouteHandler())
}
};
}
#endregion
}
}

View File

@@ -9,6 +9,7 @@ namespace Orchard.Core.Contents.ViewModels {
}
public string Id { get; set; }
public int? ContainerId { get; set; }
public string TypeName {
get { return Id; }

View File

@@ -78,6 +78,7 @@
<Compile Include="Contents\Drivers\ContentsDriver.cs" />
<Compile Include="Contents\Handlers\ContentsHandler.cs" />
<Compile Include="Contents\Permissions.cs" />
<Compile Include="Contents\Routes.cs" />
<Compile Include="Contents\ViewModels\PublishContentViewModel.cs" />
<Compile Include="PublishLater\Drivers\PublishLaterPartDriver.cs" />
<Compile Include="PublishLater\Models\PublishLaterPart.cs" />

View File

@@ -2,4 +2,4 @@
<%@ Import Namespace="Orchard.Mvc.ViewModels"%>
<%@ Import Namespace="Orchard.Blogs.Models"%>
<%: Html.UnorderedList(Model, (bp, i) => Html.DisplayForItem(bp), "blogPosts contentItems") %>
<% if (Model.Count() < 1) { %><div class="info message"><%: T("There are no posts for this blog.") %></div><% } %>
<% if (Model.Count() < 1) { %><div class="info message"><%: T("There are no posts for this blog.") %></div><% } %>