pub struct WidgetFilter {
pub key: String,
pub label: String,
pub kind: WidgetFilterKind,
pub default: Option<String>,
pub active: Option<String>,
pub active_start: Option<String>,
pub active_end: Option<String>,
pub carry: String,
pub carry_lead: String,
}Expand description
A control the admin renders in a widget’s header, declared at registration time and rendered for every widget kind.
Before this existed the only filter in the admin was a [7d][30d][90d] chip
strip hardcoded inside line.html, which meant a bar chart or a table could
not be filtered at all, and no widget could offer anything but a period. A
filter is now data: the widget declares it, the admin renders it, and the
value arrives in WidgetParams.
Widget::new("orders_by_status", "Orders", WidgetKind::Bar, data_fn)
.filter(WidgetFilter::period_default())
.filter(WidgetFilter::choice("status", "Status", [
("open", "Open"), ("paid", "Paid"),
]))The chosen value is sticky per user: picking one persists to the user’s admin preferences, so it survives a reload the same way a period chip does.
Fields§
§key: StringQuery-parameter name. "period" for a period filter, "start"/"end"
are implied by a date range, anything else for a choice.
label: StringLabel shown beside the control.
kind: WidgetFilterKindWhich control to render.
default: Option<String>Value selected when the user has never touched this filter.
active: Option<String>Resolved value for THIS request — URL, else the user’s saved choice,
else default. Filled in by the handler; ignored at registration.
active_start: Option<String>Resolved range ends, for a WidgetFilterKind::DateRange only.
Filled in by the handler; ignored at registration.
active_end: Option<String>§carry: StringQuery-string fragment carrying every OTHER filter’s current value, e.g.
"&status=paid&period=7d". Filled in by the handler.
It lives here, computed in Rust, because the alternative was assembling
it in the template with split/trim gymnastics — and a control that
gets this wrong silently resets its neighbours the moment you touch it.
carry_lead: StringThe same fragment without the leading &, for a control that starts the
query string rather than appending to one (a <select> whose own value
htmx appends via hx-include).
Implementations§
Source§impl WidgetFilter
impl WidgetFilter
Sourcepub fn period_default() -> Self
pub fn period_default() -> Self
The conventional [7d] [30d] [90d] strip — what line.html hardcoded.
Sourcepub fn date_range() -> Self
pub fn date_range() -> Self
A start/end date pair. Reaches the closure as params.start / params.end,
which take precedence over period when both are present.
Sourcepub fn choice<I, V, L>(
key: impl Into<String>,
label: impl Into<String>,
options: I,
) -> Self
pub fn choice<I, V, L>( key: impl Into<String>, label: impl Into<String>, options: I, ) -> Self
A <select> writing ?<key>=. Read it back with params.choice(key).
Sourcepub fn with_default(self, value: impl Into<String>) -> Self
pub fn with_default(self, value: impl Into<String>) -> Self
Pre-select a value on first paint.
Sourcepub fn active_value(&self) -> Option<&str>
pub fn active_value(&self) -> Option<&str>
The value in force for this request.
Trait Implementations§
Source§impl Clone for WidgetFilter
impl Clone for WidgetFilter
Source§fn clone(&self) -> WidgetFilter
fn clone(&self) -> WidgetFilter
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for WidgetFilter
impl Debug for WidgetFilter
Source§impl<'de> Deserialize<'de> for WidgetFilter
impl<'de> Deserialize<'de> for WidgetFilter
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for WidgetFilter
impl RefUnwindSafe for WidgetFilter
impl Send for WidgetFilter
impl Sync for WidgetFilter
impl Unpin for WidgetFilter
impl UnsafeUnpin for WidgetFilter
impl UnwindSafe for WidgetFilter
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<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
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);