From 0b3136cf20c72f084df99c733e877c28a4c8ec2c Mon Sep 17 00:00:00 2001 From: Rusty Swayne Date: Mon, 9 Jun 2014 09:14:26 -0700 Subject: [PATCH] Patched Contains query & implemented SortExpression --- .../TemplateQuery/TemplateQueryController.cs | 30 +++++++++++++++---- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/src/Umbraco.Web/Editors/TemplateQuery/TemplateQueryController.cs b/src/Umbraco.Web/Editors/TemplateQuery/TemplateQueryController.cs index b922f6af36..9107f06f46 100644 --- a/src/Umbraco.Web/Editors/TemplateQuery/TemplateQueryController.cs +++ b/src/Umbraco.Web/Editors/TemplateQuery/TemplateQueryController.cs @@ -53,7 +53,7 @@ namespace Umbraco.Web.Editors { new PropertyModel() { Name = "Id", Alias = "id", Type = "int" }, new PropertyModel() { Name = "Name", Alias = "name", Type = "string" }, - new PropertyModel() { Name = "Url", Alias = "url", Type = "string" }, + //new PropertyModel() { Name = "Url", Alias = "url", Type = "string" }, new PropertyModel() { Name = "Creation Date", Alias = "createDate", Type = "datetime" }, new PropertyModel() { Name = "Publishing Date", Alias = "publishDate", Type = "datetime" } @@ -158,13 +158,13 @@ namespace Umbraco.Web.Editors break; case Operathor.Contains: - // .Where() - operation = string.Format("{0}.Contains(\"{1}\")", condition.Property.Name.ToLowerInvariant(), condition.ConstraintValue.ToLowerInvariant()); + + operation = string.Format("{0}.ToLowerInvariant().Contains(\"{1}\")", condition.Property.Name, condition.ConstraintValue.ToLowerInvariant()); break; case Operathor.NotContains: - operation = string.Format("!{0}.Contains(\"{1}\")", condition.Property.Name.ToLowerInvariant(), condition.ConstraintValue.ToLowerInvariant()); + operation = string.Format("!{0}.ToLowerInvariant().Contains(\"{1}\")", condition.Property.Name, condition.ConstraintValue.ToLowerInvariant()); break; } @@ -189,8 +189,8 @@ namespace Umbraco.Web.Editors // TODO write extension to determine if built in property or not contents = model.SortExpression.SortDirection == "ascending" - ? contents.OrderBy(x => x.GetPropertyValue(model.SortExpression.Property.Alias)).ToList() - : contents.OrderByDescending(x => x.GetPropertyValue(model.SortExpression.Property.Alias)).ToList(); + ? contents.OrderBy(x => GetDefaultPropertyValue(x, model.SortExpression.Property)).ToList() + : contents.OrderByDescending(x => GetDefaultPropertyValue(x, model.SortExpression.Property)).ToList(); timer.Stop(); @@ -223,6 +223,24 @@ namespace Umbraco.Web.Editors return queryResult; } + private object GetDefaultPropertyValue(IPublishedContent content, PropertyModel prop) + { + switch (prop.Alias) + { + case "id" : + return content.Id; + case "createDate" : + return content.CreateDate; + case "publishDate": + return content.UpdateDate; + case "name": + return content.Name; + default : + return content.Name; + + } + } + private IEnumerable GetChildContentTypeAliases(IPublishedContent targetNode, IPublishedContent current) { var aliases = new List();