pub struct AdminAction<M> { /* private fields */ }Expand description
An action of a resource’s list (Filament’s bulk actions): a button over
the selected rows that runs run with their records and shows the
toast it returns. With row, each row’s menu has it too.
use renox_admin::AdminAction;
let deactivate = AdminAction::new("deactivate", "Deactivate", |products: Vec<Product>, cx| async move {
let ids: Vec<i64> = products.iter().map(|p| p.id).collect();
let n = Product::query().where_in("id", ids).update(&cx.state.db, &[("active", &false)]).await?;
Ok(Toast::success(format!("{n} products deactivated.")))
})
.confirm("Deactivate the selected products?")
.row();Every record must pass AdminResource::allows for the action’s
ability (update by default), or nothing runs (403).
Implementations§
Source§impl<M: Send + 'static> AdminAction<M>
impl<M: Send + 'static> AdminAction<M>
Sourcepub fn new<F, Fut>(key: &str, label: &str, run: F) -> Self
pub fn new<F, Fut>(key: &str, label: &str, run: F) -> Self
An action named key (letters, digits, _ and -; part of its
address), shown as label, that runs run.
Sourcepub fn ability(self, ability: &str) -> Self
pub fn ability(self, ability: &str) -> Self
The ability each record must allow (update by default).
Sourcepub fn form(self, fields: Vec<Field>) -> Self
pub fn form(self, fields: Vec<Field>) -> Self
Asks for input first: the button opens a sheet with these fields
(any Field except belongs_to), and the action runs once they
are valid, with what was typed in ActionContext::input. A field
is checked as far as its declaration goes: required, numbers and
dates that read as such, min and max, a select’s choices.
use renox_admin::{AdminAction, Field};
let reprice = AdminAction::new("reprice", "Change price by %", |products: Vec<Product>, cx| async move {
let percent: f64 = cx.input.parse("percent").unwrap_or(0.0);
for product in &products {
let price = (product.price as f64 * (1.0 + percent / 100.0)).round() as i64;
Product::query()
.where_eq("id", product.id)
.update(&cx.state.db, &[("price", &price)])
.await?;
}
Ok(Toast::success(format!("{} prices changed by {percent} %.", products.len())))
})
.form(vec![Field::number("percent", "Percent").required().min(-90).max(500).suffix("%")])
.description("Every selected product's price changes by this much.")
.submit_label("Change prices")
.row();Sourcepub fn description(self, text: &str) -> Self
pub fn description(self, text: &str) -> Self
A line under the title of the input sheet (form).
Sourcepub fn submit_label(self, label: &str) -> Self
pub fn submit_label(self, label: &str) -> Self
The input sheet’s button, instead of the action’s label.
Source§impl<M: StateMachine + Send + Sync + 'static> AdminAction<M>
impl<M: StateMachine + Send + Sync + 'static> AdminAction<M>
Sourcepub fn transitions() -> Vec<Self>
pub fn transitions() -> Vec<Self>
One row action per transition of M’s machine (system transitions
left out), named like the transition, that runs it as the panel’s
user with the engine’s checks: permission, from state and guards.
A transition that needs a reason asks for it in a sheet. Use it as
the resource’s actions.
The view page offers only the ones that are
available for the record.
Trait Implementations§
Source§impl<M> Clone for AdminAction<M>
impl<M> Clone for AdminAction<M>
Auto Trait Implementations§
impl<M> !RefUnwindSafe for AdminAction<M>
impl<M> !UnwindSafe for AdminAction<M>
impl<M> Freeze for AdminAction<M>
impl<M> Send for AdminAction<M>
impl<M> Sync for AdminAction<M>
impl<M> Unpin for AdminAction<M>
impl<M> UnsafeUnpin for AdminAction<M>
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 more