]> uap-core.de Git - note.git/commitdiff
add backend reference to the note view model main
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Fri, 29 May 2026 15:34:06 +0000 (17:34 +0200)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Fri, 29 May 2026 15:34:06 +0000 (17:34 +0200)
application/src/note.rs
application/src/notebook.rs

index 311eb7265a9856e5a3cefb3f7cc5569a010f36d6..2307764f931a9f9ef0d03524a0795670803a72fc 100644 (file)
@@ -1,3 +1,4 @@
+use std::rc::Rc;
 use sea_orm::prelude::DateTimeWithTimeZone;
 use sea_orm::sea_query::prelude::Utc;
 use sea_orm::{NotSet, Set};
@@ -7,8 +8,11 @@ use ui_rs::ui::*;
 use crate::backend::BackendHandle;
 use crate::window::NoteTypeTabView;
 
-#[derive(UiModel, Default)]
+#[derive(UiModel)]
 pub struct Note {
+    pub backend: Rc<BackendHandle>,
+
+    pub collection_id: i32,
     pub note_id: i32,
     pub content_id: i32,
 
@@ -27,6 +31,23 @@ pub struct Note {
 
 #[ui_actions]
 impl Note {
+    pub fn new(collection_id: i32, backend: Rc<BackendHandle>) -> Self {
+        Note {
+            backend: backend,
+            collection_id: collection_id,
+
+            note_id: 0,
+            content_id: 0,
+            kind: NoteType::PlainTextNote,
+            created: Default::default(),
+            title_start: -1,
+            title_end: -1,
+
+            note_type: Default::default(),
+            text: Default::default(),
+        }
+    }
+
     pub fn init_from_model(&mut self, model: &entity::note::Model) {
         self.note_id = model.note_id;
 
index 0eb23c884fc0480f35c82041b77e3b5e6d81c7eb..a9be563016d1d2ffb0712c193b25cd349e3e790c 100644 (file)
@@ -3,12 +3,13 @@ use ui_rs::{action, ui_actions, UiModel};
 use ui_rs::ui::*;
 
 use entity::note::{Model as Note};
-use crate::backend::BackendHandle;
+use crate::backend::{BackendHandle, BroadcastMessage};
 
 #[derive(UiModel)]
 pub struct Notebook {
     pub doc_ref: UiDocRef<Notebook>,
     pub backend: Rc<BackendHandle>,
+    pub broadcast_rx: tokio::sync::broadcast::Receiver<BroadcastMessage>,
     pub collection_id: i32,
 
     pub selected_note: Option<UiDoc<crate::note::Note>>,
@@ -23,6 +24,7 @@ impl Notebook {
         Notebook {
             doc_ref: Default::default(),
             backend: Rc::new(backend.clone()),
+            broadcast_rx: backend.btx.subscribe(),
             collection_id: id,
             selected_note: None,
             notes: Default::default()
@@ -66,7 +68,7 @@ impl Notebook {
                 self.selected_note = None;
 
                 // Create the new note
-                let note_data: crate::note::Note = Default::default();
+                let note_data = crate::note::Note::new(self.collection_id, self.backend.clone());
 
                 // Create the note document object
                 let note_doc = UiDoc::new2(note_data, |n,d| {
@@ -106,6 +108,17 @@ impl Notebook {
             }
         }
     }
+
+    #[action]
+    pub fn message(&mut self, _event: &ActionEvent) {
+        while let Ok(msg) = self.broadcast_rx.try_recv() {
+            match msg {
+                _ => {
+                    
+                },
+            }
+        }
+    }
 }
 
 pub fn notelist_getvalue<'a>(elm: &Note, col: i32, _row: i32) -> ListValue<'a> {