Merge pull request #3602 from leigh-pointer/ENH#3538-PgModDateActive

Start Date and Expiry Date for Module instances and Pages #3538
This commit is contained in:
Shaun Walker
2024-01-05 12:09:19 -05:00
committed by GitHub
18 changed files with 424 additions and 156 deletions

View File

@ -75,10 +75,16 @@ namespace Oqtane.Models
[NotMapped]
public string ContainerType { get; set; }
[NotMapped]
public DateTime? EffectiveDate { get; set; }
[NotMapped]
public DateTime? ExpiryDate { get; set; }
#endregion
#region SiteRouter properties
[NotMapped]
public string ModuleType { get; set; }
[NotMapped]

View File

@ -82,6 +82,14 @@ namespace Oqtane.Models
public bool IsNavigation { get; set; }
public bool IsClickable { get; set; }
public int? UserId { get; set; }
/// <summary>
/// Start of when this assignment is valid. See also <see cref="ExpiryDate"/>
/// </summary>
public DateTime? EffectiveDate { get; set; }
/// <summary>
/// End of when this assignment is valid. See also <see cref="EffectiveDate"/>
/// </summary>
public DateTime? ExpiryDate { get; set; }
public bool IsPersonalizable { get; set; }
#region IDeletable Properties

View File

@ -41,7 +41,14 @@ namespace Oqtane.Models
/// Reference to a Razor Container which wraps this module instance.
/// </summary>
public string ContainerType { get; set; }
/// <summary>
/// Start of when this assignment is valid. See also <see cref="ExpiryDate"/>
/// </summary>
public DateTime? EffectiveDate { get; set; }
/// <summary>
/// End of when this assignment is valid. See also <see cref="EffectiveDate"/>
/// </summary>
public DateTime? ExpiryDate { get; set; }
#region IDeletable Properties
public string DeletedBy { get; set; }

View File

@ -572,7 +572,55 @@ namespace Oqtane.Shared
return (localDateTime?.Date, localTime);
}
public static bool IsPageModuleVisible(DateTime? effectiveDate, DateTime? expiryDate)
{
DateTime currentUtcTime = DateTime.UtcNow;
if (effectiveDate.HasValue && expiryDate.HasValue)
{
return currentUtcTime >= effectiveDate.Value && currentUtcTime <= expiryDate.Value;
}
else if (effectiveDate.HasValue)
{
return currentUtcTime >= effectiveDate.Value;
}
else if (expiryDate.HasValue)
{
// Include equality check here
return currentUtcTime <= expiryDate.Value;
}
else
{
return true;
}
}
public static bool ValidateEffectiveExpiryDates(DateTime? effectiveDate, DateTime? expiryDate)
{
// Treat DateTime.MinValue as null
effectiveDate ??= DateTime.MinValue;
expiryDate ??= DateTime.MinValue;
// Check if both effectiveDate and expiryDate have values
if (effectiveDate != DateTime.MinValue && expiryDate != DateTime.MinValue)
{
return effectiveDate <= expiryDate;
}
// Check if only effectiveDate has a value
else if (effectiveDate != DateTime.MinValue)
{
return true;
}
// Check if only expiryDate has a value
else if (expiryDate != DateTime.MinValue)
{
return true;
}
// If neither effectiveDate nor expiryDate has a value, consider the page/module visible
else
{
return true;
}
}
[Obsolete("ContentUrl(Alias alias, int fileId) is deprecated. Use FileUrl(Alias alias, int fileId) instead.", false)]
public static string ContentUrl(Alias alias, int fileId)
{