feat(pages): card sections, CTA band, section looks and optional hero image in services-counter
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFUzfiCVCgCVJZq4NDEqZs
This commit is contained in:
1 parent
2ff117e41d
commit
cc962ebfcf
6 files changed
+234
-5
No files matched your search
+5
-1
@@ -11,7 +11,8 @@ import java.util.List;
|
||||
/**
|
||||
* One landing-page block. Which fields apply depends on {@code type}:
|
||||
* HERO (imageId, heading, text, button), RICH_TEXT (html), IMAGE_TEXT (imageId, imagePosition, heading, html, button),
|
||||
* FAQ (heading, items), FORM (heading, eventUuid).
|
||||
* FAQ (heading, items), FORM (heading, eventUuid), HTML (html), FEATURES (heading, text, cards), STEPS (heading, cards),
|
||||
* TRUST (cards), CTA (heading, text, button). Any block may carry anchor and look.
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@@ -27,7 +28,10 @@ public class CmsBlock {
|
||||
private String buttonUrl;
|
||||
/** Optional link name: the block's id on the public page, the target of a #name link (add-page-anchor-links). */
|
||||
private String anchor;
|
||||
/** DEFAULT (or absent), MUTED, DARK or ACCENT (add-page-sections). */
|
||||
private String look;
|
||||
private List<CmsFaqItem> items;
|
||||
private List<CmsCard> cards;
|
||||
/** A Snowflake value beyond JavaScript number precision: written as a string, read from either. */
|
||||
@JsonSerialize(using = ToStringSerializer.class)
|
||||
private Long eventUuid;
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.solvway.services.counter.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
|
||||
/** One card of a FEATURES (icon, title, text), STEPS (title, text) or TRUST (title) block (add-page-sections). */
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public record CmsCard(String icon, String title, String text) {}
|
||||
+68
-1
@@ -1,6 +1,7 @@
|
||||
package com.solvway.services.counter.service;
|
||||
|
||||
import com.solvway.services.counter.dto.CmsBlock;
|
||||
import com.solvway.services.counter.dto.CmsCard;
|
||||
import com.solvway.services.counter.dto.CmsFaqItem;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.web.server.ResponseStatusException;
|
||||
@@ -16,12 +17,17 @@ import java.util.regex.Pattern;
|
||||
* Co-Lite changes: images are uploaded ids of the page's company, FORM points at an event of that company,
|
||||
* buttons may also use mailto: and tel:, and rich-text HTML holding scripts is refused (the public page sanitises as well).
|
||||
* The HTML block (custom HTML) is exempt from the script check: it is served only inside a sandboxed frame.
|
||||
* add-page-sections adds FEATURES, STEPS, TRUST and CTA, a look on any block, and makes the HERO image optional.
|
||||
* Throws 422 on the first violation, with the reason "path|MessageCode".
|
||||
*/
|
||||
public final class CmsBlockValidator {
|
||||
private static final int MAX_BLOCKS = 30;
|
||||
/** A block link name (add-page-anchor-links); a same-page link is "#" plus one. "reg-" is the sign-up form's own ids. */
|
||||
static final Pattern ANCHOR = Pattern.compile("(?!reg-)[a-z0-9][a-z0-9-]{0,39}");
|
||||
/** Section looks and feature icons (add-page-sections). */
|
||||
private static final Set<String> LOOKS = Set.of("DEFAULT", "MUTED", "DARK", "ACCENT");
|
||||
static final Set<String> ICONS = Set.of("wifi", "phone", "tv", "monitor", "lock", "shield-check", "cloud", "wrench", "headset", "users", "calendar", "star");
|
||||
private static final Set<String> CARD_TYPES = Set.of("FEATURES", "STEPS", "TRUST");
|
||||
private static final Pattern SCRIPT = Pattern.compile("(?i)<\\s*script|\\son[a-z]+\\s*=|javascript\\s*:");
|
||||
|
||||
private CmsBlockValidator() {
|
||||
@@ -50,9 +56,17 @@ public final class CmsBlockValidator {
|
||||
throw refuse(path + ".anchor", "PagesAnchorTaken");
|
||||
}
|
||||
}
|
||||
if (b.getLook() != null && !LOOKS.contains(b.getLook())) {
|
||||
throw refuse(path + ".look", "PagesBadLook");
|
||||
}
|
||||
if (b.getCards() != null && !CARD_TYPES.contains(b.getType())) {
|
||||
throw refuse(path + ".cards", "PagesUnusedField");
|
||||
}
|
||||
switch (b.getType()) {
|
||||
case "HERO" -> {
|
||||
image(b, path, ownImage);
|
||||
if (b.getImageId() != null) {
|
||||
image(b, path, ownImage);
|
||||
}
|
||||
required(b.getHeading(), path + ".heading");
|
||||
max(b.getHeading(), path + ".heading", 120);
|
||||
max(b.getText(), path + ".text", 300);
|
||||
@@ -80,6 +94,30 @@ public final class CmsBlockValidator {
|
||||
throw refuse(path + ".eventUuid", "PagesBadEvent");
|
||||
}
|
||||
}
|
||||
case "FEATURES" -> {
|
||||
required(b.getHeading(), path + ".heading");
|
||||
max(b.getHeading(), path + ".heading", 120);
|
||||
max(b.getText(), path + ".text", 300);
|
||||
cards(b, path, true, true);
|
||||
}
|
||||
case "STEPS" -> {
|
||||
required(b.getHeading(), path + ".heading");
|
||||
max(b.getHeading(), path + ".heading", 120);
|
||||
cards(b, path, false, true);
|
||||
}
|
||||
case "TRUST" -> {
|
||||
if (b.getHeading() != null) {
|
||||
throw refuse(path + ".heading", "PagesUnusedField");
|
||||
}
|
||||
cards(b, path, false, false);
|
||||
}
|
||||
case "CTA" -> {
|
||||
required(b.getHeading(), path + ".heading");
|
||||
max(b.getHeading(), path + ".heading", 120);
|
||||
max(b.getText(), path + ".text", 300);
|
||||
required(b.getButtonLabel(), path + ".buttonLabel");
|
||||
button(b, path);
|
||||
}
|
||||
default -> throw refuse(path + ".type", "PagesUnknownType");
|
||||
}
|
||||
}
|
||||
@@ -131,6 +169,35 @@ public final class CmsBlockValidator {
|
||||
}
|
||||
}
|
||||
|
||||
/** 2 to 6 cards; an icon from the list where the type uses one, a title (80), a text (300) where used, nothing else. */
|
||||
private static void cards(CmsBlock b, String path, boolean icon, boolean text) {
|
||||
List<CmsCard> cards = b.getCards();
|
||||
if (cards == null || cards.size() < 2 || cards.size() > 6) {
|
||||
throw refuse(path + ".cards", "PagesCardCount");
|
||||
}
|
||||
for (int i = 0; i < cards.size(); i++) {
|
||||
CmsCard card = cards.get(i);
|
||||
String cardPath = path + ".cards[" + i + "]";
|
||||
if (card == null) {
|
||||
throw refuse(cardPath + ".title", "PagesRequired");
|
||||
}
|
||||
if (icon && (card.icon() == null || !ICONS.contains(card.icon()))) {
|
||||
throw refuse(cardPath + ".icon", "PagesBadIcon");
|
||||
}
|
||||
if (!icon && card.icon() != null) {
|
||||
throw refuse(cardPath + ".icon", "PagesUnusedField");
|
||||
}
|
||||
required(card.title(), cardPath + ".title");
|
||||
max(card.title(), cardPath + ".title", 80);
|
||||
if (text) {
|
||||
required(card.text(), cardPath + ".text");
|
||||
max(card.text(), cardPath + ".text", 300);
|
||||
} else if (card.text() != null) {
|
||||
throw refuse(cardPath + ".text", "PagesUnusedField");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void button(CmsBlock b, String path) {
|
||||
boolean hasLabel = b.getButtonLabel() != null && !b.getButtonLabel().isBlank();
|
||||
boolean hasUrl = b.getButtonUrl() != null && !b.getButtonUrl().isBlank();
|
||||
|
||||
Reference in new issue
Block a user