pub struct Widget {
pub key: &'static str,
pub title: String,
pub kind: WidgetKind,
pub default_span: Span,
pub permission: Option<&'static str>,
pub data: WidgetDataFn,
pub default_period: Option<&'static str>,
pub filters: Vec<WidgetFilter>,
}Expand description
A registered dashboard widget.
Register via AdminPlugin::register_widget(...).
Fields§
§key: &'static strURL-safe unique key, e.g. "umbral_total_models".
title: StringHuman-readable title shown in the widget card header.
kind: WidgetKindDetermines which renderer (KPI card, chart, table, feed).
default_span: SpanDefault grid span when the user hasn’t customized.
permission: Option<&'static str>Optional permission codename. None = any staff user may see.
data: WidgetDataFnAsync function that computes and returns the payload.
default_period: Option<&'static str>Default period preset used by line/bar/etc. widgets that
carry a period-chip strip — "7d", "30d", "90d". When
Some, the handler pre-fills WidgetParams.period from
this value on first load (no ?period= in the URL), so
the matching chip renders highlighted AND the data
closure receives the same period via params.period_days().
None falls back to whatever the template / data closure
chooses as its fallback.
filters: Vec<WidgetFilter>Controls rendered in this widget’s header — see WidgetFilter.
Empty means no controls, with one compatibility exception: a
WidgetKind::Line with no declared filters still gets the historic
[7d][30d][90d] strip, because that strip used to be hardcoded in
line.html and removing it would silently strip controls from every
line chart already in the wild.
Implementations§
Source§impl Widget
impl Widget
Sourcepub fn new(
key: &'static str,
title: impl Into<String>,
kind: WidgetKind,
data: WidgetDataFn,
) -> Self
pub fn new( key: &'static str, title: impl Into<String>, kind: WidgetKind, data: WidgetDataFn, ) -> Self
Build a widget without naming every field.
Prefer this over a struct literal. Widget grows fields as the
dashboard grows (this is how filters arrived), and every new field
breaks every literal that spells out the old ones. Going through the
builder means the next field costs you nothing.
Widget::new("orders", "Orders", WidgetKind::Bar, data_fn)
.with_span(6, 2)
.filter(WidgetFilter::period_default())Sourcepub fn with_permission(self, codename: &'static str) -> Self
pub fn with_permission(self, codename: &'static str) -> Self
Gate the widget behind a permission codename.
Sourcepub fn filter(self, filter: WidgetFilter) -> Self
pub fn filter(self, filter: WidgetFilter) -> Self
Add one filter control to the widget header.
Sourcepub fn with_filters(
self,
filters: impl IntoIterator<Item = WidgetFilter>,
) -> Self
pub fn with_filters( self, filters: impl IntoIterator<Item = WidgetFilter>, ) -> Self
Replace the widget’s filters wholesale.
Sourcepub fn with_span(self, cols: u8, rows: u8) -> Self
pub fn with_span(self, cols: u8, rows: u8) -> Self
Override the default grid span. Lets a caller resize a builtin (or any pre-built widget) at registration time without having to re-construct the whole struct literal:
.register_widget(builtin_total_models_widget().with_span(6, 2))
.register_widget(builtin_recent_users_widget().with_span(6, 2))cols is clamped at the 12-col grid; rows is whatever
the dashboard’s auto-rows-[...] accepts (1 = 120px).
Sourcepub fn with_default_period(self, period: &'static str) -> Self
pub fn with_default_period(self, period: &'static str) -> Self
Pre-select a period chip on the widget — "7d", "30d",
"90d". On first load (no ?period= in the URL), the
handler stamps this into WidgetParams.period before
calling the data closure, so the chip strip highlights
the right preset AND the data fn computes the right
window. Override on a per-request basis happens via the
chip clicks (which send their own ?period= query).
shop_daily_sales_chart().with_default_period("7d")
// → first paint shows 7d highlighted, 7 days of data;
// clicking "30d" hands control to the URL state.Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Widget
impl !UnwindSafe for Widget
impl Freeze for Widget
impl Send for Widget
impl Sync for Widget
impl Unpin for Widget
impl UnsafeUnpin for Widget
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi Quirk value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();Source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
Source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);