172 lines
7.1 KiB
C#
172 lines
7.1 KiB
C#
using SlpModularCms.Core.Media;
|
|
|
|
namespace SlpModularCms.Modules.Hero.Data.Entities;
|
|
|
|
/// <summary>The hero of the site in one language: texts, up to two buttons, the display and the slides.</summary>
|
|
public class HeroContent
|
|
{
|
|
public Guid Id { get; set; }
|
|
|
|
/// <summary>Unique; only <see cref="HeroLanguages.Default"/> is exposed and edited now, the column keeps the model ready for more.</summary>
|
|
public string Language { get; set; } = HeroLanguages.Default;
|
|
|
|
public string Title { get; set; } = string.Empty;
|
|
public string? Tagline { get; set; }
|
|
public string? Lead { get; set; }
|
|
public string Display { get; set; } = HeroDisplays.Single;
|
|
public string? Button1Label { get; set; }
|
|
public string? Button1Target { get; set; }
|
|
public string? Button2Label { get; set; }
|
|
public string? Button2Target { get; set; }
|
|
public DateTimeOffset UpdatedAt { get; set; }
|
|
public Guid LastModifiedByUserId { get; set; }
|
|
|
|
public List<HeroSlide> Slides { get; set; } = [];
|
|
}
|
|
|
|
public class HeroSlide
|
|
{
|
|
public Guid Id { get; set; }
|
|
public Guid HeroId { get; set; }
|
|
public Guid ImageId { get; set; }
|
|
public HeroImage? Image { get; set; }
|
|
public string Alt { get; set; } = string.Empty;
|
|
public bool Decorative { get; set; }
|
|
public int SortOrder { get; set; }
|
|
public bool IsActive { get; set; } = true;
|
|
|
|
// The slide's OWN crop (phase 2, crop per use). All null = no override: the slide uses its photo's crop and set exactly
|
|
// as before. FocusX/FocusY/Zoom set = the slide has its own crop (the wide and tall overrides are optional on top).
|
|
public double? FocusX { get; set; }
|
|
public double? FocusY { get; set; }
|
|
public double? Zoom { get; set; }
|
|
public double? WideFocusX { get; set; }
|
|
public double? WideFocusY { get; set; }
|
|
public double? WideZoom { get; set; }
|
|
public double? TallFocusX { get; set; }
|
|
public double? TallFocusY { get; set; }
|
|
public double? TallZoom { get; set; }
|
|
|
|
/// <summary>The set cut for the slide's own crop; empty until it is complete (the photo's set stays live until then).</summary>
|
|
public string? SetHash { get; set; }
|
|
public List<HeroVariant>? Variants { get; set; }
|
|
|
|
/// <summary>True when the slide has a crop of its own.</summary>
|
|
public bool HasOwnCrop => FocusX is not null && FocusY is not null;
|
|
|
|
public void ClearOwnCrop()
|
|
{
|
|
(FocusX, FocusY, Zoom) = (null, null, null);
|
|
(WideFocusX, WideFocusY, WideZoom) = (null, null, null);
|
|
(TallFocusX, TallFocusY, TallZoom) = (null, null, null);
|
|
SetHash = null;
|
|
Variants = null;
|
|
}
|
|
}
|
|
|
|
/// <summary>A stored image: the original (never served), where the subject is, and the current set of variants.</summary>
|
|
public class HeroImage
|
|
{
|
|
public Guid Id { get; set; }
|
|
|
|
/// <summary>SHA-256 of the file as uploaded (hex); the same photo uploaded twice is one image.</summary>
|
|
public string OriginalSha256 { get; set; } = string.Empty;
|
|
public string OriginalKey { get; set; } = string.Empty;
|
|
public string SourceFormat { get; set; } = string.Empty;
|
|
public int Width { get; set; }
|
|
public int Height { get; set; }
|
|
public long Bytes { get; set; }
|
|
|
|
public double FocusX { get; set; } = 0.5;
|
|
public double FocusY { get; set; } = 0.5;
|
|
public double Zoom { get; set; } = 1.0;
|
|
public double? WideFocusX { get; set; }
|
|
public double? WideFocusY { get; set; }
|
|
public double? WideZoom { get; set; }
|
|
public double? TallFocusX { get; set; }
|
|
public double? TallFocusY { get; set; }
|
|
public double? TallZoom { get; set; }
|
|
|
|
public string SetHash { get; set; } = string.Empty;
|
|
public List<HeroVariant> Variants { get; set; } = [];
|
|
|
|
public DateTimeOffset CreatedAt { get; set; }
|
|
public Guid CreatedByUserId { get; set; }
|
|
|
|
/// <summary>The file name as uploaded (for display only, cleaned; never used as a path). Null for photos uploaded before it was stored.</summary>
|
|
public string? OriginalFileName { get; set; }
|
|
|
|
/// <summary>The moment the photo was last detached from a slide; null while it was never used. The clean-up counts from here (decision 8).</summary>
|
|
public DateTimeOffset? LastUsedAt { get; set; }
|
|
|
|
/// <summary>Set when the photo was moved to the trash; its files stay for <c>Media:TrashDays</c> and it is hidden from the hero.</summary>
|
|
public DateTimeOffset? DeletedAt { get; set; }
|
|
|
|
public FocusSetting General => new FocusSetting(FocusX, FocusY, Zoom).Normalize();
|
|
|
|
public FocusSetting FocusFor(string ratio) => ratio switch
|
|
{
|
|
"wide" when WideFocusX is not null && WideFocusY is not null => new FocusSetting(WideFocusX.Value, WideFocusY.Value, WideZoom ?? Zoom).Normalize(),
|
|
"tall" when TallFocusX is not null && TallFocusY is not null => new FocusSetting(TallFocusX.Value, TallFocusY.Value, TallZoom ?? Zoom).Normalize(),
|
|
_ => General,
|
|
};
|
|
}
|
|
|
|
/// <summary>
|
|
/// The same photo as <see cref="HeroImage"/>, always stored in <c>HeroImages</c>. Only used while the photos live in the
|
|
/// library (phase 3b): then <c>HeroImages</c> is kept up to date from the library rows so the switch can be turned back.
|
|
/// </summary>
|
|
public class LegacyHeroImage
|
|
{
|
|
public Guid Id { get; set; }
|
|
public string OriginalSha256 { get; set; } = string.Empty;
|
|
public string OriginalKey { get; set; } = string.Empty;
|
|
public string SourceFormat { get; set; } = string.Empty;
|
|
public int Width { get; set; }
|
|
public int Height { get; set; }
|
|
public long Bytes { get; set; }
|
|
public double FocusX { get; set; } = 0.5;
|
|
public double FocusY { get; set; } = 0.5;
|
|
public double Zoom { get; set; } = 1.0;
|
|
public double? WideFocusX { get; set; }
|
|
public double? WideFocusY { get; set; }
|
|
public double? WideZoom { get; set; }
|
|
public double? TallFocusX { get; set; }
|
|
public double? TallFocusY { get; set; }
|
|
public double? TallZoom { get; set; }
|
|
public string SetHash { get; set; } = string.Empty;
|
|
public List<HeroVariant> Variants { get; set; } = [];
|
|
public DateTimeOffset CreatedAt { get; set; }
|
|
public Guid CreatedByUserId { get; set; }
|
|
public string? OriginalFileName { get; set; }
|
|
public DateTimeOffset? LastUsedAt { get; set; }
|
|
public DateTimeOffset? DeletedAt { get; set; }
|
|
}
|
|
|
|
/// <summary>One file of the current set: the ratio, its pixel size, the type and the file name inside the set.</summary>
|
|
public record HeroVariant(string Ratio, int Width, int Height, string Type, string FileName, long Bytes);
|
|
|
|
/// <summary>A set or an original that nothing uses any more; the clean-up deletes it once the retention time has passed.</summary>
|
|
public class HeroRetiredFile
|
|
{
|
|
public Guid Id { get; set; }
|
|
|
|
/// <summary><c>set</c> (a set hash) or <c>original</c> (an original key).</summary>
|
|
public string Kind { get; set; } = string.Empty;
|
|
public string Key { get; set; } = string.Empty;
|
|
public DateTimeOffset RetiredAt { get; set; }
|
|
}
|
|
|
|
public static class HeroLanguages
|
|
{
|
|
public const string Default = "nl";
|
|
}
|
|
|
|
public static class HeroDisplays
|
|
{
|
|
public const string Single = "single";
|
|
public const string Slideshow = "slideshow";
|
|
|
|
public static bool IsValid(string? value) => value is Single or Slideshow;
|
|
}
|