mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-04-05 21:01:35 +08:00
Projections: Updating QueryVersionScopeOptions and ProjectionManager to support Draft-only Queries (#8111)
This commit is contained in:
parent
c68bb8bf77
commit
fab98c5adb
@ -14,7 +14,7 @@ namespace Orchard.Projections.Descriptors.Filter {
|
||||
|
||||
public QueryPartRecord QueryPartRecord { get; set; }
|
||||
public string GetFilterColumnName() {
|
||||
return QueryPartRecord != null && QueryPartRecord.VersionScope == QueryVersionScopeOptions.Latest ? "LatestValue" : "Value";
|
||||
return QueryPartRecord.GetVersionedFieldIndexColumnName();
|
||||
}
|
||||
}
|
||||
}
|
@ -14,7 +14,7 @@ namespace Orchard.Projections.Descriptors.SortCriterion {
|
||||
|
||||
public QueryPartRecord QueryPartRecord { get; set; }
|
||||
public string GetSortColumnName() {
|
||||
return QueryPartRecord != null && QueryPartRecord.VersionScope == QueryVersionScopeOptions.Latest ? "LatestValue" : "Value";
|
||||
return QueryPartRecord.GetVersionedFieldIndexColumnName();
|
||||
}
|
||||
}
|
||||
}
|
@ -44,6 +44,8 @@ namespace Orchard.Projections.Drivers {
|
||||
|
||||
var element = context.Element(part.PartDefinition.Name);
|
||||
|
||||
element.SetAttributeValue("VersionScope", part.VersionScope);
|
||||
|
||||
element.Add(
|
||||
new XElement("FilterGroups",
|
||||
part.FilterGroups.Select(filterGroup =>
|
||||
@ -121,6 +123,8 @@ namespace Orchard.Projections.Drivers {
|
||||
return;
|
||||
}
|
||||
|
||||
context.ImportAttribute(part.PartDefinition.Name, "VersionScope", scope => part.VersionScope = (QueryVersionScopeOptions)Enum.Parse(typeof(QueryVersionScopeOptions), scope));
|
||||
|
||||
var queryElement = context.Data.Element(part.PartDefinition.Name);
|
||||
|
||||
part.Record.FilterGroups.Clear();
|
||||
|
@ -0,0 +1,9 @@
|
||||
namespace Orchard.Projections.Models {
|
||||
public static class QueryPartRecordExtensions {
|
||||
public static string GetVersionedFieldIndexColumnName(this QueryPartRecord queryPartRecord) {
|
||||
return queryPartRecord == null ?
|
||||
QueryVersionScopeOptions.Published.ToVersionedFieldIndexColumnName() :
|
||||
queryPartRecord.VersionScope.ToVersionedFieldIndexColumnName();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
using Orchard.ContentManagement;
|
||||
|
||||
namespace Orchard.Projections {
|
||||
public static class QueryVersionScopeOptionsExtensions {
|
||||
public static VersionOptions ToVersionOptions(this QueryVersionScopeOptions scope) {
|
||||
switch (scope) {
|
||||
case QueryVersionScopeOptions.Latest:
|
||||
return VersionOptions.Latest;
|
||||
case QueryVersionScopeOptions.Draft:
|
||||
return VersionOptions.Draft;
|
||||
default:
|
||||
return VersionOptions.Published;
|
||||
}
|
||||
}
|
||||
|
||||
public static string ToVersionedFieldIndexColumnName(this QueryVersionScopeOptions scope) {
|
||||
switch (scope) {
|
||||
case QueryVersionScopeOptions.Latest:
|
||||
case QueryVersionScopeOptions.Draft:
|
||||
return "LatestValue";
|
||||
default:
|
||||
return "Value";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -25,7 +25,7 @@ namespace Orchard.Projections.FieldTypeEditors {
|
||||
}
|
||||
|
||||
public Action<IHqlExpressionFactory> GetFilterPredicate(dynamic formState) {
|
||||
return BooleanFilterForm.GetFilterPredicate(formState, formState.VersionScope == QueryVersionScopeOptions.Latest ? "LatestValue" : "Value");
|
||||
return BooleanFilterForm.GetFilterPredicate(formState, ((QueryVersionScopeOptions)formState.VersionScope).ToVersionedFieldIndexColumnName());
|
||||
}
|
||||
|
||||
public LocalizedString DisplayFilter(string fieldName, string storageName, dynamic formState) {
|
||||
|
@ -29,7 +29,7 @@ namespace Orchard.Projections.FieldTypeEditors {
|
||||
}
|
||||
|
||||
public Action<IHqlExpressionFactory> GetFilterPredicate(dynamic formState) {
|
||||
return DateTimeFilterForm.GetFilterPredicate(formState, formState.VersionScope == QueryVersionScopeOptions.Latest ? "LatestValue" : "Value", _clock.UtcNow, true);
|
||||
return DateTimeFilterForm.GetFilterPredicate(formState, ((QueryVersionScopeOptions)formState.VersionScope).ToVersionedFieldIndexColumnName(), _clock.UtcNow, true);
|
||||
}
|
||||
|
||||
public LocalizedString DisplayFilter(string fieldName, string storageName, dynamic formState) {
|
||||
|
@ -27,7 +27,7 @@ namespace Orchard.Projections.FieldTypeEditors {
|
||||
}
|
||||
|
||||
public Action<IHqlExpressionFactory> GetFilterPredicate(dynamic formState) {
|
||||
return NumericFilterForm.GetFilterPredicate(formState, formState.VersionScope == QueryVersionScopeOptions.Latest ? "LatestValue" : "Value");
|
||||
return NumericFilterForm.GetFilterPredicate(formState, ((QueryVersionScopeOptions)formState.VersionScope).ToVersionedFieldIndexColumnName());
|
||||
}
|
||||
|
||||
public LocalizedString DisplayFilter(string fieldName, string storageName, dynamic formState) {
|
||||
|
@ -28,7 +28,7 @@ namespace Orchard.Projections.FieldTypeEditors {
|
||||
}
|
||||
|
||||
public Action<IHqlExpressionFactory> GetFilterPredicate(dynamic formState) {
|
||||
return NumericFilterForm.GetFilterPredicate(formState, formState.VersionScope == QueryVersionScopeOptions.Latest ? "LatestValue" : "Value");
|
||||
return NumericFilterForm.GetFilterPredicate(formState, ((QueryVersionScopeOptions)formState.VersionScope).ToVersionedFieldIndexColumnName());
|
||||
}
|
||||
|
||||
public LocalizedString DisplayFilter(string fieldName, string storageName, dynamic formState) {
|
||||
|
@ -34,7 +34,7 @@ namespace Orchard.Projections.FieldTypeEditors {
|
||||
}
|
||||
|
||||
public Action<IHqlExpressionFactory> GetFilterPredicate(dynamic formState) {
|
||||
return NumericFilterForm.GetFilterPredicate(formState, formState.VersionScope == QueryVersionScopeOptions.Latest ? "LatestValue" : "Value");
|
||||
return NumericFilterForm.GetFilterPredicate(formState, ((QueryVersionScopeOptions)formState.VersionScope).ToVersionedFieldIndexColumnName());
|
||||
}
|
||||
|
||||
public LocalizedString DisplayFilter(string fieldName, string storageName, dynamic formState) {
|
||||
|
@ -25,7 +25,7 @@ namespace Orchard.Projections.FieldTypeEditors {
|
||||
}
|
||||
|
||||
public Action<IHqlExpressionFactory> GetFilterPredicate(dynamic formState) {
|
||||
return StringFilterForm.GetFilterPredicate(formState, formState.VersionScope == QueryVersionScopeOptions.Latest ? "LatestValue" : "Value");
|
||||
return StringFilterForm.GetFilterPredicate(formState, ((QueryVersionScopeOptions)formState.VersionScope).ToVersionedFieldIndexColumnName());
|
||||
}
|
||||
|
||||
public LocalizedString DisplayFilter(string fieldName, string storageName, dynamic formState) {
|
||||
|
@ -1,6 +1,4 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Orchard.Projections.Models {
|
||||
namespace Orchard.Projections.Models {
|
||||
public abstract class FieldIndexRecord {
|
||||
public virtual int Id { get; set; }
|
||||
public virtual string PropertyName { get; set; }
|
||||
@ -25,5 +23,4 @@ namespace Orchard.Projections.Models {
|
||||
public virtual decimal? Value { get; set; }
|
||||
public virtual decimal? LatestValue { get; set; }
|
||||
}
|
||||
|
||||
}
|
@ -11,8 +11,8 @@ namespace Orchard.Projections.Models {
|
||||
}
|
||||
|
||||
public QueryVersionScopeOptions VersionScope {
|
||||
get { return this.Retrieve(x => x.VersionScope); }
|
||||
set { this.Store(x => x.VersionScope, value); }
|
||||
get { return Retrieve(x => x.VersionScope); }
|
||||
set { Store(x => x.VersionScope, value); }
|
||||
}
|
||||
public IList<SortCriterionRecord> SortCriteria {
|
||||
get { return Record.SortCriteria; }
|
||||
|
@ -1,6 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Xml.Serialization;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.ContentManagement.Records;
|
||||
using Orchard.Data.Conventions;
|
||||
|
||||
@ -26,6 +25,5 @@ namespace Orchard.Projections.Models {
|
||||
[CascadeAllDeleteOrphan, Aggregate]
|
||||
[XmlArray("Layouts")]
|
||||
public virtual IList<LayoutRecord> Layouts { get; set; }
|
||||
|
||||
}
|
||||
}
|
@ -128,6 +128,8 @@
|
||||
<Content Include="Web.config" />
|
||||
<Content Include="Scripts\Web.config" />
|
||||
<Content Include="Styles\Web.config" />
|
||||
<Compile Include="Extensions\QueryPartRecordExtensions.cs" />
|
||||
<Compile Include="Extensions\QueryVersionScopeOptionsExtensions.cs" />
|
||||
<Compile Include="Permissions.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Content Include="Module.txt" />
|
||||
|
@ -1,11 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
|
||||
namespace Orchard.Projections {
|
||||
public enum QueryVersionScopeOptions {
|
||||
namespace Orchard.Projections {
|
||||
public enum QueryVersionScopeOptions {
|
||||
Published,
|
||||
Latest
|
||||
Latest,
|
||||
Draft
|
||||
}
|
||||
}
|
@ -4,11 +4,11 @@ using System.Linq;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.Data;
|
||||
using Orchard.Forms.Services;
|
||||
using Orchard.Projections.Descriptors;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Projections.Descriptors.Property;
|
||||
using Orchard.Projections.Descriptors;
|
||||
using Orchard.Projections.Descriptors.Filter;
|
||||
using Orchard.Projections.Descriptors.Layout;
|
||||
using Orchard.Projections.Descriptors.Property;
|
||||
using Orchard.Projections.Descriptors.SortCriterion;
|
||||
using Orchard.Projections.Models;
|
||||
using Orchard.Tokens;
|
||||
@ -200,17 +200,11 @@ namespace Orchard.Projections.Services {
|
||||
tokens = new Dictionary<string, object>();
|
||||
}
|
||||
|
||||
// pre-executing all groups
|
||||
var versionScope = queryRecord.VersionScope;
|
||||
foreach (var group in queryRecord.FilterGroups) {
|
||||
var version = queryRecord.VersionScope.ToVersionOptions();
|
||||
|
||||
IHqlQuery contentQuery;
|
||||
if (versionScope == QueryVersionScopeOptions.Latest) {
|
||||
contentQuery = _contentManager.HqlQuery().ForVersion(VersionOptions.Latest);
|
||||
}
|
||||
else {
|
||||
contentQuery = _contentManager.HqlQuery().ForVersion(VersionOptions.Published);
|
||||
}
|
||||
// pre-executing all groups
|
||||
foreach (var group in queryRecord.FilterGroups) {
|
||||
var contentQuery = _contentManager.HqlQuery().ForVersion(version);
|
||||
|
||||
// iterate over each filter to apply the alterations to the query object
|
||||
foreach (var filter in group.Filters) {
|
||||
@ -245,7 +239,7 @@ namespace Orchard.Projections.Services {
|
||||
var sortCriterionContext = new SortCriterionContext {
|
||||
Query = contentQuery,
|
||||
State = FormParametersHelper.ToDynamic(sortCriterion.State),
|
||||
QueryPartRecord= queryRecord
|
||||
QueryPartRecord = queryRecord
|
||||
};
|
||||
|
||||
string category = sortCriterion.Category;
|
||||
|
Loading…
Reference in New Issue
Block a user