Skip to content

Commit

Permalink
Fixing project details (name, description..); Cleaning up the code; a…
Browse files Browse the repository at this point in the history
…dding TitlePart to Slide.
  • Loading branch information
milosh-96 committed Jan 13, 2025
1 parent 08f8513 commit 2ce2a89
Show file tree
Hide file tree
Showing 17 changed files with 72 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
<Title>Lombiq UI Kit Widgets for Orchard Core - UI Test Extensions</Title>
<Authors>Lombiq Technologies</Authors>
<Copyright>Copyright © 2022, Lombiq Technologies Ltd.</Copyright>
<Description>Lombiq UI Kit for Orchard Core - UI Test Extensions: Extensions to aid in UI testing Lombiq UI Kit for Orchard Core.</Description>
<Description>Lombiq UI Kit Widgets for Orchard Core - UI Test Extensions: Extensions to aid in UI testing Lombiq UI Kit Widgets for Orchard Core.</Description>
<PackageIcon>NuGetIcon.png</PackageIcon>
<PackageTags>OrchardCore;Lombiq;AspNetCore;UIKit</PackageTags>
<RepositoryUrl>https://github.com/Lombiq/Orchard-Chart.js</RepositoryUrl>
<PackageTags>OrchardCore;Lombiq;AspNetCore;UIKit;UIKit.Widgets</PackageTags>
<RepositoryUrl>https://github.com/Lombiq/Orchard-UIKit</RepositoryUrl>
<PackageProjectUrl>https://github.com/Lombiq/Orchard-UIKit/blob/dev/Lombiq.UIKit.Widgets.Tests.UI/Readme.md</PackageProjectUrl>
<PackageLicenseExpression>BSD-3-Clause</PackageLicenseExpression>
</PropertyGroup>
Expand Down
6 changes: 3 additions & 3 deletions Lombiq.UIKit.Widgets.Tests.UI/Readme.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
9 changes: 9 additions & 0 deletions Lombiq.UIKit.Widgets/Constants/ContentTypes.cs
Original file line number Diff line number Diff line change
@@ -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";
}
2 changes: 1 addition & 1 deletion Lombiq.UIKit.Widgets/Handlers/SlidePartHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ namespace Lombiq.UIKit.Widgets.Handlers;
public class SlidePartHandler : ContentPartHandler<SlidePart>
{
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);
}
42 changes: 21 additions & 21 deletions Lombiq.UIKit.Widgets/Migrations/CarouselWidgetMigrations.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
using Lombiq.HelpfulLibraries.OrchardCore.Contents;
using Lombiq.UIKit.Widgets.Constants;
using Lombiq.UIKit.Widgets.Models;
using Lombiq.UIKit.Widgets.Settings;
using OrchardCore.ContentManagement.Metadata;
using OrchardCore.ContentManagement.Metadata.Settings;
using OrchardCore.Data.Migration;
using OrchardCore.Flows.Models;
using OrchardCore.Media.Settings;
using OrchardCore.Title.Models;

namespace Lombiq.UIKit.Widgets.Migrations;

Expand All @@ -17,35 +19,33 @@ public class CarouselWidgetMigrations : DataMigration

public async Task<int> CreateAsync()
{
await _contentDefinitionManager.AlterPartDefinitionAsync<SlidePart>(
part =>
await _contentDefinitionManager.AlterPartDefinitionAsync<SlidePart>(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));

Expand Down
1 change: 1 addition & 0 deletions Lombiq.UIKit.Widgets/Models/CarouselWidgetPart.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using OrchardCore.ContentManagement;

namespace Lombiq.UIKit.Widgets.Models;

public class CarouselWidgetPart : ContentPart;
3 changes: 1 addition & 2 deletions Lombiq.UIKit.Widgets/Models/SlidePart.cs
Original file line number Diff line number Diff line change
@@ -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();
}
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -75,10 +75,10 @@
"CreatedUtc": null,
"Owner": "4d1m8j4trsk4px1att6bte204r",
"Author": "admin",
"TitlePart": {
"Text": "About"
},
"SlidePart": {
"Title": {
"Text": "About"
},
"Image": {
"Paths": [
"about-bg.jpg"
Expand All @@ -101,10 +101,10 @@
"CreatedUtc": null,
"Owner": "4d1m8j4trsk4px1att6bte204r",
"Author": "admin",
"TitlePart": {
"Text": "About"
},
"SlidePart": {
"Title": {
"Text": "Features"
},
"Image": {
"Paths": [
"meadow-orchard.jpg"
Expand All @@ -127,10 +127,10 @@
"CreatedUtc": null,
"Owner": "4d1m8j4trsk4px1att6bte204r",
"Author": "admin",
"TitlePart": {
"Text": "Support"
},
"SlidePart": {
"Title": {
"Text": "Support"
},
"Image": {
"Paths": [
"home-bg.jpg"
Expand All @@ -153,10 +153,10 @@
"CreatedUtc": null,
"Owner": "4d1m8j4trsk4px1att6bte204r",
"Author": "admin",
"TitlePart": {
"Text": "Modern"
},
"SlidePart": {
"Title": {
"Text": "Modern"
},
"Image": {
"Paths": [
"post-bg.jpg"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
using OrchardCore.DisplayManagement.Views;

namespace Lombiq.UIKit.Widgets.Settings;

public class CarouselWidgetPartSettingsDisplayDriver : ContentTypePartDefinitionDisplayDriver<CarouselWidgetPart>
{
public override IDisplayResult Edit(ContentTypePartDefinition model, BuildEditorContext context) =>
Initialize<CarouselWidgetPartSettingsViewModel>("CarouselWidgetPartSettings_Edit", viewModel =>
{
var settings = model.GetSettings<CarouselWidgetPartSettings>();

viewModel.Options = settings.Options;
viewModel.OptionsJsonSerialized = settings.OptionsJsonSerialized;
}).Location("Content");

public override async Task<IDisplayResult> UpdateAsync(ContentTypePartDefinition model, UpdateTypePartEditorContext context)
Expand All @@ -23,12 +24,12 @@ public override async Task<IDisplayResult> 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);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace Lombiq.UIKit.Widgets.Settings;

public class CarouselWidgetPartSettingsViewModel
{
public string? Options { get; set; }
public string? OptionsJsonSerialized { get; set; }
}
1 change: 1 addition & 0 deletions Lombiq.UIKit.Widgets/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using OrchardCore.Modules;

namespace Lombiq.UIKit.Widgets;

public sealed class Startup : StartupBase
{
public override void ConfigureServices(IServiceCollection services)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using OrchardCore.ContentManagement;

namespace Lombiq.UIKit.Widgets.ViewModels;

public class CarouselWidgetPartViewModel
{
[BindNever]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@using Lombiq.UIKit.Widgets.Settings
@using OrchardCore.ResourceManagement
@inject IResourceManager _resourceManager;
@inject IResourceManager _resourceManager

<style asp-name="codemirror"></style>
<script asp-name="codemirror"></script>
Expand All @@ -10,8 +10,8 @@

<div>
<div class="form-group">
<label asp-for="Options">@T["Options"]</label>
<textarea class="form-control" id="optionsEditor" asp-for="Options"></textarea>
<label asp-for="OptionsJsonSerialized">@T["JSON options"]</label>
<textarea class="form-control" id="optionsEditor" asp-for="OptionsJsonSerialized"></textarea>
<div class="hint">
@T[string.Format("Slick configuration. Check <a href=\"{0}\" target=\"_blank\">{0}</a> for more details.", "https://kenwheeler.github.io/slick/#settings")]
</div>
Expand Down
1 change: 0 additions & 1 deletion Lombiq.UIKit.Widgets/Views/Home/Index.cshtml

This file was deleted.

8 changes: 3 additions & 5 deletions Lombiq.UIKit.Widgets/Views/Widget-CarouselWidget.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
@using OrchardCore.DisplayManagement
@using OrchardCore.Flows.Models

@inject IContentDefinitionManager _contentDefinitionManager;
@inject IContentDefinitionManager _contentDefinitionManager

@{
var typeDefinition = await _contentDefinitionManager.GetTypeDefinitionAsync("CarouselWidget");
Expand All @@ -22,14 +22,12 @@
var bagItems = ((ContentItem)Model.ContentItem).As<BagPart>().ContentItems.Select(contentItem => contentItem.As<SlidePart>());
var items = new List<IShape>();

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;
}

<shape type="SlickCarousel"
AdditionalClasses="slickCarouselSample"
prop-Shapes="@items"
prop-MergeSettings="@carouselSettings"></shape>

</div>

0 comments on commit 2ce2a89

Please sign in to comment.