Skip to main content

rustio_admin/view_layer/
modes.rs

1//! View modes — the layouts a collection of records can be rendered in.
2
3use serde::{Deserialize, Serialize};
4
5// public:
6/// The visual layout used to render a collection of records.
7#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
8#[serde(rename_all = "snake_case")]
9pub enum ViewMode {
10    /// Traditional column-based admin table.
11    Table,
12    /// Richer row layout built around primary/secondary/composed cells.
13    List,
14    /// Card grid using the primary field as the card title.
15    Cards,
16    /// Dense layout for large datasets.
17    Compact,
18}
19
20impl ViewMode {
21    // public:
22    /// Slug used in URLs and the mode switcher, e.g. `?view=cards`.
23    pub fn slug(self) -> &'static str {
24        match self {
25            ViewMode::Table => "table",
26            ViewMode::List => "list",
27            ViewMode::Cards => "cards",
28            ViewMode::Compact => "compact",
29        }
30    }
31
32    // public:
33    /// Parse a slug coming from a query string. Unknown values return `None`
34    /// so the caller can fall back to the spec default.
35    pub fn from_slug(slug: &str) -> Option<Self> {
36        match slug {
37            "table" => Some(ViewMode::Table),
38            "list" => Some(ViewMode::List),
39            "cards" => Some(ViewMode::Cards),
40            "compact" => Some(ViewMode::Compact),
41            _ => None,
42        }
43    }
44}