Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(sln): remove obsolete api references #54

Merged
merged 4 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ on:
- "**.targets"
- "**.sln"
- "**/Client/**/*.json"
- ".github/workflows/ci.yml"
pull_request:
branches: [main]
paths:
Expand All @@ -23,6 +24,7 @@ on:
- "**.targets"
- "**.sln"
- "**/Client/**/*.json"
- ".github/workflows/ci.yml"

jobs:
build:
Expand All @@ -39,10 +41,10 @@ jobs:
SIGN_FILE: false

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Setup .NET
uses: actions/setup-dotnet@v3
uses: actions/setup-dotnet@v4
with:
global-json-file: global.json

Expand All @@ -53,4 +55,4 @@ jobs:
run: dotnet build --configuration Release --no-restore

- name: Test Solution
run: dotnet test --configuration Release --no-build --no-restore
run: dotnet test --configuration Release --no-build --no-restore
12 changes: 6 additions & 6 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
<DisableImplicitNuGetFallbackFolder>true</DisableImplicitNuGetFallbackFolder>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="Kentico.Xperience.Admin" Version="29.5.0" />
<PackageVersion Include="Kentico.Xperience.Azurestorage" Version="29.5.0" />
<PackageVersion Include="Kentico.Xperience.Cloud" Version="29.5.0" />
<PackageVersion Include="Kentico.Xperience.Imageprocessing" Version="29.5.0" />
<PackageVersion Include="Kentico.Xperience.WebApp" Version="29.5.0" />
<PackageVersion Include="Kentico.Xperience.Core.Tests" Version="29.5.0" />
<PackageVersion Include="Kentico.Xperience.Admin" Version="29.5.3" />
<PackageVersion Include="Kentico.Xperience.Azurestorage" Version="29.5.3" />
<PackageVersion Include="Kentico.Xperience.Cloud" Version="29.5.3" />
<PackageVersion Include="Kentico.Xperience.Imageprocessing" Version="29.5.3" />
<PackageVersion Include="Kentico.Xperience.WebApp" Version="29.5.3" />
<PackageVersion Include="Kentico.Xperience.Core.Tests" Version="29.5.3" />
<PackageVersion Include="Algolia.Search" Version="6.16.0" />
<PackageVersion Include="Microsoft.Extensions.Configuration.UserSecrets" Version="6.0.1" />
<PackageVersion Include="SonarAnalyzer.CSharp" Version="9.6.0.74858" />
Expand Down
2 changes: 1 addition & 1 deletion examples/DancingGoat/.config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"isRoot": true,
"tools": {
"kentico.xperience.dbmanager": {
"version": "29.5.0",
"version": "29.5.3",
"commands": [
"kentico-xperience-dbmanager"
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public async Task<ViewViewComponentResult> InvokeAsync(WebPageRelatedItem articl
{
var languageName = currentLanguageRetriever.Get();

var articlesSection = await articlesSectionRepository.GetArticlesSection(articlesSectionItem.WebPageGuid, languageName);
var articlesSection = await articlesSectionRepository.GetArticlesSection(articlesSectionItem.WebPageGuid, languageName, HttpContext.RequestAborted);
if (articlesSection == null)
{
return View("~/Components/ViewComponents/Articles/Default.cshtml", ArticlesSectionViewModel.GetViewModel(null, Enumerable.Empty<ArticleViewModel>(), string.Empty));
Expand All @@ -55,11 +55,11 @@ public async Task<ViewViewComponentResult> InvokeAsync(WebPageRelatedItem articl
var models = new List<ArticleViewModel>();
foreach (var article in articlePages)
{
var model = await ArticleViewModel.GetViewModel(article, urlRetriever, languageName);
var model = await ArticleViewModel.GetViewModel(article, urlRetriever, languageName, HttpContext.RequestAborted);
models.Add(model);
}

var url = (await urlRetriever.Retrieve(articlesSection, languageName)).RelativePath;
var url = (await urlRetriever.Retrieve(articlesSection, languageName, HttpContext.RequestAborted)).RelativePath;

var viewModel = ArticlesSectionViewModel.GetViewModel(articlesSection, models, url);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@
}
else
{
<a href="#" class="ourcoffee-tile-link">
<h2 class="ourcoffee-tile-text center-text">@Model.Name</h2>
<span class="cafe-overlay"> </span>
@if (!string.IsNullOrEmpty(Model.PhotoPath))
{
<img src="@Url.Content(Model.PhotoPath)" alt="@Model.PhotoShortDescription" title="@Model.Name" class="ourcoffee-tile-image" loading="lazy" />
}
</a>
<h2 class="ourcoffee-tile-text center-text">@Model.Name</h2>
<span class="cafe-overlay"> </span>
@if (!string.IsNullOrEmpty(Model.PhotoPath))
{
<img src="@Url.Content(Model.PhotoPath)" alt="@Model.PhotoShortDescription" title="@Model.Name" class="ourcoffee-tile-image" loading="lazy" />
}
}
</div>
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Threading;

using CMS.Websites;

using DancingGoat.Models;

using Kentico.Content.Web.Mvc.Routing;

using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ViewComponents;

Expand All @@ -13,9 +18,37 @@ namespace DancingGoat.ViewComponents
/// </summary>
public class CafeCardSectionViewComponent : ViewComponent
{
public ViewViewComponentResult Invoke(IEnumerable<CafeViewModel> cafes)
private readonly ContactsPageRepository contactsPageRepository;
private readonly IWebPageUrlRetriever webPageUrlRetriever;
private readonly IPreferredLanguageRetriever currentLanguageRetriever;


public CafeCardSectionViewComponent(IPreferredLanguageRetriever currentLanguageRetriever, ContactsPageRepository contactsPageRepository, IWebPageUrlRetriever webPageUrlRetriever)
{
this.currentLanguageRetriever = currentLanguageRetriever;
this.contactsPageRepository = contactsPageRepository;
this.webPageUrlRetriever = webPageUrlRetriever;
}


public async Task<ViewViewComponentResult> InvokeAsync(IEnumerable<CafeViewModel> cafes)
{
return View("~/Components/ViewComponents/CafeCardSection/Default.cshtml", cafes.Take(3));
string languageName = currentLanguageRetriever.Get();
string contactsPagePath = await GetContactsPagePath(languageName, HttpContext.RequestAborted);
var model = new CafeCardSectionViewModel(cafes, contactsPagePath);

return View("~/Components/ViewComponents/CafeCardSection/Default.cshtml", model);
}


private async Task<string> GetContactsPagePath(string languageName, CancellationToken cancellationToken)
{
const string CONTACTS_PAGE_TREE_PATH = "/Contacts";

var contactsPage = await contactsPageRepository.GetContactsPage(CONTACTS_PAGE_TREE_PATH, languageName, cancellationToken);
var url = await webPageUrlRetriever.Retrieve(contactsPage, cancellationToken);

return url.RelativePath;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System.Collections.Generic;

using DancingGoat.Models;

namespace DancingGoat.ViewComponents
{
public record CafeCardSectionViewModel(IEnumerable<CafeViewModel> Cafes, string ContactsPagePath)
{
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
@using DancingGoat.Models
@model IEnumerable<CafeViewModel>
@using DancingGoat.ViewComponents
@model CafeCardSectionViewModel

<div class="row cafe-cards">
<div class="title-wrapper">
<h1 class="title-tab">@HtmlLocalizer["Taste our coffee"]</h1>
</div>
<div class="row row--with-cols-padding">
@foreach (var cafe in Model)
@foreach (var cafe in Model.Cafes)
{
<div class="col-md-4">
<vc:cafe cafe="@cafe" />
<a href="@Model.ContactsPagePath" class="ourcoffee-tile-link">
<vc:cafe cafe="@cafe" />
</a>
</div>
}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ public async Task<IViewComponentResult> InvokeAsync()
{
ConsentShortText = (await consent.GetConsentTextAsync(currentLanguage)).ShortText,
ReturnPageUrl = webPageDataContextRetriever.TryRetrieve(out var currentWebPageContext)
? (await urlRetriever.Retrieve(currentWebPageContext.WebPage.WebPageItemID, currentLanguage)).RelativePath
? (await urlRetriever.Retrieve(currentWebPageContext.WebPage.WebPageItemID, currentLanguage, cancellationToken: HttpContext.RequestAborted)).RelativePath
: (HttpContext.Request.PathBase + HttpContext.Request.Path).Value
};

var contact = ContactManagementContext.CurrentContact;
if ((contact != null) && consentAgreementService.IsAgreed(contact, consent))
{
consentModel.IsConsentAgreed = true;
consentModel.PrivacyPageUrl = Url.Content((await urlRetriever.Retrieve(PrivacyPageConstants.PRIVACY_PAGE_TREE_PATH, websiteChannelContext.WebsiteChannelName, currentLanguage)).RelativePath);
consentModel.PrivacyPageUrl = Url.Content((await urlRetriever.Retrieve(PrivacyPageConstants.PRIVACY_PAGE_TREE_PATH, websiteChannelContext.WebsiteChannelName, currentLanguage, cancellationToken: HttpContext.RequestAborted)).RelativePath);
}

return View("~/Components/ViewComponents/TrackingConsent/Default.cshtml", consentModel);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,22 @@ public async Task<ActionResult> Index(CancellationToken cancellationToken)
private async Task<ContactsIndexViewModel> GetIndexViewModel(ContactsPage contactsPage, CancellationToken cancellationToken)
{
var languageName = currentLanguageRetriever.Get();
var cafes = await cafeRepository.GetCompanyCafes(4, languageName, cancellationToken);
var cafes = (await cafeRepository.GetCafes(0, languageName, cancellationToken)).ToList();
var companyCafes = cafes.Where(c => c.CafeIsCompanyCafe).OrderBy(c => c.CafeName);
var partnerCafes = cafes.Where(c => !c.CafeIsCompanyCafe).OrderBy(c => c.CafeCity);
var contact = await contactRepository.GetContact(languageName, HttpContext.RequestAborted);

return new ContactsIndexViewModel
{
CompanyContact = ContactViewModel.GetViewModel(contact),
CompanyCafes = GetCompanyCafesModel(cafes),
CompanyCafes = GetCafesModel(companyCafes),
PartnerCafes = GetCafesModel(partnerCafes),
WebPage = contactsPage
};
}


private List<CafeViewModel> GetCompanyCafesModel(IEnumerable<Cafe> cafes)
private List<CafeViewModel> GetCafesModel(IEnumerable<Cafe> cafes)
{
return cafes.Select(cafe => CafeViewModel.GetViewModel(cafe)).ToList();
}
Expand Down
Binary file added examples/DancingGoat/Data/Template.zip
Binary file not shown.
12 changes: 5 additions & 7 deletions examples/DancingGoat/Models/Reusable/Cafe/CafeRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

using CMS.ContentEngine;
using CMS.Helpers;
using CMS.Websites;
using CMS.Websites.Routing;

namespace DancingGoat.Models
Expand All @@ -30,13 +29,13 @@ public CafeRepository(
}

/// <summary>
/// Returns an enumerable collection of company cafes ordered by a position in the content tree.
/// Returns an enumerable collection of cafes.
/// </summary>
public async Task<IEnumerable<Cafe>> GetCompanyCafes(int count, string languageName, CancellationToken cancellationToken = default)
public async Task<IEnumerable<Cafe>> GetCafes(int count, string languageName, CancellationToken cancellationToken = default)
{
var queryBuilder = GetQueryBuilder(count, languageName);

var cacheSettings = new CacheSettings(5, WebsiteChannelContext.WebsiteChannelName, nameof(CafeRepository), languageName, nameof(GetCompanyCafes), count);
var cacheSettings = new CacheSettings(5, WebsiteChannelContext.WebsiteChannelName, nameof(CafeRepository), nameof(GetCafes), count, languageName);

return await GetCachedQueryResult<Cafe>(queryBuilder, null, cacheSettings, GetDependencyCacheKeys, cancellationToken);
}
Expand All @@ -47,9 +46,8 @@ private static ContentItemQueryBuilder GetQueryBuilder(int count, string languag
return new ContentItemQueryBuilder()
.ForContentType(Cafe.CONTENT_TYPE_NAME,
config => config
.WithLinkedItems(1)
.TopN(count)
.Where(where => where.WhereTrue(nameof(Cafe.CafeIsCompanyCafe))))
.WithLinkedItems(1)
.TopN(count))
.InLanguage(languageName);
}

Expand Down
44 changes: 20 additions & 24 deletions examples/DancingGoat/Models/Reusable/Tag/TagViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,35 @@

using Tag = CMS.ContentEngine.Tag;

namespace DancingGoat.Models
namespace DancingGoat.Models;

public record TagViewModel(string Name, int Level, Guid Value, bool IsChecked = false)
{
public record TagViewModel(string Name, int Level, Guid Value, bool IsChecked = false)
{
private const int ROOT_TAG_ID = 0;
private const int ROOT_TAG_ID = 0;

public static TagViewModel GetViewModel(Tag tag, int level = 0)
{
return new TagViewModel(tag.Title, level, tag.Identifier);
}
public static TagViewModel GetViewModel(Tag tag, int level = 0) => new TagViewModel(tag.Title, level, tag.Identifier);


public static List<TagViewModel> GetViewModels(IEnumerable<Tag> tags)
{
var result = new List<TagViewModel>();
var tagsByParentId = tags.GroupBy(tag => tag.ParentID).ToDictionary(group => group.Key, group => group.ToList());
public static List<TagViewModel> GetViewModels(IEnumerable<Tag> tags)
{
var result = new List<TagViewModel>();
var tagsByParentId = tags.GroupBy(tag => tag.ParentID).ToDictionary(group => group.Key, group => group.ToList());

if (tagsByParentId.TryGetValue(ROOT_TAG_ID, out var firstLevelTags))
{
GetTagsWithTagViewModels(firstLevelTags, ROOT_TAG_ID);
}
if (tagsByParentId.TryGetValue(ROOT_TAG_ID, out var firstLevelTags))
{
GetTagsWithTagViewModels(firstLevelTags, ROOT_TAG_ID);
}

return result;
return result;


void GetTagsWithTagViewModels(IEnumerable<Tag> currentLevelTags, int level)
void GetTagsWithTagViewModels(IEnumerable<Tag> currentLevelTags, int level)
{
foreach (var tag in currentLevelTags.OrderBy(tag => tag.Order))
{
foreach (var tag in currentLevelTags.OrderBy(tag => tag.Order))
{
var children = tagsByParentId.TryGetValue(tag.ID, out var childrenTags) ? childrenTags : Enumerable.Empty<Tag>();
result.Add(GetViewModel(tag, level));
GetTagsWithTagViewModels(children, level + 1);
}
var children = tagsByParentId.TryGetValue(tag.ID, out var childrenTags) ? childrenTags : Enumerable.Empty<Tag>();
result.Add(GetViewModel(tag, level));
GetTagsWithTagViewModels(children, level + 1);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;

using CMS.Websites;
Expand All @@ -11,11 +12,11 @@ public record ArticleViewModel(string Title, string TeaserUrl, string Summary, s
/// <summary>
/// Validates and maps <see cref="ArticlePage"/> to a <see cref="ArticleViewModel"/>.
/// </summary>
public static async Task<ArticleViewModel> GetViewModel(ArticlePage articlePage, IWebPageUrlRetriever urlRetriever, string languageName)
public static async Task<ArticleViewModel> GetViewModel(ArticlePage articlePage, IWebPageUrlRetriever urlRetriever, string languageName, CancellationToken cancellationToken = default)
{
var teaser = articlePage.ArticlePageTeaser.FirstOrDefault();

var url = await urlRetriever.Retrieve(articlePage, languageName);
var url = await urlRetriever.Retrieve(articlePage, languageName, cancellationToken);

return new ArticleViewModel(
articlePage.ArticleTitle,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ public class ContactsIndexViewModel : IWebPageBasedViewModel
public List<CafeViewModel> CompanyCafes { get; set; }


/// <summary>
/// The partner cafes data.
/// </summary>
public List<CafeViewModel> PartnerCafes { get; set; }


/// <inheritdoc/>
public IWebPageFieldsSource WebPage { get; init; }
}
Expand Down
Loading