armature_admin/
dashboard.rs1use crate::{AdminInstance, QuickAction, StatCard};
4use serde::{Deserialize, Serialize};
5
6#[derive(Debug, Clone, Serialize, Deserialize)]
8pub struct DashboardView {
9 pub title: String,
11 pub stats: Vec<StatCard>,
13 pub quick_actions: Vec<QuickAction>,
15 pub model_summaries: Vec<ModelSummary>,
17}
18
19impl DashboardView {
20 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, 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 pub fn with_stats(mut self, stats: Vec<StatCard>) -> Self {
63 self.stats = stats;
64 self
65 }
66}
67
68#[derive(Debug, Clone, Serialize, Deserialize)]
70pub struct ModelSummary {
71 pub name: String,
73 pub verbose_name: String,
75 pub icon: Option<String>,
77 pub count: usize,
79 pub recent_count: usize,
81 pub url: String,
83}