Skip to content

Commit

Permalink
GH-69 :: adjust cherry-picked code
Browse files Browse the repository at this point in the history
  • Loading branch information
kentico-matthews committed Aug 26, 2024
1 parent b0bd3b2 commit 063ce41
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using Kentico.PageBuilder.Web.Mvc;
using Kentico.Xperience.Admin.Base.FormAnnotations;
using Kentico.Xperience.Admin.Websites.FormAnnotations;
using TrainingGuides.Web.Features.Shared.OptionProviders;

namespace TrainingGuides.Web.Features.Articles.Widgets.ArticleList;

Expand All @@ -27,16 +26,7 @@ public class ArticleListWidgetProperties : IWidgetProperties

[DropDownComponent(
Label = "Order articles by",
DataProviderType = typeof(DropdownEnumOptionProvider<OrderByOption>),
Options = "NewestFirst;Newest first\r\nOldestFirst;Oldest first",
Order = 40)]
public string OrderBy { get; set; } = OrderByOption.NewestFirst.ToString();
}

public enum OrderByOption
{
[Description("Newest first")]
NewestFirst,
[Description("Oldest first")]
OldestFirst

public string OrderBy { get; set; } = "NewstFirst";
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public async Task<ViewViewComponentResult> InvokeAsync(ArticleListWidgetProperti
selectedPagePath,
3);

model.Articles = (properties.OrderBy.Equals(OrderByOption.OldestFirst.ToString())
model.Articles = (properties.OrderBy.Equals("OldestFirst", StringComparison.OrdinalIgnoreCase)
? (await GetArticlePageViewModels(articlePages)).OrderBy(article => article.CreatedOn)
: (await GetArticlePageViewModels(articlePages)).OrderByDescending(article => article.CreatedOn))
.Take(properties.TopN)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,33 +120,6 @@ public async Task<IEnumerable<T>> RetrieveWebPageChildrenByPath(
return pages;
}

public async Task<IEnumerable<T>> RetrieveWebPageChildrenByPath(
string parentPageContentTypeName,
string parentPagePath,
Action<ContentTypeQueryParameters> contentTypeQueryParameters,
int depth = 1)
{
var builder = new ContentItemQueryBuilder()
.ForContentType(
parentPageContentTypeName,
config => contentTypeQueryParameters(
config
.ForWebsite(webSiteChannelContext.WebsiteChannelName, [PathMatch.Children(parentPagePath)])
.WithLinkedItems(depth)
)
)
.InLanguage(preferredLanguageRetriever.Get());

var queryExecutorOptions = new ContentQueryExecutionOptions
{
ForPreview = webSiteChannelContext.IsPreview
};

var pages = await contentQueryExecutor.GetMappedWebPageResult<T>(builder, queryExecutorOptions);

return pages;
}



/// <summary>
Expand Down Expand Up @@ -222,18 +195,6 @@ private async Task<IEnumerable<IContentItemFieldsSource>> RetrieveContentItems(A
return await contentQueryExecutor.GetMappedResult<IContentItemFieldsSource>(builder);
}

/// <summary>
/// Retrieeves reusable content items based on the provided reusable field schema name, further filtring by the provided content query parameters.
/// </summary>
/// <param name="schemaName">The name of the reusable field schema</param>
/// <param name="contentQueryParameters">Content query filter</param>
/// <returns>Enumerable list of content items</returns>
public async Task<IEnumerable<IContentItemFieldsSource>> RetrieveContentItemsBySchema(string schemaName, Action<ContentQueryParameters> contentQueryParameters) =>
await RetrieveContentItems(contentQueryParameters, contentTypesQueryParameters =>
{
contentTypesQueryParameters.OfReusableSchema(schemaName);
});

private async Task<IEnumerable<IWebPageFieldsSource>> RetrieveWebPages(Action<ContentQueryParameters> parameters)
{
var builder = new ContentItemQueryBuilder();
Expand Down Expand Up @@ -262,4 +223,20 @@ private async Task<IEnumerable<IWebPageFieldsSource>> RetrieveWebPages(Action<Co

return pages.FirstOrDefault();
}

/// <summary>
/// Retrieves the IWebPageFieldsSource of a web page item by Guid.
/// </summary>
/// <param name="webPageItemGuid">the Guid of the web page item</param>
/// <returns><see cref="IWebPageFieldsSource"/> object containing generic <see cref="WebPageFields"/> for the item</returns>
public async Task<IWebPageFieldsSource?> RetrieveWebPageByGuid(
Guid webPageItemGuid)
{
var pages = await RetrieveWebPages(parameters =>
{
parameters.Where(where => where.WhereEquals(nameof(WebPageFields.WebPageItemGUID), webPageItemGuid));
});

return pages.FirstOrDefault();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@ public Task<IEnumerable<T>> RetrieveWebPageChildrenByPath(
string path,
int depth = 1);

public Task<IEnumerable<T>> RetrieveWebPageChildrenByPath(
string parentPageContentTypeName,
string path,
Action<ContentTypeQueryParameters> contentTypeQueryParameters,
int depth = 1);

public Task<T?> RetrieveContentItemByGuid(
Guid contentItemGuid,
string contentTypeName,
Expand All @@ -42,5 +36,4 @@ public interface IContentItemRetrieverService

public Task<IWebPageFieldsSource?> RetrieveWebPageByGuid(Guid webPageItemGuid);

public Task<IEnumerable<IContentItemFieldsSource>> RetrieveContentItemsBySchema(string schemaName, Action<ContentQueryParameters> contentQueryParameters);
}

0 comments on commit 063ce41

Please sign in to comment.