Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Dashboard Widgets

A dashboard widget is a card a module registers for the home dashboard, a board each operator arranges for themselves.

Write a widget

use laterite_admin::widget::{Size, Widget, WidgetCx, WidgetReg};
use laterite_admin::{html::Markup, AdminRegistry};
use laterite_core::arrange::{slot, Position};
use laterite_core::{t, Text};
use std::sync::Arc;

struct Sales;

#[laterite_core::strata::async_trait]
impl Widget for Sales {
    fn code(&self) -> &str {
        "acme.sales"
    }
    fn label(&self) -> Text {
        t!("Sales today")
    }
    fn description(&self) -> Option<Text> {
        Some(t!("Orders and revenue since midnight."))
    }
    fn permission(&self) -> Option<&str> {
        Some("acme.view_sales")
    }
    fn size(&self) -> Size {
        Size::Third
    }
    fn refresh(&self) -> Option<u32> {
        Some(30)
    }
    async fn render(&self, cx: &WidgetCx<'_>) -> Result<Markup, String> {
        let count = acme::orders::today(cx.db()).await.map_err(|e| e.to_string())?;
        Ok(Markup::raw_unchecked(format!("<p class=\"lat-widget__name\">{count}</p>")))
    }
}

fn register(&self, registry: &mut laterite_core::Registry) {
    registry.add_widget(
        WidgetReg::new(Arc::new(Sales)).position(Position::new().slot(slot::APPLICATION)),
    );
}
MethodReturnsDefault
codevendor.name, unique across modulesrequired
labelthe heading, a Textrequired
descriptiona line under the label in Add widgetnone
permissionthe permission an operator needs to see itshown to every operator
sizeSize::Third, Size::Half, Size::Full: 7, 10 or 20 of the board’s columns when first placedHalf
refreshseconds between fetches of the bodyrendered once with the page
renderthe body as Markup; an Err shows a notice inside the framerequired

WidgetCx gives db(), base(), t(&Text), shell, user and size.

Arrange the dashboard

[backend.order]
"backend.dashboard" = ["acme.sales", "backend.welcome"]

Widgets sit in the backend.dashboard hierarchy; a widget may take slot::HOME, slot::APPLICATION or slot::SYSTEM, and lands in slot::APPLICATION unless its position says otherwise.

Replace a built-in widget

CodeShowsPermission
backend.welcomethe operator’s namenone
backend.managea card per section they may opennone
backend.activitythe latest audit-log entries, refreshed every minutebackend.view_audit_log
backend.statusthe framework version, database and timezonebackend.manage_plugins

A module registering a widget under a built-in’s code replaces it.