1use serde::Serialize;
2use std::collections::HashMap;
3
4#[derive(Serialize)]
7#[serde(tag = "type", rename_all = "lowercase")]
8pub enum NavItem {
9 Entity(EntityRef),
10 Group {
11 label: String,
12 entities: Vec<EntityRef>,
13 active: bool,
15 },
16}
17
18#[derive(Serialize)]
19pub struct EntityRef {
20 pub name: String,
21 pub label: String,
22 pub icon: String,
23 pub group: Option<String>,
24}
25
26#[derive(Serialize)]
27pub struct FieldContext {
28 pub name: String,
29 pub label: String,
30 pub field_type: String,
31 pub readonly: bool,
32 pub hidden: bool,
33 pub list_only: bool,
34 pub form_only: bool,
35 pub required: bool,
36 pub help_text: Option<String>,
37 pub options: Vec<(String, String)>,
38 pub selected_ids: Vec<String>,
40 pub accept: Vec<String>,
42}
43
44#[derive(Serialize)]
45pub struct RowContext {
46 pub id: String,
47 pub data: HashMap<String, String>,
48}
49
50#[derive(Serialize)]
51pub struct ActionContext {
52 pub name: String,
53 pub label: String,
54 pub target: String,
55 pub confirm: Option<String>,
56 pub icon: Option<String>,
57 pub class: Option<String>,
58}
59
60#[derive(Serialize)]
61pub struct ListContext {
62 pub admin_title: String,
63 pub admin_icon: String,
64 pub entities: Vec<EntityRef>,
65 pub nav: Vec<NavItem>,
66 pub current_entity: String,
67 pub entity_name: String,
68 pub entity_label: String,
69 pub columns: Vec<String>,
70 pub column_types: HashMap<String, String>,
71 pub rows: Vec<RowContext>,
72 pub actions: Vec<ActionContext>,
73 pub search: String,
74 pub page: u64,
75 pub total_pages: u64,
76 pub order_by: String,
77 pub order_dir: String,
78 pub filter_fields: Vec<FieldContext>,
79 pub active_filters: HashMap<String, String>,
80 pub bulk_delete: bool,
81 pub bulk_export: bool,
82 pub export_columns: Vec<(String, String)>, pub flash_success: Option<String>,
84 pub flash_error: Option<String>,
85 pub can_create: bool,
86 pub can_edit: bool,
87 pub can_delete: bool,
88 pub show_auth_nav: bool,
89}
90
91#[derive(Serialize)]
92pub struct FormContext {
93 pub admin_title: String,
94 pub admin_icon: String,
95 pub entities: Vec<EntityRef>,
96 pub nav: Vec<NavItem>,
97 pub current_entity: String,
98 pub entity_name: String,
99 pub entity_label: String,
100 pub fields: Vec<FieldContext>,
101 pub values: HashMap<String, String>,
102 pub errors: HashMap<String, String>,
103 pub is_create: bool,
104 pub record_id: String,
105 pub csrf_token: String,
106 pub flash_success: Option<String>,
107 pub flash_error: Option<String>,
108 pub can_save: bool,
109 pub show_auth_nav: bool,
110}
111
112#[derive(Serialize)]
113pub struct LoginContext {
114 pub admin_title: String,
115 pub error: Option<String>,
116 pub csrf_token: String,
117 pub next: Option<String>,
118}
119
120#[derive(Serialize)]
121pub struct FlashContext {
122 pub success: Option<String>,
123 pub error: Option<String>,
124}