IComponentRenderCondition
Component render conditions are used by the "Conditional panel" component to determine if the content placed inside the conditional panel should be shown or not. The conditional panel takes in a list of IComponentRenderConditions and can be configured to be only shown when some or all applied render conditions are satisified. There are a few implementations included in the Lisa.Modules.StandardViewComponents module, such as the AuthenticatedUserCondition which is satisified when a user is authenticated (any or a specific user), the DataBindingContextValueCondition which is satisfied when a certain field in the DataBindingContext has a specific value and the IsCurrentPageRenderCondition which is satisfied if the user is on a certain page.
Interface declaration
public interface IComponentRenderCondition { bool ConditionSatisfied(RenderConditionContext context); string GetReason(RenderConditionContext context); }
Example
Here's the implementation of the IsCurrentPageRenderCondition which allows you to select a certain page and whether the condition should be satisified if the current page matches the selected page, or does not match the selected page.
[DisplayName("Current page condition")] [Description("Allows you to specify a page, and if the current page matches (or does not match) this page, the condition will be satisfied.")] public class IsCurrentPageRenderCondition : IComponentRenderCondition { [EditorBrowsable] [DisplayName("Page")] [Description("The page for which this condition will be satisfied")] [Editor(PropertyEditors.PageSelectionEditor, "")] public Guid? PageId { get; set; } [EditorBrowsable] [DisplayName("Comparison type")] [Description("Specifies whether the current page needs to match (or not match) the current page")] public RenderConditionComparisonType ComparisonType { get; set; } public bool ConditionSatisfied(RenderConditionContext context) { if (PageId.HasValue) { return ( (ComparisonType == RenderConditionComparisonType.Is && PageId.HasValue && PageId.Value == context.PageRequest.Page?.Id) || (ComparisonType == RenderConditionComparisonType.IsNot && PageId.HasValue && PageId.Value != context.PageRequest.Page?.Id) ); } // If no page has been specified, condition is satisfied return true; } public string GetReason(RenderConditionContext context) { if (PageId.HasValue) { if (ComparisonType == RenderConditionComparisonType.Is) { return string.Format("Page is {0}, needs to be {1}", context.PageRequest.Page.Id, PageId.Value); } else { return string.Format("Page is {0}, must not be {1}", context.PageRequest.Page?.Id, PageId.Value); } } return string.Empty; } }
Registration
This is how the implementation is registered into the DI container in Veva, this should be done in your module config file (The class which implements IModule).
public void ConfigureServices(IServiceCollection services, IConfiguration configuration) { services.AddNamed<IComponentRenderCondition, IsCurrentPageRenderCondition>(ServiceLifetime.Transient); }