Skip to content

Commit

Permalink
Merge pull request #20266 from abpframework/auto-merge/prerel-8-3/2817
Browse files Browse the repository at this point in the history
Merge branch dev with prerel-8.3
  • Loading branch information
maliming authored Jul 23, 2024
2 parents 1e92ee8 + a80df5f commit 17c1c92
Show file tree
Hide file tree
Showing 89 changed files with 10,984 additions and 262 deletions.
1 change: 1 addition & 0 deletions docs/en/Modules/Cms-Kit/Index.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ The following features are currently available:
* Provides a [**menu**](Menus.md) system to manage public menus dynamically.
* Provides a [**global resources**](Global-Resources.md) system to add global styles and scripts dynamically.
* Provides a [**Dynamic Widget**](Dynamic-Widget.md) system to create dynamic widgets for page and blog posts.
* Provides a [**Marked Item**](MarkedItems.md) system to mark any kind of resource, like a blog post or a product, as a favorite, starred, flagged, or bookmarked.

> You can click on the any feature links above to understand and learn how to use it.
Expand Down
123 changes: 123 additions & 0 deletions docs/en/Modules/Cms-Kit/MarkedItems.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
# Marked Item System

CMS kit provides a marking system to mark any kind of resource, like a blog post or a product, as a favorite, starred, flagged, or bookmarked.

Marked toggling component allows users to mark your items via pre-defined icons/emojis. Here how the marked toggling components may look like:

![markedItems](../../images/cmskit-module-markedItems.png)


you can also customize the marking icons shown in the toggling components.

## Enabling the Marked Item Feature

By default, CMS Kit features are disabled. Therefore, you need to enable the features you want, before starting to use it. You can use the [Global Feature](../../Global-Features.md) system to enable/disable CMS Kit features on development time. Alternatively, you can use the ABP Framework's [Feature System](https://docs.abp.io/en/abp/latest/Features) to disable a CMS Kit feature on runtime.

> Check the ["How to Install" section of the CMS Kit Module documentation](Index.md#how-to-install) to see how to enable/disable CMS Kit features on development time.
## Options

Marking system provides a simple approach to define your entity type with mark types like favorite or starred. For example, if you want to use the marking system for products, you need to define an entity type named `product` with the icon name.

`CmsKitMarkedItemOptions` can be configured in YourModule.cs, in the `ConfigureServices` method of your [module](https://docs.abp.io/en/abp/latest/Module-Development-Basics). Example:

```csharp
Configure<CmsKitMarkedItemOptions>(options =>
{
options.EntityTypes.Add(
new MarkedItemEntityTypeDefinition(
"product",
StandardMarkedItems.Favorite
)
);
});
```

`CmsKitMarkedItemOptions` properties:

- `EntityTypes`: List of defined entity types (`CmsKitMarkedItemOptions`) in the marking system.

`MarkedItemEntityTypeDefinition` properties:

- `EntityType`: Name of the entity type.
- `IconName`: The name of the icon.

## The Marked Item widget

The marking system provides a toggle widget to allow users to add/remove the marks from an item. You can place the widget with the item as shown below:

``` csharp
@await Component.InvokeAsync(typeof (MarkedItemToggleViewComponent), new
{
entityId = "...",
entityType = "product",
needsConfirmation = true // (optional)
})
```
* `entityType` was explained in the previous section.
* `entityId` should be the unique id of the product, in this example. If you have a Product entity, you can use its Id here.
* `needsConfirmation` An optional parameter to let the user confirm when removing the mark.

# Internals

## Domain Layer

#### Aggregates

This module follows the [Entity Best Practices & Conventions](https://docs.abp.io/en/abp/latest/Best-Practices/Entities) guide.

##### UserMarkedItem

A user markedItem represents a user has marking on the item.

- `UserMarkedItem` (aggregate root): Represents a marked item in the system.

#### Repositories

This module follows the [Repository Best Practices & Conventions](https://docs.abp.io/en/abp/latest/Best-Practices/Repositories) guide.

Following custom repositories are defined for this feature:

- `IUserMarkedItemRepository`


#### Domain services

This module follows the [Domain Services Best Practices & Conventions](https://docs.abp.io/en/abp/latest/Best-Practices/Domain-Services) guide.

##### Marked Item Manager

`MarkedItemManager` is used to perform some operations for the `UserMarkedItem` aggregate root.

### Application layer

#### Application services

- `MarkedItemPublicAppService` (implements `IMarkedItemPublicAppService`): Implements the use cases of marking system.

### Database providers

#### Common

##### Table / collection prefix & schema

All tables/collections use the `Cms` prefix by default. Set static properties on the `CmsKitDbProperties` class if you need to change the table prefix or set a schema name (if supported by your database provider).

##### Connection string

This module uses `CmsKit` for the connection string name. If you don't define a connection string with this name, it fallbacks to the `Default` connection string.

See the [connection strings](https://docs.abp.io/en/abp/latest/Connection-Strings) documentation for details.

#### Entity Framework Core

##### Tables

- CmsUserMarkedItems

#### MongoDB

##### Collections

- **CmsUserMarkedItems**

Binary file added docs/en/images/cmskit-module-markedItems.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
using Microsoft.AspNetCore.Http;
using Volo.Abp.DependencyInjection;
using Volo.CmsKit.Public.Pages;
using Volo.CmsKit.MarkedItems;


#if EntityFrameworkCore
Expand Down Expand Up @@ -234,6 +235,16 @@ private void ConfigureCmsKit()
{
options.EntityTypes.Add(new RatingEntityTypeDefinition("quote"));
});

Configure<CmsKitMarkedItemOptions>(options =>
{
options.EntityTypes.Add(
new MarkedItemEntityTypeDefinition(
"product",
StandardMarkedItems.Favorite
)
);
});
}

public override void OnApplicationInitialization(ApplicationInitializationContext context)
Expand Down
30 changes: 30 additions & 0 deletions modules/cms-kit/host/Volo.CmsKit.Web.Unified/Pages/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
@using Volo.CmsKit.GlobalFeatures
@using Volo.CmsKit.Pages
@using Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Commenting
@using Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.MarkedItemToggle
@using Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Rating
@using Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.ReactionSelection
@using Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Tags
Expand Down Expand Up @@ -118,3 +119,32 @@
}
</abp-column>
</abp-row>


<hr />
<abp-row>
@for (int i = 1; i <= 4; i++)
{
var name = $"Item {i}";
<abp-column>
<abp-card background="Light" text-color="Dark" border="Success" class="mb-3" style="max-width: 18rem;">
<abp-card-header class="d-flex justify-content-between">
<div>
Item
</div>
<div>
@await Component.InvokeAsync(typeof(MarkedItemToggleViewComponent), new
{
entityId = name,
entityType = "product",
needsConfirmation = true // (optional)
})
</div>
</abp-card-header>
<abp-card-body>
<abp-card-title>@name</abp-card-title>
</abp-card-body>
</abp-card>
</abp-column>
}
</abp-row>
4 changes: 4 additions & 0 deletions modules/cms-kit/src/Volo.CmsKit.Common.Web/CmsKitUiOptions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using JetBrains.Annotations;
using Volo.CmsKit.Web.MarkedItems;
using Volo.CmsKit.Web.Reactions;

namespace Volo.CmsKit.Web;
Expand All @@ -10,9 +11,12 @@ public class CmsKitUiOptions

public CmsKitUiCommentOptions CommentsOptions { get; }

public MarkedItemIconDictionary MarkedItemIcons { get; }

public CmsKitUiOptions()
{
ReactionIcons = new ReactionIconDictionary();
CommentsOptions = new CmsKitUiCommentOptions();
MarkedItemIcons = new MarkedItemIconDictionary();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System.Collections.Generic;
using Volo.Abp;

namespace Volo.CmsKit.Web.Icons;

public static class IconDictionaryHelper
{
public static string GetLocalizedIcon(
Dictionary<string, LocalizableIconDictionary> dictionary,
string name,
string cultureName = null)
{
var icon = dictionary.GetOrDefault(name);
if (icon == null)
{
throw new AbpException($"No icon defined for the item with name '{name}'");
}

return icon.GetLocalizedIconOrDefault(cultureName);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System.Collections.Generic;
using Volo.Abp;

namespace Volo.CmsKit.Web.Icons;

public class LocalizableIconDictionaryBase : Dictionary<string, LocalizableIconDictionary>
{
public string GetLocalizedIcon(string name, string cultureName = null)
{
var icon = this.GetOrDefault(name);
if (icon == null)
{
throw new AbpException($"No icon defined for the item with name '{name}'");
}

return icon.GetLocalizedIconOrDefault(cultureName);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
using Volo.CmsKit.Web.Icons;

namespace Volo.CmsKit.Web.MarkedItems;

public class MarkedItemIconDictionary : LocalizableIconDictionaryBase
{
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,7 @@
using System.Collections.Generic;
using Volo.Abp;
using Volo.CmsKit.Web.Icons;
using Volo.CmsKit.Web.Icons;

namespace Volo.CmsKit.Web.Reactions;

public class ReactionIconDictionary : Dictionary<string, LocalizableIconDictionary>
public class ReactionIconDictionary : LocalizableIconDictionaryBase
{
public string GetLocalizedIcon(string name, string cultureName = null)
{
var icon = this.GetOrDefault(name);
if (icon == null)
{
throw new AbpException($"No icon defined for the reaction with name '{name}'");
}

return icon.GetLocalizedIconOrDefault(cultureName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,11 @@ public static class MediaDescriptors
public const string InvalidName = "CmsKit:Media:0001";
public const string EntityTypeDoesntExist = "CmsKit:Media:0002";
}

public static class MarkedItems
{
public const string EntityCannotBeMarked = "CmsKit:MarkedItem:0001";
public const string MarkedItemDefinitionNotFound = "CmsKit:MarkedItem:0002";
public const string DuplicateMarkedItem = "CmsKit:MarkedItem:0003";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,15 @@ public override void Define(IFeatureDefinitionContext context)
L("Feature:TagEnableDescription"),
new ToggleStringValueType());
}

if (GlobalFeatureManager.Instance.IsEnabled<MarkedItemsFeature>())
{
group.AddFeature(CmsKitFeatures.MarkedItemEnable,
"true",
L("Feature:MarkedItemEnable"),
L("Feature:MarkedItemEnableDescription"),
new ToggleStringValueType());
}
}

private static LocalizableString L(string name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ public static class CmsKitFeatures
public const string RatingEnable = GroupName + ".RatingEnable";
public const string ReactionEnable = GroupName + ".ReactionEnable";
public const string TagEnable = GroupName + ".TagEnable";
public const string MarkedItemEnable = GroupName + ".MarkedItemEnable";
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public class GlobalCmsKitFeatures : GlobalModuleFeatures

public BlogPostScrollIndexFeature BlogPostScrollIndex => GetFeature<BlogPostScrollIndexFeature>();

public MarkedItemsFeature MarkedItemsFeature => GetFeature<MarkedItemsFeature>();

public GlobalCmsKitFeatures([NotNull] GlobalFeatureManager featureManager)
: base(featureManager)
{
Expand All @@ -43,5 +45,6 @@ public GlobalCmsKitFeatures([NotNull] GlobalFeatureManager featureManager)
AddFeature(new MenuFeature(this));
AddFeature(new GlobalResourcesFeature(this));
AddFeature(new BlogPostScrollIndexFeature(this));
AddFeature(new MarkedItemsFeature(this));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using JetBrains.Annotations;
using Volo.Abp.GlobalFeatures;

namespace Volo.CmsKit.GlobalFeatures;

[GlobalFeatureName(Name)]
public class MarkedItemsFeature : GlobalFeature
{
public const string Name = "CmsKit.MarkedItems";

internal MarkedItemsFeature(
[NotNull] GlobalCmsKitFeatures cmsKit
) : base(cmsKit)
{
}

public override void Enable()
{
var userFeature = FeatureManager.Modules.CmsKit().User;
if (!userFeature.IsEnabled)
{
userFeature.Enable();
}

base.Enable();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,17 @@
"CmsKit:Page:0001": "عنوان url المقدم ({Slug}) موجود بالفعل. يرجى المحاولة مع عنوان url مختلف.",
"CmsKit:Rating:0001": "لا يمكن تصنيف الكيان {EntityType}.",
"CmsKit:Reaction:0001": "لا يمكن أن يحتوي الكيان {EntityType} على ردود أفعال.",
"CmsKit:MarkedItem:0001": "لا يمكن أن تمييز الكيان {EntityType}.",
"CmsKit:MarkedItem:0002": "لم يتم العثور على تعريف لنوع الكيان '{EntityType}'.",
"CmsKit:MarkedItem:0003": "يوجد بالفعل تعريف لنوع الكيان '{EntityType}'. يجب أن يكون لكل نوع كيان تعريف واحد فقط.",
"CmsKit:Tag:0002": "الكيان غير قابل للوسم!",
"CommentAuthorizationExceptionMessage": "هذه التعليقات غير مسموح بها للعرض العام.",
"CommentDeletionConfirmationMessage": "سيتم حذف هذا التعليق وجميع الردود!",
"CmsKit:Modals:Login": "تسجيل الدخول",
"CmsKit:Modals:LoginModalDefaultMessage": "سجل الدخول لتتمكن من اجراء هذه العملية",
"CmsKit:Modals:YouAreNotAuthenticated": "انت غير مصرح",
"CmsKit:MarkedItem:LoginMessage": "الرجاء تسجيل الدخول لتحديد هذا العنصر.",
"CmsKit:MarkedItem:ToggleConfirmation": "هل أنت متأكد أنك تريد تغيير حالة العنصر المميز؟",
"Comments": "تعليقات",
"Content": "المحتوى",
"ContentDeletionConfirmationMessage": "هل أنت متأكد من حذف هذا المحتوى؟",
Expand Down Expand Up @@ -212,6 +220,8 @@
"Feature:RatingEnableDescription": "نظام تصنيف CMS Kit الذي يسمح للمستخدمين بتقييم الكيانات مثل BlogPost.",
"Feature:ReactionEnable": "رد فعل",
"Feature:ReactionEnableDescription": "نظام التفاعل الخاص بـ CMS Kit الذي يسمح للمستخدمين بإرسال ردود أفعال إلى كيانات مثل BlogPost، والتعليقات، وما إلى ذلك.",
"Feature:MarkedItemEnable": "تمييز العنصر",
"Feature:MarkedItemEnableDescription": "نظام التفاعل الخاص بـ CMS Kit الذي يسمح للمستخدمين بتمييز الكيانات كجعلها مفضلة.",
"Feature:TagEnable": "وضع العلامات",
"Feature:TagEnableDescription": "نظام علامات CMS Kit الذي يسمح بوضع علامات على الكيانات مثل BlogPost.",
"DeleteBlogPostMessage": "سيتم حذف المدونة. هل أنت متأكد؟",
Expand Down
Loading

0 comments on commit 17c1c92

Please sign in to comment.