Updating Eager Fetch to use records instead of parts

This commit is contained in:
Sebastien Ros
2013-10-03 14:39:50 -07:00
parent a954b9c0e2
commit 56bed398f4
6 changed files with 67 additions and 68 deletions

View File

@@ -130,7 +130,7 @@
<Compile Include="Models\NavigationQueryPart.cs" />
<Compile Include="Models\NavigationQueryPartRecord.cs" />
<Compile Include="Models\QueryPart.cs" />
<Compile Include="Providers\Filters\ContentPartsForm.cs" />
<Compile Include="Providers\Filters\ContentPartRecordsForm.cs" />
<Compile Include="Providers\Filters\EagerFetchFilter.cs" />
<Compile Include="Providers\Layouts\RawLayout.cs" />
<Compile Include="Providers\Layouts\RawLayoutForms.cs" />

View File

@@ -0,0 +1,52 @@
using System;
using System.Linq;
using System.Web.Mvc;
using Orchard.ContentManagement.Records;
using Orchard.DisplayManagement;
using Orchard.Environment.ShellBuilders.Models;
using Orchard.Forms.Services;
using Orchard.Localization;
namespace Orchard.Projections.Providers.Filters {
public class ContentPartRecordsForm : IFormProvider {
private readonly ShellBlueprint _shellBlueprint;
protected dynamic Shape { get; set; }
public Localizer T { get; set; }
public ContentPartRecordsForm(
ShellBlueprint shellBlueprint,
IShapeFactory shapeFactory) {
_shellBlueprint = shellBlueprint;
Shape = shapeFactory;
T = NullLocalizer.Instance;
}
public void Describe(DescribeContext context) {
Func<IShapeFactory, object> form =
shape => {
var f = Shape.Form(
Id: "AnyOfContentPartRecords",
_Parts: Shape.SelectList(
Id: "contentpartrecordss", Name: "ContentPartRecords",
Title: T("Content part records"),
Description: T("Select some content part records."),
Size: 10,
Multiple: true
)
);
foreach (var recordBluePrint in _shellBlueprint.Records.OrderBy(x => x.Type.Name)) {
if (typeof(ContentPartRecord).IsAssignableFrom(recordBluePrint.Type) || typeof(ContentPartVersionRecord).IsAssignableFrom(recordBluePrint.Type)) {
f._Parts.Add(new SelectListItem { Value = recordBluePrint.Type.Name, Text = recordBluePrint.Type.Name });
}
}
return f;
};
context.Form("ContentPartRecordsForm", form);
}
}
}

View File

@@ -1,51 +0,0 @@
using System;
using System.Linq;
using System.Web.Mvc;
using Orchard.ContentManagement.MetaData;
using Orchard.DisplayManagement;
using Orchard.Forms.Services;
using Orchard.Localization;
namespace Orchard.Projections.Providers.Filters {
public class ContentPartsForm : IFormProvider {
private readonly IContentDefinitionManager _contentDefinitionManager;
protected dynamic Shape { get; set; }
public Localizer T { get; set; }
public ContentPartsForm(
IShapeFactory shapeFactory,
IContentDefinitionManager contentDefinitionManager) {
_contentDefinitionManager = contentDefinitionManager;
Shape = shapeFactory;
T = NullLocalizer.Instance;
}
public void Describe(DescribeContext context) {
Func<IShapeFactory, object> form =
shape => {
var f = Shape.Form(
Id: "AnyOfContentParts",
_Parts: Shape.SelectList(
Id: "contentparts", Name: "ContentParts",
Title: T("Content parts"),
Description: T("Select some content parts."),
Size: 10,
Multiple: true
)
);
f._Parts.Add(new SelectListItem { Value = "", Text = T("Any").Text });
foreach (var contentPart in _contentDefinitionManager.ListPartDefinitions().OrderBy(x => x.Name)) {
f._Parts.Add(new SelectListItem { Value = contentPart.Name, Text = contentPart.Name });
}
return f;
};
context.Form("ContentPartsForm", form);
}
}
}

View File

@@ -13,30 +13,30 @@ namespace Orchard.Projections.Providers.Filters {
public void Describe(DescribeFilterContext describe) {
describe.For("Content", T("Content"),T("Content"))
.Element("EagerFetch", T("Eager fetch"), T("Eager fetch content parts"),
.Element("EagerFetch", T("Eager fetch"), T("Eager fetch content part records"),
ApplyFilter,
DisplayFilter,
"ContentPartsForm"
"ContentPartRecordsForm"
);
}
public void ApplyFilter(FilterContext context) {
var contentPartNames = (string)context.State.ContentParts;
if (!String.IsNullOrEmpty(contentPartNames)) {
var contentParts = contentPartNames.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
var contentPartRecords = (string)context.State.ContentPartRecords;
if (!String.IsNullOrEmpty(contentPartRecords)) {
var contentParts = contentPartRecords.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
context.Query = context.Query.Include(contentParts);
}
}
public LocalizedString DisplayFilter(FilterContext context) {
string contentparts = context.State.ContentParts;
string contentpartrecords = context.State.ContentPartRecords;
if (String.IsNullOrEmpty(contentparts)) {
return T("No content part");
if (String.IsNullOrEmpty(contentpartrecords)) {
return T("No content part record");
}
return T("Eager fetch parts {0}", contentparts);
return T("Eager fetch part records {0}", contentpartrecords);
}
}
}

View File

@@ -18,7 +18,7 @@ namespace Orchard.ContentManagement {
private readonly IEnumerable<ISqlStatementProvider> _sqlStatementProviders;
private readonly ShellSettings _shellSettings;
private VersionOptions _versionOptions;
private string[] _includedPartNames = new string[0];
private string[] _includedPartRecords = new string[0];
private bool _cacheable;
protected IJoin _from;
@@ -161,8 +161,8 @@ namespace Orchard.ContentManagement {
return this;
}
public IHqlQuery Include(params string[] partNames) {
_includedPartNames = _includedPartNames.Union(partNames).ToArray();
public IHqlQuery Include(params string[] contentPartRecords) {
_includedPartRecords = _includedPartRecords.Union(contentPartRecords).ToArray();
return this;
}
@@ -202,9 +202,7 @@ namespace Orchard.ContentManagement {
.List<IDictionary>()
.Select(x => (int)x["Id"]);
var contentPartRecords = _includedPartNames.Select(part => part + "Record").ToList();
return ContentManager.GetManyByVersionId(ids, new QueryHints().ExpandRecords(contentPartRecords));
return ContentManager.GetManyByVersionId(ids, new QueryHints().ExpandRecords(_includedPartRecords));
}
public int Count() {

View File

@@ -22,7 +22,7 @@ namespace Orchard.ContentManagement {
/// <summary>
/// Eagerly fetches specific content parts.
/// </summary>
IHqlQuery Include(params string[] contentParts);
IHqlQuery Include(params string[] contentPartRecords);
/// <summary>
/// Adds versioning options to the query.