Class BadgeDef
juneau-badges.js.
The endpoint returns {total, mine?, items?[]}. The badge is presentation only: the endpoint must
still authorize the caller, and a page should not declare a badge for users who cannot read it.
Example:
- Since:
- 10.0.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumplacementwire tokens.static enumscope.bywire tokens.static enumtonewire tokens. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final longDefault poll interval, in milliseconds, applied byjuneau-badges.jswhenrefreshMsis unset.static final intDefault tooltip item cap, applied byjuneau-badges.jswhentooltipMaxis unset.static final longThe minimum poll interval, in milliseconds (refreshMs.minimum). -
Method Summary
Modifier and TypeMethodDescriptionstatic BadgeDefCreates a badge with the given id.Sets the click-target URL.Sets this badge's label templates.Sets extra request parameters merged into every poll (ahead of the scope params).placement(BadgeDef.Placement value) Sets where this badge renders.Sets the card ids toJuneauViews.tables.reload(el, {resetPaging: false})when a previously-seen item id drains from the badge's response.refreshesAllowMissing(String... value) Sets card ids, added torefreshes, that are allowed to be absent from the page being rendered.refreshMs(long intervalMs) Sets the poll interval.Sets this badge's scope: the request param to key the poll on, how to resolve its value, and (optionally) the authoritative value map.Sets the same-origin endpoint this badge polls.stateFilter(String column) Sets the columnhref's destination page filters on, viaJuneauViews.urlState.encode(...).Sets the card id this badge is anchored to.Serializes this definition to the compact JSON theheader.badges[]contract carries, hand-built (rather than reflected) so the key set and order match the schema exactly.tone(BadgeDef.Tone value) Sets this badge's tone.tooltipMax(int value) Sets the tooltip popover's item cap.voidvalidate()Validates this definition.visibleWhen(VisibilityRule... value) Sets the dynamic-visibility rules gating this badge; all must match (AND).
-
Field Details
-
MIN_REFRESH_MS
The minimum poll interval, in milliseconds (refreshMs.minimum).- See Also:
-
DEFAULT_REFRESH_MS
Default poll interval, in milliseconds, applied byjuneau-badges.jswhenrefreshMsis unset.- See Also:
-
DEFAULT_TOOLTIP_MAX
Default tooltip item cap, applied byjuneau-badges.jswhentooltipMaxis unset.- See Also:
-
-
Method Details
-
create
Creates a badge with the given id.- Parameters:
id- This badge's own id, unique across every Java- and FTL-declared badge on the page (C3 E-B15). Must not benull or blank.- Returns:
- A new
BadgeDef. - Throws:
IllegalArgumentException- Ifidisnull or blank.
-
src
Sets the same-origin endpoint this badge polls.- Parameters:
value- The endpoint path. Checked byvalidate(): present (E-61) and a same-origin path perSafePathTemplate.isSameOriginPath(String).- Returns:
- This object.
-
params
Sets extra request parameters merged into every poll (ahead of the scope params).- Parameters:
value- The parameters.- Returns:
- This object.
-
refreshMs
Sets the poll interval.- Parameters:
intervalMs- The desired interval, in milliseconds. Checked againstMIN_REFRESH_MSbyvalidate()(E-62) — unlikeRegionDef.refreshMs(long), this is rejected, not clamped.- Returns:
- This object.
-
scope
Sets this badge's scope: the request param to key the poll on, how to resolve its value, and (optionally) the authoritative value map.- Parameters:
param- The query parameter name sent with the poll. Must not benull or blank.by-BadgeDef.ScopeBy.NAVorBadgeDef.ScopeBy.VIEW.values- The authoritative value map, keyed by nav-leaf or view-tab id, ornull for an unscoped badge that still carries aby.- Returns:
- This object.
-
label
Sets this badge's label templates.- Parameters:
value- A map with any of the keysone,other,mine, each a{total}/{mine}template. Unset keys fall back to the stock defaults injuneau-badges.js.- Returns:
- This object.
-
tooltipMax
Sets the tooltip popover's item cap.- Parameters:
value- The cap, 0-50. Not range-checked here; schema `$defs/badge.tooltipMax` enforces it for FTL-declared badges, and an out-of-range Java value is simply clamped byjuneau-badges.jsat render time.- Returns:
- This object.
-
href
Sets the click-target URL.- Parameters:
value- The destination. Must be a same-origin path perSafePathTemplate.isSameOriginPath(String);validate()rejects anything else, andjuneau-badges.jsrefuses an unsafehrefagain at run time (E-JS-82).- Returns:
- This object.
-
stateFilter
Sets the columnhref's destination page filters on, viaJuneauViews.urlState.encode(...). Requires a non-emptyscope(java.lang.String, org.apache.juneau.console.views.BadgeDef.ScopeBy, java.util.Map<java.lang.String, java.util.List<java.lang.String>>)to have any effect.- Parameters:
column- The destination table's filter column name.- Returns:
- This object.
-
refreshes
Sets the card ids toJuneauViews.tables.reload(el, {resetPaging: false})when a previously-seen item id drains from the badge's response.Every id here must name a card on the page being rendered, unless it is also listed in
refreshesAllowMissing(String...).- Parameters:
value- The card ids, in reload order.- Returns:
- This object.
-
refreshesAllowMissing
Sets card ids, added torefreshes, that are allowed to be absent from the page being rendered.A page normally rejects a
refreshesid that names no card on it, which catches typos at build time. Use this for a header badge that refreshes a card living on another page: the client skips a card that is not mounted. The ids named here are exempt from that check; every id passed torefreshesstays strict. The name follows therefreshes/stateFilternoun style of this builder: the opt-in is per id, not a page-wide switch.- Parameters:
value- The card ids that may live on another page.- Returns:
- This object.
-
placement
Sets where this badge renders.- Parameters:
value-BadgeDef.Placement.HEADER(default) orBadgeDef.Placement.TOOLBAR.- Returns:
- This object.
-
table
Sets the card id this badge is anchored to. Required whenplacementisBadgeDef.Placement.TOOLBAR(E-66) and whenscope(java.lang.String, org.apache.juneau.console.views.BadgeDef.ScopeBy, java.util.Map<java.lang.String, java.util.List<java.lang.String>>)'sbyisBadgeDef.ScopeBy.VIEW(uncoded).- Parameters:
value- The card id.- Returns:
- This object.
-
tone
Sets this badge's tone.- Parameters:
value-BadgeDef.Tone.INFO,BadgeDef.Tone.WARNING(default) orBadgeDef.Tone.DANGER.- Returns:
- This object.
-
visibleWhen
Sets the dynamic-visibility rules gating this badge; all must match (AND).- Parameters:
value- The rules, or none for an always-visible badge.- Returns:
- This object.
-
validate
Validates this definition.Enforces E-61 (no
src), a same-originsrcandhref, E-62 (refreshMsbelowMIN_REFRESH_MS), E-66 (BadgeDef.Placement.TOOLBARwithouttable), and the view-scope rule (uncoded:BadgeDef.ScopeBy.VIEWwithouttable). The "table/refreshes name a real card id" rule and the "scope.values key is a real nav node id" need the rest of the page and run inPageCaptureat</@console>instead.- Throws:
IllegalArgumentException- If this definition is not well-formed.
-
toContractMap
Serializes this definition to the compact JSON theheader.badges[]contract carries, hand-built (rather than reflected) so the key set and order match the schema exactly.- Returns:
- An ordered
Mapready forJson.of(...).
-