fixing lots of bugs
This commit is contained in:
parent
da735aa00b
commit
0ba3e7588b
24 changed files with 781 additions and 486 deletions
|
|
@ -208,7 +208,7 @@ pub struct PresentationModelRust {
|
|||
highest_id: i32,
|
||||
presentations: Vec<Presentation>,
|
||||
inner_presentations: Vec<Presentation>,
|
||||
db: SqliteConnection
|
||||
db: SqliteConnection,
|
||||
}
|
||||
|
||||
impl Default for PresentationModelRust {
|
||||
|
|
@ -226,14 +226,18 @@ impl Default for PresentationModelRust {
|
|||
let mut db_url = String::from("sqlite://");
|
||||
db_url.push_str(data.to_str().unwrap());
|
||||
rt.block_on(async {
|
||||
SqliteConnection::connect(&db_url).await.expect("problems")
|
||||
SqliteConnection::connect(&db_url)
|
||||
.await
|
||||
.expect("problems")
|
||||
})
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_presentation(index: i32) -> color_eyre::Result<Presentation> {
|
||||
pub fn get_presentation(
|
||||
index: i32,
|
||||
) -> color_eyre::Result<Presentation> {
|
||||
let rt = tokio::runtime::Runtime::new().unwrap();
|
||||
let mut db = {
|
||||
let mut data = dirs::data_local_dir().unwrap();
|
||||
|
|
@ -242,11 +246,13 @@ pub fn get_presentation(index: i32) -> color_eyre::Result<Presentation> {
|
|||
let mut db_url = String::from("sqlite://");
|
||||
db_url.push_str(data.to_str().unwrap());
|
||||
rt.block_on(async {
|
||||
SqliteConnection::connect(&db_url).await.expect("problems")
|
||||
SqliteConnection::connect(&db_url)
|
||||
.await
|
||||
.expect("problems")
|
||||
})
|
||||
};
|
||||
rt.block_on(async {
|
||||
let result = query_as!(Presentation, r#"SELECT id as "id: i32", title as "title!", filePath as "path!", html as "html!", pageCount as "page_count!: i32" from presentations where id = ?"#, index).fetch_one(&mut db).await?;
|
||||
let result = query_as!(Presentation, r#"SELECT id as "id: i32", title as "title!", file_path as "path!", html as "html!", pageCount as "page_count!: i32" from presentations where id = ?"#, index).fetch_one(&mut db).await?;
|
||||
Ok(result)
|
||||
})
|
||||
}
|
||||
|
|
@ -263,7 +269,7 @@ impl presentation_model::PresentationModel {
|
|||
pub fn setup(mut self: Pin<&mut Self>) {
|
||||
let rt = tokio::runtime::Runtime::new().unwrap();
|
||||
rt.block_on(async {
|
||||
let result = query_as!(Presentation, r#"SELECT id as "id: i32", title as "title!", filePath as "path!", html as "html!", pageCount as "page_count!: i32" from presentations"#).fetch_all(&mut self.as_mut().rust_mut().db).await;
|
||||
let result = query_as!(Presentation, r#"SELECT id as "id: i32", title as "title!", file_path as "path!", html as "html!", pageCount as "page_count!: i32" from presentations"#).fetch_all(&mut self.as_mut().rust_mut().db).await;
|
||||
match result {
|
||||
Ok(p) => p.into_iter().for_each(|p| self.as_mut().add_presentation(p)),
|
||||
Err(e) => error!("There was an error in converting songs: {e}"),
|
||||
|
|
@ -278,7 +284,12 @@ impl presentation_model::PresentationModel {
|
|||
let rt = tokio::runtime::Runtime::new().unwrap();
|
||||
|
||||
rt.block_on(async {
|
||||
let result = query!("delete from presentations where id = ?", index).execute(&mut self.as_mut().rust_mut().db).await;
|
||||
let result = query!(
|
||||
"delete from presentations where id = ?",
|
||||
index
|
||||
)
|
||||
.execute(&mut self.as_mut().rust_mut().db)
|
||||
.await;
|
||||
match result {
|
||||
Ok(_i) => {
|
||||
unsafe {
|
||||
|
|
@ -365,7 +376,7 @@ impl presentation_model::PresentationModel {
|
|||
rt.block_on(async {
|
||||
let presentation_title = presentation_title.to_string();
|
||||
let presentation_path = presentation_path.to_string();
|
||||
let result = query!(r#"INSERT into presentations (id, title, filePath, html, pageCount) VALUES (?, ?, ?, ?, ?)"#,
|
||||
let result = query!(r#"INSERT into presentations (id, title, file_path, html, pageCount) VALUES (?, ?, ?, ?, ?)"#,
|
||||
presentation_id,
|
||||
presentation_title,
|
||||
presentation_path,
|
||||
|
|
@ -503,9 +514,13 @@ impl presentation_model::PresentationModel {
|
|||
let rt = tokio::runtime::Runtime::new().unwrap();
|
||||
rt.block_on(async {
|
||||
let title = updated_title.to_string();
|
||||
let result = query!("UPDATE presentations SET title = ? where id = ?", title, index)
|
||||
.execute(&mut self.as_mut().rust_mut().db)
|
||||
.await;
|
||||
let result = query!(
|
||||
"UPDATE presentations SET title = ? where id = ?",
|
||||
title,
|
||||
index
|
||||
)
|
||||
.execute(&mut self.as_mut().rust_mut().db)
|
||||
.await;
|
||||
match result {
|
||||
Ok(_i) => {
|
||||
for presentation in self
|
||||
|
|
@ -516,9 +531,11 @@ impl presentation_model::PresentationModel {
|
|||
.filter(|x| x.id == index)
|
||||
{
|
||||
presentation.title = title.clone();
|
||||
debug!(title = presentation.title,
|
||||
title = title,
|
||||
"updated presentation title");
|
||||
debug!(
|
||||
title = presentation.title,
|
||||
title = title,
|
||||
"updated presentation title"
|
||||
);
|
||||
}
|
||||
self.as_mut().data_changed(
|
||||
model_index,
|
||||
|
|
@ -530,7 +547,7 @@ impl presentation_model::PresentationModel {
|
|||
Err(e) => {
|
||||
error!("Error connecting to db: {e}");
|
||||
false
|
||||
},
|
||||
}
|
||||
}
|
||||
});
|
||||
true
|
||||
|
|
@ -549,9 +566,13 @@ impl presentation_model::PresentationModel {
|
|||
|
||||
let rt = tokio::runtime::Runtime::new().unwrap();
|
||||
rt.block_on(async {
|
||||
let result = query!("UPDATE presentations SET pageCount = ? where id = ?", updated_page_count, index)
|
||||
.execute(&mut self.as_mut().rust_mut().db)
|
||||
.await;
|
||||
let result = query!(
|
||||
"UPDATE presentations SET pageCount = ? where id = ?",
|
||||
updated_page_count,
|
||||
index
|
||||
)
|
||||
.execute(&mut self.as_mut().rust_mut().db)
|
||||
.await;
|
||||
match result {
|
||||
Ok(_i) => {
|
||||
for presentation in self
|
||||
|
|
@ -561,10 +582,13 @@ impl presentation_model::PresentationModel {
|
|||
.iter_mut()
|
||||
.filter(|x| x.id == index)
|
||||
{
|
||||
presentation.page_count = updated_page_count.clone();
|
||||
debug!(title = presentation.title,
|
||||
page_count = updated_page_count,
|
||||
"updated presentation page_count");
|
||||
presentation.page_count =
|
||||
updated_page_count.clone();
|
||||
debug!(
|
||||
title = presentation.title,
|
||||
page_count = updated_page_count,
|
||||
"updated presentation page_count"
|
||||
);
|
||||
}
|
||||
self.as_mut().data_changed(
|
||||
model_index,
|
||||
|
|
@ -576,7 +600,7 @@ impl presentation_model::PresentationModel {
|
|||
Err(e) => {
|
||||
error!("Error connecting to db: {e}");
|
||||
false
|
||||
},
|
||||
}
|
||||
}
|
||||
});
|
||||
true
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue