mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-26 20:16:15 +08:00
[Fixes #7862] Orchard.Taxonomies, allow autocomplete query to return results when no query term is passed (#7865)
Fixes #7862
This commit is contained in:
committed by
Sébastien Ros
parent
244ea89b27
commit
f5192d89c7
@@ -36,19 +36,23 @@ namespace Orchard.Taxonomies.Controllers {
|
|||||||
if (!_authorizer.Authorize(StandardPermissions.AccessAdminPanel)) {
|
if (!_authorizer.Authorize(StandardPermissions.AccessAdminPanel)) {
|
||||||
throw new UnauthorizedAccessException("Can't access the admin");
|
throw new UnauthorizedAccessException("Can't access the admin");
|
||||||
}
|
}
|
||||||
if (string.IsNullOrEmpty(query)) return new List<Tag>();
|
|
||||||
var allTerms = leavesOnly
|
var allTerms = leavesOnly
|
||||||
? _taxonomyService.GetTerms(taxonomyId).ToList()
|
? _taxonomyService.GetTerms(taxonomyId).ToList()
|
||||||
: new List<TermPart>();
|
: new List<TermPart>();
|
||||||
|
|
||||||
var matchingTerms = _contentManager.Query<TermPart, TermPartRecord>()
|
var matchingTerms = _contentManager.Query<TermPart, TermPartRecord>()
|
||||||
.Where(t => t.TaxonomyId == taxonomyId)
|
.Where(t => t.TaxonomyId == taxonomyId)
|
||||||
.Join<TitlePartRecord>()
|
.Join<TitlePartRecord>();
|
||||||
.Where(r => r.Title.Contains(query))
|
|
||||||
.List()
|
if (!string.IsNullOrEmpty(query))
|
||||||
.Select(t => BuildTag(t, leavesOnly, allTerms))
|
matchingTerms = matchingTerms.Where(r => r.Title.Contains(query));
|
||||||
.OrderBy(t => t.Label)
|
|
||||||
.ToList();
|
var resultingTerms = matchingTerms.List()
|
||||||
return matchingTerms;
|
.Select(t => BuildTag(t, leavesOnly, allTerms))
|
||||||
|
.OrderBy(t => t.Label)
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
return resultingTerms;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Tag BuildTag(TermPart term, bool leavesOnly, IEnumerable<TermPart> terms) {
|
private static Tag BuildTag(TermPart term, bool leavesOnly, IEnumerable<TermPart> terms) {
|
||||||
|
|||||||
Reference in New Issue
Block a user