pub async fn list_query<R>(
cx: &Cx,
) -> Result<Query<List<<R as Resource>::Model>>, Error>where
R: Resource,Expand description
R’s records as its list shows them in this request: the scoped_query
the list reads, narrowed by its tab, search and filters, unordered. A
list_widget reading it shows figures that follow the list,
and reruns with it as the reader searches, filters or switches tabs.
Outside R’s list page, as on a dashboard, it reads the list’s first tab with no search or
filter. Like the list, it leaves out a filter it cannot apply, and the trashed records unless
the list’s trash control asks for them. Count what it selects with
db::count.
use tablo_core::{Stat, Widget, db, list_query};
use topcoat::{Result, context::Cx, view::View};
struct Published;
impl Widget for Published {
async fn render(cx: &Cx) -> Result<impl View> {
let published = list_query::<PostResource>(cx)
.await?
.filter(Post::fields().published().eq(true));
let count = db::count(cx, published).await?;
Ok(tablo_core::stats(
cx,
vec![Stat::new("Published", count.to_string())],
))
}
}A tab and a filter can ask one column for two values. Toasty then folds the query’s filter to
false, and panics planning an include over it: count the query, or ask it for a row, before
loading its rows with their relations.
§Errors
403 when the request may not open R’s list, the check can_list makes,
which fails the whole page the widget is on: a widget on another page asks can_list first.
The database failing a filter’s check.