Separate driver for lists

--HG--
branch : 1.x
extra : rebase_source : 11fd73323325581ec561f1043de916e8c4737b49
This commit is contained in:
piedone@pyrocenter.hu
2011-11-28 20:31:58 +01:00
parent c44d4a06d3
commit 32ab009bbf
3 changed files with 61 additions and 29 deletions

View File

@@ -46,43 +46,39 @@ namespace Orchard.Core.Containers.Drivers {
if (!part.ItemsShown) if (!part.ItemsShown)
return null; return null;
return Combined( return ContentShape("Parts_Container_Contained",
ContentShape("Parts_Container_Contained", () => {
() => { var container = part.ContentItem;
var container = part.ContentItem;
IContentQuery<ContentItem> query = _contentManager IContentQuery<ContentItem> query = _contentManager
.Query(VersionOptions.Published) .Query(VersionOptions.Published)
.Join<CommonPartRecord>().Where(cr => cr.Container.Id == container.Id); .Join<CommonPartRecord>().Where(cr => cr.Container.Id == container.Id);
var descendingOrder = part.OrderByDirection == (int)OrderByDirection.Descending; var descendingOrder = part.OrderByDirection == (int)OrderByDirection.Descending;
query = query.OrderBy(part.OrderByProperty, descendingOrder); query = query.OrderBy(part.OrderByProperty, descendingOrder);
_feedManager.Register(container.As<RoutePart>().Title, "rss", new RouteValueDictionary { { "containerid", container.Id } }); _feedManager.Register(container.As<RoutePart>().Title, "rss", new RouteValueDictionary { { "containerid", container.Id } });
var pager = new Pager(_siteService.GetSiteSettings(), part.PagerParameters); var pager = new Pager(_siteService.GetSiteSettings(), part.PagerParameters);
pager.PageSize = part.PagerParameters.PageSize != null && part.Paginated pager.PageSize = part.PagerParameters.PageSize != null && part.Paginated
? pager.PageSize ? pager.PageSize
: part.PageSize; : part.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;
var pageOfItems = query.Slice(startIndex, pager.PageSize).ToList(); var pageOfItems = query.Slice(startIndex, pager.PageSize).ToList();
var listShape = shapeHelper.List(); var listShape = shapeHelper.List();
listShape.AddRange(pageOfItems.Select(item => _contentManager.BuildDisplay(item, "Summary"))); listShape.AddRange(pageOfItems.Select(item => _contentManager.BuildDisplay(item, "Summary")));
listShape.Classes.Add("content-items"); listShape.Classes.Add("content-items");
listShape.Classes.Add("list-items"); listShape.Classes.Add("list-items");
return shapeHelper.Parts_Container_Contained( return shapeHelper.Parts_Container_Contained(
List: listShape, List: listShape,
Pager: pagerShape Pager: pagerShape
); );
}), });
ContentShape("Parts_Container_Contained_SummaryAdmin",
() => shapeHelper.Parts_Container_Contained_SummaryAdmin(ContentPart: part))
);
} }
protected override DriverResult Editor(ContainerPart part, dynamic shapeHelper) { protected override DriverResult Editor(ContainerPart part, dynamic shapeHelper) {

View File

@@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Orchard.ContentManagement.Drivers;
using Orchard.Core.Containers.Models;
using Orchard.ContentManagement.MetaData;
using Orchard.Settings;
using Orchard.Core.Feeds;
namespace Orchard.Lists.Drivers {
public class ContainerPartDriver : Orchard.Core.Containers.Drivers.ContainerPartDriver {
public ContainerPartDriver(
IContentDefinitionManager contentDefinitionManager,
IOrchardServices orchardServices,
ISiteService siteService,
IFeedManager feedManager)
: base(contentDefinitionManager, orchardServices, siteService, feedManager)
{
}
protected override DriverResult Display(ContainerPart part, string displayType, dynamic shapeHelper) {
var shape = base.Display(part, displayType, (object)shapeHelper); // shapeHelper casting to avoid compiler error
if (shape == null) return null;
return Combined(
shape,
ContentShape("Parts_Container_Contained_SummaryAdmin",
() => shapeHelper.Parts_Container_Contained_SummaryAdmin(ContentPart: part))
);
}
}
}

View File

@@ -49,6 +49,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="AdminMenu.cs" /> <Compile Include="AdminMenu.cs" />
<Compile Include="Drivers\ContainerPartDriver.cs" />
<Compile Include="Handlers\ContainerPartHandler.cs" /> <Compile Include="Handlers\ContainerPartHandler.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Routes.cs" /> <Compile Include="Routes.cs" />
@@ -105,6 +106,7 @@
<ItemGroup> <ItemGroup>
<Content Include="Views\Admin\Choose.cshtml" /> <Content Include="Views\Admin\Choose.cshtml" />
</ItemGroup> </ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" /> <Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- To modify your build process, add your task inside one of the targets below and uncomment it.