Skip to main content

armature_admin/
dashboard.rs

1//! Dashboard views for admin
2
3use crate::{AdminInstance, QuickAction, StatCard};
4use serde::{Deserialize, Serialize};
5
6/// Dashboard view data
7#[derive(Debug, Clone, Serialize, Deserialize)]
8pub struct DashboardView {
9    /// Page title
10    pub title: String,
11    /// Statistics cards
12    pub stats: Vec<StatCard>,
13    /// Quick actions
14    pub quick_actions: Vec<QuickAction>,
15    /// Model summaries
16    pub model_summaries: Vec<ModelSummary>,
17}
18
19impl DashboardView {
20    /// Create a new dashboard view
21    pub fn new(admin: &AdminInstance) -> Self {
22        let model_summaries = admin
23            .models()
24            .iter()
25            .map(|m| ModelSummary {
26                name: m.name.clone(),
27                verbose_name: m.verbose_name.clone(),
28                icon: m.icon.clone(),
29                count: 0, // Would be populated from database
30                recent_count: 0,
31                url: format!("{}/{}", admin.config.base_path, m.name),
32            })
33            .collect();
34
35        Self {
36            title: admin.config.title.clone(),
37            stats: vec![StatCard {
38                title: "Total Records".to_string(),
39                value: "0".to_string(),
40                change: None,
41                icon: Some("database".to_string()),
42                color: None,
43                link: None,
44            }],
45            quick_actions: admin
46                .models()
47                .iter()
48                .filter(|m| m.can_add)
49                .take(4)
50                .map(|m| QuickAction {
51                    label: format!("Add {}", m.verbose_name_singular),
52                    url: format!("{}/{}/add", admin.config.base_path, m.name),
53                    icon: Some("plus".to_string()),
54                    css_class: None,
55                })
56                .collect(),
57            model_summaries,
58        }
59    }
60
61    /// Set statistics
62    pub fn with_stats(mut self, stats: Vec<StatCard>) -> Self {
63        self.stats = stats;
64        self
65    }
66}
67
68/// Model summary for dashboard
69#[derive(Debug, Clone, Serialize, Deserialize)]
70pub struct ModelSummary {
71    /// Model name
72    pub name: String,
73    /// Verbose name
74    pub verbose_name: String,
75    /// Icon
76    pub icon: Option<String>,
77    /// Total record count
78    pub count: usize,
79    /// Recent record count
80    pub recent_count: usize,
81    /// URL to list view
82    pub url: String,
83}