From: Olaf Wintermann Date: Fri, 29 May 2026 15:34:06 +0000 (+0200) Subject: add backend reference to the note view model X-Git-Url: https://uap-core.de/gitweb/?a=commitdiff_plain;h=refs%2Fheads%2Fmain;p=note.git add backend reference to the note view model --- diff --git a/application/src/note.rs b/application/src/note.rs index 311eb72..2307764 100644 --- a/application/src/note.rs +++ b/application/src/note.rs @@ -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, + + 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) -> 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; diff --git a/application/src/notebook.rs b/application/src/notebook.rs index 0eb23c8..a9be563 100644 --- a/application/src/notebook.rs +++ b/application/src/notebook.rs @@ -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, pub backend: Rc, + pub broadcast_rx: tokio::sync::broadcast::Receiver, pub collection_id: i32, pub selected_note: Option>, @@ -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> {