Browse Source

delegate result handle to the transaction initiator

master
yggverse 2 months ago
parent
commit
47e2bc4617
  1. 18
      src/app.rs
  2. 78
      src/app/browser.rs
  3. 30
      src/app/browser/widget.rs
  4. 43
      src/app/browser/window.rs
  5. 58
      src/app/browser/window/tab.rs
  6. 40
      src/app/browser/window/tab/label.rs

18
src/app.rs

@ -120,7 +120,11 @@ impl App {
match Database::records(&transaction) { match Database::records(&transaction) {
Ok(records) => { Ok(records) => {
for record in records { for record in records {
browser.restore(&transaction, &record.id); if let Err(e) =
browser.restore(&transaction, &record.id)
{
todo!("{e}")
}
} }
} }
Err(e) => todo!("{e}"), Err(e) => todo!("{e}"),
@ -158,7 +162,11 @@ impl App {
match Database::delete(&transaction, &record.id) { match Database::delete(&transaction, &record.id) {
Ok(_) => { Ok(_) => {
// Delegate clean action to childs // Delegate clean action to childs
browser.clean(&transaction, &record.id); if let Err(e) =
browser.clean(&transaction, &record.id)
{
todo!("{e}")
}
} }
Err(e) => todo!("{e}"), Err(e) => todo!("{e}"),
} }
@ -168,10 +176,12 @@ impl App {
match Database::add(&transaction) { match Database::add(&transaction) {
Ok(_) => { Ok(_) => {
// Delegate save action to childs // Delegate save action to childs
browser.save( if let Err(e) = browser.save(
&transaction, &transaction,
&Database::last_insert_id(&transaction), &Database::last_insert_id(&transaction),
); ) {
todo!("{e}")
}
} }
Err(e) => todo!("{e}"), Err(e) => todo!("{e}"),
} }

78
src/app/browser.rs

@ -191,54 +191,84 @@ impl Browser {
} }
// Actions // Actions
pub fn clean(&self, tx: &Transaction, app_id: &i64) { pub fn clean(&self, transaction: &Transaction, app_id: &i64) -> Result<(), String> {
match Database::records(tx, app_id) { match Database::records(transaction, app_id) {
Ok(records) => { Ok(records) => {
for record in records { for record in records {
match Database::delete(tx, &record.id) { match Database::delete(transaction, &record.id) {
Ok(_) => { Ok(_) => {
// Delegate clean action to childs // Delegate clean action to childs
// @TODO if let Err(e) = self.window.clean(transaction, &record.id) {
// self.header.clean(record.id); return Err(e.to_string());
self.window.clean(tx, &record.id);
self.widget.clean(tx, &record.id);
} }
Err(e) => todo!("{e}"),
if let Err(e) = self.widget.clean(transaction, &record.id) {
return Err(e.to_string());
} }
/* @TODO
if let Err(e) = self.header.clean(transaction, &record.id) {
return Err(e.to_string());
} */
} }
Err(e) => return Err(e.to_string()),
} }
Err(e) => todo!("{e}"),
} }
} }
Err(e) => return Err(e.to_string()),
}
pub fn restore(&self, tx: &Transaction, app_id: &i64) { Ok(())
match Database::records(tx, app_id) { }
pub fn restore(&self, transaction: &Transaction, app_id: &i64) -> Result<(), String> {
match Database::records(transaction, app_id) {
Ok(records) => { Ok(records) => {
for record in records { for record in records {
// Delegate restore action to childs // Delegate restore action to childs
// @TODO if let Err(e) = self.widget.restore(transaction, &record.id) {
// self.header.restore(record.id); return Err(e.to_string());
self.window.restore(tx, &record.id);
self.widget.restore(tx, &record.id);
} }
if let Err(e) = self.window.restore(transaction, &record.id) {
return Err(e.to_string());
}
/* @TODO
if let Err(e) = self.header.restore(transaction, &record.id) {
return Err(e.to_string());
} */
} }
Err(e) => todo!("{e}"),
} }
Err(e) => return Err(e.to_string()),
}
Ok(())
} }
pub fn save(&self, tx: &Transaction, app_id: &i64) { pub fn save(&self, transaction: &Transaction, app_id: &i64) -> Result<(), String> {
match Database::add(tx, app_id) { match Database::add(transaction, app_id) {
Ok(_) => { Ok(_) => {
let id = Database::last_insert_id(transaction);
// Delegate save action to childs // Delegate save action to childs
let id = Database::last_insert_id(tx); if let Err(e) = self.widget.save(transaction, &id) {
return Err(e.to_string());
}
// @TODO if let Err(e) = self.window.save(transaction, &id) {
// self.header.save(id); return Err(e.to_string());
self.window.save(tx, &id); }
self.widget.save(tx, &id);
/* @TODO
if let Err(e) = self.header.save(transaction, &id) {
return Err(e.to_string());
} */
} }
Err(e) => todo!("{e}"), Err(e) => return Err(e.to_string()),
} }
Ok(())
} }
// Getters // Getters

30
src/app/browser/widget.rs

@ -31,25 +31,27 @@ impl Widget {
} }
// Actions // Actions
pub fn clean(&self, tx: &Transaction, app_browser_id: &i64) { pub fn clean(&self, transaction: &Transaction, app_browser_id: &i64) -> Result<(), String> {
match Database::records(tx, app_browser_id) { match Database::records(transaction, app_browser_id) {
Ok(records) => { Ok(records) => {
for record in records { for record in records {
match Database::delete(tx, &record.id) { match Database::delete(transaction, &record.id) {
Ok(_) => { Ok(_) => {
// Delegate clean action to childs // Delegate clean action to childs
// nothing yet.. // nothing yet..
} }
Err(e) => todo!("{e}"), Err(e) => return Err(e.to_string()),
} }
} }
} }
Err(e) => todo!("{e}"), Err(e) => return Err(e.to_string()),
} }
Ok(())
} }
pub fn restore(&self, tx: &Transaction, app_browser_id: &i64) { pub fn restore(&self, transaction: &Transaction, app_browser_id: &i64) -> Result<(), String> {
match Database::records(tx, app_browser_id) { match Database::records(transaction, app_browser_id) {
Ok(records) => { Ok(records) => {
for record in records { for record in records {
// Restore widget // Restore widget
@ -61,13 +63,15 @@ impl Widget {
// nothing yet.. // nothing yet..
} }
} }
Err(e) => todo!("{e}"), Err(e) => return Err(e.to_string()),
} }
Ok(())
} }
pub fn save(&self, tx: &Transaction, app_browser_id: &i64) { pub fn save(&self, transaction: &Transaction, app_browser_id: &i64) -> Result<(), String> {
match Database::add( match Database::add(
tx, transaction,
app_browser_id, app_browser_id,
&self.gobject.default_width(), &self.gobject.default_width(),
&self.gobject.default_height(), &self.gobject.default_height(),
@ -75,11 +79,13 @@ impl Widget {
) { ) {
Ok(_) => { Ok(_) => {
// Delegate save action to childs // Delegate save action to childs
// let id = self.database.last_insert_id(tx); // let id = self.database.last_insert_id(transaction);
// nothing yet.. // nothing yet..
} }
Err(e) => todo!("{e}"), Err(e) => return Err(e.to_string()),
} }
Ok(())
} }
// Getters // Getters

43
src/app/browser/window.rs

@ -80,43 +80,58 @@ impl Window {
self.tab.update(); self.tab.update();
} }
pub fn clean(&self, tx: &Transaction, app_browser_id: &i64) { pub fn clean(&self, transaction: &Transaction, app_browser_id: &i64) -> Result<(), String> {
match Database::records(tx, app_browser_id) { match Database::records(transaction, app_browser_id) {
Ok(records) => { Ok(records) => {
for record in records { for record in records {
match Database::delete(tx, &record.id) { match Database::delete(transaction, &record.id) {
Ok(_) => { Ok(_) => {
// Delegate clean action to childs // Delegate clean action to childs
self.tab.clean(tx, &record.id); if let Err(e) = self.tab.clean(transaction, &record.id) {
return Err(e.to_string());
}
} }
Err(e) => todo!("{e}"), Err(e) => return Err(e.to_string()),
} }
} }
} }
Err(e) => todo!("{e}"), Err(e) => return Err(e.to_string()),
} }
Ok(())
} }
pub fn restore(&self, tx: &Transaction, app_browser_id: &i64) { pub fn restore(&self, transaction: &Transaction, app_browser_id: &i64) -> Result<(), String> {
match Database::records(tx, app_browser_id) { match Database::records(transaction, app_browser_id) {
Ok(records) => { Ok(records) => {
for record in records { for record in records {
// Delegate restore action to childs // Delegate restore action to childs
self.tab.restore(tx, &record.id); if let Err(e) = self.tab.restore(transaction, &record.id) {
return Err(e.to_string());
}
} }
} }
Err(e) => todo!("{e}"), Err(e) => return Err(e.to_string()),
} }
Ok(())
} }
pub fn save(&self, tx: &Transaction, app_browser_id: &i64) { pub fn save(&self, transaction: &Transaction, app_browser_id: &i64) -> Result<(), String> {
match Database::add(tx, app_browser_id) { match Database::add(transaction, app_browser_id) {
Ok(_) => { Ok(_) => {
// Delegate save action to childs // Delegate save action to childs
self.tab.save(tx, &Database::last_insert_id(tx)); if let Err(e) = self
.tab
.save(transaction, &Database::last_insert_id(transaction))
{
return Err(e.to_string());
} }
Err(e) => todo!("{e}"),
} }
Err(e) => return Err(e.to_string()),
}
Ok(())
} }
// Getters // Getters

58
src/app/browser/window/tab.rs

@ -213,46 +213,66 @@ impl Tab {
} }
} }
pub fn clean(&self, tx: &Transaction, app_browser_window_id: &i64) { pub fn clean(
match Database::records(tx, app_browser_window_id) { &self,
transaction: &Transaction,
app_browser_window_id: &i64,
) -> Result<(), String> {
match Database::records(transaction, app_browser_window_id) {
Ok(records) => { Ok(records) => {
for record in records { for record in records {
match Database::delete(tx, &record.id) { match Database::delete(transaction, &record.id) {
Ok(_) => { Ok(_) => {
// Delegate clean action to childs // Delegate clean action to childs
for (_, item) in self.index.borrow().iter() { for (_, item) in self.index.borrow().iter() {
item.label.clean(tx, &record.id); if let Err(e) = item.label.clean(transaction, &record.id) {
// @TODO item.page.clean(tx, &record.id); return Err(e.to_string());
} }
// @TODO item.page.clean(transaction, &record.id);
} }
Err(e) => todo!("{e}"),
} }
Err(e) => return Err(e.to_string()),
} }
} }
Err(e) => todo!("{e}"),
} }
Err(e) => return Err(e.to_string()),
}
Ok(())
} }
pub fn restore(&self, tx: &Transaction, app_browser_window_id: &i64) { pub fn restore(
match Database::records(tx, app_browser_window_id) { &self,
transaction: &Transaction,
app_browser_window_id: &i64,
) -> Result<(), String> {
match Database::records(transaction, app_browser_window_id) {
Ok(records) => { Ok(records) => {
for record in records { for record in records {
let item = self.append(None, record.is_current); let item = self.append(None, record.is_current);
// Delegate restore action to childs // Delegate restore action to childs
item.label.restore(tx, &record.id); if let Err(e) = item.label.restore(transaction, &record.id) {
// item.page.restore(tx, record.id); return Err(e.to_string());
} }
// item.page.restore(transaction, record.id);
} }
Err(e) => todo!("{e}"),
} }
Err(e) => return Err(e.to_string()),
} }
pub fn save(&self, tx: &Transaction, app_browser_window_id: &i64) { Ok(())
}
pub fn save(
&self,
transaction: &Transaction,
app_browser_window_id: &i64,
) -> Result<(), String> {
let mut page_number = 0; let mut page_number = 0;
for (_, item) in self.index.borrow().iter() { for (_, item) in self.index.borrow().iter() {
match Database::add( match Database::add(
tx, transaction,
app_browser_window_id, app_browser_window_id,
&match self.widget.gobject().current_page() { &match self.widget.gobject().current_page() {
Some(number) => number == page_number, Some(number) => number == page_number,
@ -261,18 +281,22 @@ impl Tab {
) { ) {
Ok(_) => { Ok(_) => {
// Delegate save action to childs // Delegate save action to childs
let id = Database::last_insert_id(tx); let id = Database::last_insert_id(transaction);
item.label.save(tx, &id); if let Err(e) = item.label.save(transaction, &id) {
return Err(e.to_string());
}
// @TODO // @TODO
// item.page.save() // item.page.save()
} }
Err(e) => todo!("{e}"), Err(e) => return Err(e.to_string()),
} }
page_number += 1; page_number += 1;
} }
Ok(())
} }
// Getters // Getters

40
src/app/browser/window/tab/label.rs

@ -35,25 +35,35 @@ impl Label {
} }
// Actions // Actions
pub fn clean(&self, tx: &Transaction, app_browser_window_tab_id: &i64) { pub fn clean(
match Database::records(tx, app_browser_window_tab_id) { &self,
transaction: &Transaction,
app_browser_window_tab_id: &i64,
) -> Result<(), String> {
match Database::records(transaction, app_browser_window_tab_id) {
Ok(records) => { Ok(records) => {
for record in records { for record in records {
match Database::delete(tx, &record.id) { match Database::delete(transaction, &record.id) {
Ok(_) => { Ok(_) => {
// Delegate clean action to childs // Delegate clean action to childs
// nothing yet.. // nothing yet..
} }
Err(e) => todo!("{e}"), Err(e) => return Err(e.to_string()),
} }
} }
} }
Err(e) => todo!("{e}"), Err(e) => return Err(e.to_string()),
} }
Ok(())
} }
pub fn restore(&self, tx: &Transaction, app_browser_window_tab_id: &i64) { pub fn restore(
match Database::records(tx, app_browser_window_tab_id) { &self,
transaction: &Transaction,
app_browser_window_tab_id: &i64,
) -> Result<(), String> {
match Database::records(transaction, app_browser_window_tab_id) {
Ok(records) => { Ok(records) => {
for record in records { for record in records {
self.pin(record.is_pinned); self.pin(record.is_pinned);
@ -62,18 +72,26 @@ impl Label {
// nothing yet.. // nothing yet..
} }
} }
Err(e) => todo!("{e}"), Err(e) => return Err(e.to_string()),
} }
Ok(())
} }
pub fn save(&self, tx: &Transaction, app_browser_window_tab_id: &i64) { pub fn save(
match Database::add(tx, app_browser_window_tab_id, &self.is_pinned()) { &self,
transaction: &Transaction,
app_browser_window_tab_id: &i64,
) -> Result<(), String> {
match Database::add(transaction, app_browser_window_tab_id, &self.is_pinned()) {
Ok(_) => { Ok(_) => {
// Delegate save action to childs // Delegate save action to childs
// nothing yet.. // nothing yet..
} }
Err(e) => todo!("{e}"), Err(e) => return Err(e.to_string()),
} }
Ok(())
} }
pub fn update(&self, title: Option<&GString>) { pub fn update(&self, title: Option<&GString>) {

Loading…
Cancel
Save