updating cards

This commit is contained in:
2024-04-14 12:12:18 +03:00
parent 4ec6e32357
commit 47fd5b3b9d
14 changed files with 87 additions and 32 deletions

View File

@@ -80,7 +80,7 @@ impl ObjectImpl for MemoryCardsEditScene {
"" => None,
_ => {
let search_option = e.text().to_string();
let conditions = format!("hieroglyph LIKE '%{}%' OR reading LIKE '%{}%'", search_option, search_option);
let conditions = format!("hieroglyph LIKE '%{}%'", search_option);
Some(conditions)
}
}
@@ -108,7 +108,7 @@ impl MemoryCardsEditScene {
None => "".to_owned()
};
let sql = format!("SELECT imagename, hieroglyph, reading FROM cards {selector}");
let sql = format!("SELECT imagename, hieroglyph, reading, translation FROM cards {selector}");
let mut stmt = conn
.prepare(sql.as_str())
.unwrap();
@@ -118,7 +118,9 @@ impl MemoryCardsEditScene {
let image_path: String = get_images_store_path() + &image_path;
let hieroglyph: String = row.get(1).unwrap();
let reading: String = row.get(2).unwrap();
let entry = CardEntry::new(&image_path, &hieroglyph, &reading);
let hieroglyph = format!("{} ({})", hieroglyph, reading);
let translation: String = row.get(3).unwrap();
let entry = CardEntry::new(&image_path, &hieroglyph, &translation);
Ok(entry)
})
.unwrap();
@@ -188,10 +190,11 @@ async fn file_choose_dialog<W: IsA<gtk::Window>>(window: Rc<W>) {
let hieroglyph = w.get_hieroglyph_input();
let reading = w.get_reading_input();
let translation = w.get_translation_input();
let conn = Connection::open(get_db_path()).unwrap();
let query = "INSERT INTO cards (imagename, hieroglyph, reading) VALUES(?1, ?2, ?3)";
conn.execute(query, (&new_filename, &hieroglyph, &reading)).unwrap();
let query = "INSERT INTO cards (imagename, hieroglyph, reading, translation) VALUES(?1, ?2, ?3, ?4)";
conn.execute(query, (&new_filename, &hieroglyph, &reading, &translation)).unwrap();
w.close();
}),
);

View File

@@ -14,6 +14,8 @@ pub struct MemoryCardsNewScene {
#[template_child]
pub reading_entry: TemplateChild<Entry>,
#[template_child]
pub translation_entry: TemplateChild<Entry>,
#[template_child]
pub done_button: TemplateChild<Button>,
}

View File

@@ -33,6 +33,10 @@ impl MemoryCardsNewScene {
self.imp().reading_entry.text().to_string()
}
pub fn get_translation_input(&self) -> String {
self.imp().translation_entry.text().to_string()
}
pub fn get_done_button(&self) -> &Button {
self.imp().done_button.as_ref()
}