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

78
src/app/browser.rs

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

30
src/app/browser/widget.rs

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

43
src/app/browser/window.rs

@ -80,43 +80,58 @@ impl Window { @@ -80,43 +80,58 @@ impl Window {
self.tab.update();
}
pub fn clean(&self, tx: &Transaction, app_browser_id: &i64) {
match Database::records(tx, app_browser_id) {
pub fn clean(&self, transaction: &Transaction, app_browser_id: &i64) -> Result<(), String> {
match Database::records(transaction, app_browser_id) {
Ok(records) => {
for record in records {
match Database::delete(tx, &record.id) {
match Database::delete(transaction, &record.id) {
Ok(_) => {
// 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) {
match Database::records(tx, app_browser_id) {
pub fn restore(&self, transaction: &Transaction, app_browser_id: &i64) -> Result<(), String> {
match Database::records(transaction, app_browser_id) {
Ok(records) => {
for record in records {
// 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) {
match Database::add(tx, app_browser_id) {
pub fn save(&self, transaction: &Transaction, app_browser_id: &i64) -> Result<(), String> {
match Database::add(transaction, app_browser_id) {
Ok(_) => {
// 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

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

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

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

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

Loading…
Cancel
Save