List module
The List module allows you to manage items by showing the elements in a list.
To activate a section with a List module, the settings in the relevant section must be configured by specifying the type of DataWeb element that defines the item.
The List module supports custom actions on both the individual item and the filter.
The module can be used with the DataWeb configuration only but, if necessary, it can be customized in all its functions by setting a class inherited from the base ModuleList and overwriting the methods concerned. The new class is set in the relevant settings in DataWeb.
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Threading;
using Microsoft.Extensions.DependencyInjection;
using DataWeb.Structure;
using DataWeb.Structure.Modules;
using DataWeb.Identity;
using DataWeb.Data;
namespace App.DataWeb.Structure.Modules
{
public class ModuleProductList(Section section, NavigationContext navigationContext, IServiceProvider serviceProvider) : ModuleList(section, navigationContext, serviceProvider)
{
private readonly IContextActionService contextActionService = serviceProvider.GetService<IContextActionService>();
public override async Task<List<ContextAction>> GetActionsAsync(CancellationToken cancellationToken = default)
{
var actions = await base.GetActionsAsync(cancellationToken);
actions.Add(contextActionService.GetRemoteAction("Notify status", "FilteredItemsNotify", ContextActionType.Notification, context: "FilteredItems", isConfirmRequired: true, isReloadAfterProcess: true, isSaveItemBeforeProcess: true));
actions.Add(contextActionService.GetRemoteAction("Notify status item", "SelectedItemsNotify", ContextActionType.Tool, context: "SelectedItems"));
actions.Add(contextActionService.GetRemoteAction("Set product status", "SelectedItemsSetProductStatus", ContextActionType.Dialog, context: "SelectedItems", dialogFormName: "Form_ActionProductStatus", isConfirmRequired: true, isReloadAfterProcess: true));
return actions;
}
public override async Task<ContextAction.Result> ProcessActionAsync(ContextAction action, IUser user, List<string> itemIdMasters = null, List<Form.ProvidedValue> controlValues = null, NavigationContext navigationContext = null, CancellationToken cancellationToken = default)
{
var result = await base.ProcessActionAsync(action, user, itemIdMasters, controlValues, navigationContext, cancellationToken);
switch (action.Name)
{
case "FilteredItemsNotify":
case "SelectedItemsNotify":
result = NotifyStatus();
break;
case "SelectedItemsSetProductStatus":
result = new ContextAction.Result { IsValid = true };
break;
}
return result;
}
public ContextAction.Result NotifyStatus()
{
var result = new ContextAction.Result { IsValid = true };
return result;
}
}
}
In this example, we are integrating custom actions on both items and filtering.
This table can be used as a reference to identify areas of the ModuleList base class that can be customized by creating a derived class.
Method | Description | Possible customization |
---|---|---|
GetDataAsync | Retrieve form data, including fields, widgets, layouts, search, pagination, and actions. | Overwritable to change data loading behavior, add custom logic for specific filters, layouts, or actions. |
GetDeferredDataAsync | Retrieves "deferred" data for specified items, using input parameters. | Overwritable to handle complex asynchronous loads or to change how deferred data is retrieved. |
GetSearchSuggestionsAsync | It provides search suggestions based on filters and user input. | Customizable to add advanced suggestions or to manage specific rules for custom fields. |
SetLayoutAsync | Update the layout of the form (e.g. "Table" or "Card" mode). | Overwritable to add specific logic in layout management (e.g. custom mode). |
SetSearchAsync | Update the form's search filters based on the values provided by the user. | Customizable to handle complex filters, with support for custom validations or additional fields. |
SetPageIndexAsync | Updates the pagination index for the data list. | Overridable to change the behavior of navigation between pages or to add specific controls on the index. |
SetOrderByAsync | Change the sort settings for the form (field and mode). | Overridable to implement advanced sorting logic or to support new fields. |
GetActionsAsync | Retrieves the list of available actions, including export if enabled. | Overwritable to add custom actions or remove existing ones based on specific scenarios. |
ProcessActionAsync | Manages the execution of defined actions, such as exporting filtered or selected items. | Customizable to implement custom logic for actions, such as specific exports or custom processes. |
ProcessExportAsync | Process the export of items to an Excel file. | Overwritable to change the export format, add extra fields, or customize the organization of exported data. |
IsCompletedAsync | Determine whether an item is "completed" based on custom criteria. | Overwritable to define custom rules that establish the completion status of an item. |
CloneAsync | Clone a specific item. | Overwritable to add custom logic when cloning an item, such as changes to the clone data. |
ProcessOnItemDeleteAsync | Executed when an item is deleted, it allows extra logic to be added during deletion. | Overwritable to handle specific logic such as logs, notifications, or deletion-related updates. |
ProcessOnItemSetStatusAsync | Executed when the state of an item changes, it allows you to add custom logic for the state change. | Overwritable to handle extra updates, such as syncs or notifications, when an item's status changes. |
ProcessOnItemCloneAsync | Executed after cloning an item, it allows you to add extra logic after the cloning process. | Overwritable to implement specific changes to the clone data or to perform additional actions (e.g. updating relationships). |
ProcessOnItemMoveAsync | Executed when an item is moved, it allows you to add custom logic for the item's movement. | Overwritable to modify or update the data associated with the item during movement (e.g. updating references or dependencies). |
GetContextItemsAsync | Retrieve items for the list, applying filters, sorting, and pagination. | Overwritable to change how items are retrieved or to add specific logic for loading data. |
ProcessExportAsync | Generates an Excel file with the data of the exported items. | Customizable to handle file formatting, adding custom columns, or changes in exported data. |
The GetContextItemsAsync method can be used in various contexts to quickly retrieve both filtered and selected items (specifying the IdMasters of the items involved via itemIds). For example:
public override async Task<ContextAction.Result> ProcessActionAsync(ContextAction action, IUser user, List<string> itemIds = null, List<Form.ProvidedValue> controlValues = null, NavigationContext navigationContext = null, CancellationToken cancellationToken = default)
{
var result = await base.ProcessActionAsync(action, user, itemIds, controlValues, navigationContext, cancellationToken);
var step = navigationContext.Steps.Last();
switch (action.Name)
{
case "FilteredItemsExport":
var filteredContextItems = (await GetContextItemsAsync(cancellationToken: cancellationToken)).ContextItems;
result = new ContextAction.Result { IsValid = true, Stream = await ProcessExportAsync(filteredContextItems, cancellationToken), FileName = string.Format("{0}.xlsx", step.Section.Title), ContentType = "application/vnd.ms-excel" };
break;
case "SelectedItemsExport":
if (itemIds == null || itemIds.Count == 0)
{
return new ContextAction.Result { IsValid = false, Error = new Validation.ValidationError { Name = "ActionName", Message = "items are required" } };
}
var selectedContextItems = (await GetContextItemsAsync(itemIdMasters: itemIds, cancellationToken: cancellationToken)).ContextItems;
result = new ContextAction.Result { IsValid = true, Stream = await ProcessExportAsync(selectedContextItems, cancellationToken), FileName = string.Format("{0}.xlsx", step.Section.Title), ContentType = "application/vnd.ms-excel" };
break;
}
return result;
}