a2ui_base/model/
surface_model.rs1use std::cell::RefCell;
4use std::collections::HashMap;
5
6use super::components_model::SurfaceComponentsModel;
7use super::data_model::DataModel;
8
9pub struct PendingAction {
11 pub action_id: String,
13 pub response_path: Option<String>,
15}
16
17pub struct SurfaceModel {
19 pub id: String,
21 pub catalog_id: String,
23 pub surface_properties: Option<serde_json::Value>,
25 pub send_data_model: bool,
27 pub data_model: RefCell<DataModel>,
29 pub components: RefCell<SurfaceComponentsModel>,
31 pub pending_actions: RefCell<HashMap<String, PendingAction>>,
33}
34
35impl SurfaceModel {
36 pub fn new(
38 id: String,
39 catalog_id: String,
40 surface_properties: Option<serde_json::Value>,
41 send_data_model: bool,
42 ) -> Self {
43 Self {
44 id,
45 catalog_id,
46 surface_properties,
47 send_data_model,
48 data_model: RefCell::new(DataModel::new()),
49 components: RefCell::new(SurfaceComponentsModel::new()),
50 pending_actions: RefCell::new(HashMap::new()),
51 }
52 }
53
54 pub fn with_data_model(mut self, data: serde_json::Value) -> Self {
56 self.data_model = RefCell::new(DataModel::from_value(data));
57 self
58 }
59
60 pub fn has_root(&self) -> bool {
62 self.components.borrow().contains("root")
63 }
64}