mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-02-05 16:04:15 +00:00
implement request session restore
This commit is contained in:
parent
d7b781f604
commit
6a4790c92b
@ -120,7 +120,7 @@ impl Navigation {
|
|||||||
match Database::delete(transaction, &record.id) {
|
match Database::delete(transaction, &record.id) {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
// Delegate clean action to the item childs
|
// Delegate clean action to the item childs
|
||||||
// nothing yet..
|
self.request.clean(transaction, &record.id)?;
|
||||||
}
|
}
|
||||||
Err(e) => return Err(e.to_string()),
|
Err(e) => return Err(e.to_string()),
|
||||||
}
|
}
|
||||||
@ -139,9 +139,9 @@ impl Navigation {
|
|||||||
) -> Result<(), String> {
|
) -> Result<(), String> {
|
||||||
match Database::records(transaction, app_browser_window_tab_item_page_id) {
|
match Database::records(transaction, app_browser_window_tab_item_page_id) {
|
||||||
Ok(records) => {
|
Ok(records) => {
|
||||||
for _record in records {
|
for record in records {
|
||||||
// Delegate restore action to the item childs
|
// Delegate restore action to the item childs
|
||||||
// nothing yet..
|
self.request.restore(transaction, &record.id)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(e) => return Err(e.to_string()),
|
Err(e) => return Err(e.to_string()),
|
||||||
@ -157,10 +157,10 @@ impl Navigation {
|
|||||||
) -> Result<(), String> {
|
) -> Result<(), String> {
|
||||||
match Database::add(transaction, app_browser_window_tab_item_page_id) {
|
match Database::add(transaction, app_browser_window_tab_item_page_id) {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
// let id = Database::last_insert_id(transaction);
|
let id = Database::last_insert_id(transaction);
|
||||||
|
|
||||||
// Delegate save action to childs
|
// Delegate save action to childs
|
||||||
// nothing yet..
|
self.request.save(transaction, &id)?;
|
||||||
}
|
}
|
||||||
Err(e) => return Err(e.to_string()),
|
Err(e) => return Err(e.to_string()),
|
||||||
}
|
}
|
||||||
@ -197,7 +197,7 @@ impl Navigation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Delegate migration to childs
|
// Delegate migration to childs
|
||||||
// nothing yet..
|
Request::migrate(tx)?;
|
||||||
|
|
||||||
// Success
|
// Success
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -68,8 +68,7 @@ impl Database {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* not in use
|
|
||||||
pub fn last_insert_id(tx: &Transaction) -> i64 {
|
pub fn last_insert_id(tx: &Transaction) -> i64 {
|
||||||
tx.last_insert_rowid()
|
tx.last_insert_rowid()
|
||||||
} */
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,14 @@
|
|||||||
|
mod database;
|
||||||
|
|
||||||
|
use database::Database;
|
||||||
|
|
||||||
use gtk::{
|
use gtk::{
|
||||||
gio::SimpleAction,
|
gio::SimpleAction,
|
||||||
glib::{timeout_add_local, ControlFlow, GString, SourceId, Uri, UriFlags},
|
glib::{timeout_add_local, ControlFlow, GString, SourceId, Uri, UriFlags},
|
||||||
prelude::{ActionExt, EditableExt, EntryExt},
|
prelude::{ActionExt, EditableExt, EntryExt},
|
||||||
Entry,
|
Entry,
|
||||||
};
|
};
|
||||||
|
use sqlite::Transaction;
|
||||||
use std::{cell::RefCell, sync::Arc, time::Duration};
|
use std::{cell::RefCell, sync::Arc, time::Duration};
|
||||||
|
|
||||||
// Progressbar animation setup
|
// Progressbar animation setup
|
||||||
@ -97,6 +101,78 @@ impl Request {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn clean(
|
||||||
|
&self,
|
||||||
|
transaction: &Transaction,
|
||||||
|
app_browser_window_tab_item_page_navigation_id: &i64,
|
||||||
|
) -> Result<(), String> {
|
||||||
|
match Database::records(transaction, app_browser_window_tab_item_page_navigation_id) {
|
||||||
|
Ok(records) => {
|
||||||
|
for record in records {
|
||||||
|
match Database::delete(transaction, &record.id) {
|
||||||
|
Ok(_) => {
|
||||||
|
// Delegate clean action to the item childs
|
||||||
|
// nothing yet..
|
||||||
|
}
|
||||||
|
Err(e) => return Err(e.to_string()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(e) => return Err(e.to_string()),
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn restore(
|
||||||
|
&self,
|
||||||
|
transaction: &Transaction,
|
||||||
|
app_browser_window_tab_item_page_navigation_id: &i64,
|
||||||
|
) -> Result<(), String> {
|
||||||
|
match Database::records(transaction, app_browser_window_tab_item_page_navigation_id) {
|
||||||
|
Ok(records) => {
|
||||||
|
for record in records {
|
||||||
|
if let Some(text) = record.text {
|
||||||
|
self.widget.set_text(&text);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delegate restore action to the item childs
|
||||||
|
// nothing yet..
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(e) => return Err(e.to_string()),
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn save(
|
||||||
|
&self,
|
||||||
|
transaction: &Transaction,
|
||||||
|
app_browser_window_tab_item_page_navigation_id: &i64,
|
||||||
|
) -> Result<(), String> {
|
||||||
|
let text = self.widget.text();
|
||||||
|
|
||||||
|
match Database::add(
|
||||||
|
transaction,
|
||||||
|
app_browser_window_tab_item_page_navigation_id,
|
||||||
|
match text.is_empty() {
|
||||||
|
true => None,
|
||||||
|
false => Some(text.as_str()),
|
||||||
|
},
|
||||||
|
) {
|
||||||
|
Ok(_) => {
|
||||||
|
// let id = Database::last_insert_id(transaction);
|
||||||
|
|
||||||
|
// Delegate save action to childs
|
||||||
|
// nothing yet..
|
||||||
|
}
|
||||||
|
Err(e) => return Err(e.to_string()),
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
// Setters
|
// Setters
|
||||||
pub fn set_text(&self, value: &GString) {
|
pub fn set_text(&self, value: &GString) {
|
||||||
self.widget.set_text(value);
|
self.widget.set_text(value);
|
||||||
@ -121,4 +197,18 @@ impl Request {
|
|||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Tools
|
||||||
|
pub fn migrate(tx: &Transaction) -> Result<(), String> {
|
||||||
|
// Migrate self components
|
||||||
|
if let Err(e) = Database::init(tx) {
|
||||||
|
return Err(e.to_string());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delegate migration to childs
|
||||||
|
// nothing yet..
|
||||||
|
|
||||||
|
// Success
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,81 @@
|
|||||||
|
use sqlite::{Error, Transaction};
|
||||||
|
|
||||||
|
pub struct Table {
|
||||||
|
pub id: i64,
|
||||||
|
// pub app_browser_window_tab_item_page_navigation_id: i64, not in use
|
||||||
|
pub text: Option<String>, // can be stored as NULL
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct Database {
|
||||||
|
// nothing yet..
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Database {
|
||||||
|
pub fn init(tx: &Transaction) -> Result<usize, Error> {
|
||||||
|
tx.execute(
|
||||||
|
"CREATE TABLE IF NOT EXISTS `app_browser_window_tab_item_page_navigation_request`
|
||||||
|
(
|
||||||
|
`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||||
|
`app_browser_window_tab_item_page_navigation_id` INTEGER NOT NULL,
|
||||||
|
`text` VARCHAR(1024)
|
||||||
|
)",
|
||||||
|
[],
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn add(
|
||||||
|
tx: &Transaction,
|
||||||
|
app_browser_window_tab_item_page_navigation_id: &i64,
|
||||||
|
text: Option<&str>,
|
||||||
|
) -> Result<usize, Error> {
|
||||||
|
tx.execute(
|
||||||
|
"INSERT INTO `app_browser_window_tab_item_page_navigation_request` (
|
||||||
|
`app_browser_window_tab_item_page_navigation_id`,
|
||||||
|
`text`
|
||||||
|
) VALUES (?, ?)",
|
||||||
|
(app_browser_window_tab_item_page_navigation_id, text),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn records(
|
||||||
|
tx: &Transaction,
|
||||||
|
app_browser_window_tab_item_page_navigation_id: &i64,
|
||||||
|
) -> Result<Vec<Table>, Error> {
|
||||||
|
let mut stmt = tx.prepare(
|
||||||
|
"SELECT `id`,
|
||||||
|
`app_browser_window_tab_item_page_navigation_id`,
|
||||||
|
`text`
|
||||||
|
FROM `app_browser_window_tab_item_page_navigation_request`
|
||||||
|
WHERE `app_browser_window_tab_item_page_navigation_id` = ?",
|
||||||
|
)?;
|
||||||
|
|
||||||
|
let result = stmt.query_map([app_browser_window_tab_item_page_navigation_id], |row| {
|
||||||
|
Ok(Table {
|
||||||
|
id: row.get(0)?,
|
||||||
|
// app_browser_window_tab_item_page_navigation_id: row.get(1)?, not in use
|
||||||
|
text: row.get(2)?,
|
||||||
|
})
|
||||||
|
})?;
|
||||||
|
|
||||||
|
let mut records = Vec::new();
|
||||||
|
|
||||||
|
for record in result {
|
||||||
|
let table = record?;
|
||||||
|
records.push(table);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(records)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn delete(tx: &Transaction, id: &i64) -> Result<usize, Error> {
|
||||||
|
tx.execute(
|
||||||
|
"DELETE FROM `app_browser_window_tab_item_page_navigation_request` WHERE `id` = ?",
|
||||||
|
[id],
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/* not in use
|
||||||
|
pub fn last_insert_id(tx: &Transaction) -> i64 {
|
||||||
|
tx.last_insert_rowid()
|
||||||
|
} */
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user