Merge pull request #2803 from callumbwhyte/query-builder-updates

V8 Hackathon: Query builder updates [v8hackaton]
This commit is contained in:
Sebastiaan Janssen
2018-07-30 12:43:49 +02:00
committed by GitHub
2 changed files with 21 additions and 17 deletions

View File

@@ -22,7 +22,8 @@
function getQuerySnippet(queryExpression) {
var code = "\n@{\n" + "\tvar selection = " + queryExpression + ";\n}\n";
code += "<ul>\n" +
"\t@foreach(var item in selection){\n" +
"\t@foreach (var item in selection)\n" +
"\t{\n" +
"\t\t<li>\n" +
"\t\t\t<a href=\"@item.Url\">@item.Name</a>\n" +
"\t\t</li>\n" +

View File

@@ -1,13 +1,13 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Core.Services;
using Umbraco.Web.Models.TemplateQuery;
using Umbraco.Web.Mvc;
using Umbraco.Web.WebApi;
using System;
using System.Diagnostics;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Web.Models.TemplateQuery;
using Umbraco.Core.Services;
namespace Umbraco.Web.Editors
{
@@ -66,7 +66,7 @@ namespace Umbraco.Web.Editors
var sb = new StringBuilder();
var indention = Environment.NewLine + "\t\t\t\t\t\t";
sb.Append("Model.Content.Site()");
sb.Append("Model.Root()");
var timer = new Stopwatch();
@@ -103,7 +103,7 @@ namespace Umbraco.Web.Editors
{
// we did not find the path
sb.Clear();
sb.AppendFormat("Umbraco.TypedContent({0})", model.Source.Id);
sb.AppendFormat("Umbraco.Content({0})", model.Source.Id);
pointerNode = targetNode;
}
}
@@ -195,10 +195,16 @@ namespace Umbraco.Web.Editors
timer.Stop();
var direction = model.Sort.Direction == "ascending" ? string.Empty : " desc";
sb.Append(indention);
sb.AppendFormat(".OrderBy(\"{0}{1}\")", model.Sort.Property.Alias, direction);
if (model.Sort.Direction == "ascending")
{
sb.AppendFormat(".OrderBy(x => x.{0})", model.Sort.Property.Alias);
}
else
{
sb.AppendFormat(".OrderByDescending(x => x.{0})", model.Sort.Property.Alias);
}
}
if (model.Take > 0)
@@ -249,12 +255,10 @@ namespace Umbraco.Web.Editors
? contents.OrderBy(x => x.Id)
: contents.OrderByDescending(x => x.Id);
case "createDate":
return sortExpression.Direction == "ascending"
? contents.OrderBy(x => x.CreateDate)
: contents.OrderByDescending(x => x.CreateDate);
case "publishDate":
return sortExpression.Direction == "ascending"
? contents.OrderBy(x => x.UpdateDate)
: contents.OrderByDescending(x => x.UpdateDate);
@@ -263,7 +267,6 @@ namespace Umbraco.Web.Editors
? contents.OrderBy(x => x.Name)
: contents.OrderByDescending(x => x.Name);
default:
return sortExpression.Direction == "ascending"
? contents.OrderBy(x => x.Name)
: contents.OrderByDescending(x => x.Name);
@@ -275,10 +278,10 @@ namespace Umbraco.Web.Editors
var aliases = new List<string>();
if (targetNode == null || targetNode.Id == current.Id) return aliases;
if (targetNode.Id != current.Id)
{
aliases.Add(targetNode.ContentType.Alias);
}
aliases.AddRange(this.GetChildContentTypeAliases(targetNode.Parent, current));
@@ -293,7 +296,7 @@ namespace Umbraco.Web.Editors
public IEnumerable<ContentTypeModel> GetContentTypes()
{
var contentTypes = Services.ContentTypeService.GetAll()
.Select(x => new ContentTypeModel { Alias = x.Alias, Name = Services.TextService.Localize("template/contentOfType", tokens: new string[] { x.Name } ) })
.Select(x => new ContentTypeModel { Alias = x.Alias, Name = Services.TextService.Localize("template/contentOfType", tokens: new string[] { x.Name }) })
.OrderBy(x => x.Name).ToList();
contentTypes.Insert(0, new ContentTypeModel { Alias = string.Empty, Name = Services.TextService.Localize("template/allContent") });