Skip to main content

page_filters

Function page_filters 

Source
pub fn page_filters(cx: &Cx) -> PageFilters
Expand description

The values the request holds for the filters of the page it renders: the registered Page whose URL its path names. A widget reads them to narrow what it shows. Outside such a page, as in a resource list’s widgets, it holds none.

use tablo_core::{Stat, Widget, db, page_filters, scoped_query};
use topcoat::{Result, context::Cx, view::View};

struct Orders;

impl Widget for Orders {
    async fn render(cx: &Cx) -> Result<impl View> {
        let mut orders = scoped_query::<OrderResource>(cx)?;
        if let Some(channel) = page_filters(cx).choice("channel") {
            orders = orders.filter(Order::fields().channel().eq(channel));
        }
        let count = db::count(cx, orders).await?;
        Ok(tablo_core::stats(
            cx,
            vec![Stat::new("Orders", count.to_string())],
        ))
    }
}