diff --git a/Lombiq.UIKit.Widgets.Tests.UI/Extensions/TestCaseUITestContextExtensions.cs b/Lombiq.UIKit.Widgets.Tests.UI/Extensions/TestCaseUITestContextExtensions.cs index 99c7069..bd2a390 100644 --- a/Lombiq.UIKit.Widgets.Tests.UI/Extensions/TestCaseUITestContextExtensions.cs +++ b/Lombiq.UIKit.Widgets.Tests.UI/Extensions/TestCaseUITestContextExtensions.cs @@ -13,6 +13,8 @@ public static class TestCaseUITestContextExtensions { private const string CarouselWidgetPartSettingsUrl = "/ContentTypes/CarouselWidget/ContentParts/CarouselWidgetPart/Edit"; private const string CarouselWidgetExamplePageUrl = "/carousel-widget-example"; + private const int SlidesToShow = 3; + private const bool ShowDots = false; public static async Task TestCarouselWidgetBehaviorAsync(this UITestContext context) { @@ -24,17 +26,14 @@ public static async Task TestCarouselWidgetBehaviorAsync(this UITestContext cont public static async Task TestCarouselWidgetOptionsAsync(this UITestContext context) { - int slidesToShow = 3; - bool showDots = false; - await context.SignInDirectlyAndGoToAdminRelativeUrlAsync(CarouselWidgetPartSettingsUrl); context.WaitForPageLoad(); - var options = JsonSerializer.Serialize(new { slidesToShow, dots = showDots }); + var options = JsonSerializer.Serialize(new { SlidesToShow, dots = ShowDots }); context.ExecuteScript($"codeMirrorJsonEditor.setValue('{options}')"); await context.ClickReliablyOnSubmitAsync(); await context.GoToRelativeUrlAsync(CarouselWidgetExamplePageUrl); - context.TestCorrectNumberOfItemsIsDisplayed(slidesToShow); - context.TestCarouselWidgetDotsVisibility(showDots); + context.TestCorrectNumberOfItemsIsDisplayed(SlidesToShow); + context.TestCarouselWidgetDotsVisibility(ShowDots); } public static void TestCorrectNumberOfItemsIsDisplayed(this UITestContext context, int numberOfItems = 1) => diff --git a/Lombiq.UIKit.Widgets.Tests.UI/Lombiq.UIKit.Widgets.Tests.UI.csproj b/Lombiq.UIKit.Widgets.Tests.UI/Lombiq.UIKit.Widgets.Tests.UI.csproj index 08624d2..4cdd348 100644 --- a/Lombiq.UIKit.Widgets.Tests.UI/Lombiq.UIKit.Widgets.Tests.UI.csproj +++ b/Lombiq.UIKit.Widgets.Tests.UI/Lombiq.UIKit.Widgets.Tests.UI.csproj @@ -8,10 +8,10 @@ Lombiq UI Kit Widgets for Orchard Core - UI Test Extensions Lombiq Technologies Copyright © 2022, Lombiq Technologies Ltd. - Lombiq UI Kit for Orchard Core - UI Test Extensions: Extensions to aid in UI testing Lombiq UI Kit for Orchard Core. + Lombiq UI Kit Widgets for Orchard Core - UI Test Extensions: Extensions to aid in UI testing Lombiq UI Kit Widgets for Orchard Core. NuGetIcon.png - OrchardCore;Lombiq;AspNetCore;UIKit - https://github.com/Lombiq/Orchard-Chart.js + OrchardCore;Lombiq;AspNetCore;UIKit;UIKit.Widgets + https://github.com/Lombiq/Orchard-UIKit https://github.com/Lombiq/Orchard-UIKit/blob/dev/Lombiq.UIKit.Widgets.Tests.UI/Readme.md BSD-3-Clause diff --git a/Lombiq.UIKit.Widgets.Tests.UI/Readme.md b/Lombiq.UIKit.Widgets.Tests.UI/Readme.md index 7dcdf58..15452f2 100644 --- a/Lombiq.UIKit.Widgets.Tests.UI/Readme.md +++ b/Lombiq.UIKit.Widgets.Tests.UI/Readme.md @@ -1,10 +1,10 @@ -# Lombiq UI Kit for Orchard Core - UI Test Extensions +# Lombiq UI Kit Widgets for Orchard Core - UI Test Extensions ## About -Extension methods that test various features in UI Kit for Orchard Core. +Extension methods that test various features in UI Kit Widgets for Orchard Core. -Call these from a UI test project that also references _Lombiq.UIKit._ to verify the module's basic features; as seen in [Open-Source Orchard Core Extensions](https://github.com/Lombiq/Open-Source-Orchard-Core-Extensions). +Call these from a UI test project that also references _Lombiq.UIKit.Widgets_ to verify the module's basic features; as seen in [Open-Source Orchard Core Extensions](https://github.com/Lombiq/Open-Source-Orchard-Core-Extensions). ## Contributing and support diff --git a/Lombiq.UIKit.Widgets/Constants/ContentTypes.cs b/Lombiq.UIKit.Widgets/Constants/ContentTypes.cs new file mode 100644 index 0000000..4eff9f8 --- /dev/null +++ b/Lombiq.UIKit.Widgets/Constants/ContentTypes.cs @@ -0,0 +1,9 @@ +namespace Lombiq.UIKit.Widgets.Constants; + +public static class ContentTypes +{ + public const string SlidePart = nameof(SlidePart); + public const string Slide = "Slide"; + public const string CarouselWidgetPart = nameof(CarouselWidgetPart); + public const string CarouselWidget = "CarouselWidget"; +} diff --git a/Lombiq.UIKit.Widgets/Handlers/SlidePartHandler.cs b/Lombiq.UIKit.Widgets/Handlers/SlidePartHandler.cs index 9af6453..de9871d 100644 --- a/Lombiq.UIKit.Widgets/Handlers/SlidePartHandler.cs +++ b/Lombiq.UIKit.Widgets/Handlers/SlidePartHandler.cs @@ -6,5 +6,5 @@ namespace Lombiq.UIKit.Widgets.Handlers; public class SlidePartHandler : ContentPartHandler { public override Task UpdatedAsync(UpdateContentContext context, SlidePart part) => - Task.Run(() => context.ContentItem.DisplayText = part.Title.Text); + Task.Run(() => context.ContentItem.DisplayText = part.ContentItem.Content.TitlePart.Text); } diff --git a/Lombiq.UIKit.Widgets/Migrations/CarouselWidgetMigrations.cs b/Lombiq.UIKit.Widgets/Migrations/CarouselWidgetMigrations.cs index 11241a4..7df4e79 100644 --- a/Lombiq.UIKit.Widgets/Migrations/CarouselWidgetMigrations.cs +++ b/Lombiq.UIKit.Widgets/Migrations/CarouselWidgetMigrations.cs @@ -1,4 +1,5 @@ using Lombiq.HelpfulLibraries.OrchardCore.Contents; +using Lombiq.UIKit.Widgets.Constants; using Lombiq.UIKit.Widgets.Models; using Lombiq.UIKit.Widgets.Settings; using OrchardCore.ContentManagement.Metadata; @@ -6,6 +7,7 @@ using OrchardCore.Data.Migration; using OrchardCore.Flows.Models; using OrchardCore.Media.Settings; +using OrchardCore.Title.Models; namespace Lombiq.UIKit.Widgets.Migrations; @@ -17,35 +19,33 @@ public class CarouselWidgetMigrations : DataMigration public async Task CreateAsync() { - await _contentDefinitionManager.AlterPartDefinitionAsync( - part => + await _contentDefinitionManager.AlterPartDefinitionAsync(part => part + .WithField(part => part.Image, field => field.WithSettings(new MediaFieldSettings { - part.WithField(part => part.Title, field => field.WithPosition("0")); - part.WithField(part => part.Image, field => field.WithSettings(new MediaFieldSettings - { - Multiple = false, - }).WithPosition("1") - ); - } - ); - - await _contentDefinitionManager.AlterPartDefinitionAsync(nameof(CarouselWidgetPart), part => part - .Attachable() - .WithSettings(new CarouselWidgetPartSettings()) + Multiple = false, + }) + .WithPosition("0") + )); + + await _contentDefinitionManager.AlterPartDefinitionAsync(ContentTypes.CarouselWidgetPart, part => part + .Attachable() + .WithSettings(new CarouselWidgetPartSettings()) ); - await _contentDefinitionManager.AlterTypeDefinitionAsync("Slide", type => - type + await _contentDefinitionManager.AlterTypeDefinitionAsync(ContentTypes.Slide, type => type .Securable() - .WithPart(nameof(SlidePart))); + .WithPart(nameof(TitlePart), part => part + .WithPosition("0")) + .WithPart(ContentTypes.SlidePart, part => part + .WithPosition("1") + )); - await _contentDefinitionManager.AlterTypeDefinitionAsync("CarouselWidget", type => - type + await _contentDefinitionManager.AlterTypeDefinitionAsync(ContentTypes.CarouselWidget, type => type .Securable() - .WithPart(nameof(CarouselWidgetPart), part => part.WithSettings(new CarouselWidgetPartSettings())) + .WithPart(ContentTypes.CarouselWidgetPart, part => part.WithSettings(new CarouselWidgetPartSettings())) .WithPart(nameof(BagPart), part => part.WithSettings(new BagPartSettings { - ContainedContentTypes = ["Slide"], + ContainedContentTypes = [ContentTypes.Slide], }) ).Stereotype(CommonStereotypes.Widget)); diff --git a/Lombiq.UIKit.Widgets/Models/CarouselWidgetPart.cs b/Lombiq.UIKit.Widgets/Models/CarouselWidgetPart.cs index 5de2f14..cdd9b05 100644 --- a/Lombiq.UIKit.Widgets/Models/CarouselWidgetPart.cs +++ b/Lombiq.UIKit.Widgets/Models/CarouselWidgetPart.cs @@ -1,4 +1,5 @@ using OrchardCore.ContentManagement; namespace Lombiq.UIKit.Widgets.Models; + public class CarouselWidgetPart : ContentPart; diff --git a/Lombiq.UIKit.Widgets/Models/SlidePart.cs b/Lombiq.UIKit.Widgets/Models/SlidePart.cs index 5ac9cc1..8cdb552 100644 --- a/Lombiq.UIKit.Widgets/Models/SlidePart.cs +++ b/Lombiq.UIKit.Widgets/Models/SlidePart.cs @@ -1,10 +1,9 @@ -using OrchardCore.ContentFields.Fields; using OrchardCore.ContentManagement; using OrchardCore.Media.Fields; namespace Lombiq.UIKit.Widgets.Models; + public class SlidePart : ContentPart { - public TextField Title { get; set; } = new(); public MediaField Image { get; set; } = new(); } diff --git a/Lombiq.UIKit.Widgets/Recipes/Lombiq.UIKit.Widgets.Content.recipe.json b/Lombiq.UIKit.Widgets/Recipes/Lombiq.UIKit.Widgets.Content.recipe.json index bd5b82e..d3b7601 100644 --- a/Lombiq.UIKit.Widgets/Recipes/Lombiq.UIKit.Widgets.Content.recipe.json +++ b/Lombiq.UIKit.Widgets/Recipes/Lombiq.UIKit.Widgets.Content.recipe.json @@ -1,7 +1,7 @@ { "name": "Lombiq.UIKit.Widgets.Content", "displayName": "Lombiq UI Kit widgets - Sample Content - Carousel Widget", - "description": "Sample content for testing and demonstration of the Lombiq UI kit module.", + "description": "Sample content for testing and demonstration of the Lombiq UI kit Widgets module.", "author": "Lombiq Technologies", "website": "https://github.com/Lombiq/Orchard-UIKit", "version": "1.0", @@ -75,10 +75,10 @@ "CreatedUtc": null, "Owner": "4d1m8j4trsk4px1att6bte204r", "Author": "admin", + "TitlePart": { + "Text": "About" + }, "SlidePart": { - "Title": { - "Text": "About" - }, "Image": { "Paths": [ "about-bg.jpg" @@ -101,10 +101,10 @@ "CreatedUtc": null, "Owner": "4d1m8j4trsk4px1att6bte204r", "Author": "admin", + "TitlePart": { + "Text": "About" + }, "SlidePart": { - "Title": { - "Text": "Features" - }, "Image": { "Paths": [ "meadow-orchard.jpg" @@ -127,10 +127,10 @@ "CreatedUtc": null, "Owner": "4d1m8j4trsk4px1att6bte204r", "Author": "admin", + "TitlePart": { + "Text": "Support" + }, "SlidePart": { - "Title": { - "Text": "Support" - }, "Image": { "Paths": [ "home-bg.jpg" @@ -153,10 +153,10 @@ "CreatedUtc": null, "Owner": "4d1m8j4trsk4px1att6bte204r", "Author": "admin", + "TitlePart": { + "Text": "Modern" + }, "SlidePart": { - "Title": { - "Text": "Modern" - }, "Image": { "Paths": [ "post-bg.jpg" diff --git a/Lombiq.UIKit.Widgets/Settings/CarouselWidgetPartSettings.cs b/Lombiq.UIKit.Widgets/Settings/CarouselWidgetPartSettings.cs index 9fb981c..07042b9 100644 --- a/Lombiq.UIKit.Widgets/Settings/CarouselWidgetPartSettings.cs +++ b/Lombiq.UIKit.Widgets/Settings/CarouselWidgetPartSettings.cs @@ -4,5 +4,5 @@ namespace Lombiq.UIKit.Widgets.Settings; public class CarouselWidgetPartSettings { - public string Options { get; set; } = DefaultValues.CarouselWidgetPartOptions; + public string OptionsJsonSerialized { get; set; } = DefaultValues.CarouselWidgetPartOptions; } diff --git a/Lombiq.UIKit.Widgets/Settings/CarouselWidgetPartSettingsDisplayDriver.cs b/Lombiq.UIKit.Widgets/Settings/CarouselWidgetPartSettingsDisplayDriver.cs index 7c440af..63607e1 100644 --- a/Lombiq.UIKit.Widgets/Settings/CarouselWidgetPartSettingsDisplayDriver.cs +++ b/Lombiq.UIKit.Widgets/Settings/CarouselWidgetPartSettingsDisplayDriver.cs @@ -6,6 +6,7 @@ using OrchardCore.DisplayManagement.Views; namespace Lombiq.UIKit.Widgets.Settings; + public class CarouselWidgetPartSettingsDisplayDriver : ContentTypePartDefinitionDisplayDriver { public override IDisplayResult Edit(ContentTypePartDefinition model, BuildEditorContext context) => @@ -13,7 +14,7 @@ public override IDisplayResult Edit(ContentTypePartDefinition model, BuildEditor { var settings = model.GetSettings(); - viewModel.Options = settings.Options; + viewModel.OptionsJsonSerialized = settings.OptionsJsonSerialized; }).Location("Content"); public override async Task UpdateAsync(ContentTypePartDefinition model, UpdateTypePartEditorContext context) @@ -23,12 +24,12 @@ public override async Task UpdateAsync(ContentTypePartDefinition await context.Updater.TryUpdateModelAsync( viewModel, Prefix, - m => m.Options + model => model.OptionsJsonSerialized ); var settings = new CarouselWidgetPartSettings { - Options = viewModel.Options ?? DefaultValues.CarouselWidgetPartOptions, + OptionsJsonSerialized = viewModel.OptionsJsonSerialized ?? DefaultValues.CarouselWidgetPartOptions, }; context.Builder.WithSettings(settings); diff --git a/Lombiq.UIKit.Widgets/Settings/CarouselWidgetPartSettingsViewModel.cs b/Lombiq.UIKit.Widgets/Settings/CarouselWidgetPartSettingsViewModel.cs index b16bf47..bf4b6b7 100644 --- a/Lombiq.UIKit.Widgets/Settings/CarouselWidgetPartSettingsViewModel.cs +++ b/Lombiq.UIKit.Widgets/Settings/CarouselWidgetPartSettingsViewModel.cs @@ -1,5 +1,6 @@ namespace Lombiq.UIKit.Widgets.Settings; + public class CarouselWidgetPartSettingsViewModel { - public string? Options { get; set; } + public string? OptionsJsonSerialized { get; set; } } diff --git a/Lombiq.UIKit.Widgets/Startup.cs b/Lombiq.UIKit.Widgets/Startup.cs index 1b6d88d..52d31fd 100644 --- a/Lombiq.UIKit.Widgets/Startup.cs +++ b/Lombiq.UIKit.Widgets/Startup.cs @@ -9,6 +9,7 @@ using OrchardCore.Modules; namespace Lombiq.UIKit.Widgets; + public sealed class Startup : StartupBase { public override void ConfigureServices(IServiceCollection services) diff --git a/Lombiq.UIKit.Widgets/ViewModels/CarouselWidgetPartViewModel.cs b/Lombiq.UIKit.Widgets/ViewModels/CarouselWidgetPartViewModel.cs index 048418e..da2eb47 100644 --- a/Lombiq.UIKit.Widgets/ViewModels/CarouselWidgetPartViewModel.cs +++ b/Lombiq.UIKit.Widgets/ViewModels/CarouselWidgetPartViewModel.cs @@ -2,6 +2,7 @@ using OrchardCore.ContentManagement; namespace Lombiq.UIKit.Widgets.ViewModels; + public class CarouselWidgetPartViewModel { [BindNever] diff --git a/Lombiq.UIKit.Widgets/Views/CarouselWidgetPartSettings_Edit.cshtml b/Lombiq.UIKit.Widgets/Views/CarouselWidgetPartSettings_Edit.cshtml index b61e7b8..35b605e 100644 --- a/Lombiq.UIKit.Widgets/Views/CarouselWidgetPartSettings_Edit.cshtml +++ b/Lombiq.UIKit.Widgets/Views/CarouselWidgetPartSettings_Edit.cshtml @@ -1,6 +1,6 @@ @using Lombiq.UIKit.Widgets.Settings @using OrchardCore.ResourceManagement -@inject IResourceManager _resourceManager; +@inject IResourceManager _resourceManager @@ -10,8 +10,8 @@
- - + +
@T[string.Format("Slick configuration. Check {0} for more details.", "https://kenwheeler.github.io/slick/#settings")]
diff --git a/Lombiq.UIKit.Widgets/Views/Home/Index.cshtml b/Lombiq.UIKit.Widgets/Views/Home/Index.cshtml deleted file mode 100644 index abab7be..0000000 --- a/Lombiq.UIKit.Widgets/Views/Home/Index.cshtml +++ /dev/null @@ -1 +0,0 @@ -Template \ No newline at end of file diff --git a/Lombiq.UIKit.Widgets/Views/Widget-CarouselWidget.cshtml b/Lombiq.UIKit.Widgets/Views/Widget-CarouselWidget.cshtml index d6ebdc6..50d278c 100644 --- a/Lombiq.UIKit.Widgets/Views/Widget-CarouselWidget.cshtml +++ b/Lombiq.UIKit.Widgets/Views/Widget-CarouselWidget.cshtml @@ -5,7 +5,7 @@ @using OrchardCore.DisplayManagement @using OrchardCore.Flows.Models -@inject IContentDefinitionManager _contentDefinitionManager; +@inject IContentDefinitionManager _contentDefinitionManager @{ var typeDefinition = await _contentDefinitionManager.GetTypeDefinitionAsync("CarouselWidget"); @@ -22,14 +22,12 @@ var bagItems = ((ContentItem)Model.ContentItem).As().ContentItems.Select(contentItem => contentItem.As()); var items = new List(); - bagItems.ForEach(async (slide) => items.Add(await New.Slide(Title: slide.Title.Text, Image: slide.Image.Paths[0]))); + bagItems.ForEach(async (slide) => items.Add(await New.Slide(Title: slide.ContentItem.Content.TitlePart.Text, Image: slide.Image.Paths[0]))); - var carouselSettings = settings.Options; + var carouselSettings = settings.OptionsJsonSerialized; } -