diff options
| author | lukeflo | 2024-10-17 13:49:52 +0200 |
|---|---|---|
| committer | lukeflo | 2024-10-17 13:49:52 +0200 |
| commit | 374dd9b36dec8d122078cb7ef10dd912fef32460 (patch) | |
| tree | 57c829626f5654ed2811b08cf652396dac017244 /src | |
| parent | d54b08f8fbe372afdd9b4bc3e366555ebdef4372 (diff) | |
| download | bibiman-374dd9b36dec8d122078cb7ef10dd912fef32460.tar.gz bibiman-374dd9b36dec8d122078cb7ef10dd912fef32460.zip | |
testwise rewrite entry table parsing
Diffstat (limited to 'src')
| -rw-r--r-- | src/backend/search.rs | 22 | ||||
| -rw-r--r-- | src/frontend/app.rs | 8 | ||||
| -rw-r--r-- | src/frontend/entries.rs | 100 |
3 files changed, 82 insertions, 48 deletions
diff --git a/src/backend/search.rs b/src/backend/search.rs index f9062c8..4576d2d 100644 --- a/src/backend/search.rs +++ b/src/backend/search.rs @@ -114,17 +114,17 @@ mod tests { #[test] fn test_vector_join() { - let bibvec: EntryTableItem = EntryTableItem::new( - "Author", - "Title", - "1999", - "article", - "hello, bye", - "author_1999", - "An abstract with multiple sentences. Here is the second", - "https://www.bibiman.org", - "/home/file/path.pdf", - ); + let bibvec: EntryTableItem = EntryTableItem { + authors: "Author".to_string(), + title: "Title".to_string(), + year: "1999".to_string(), + pubtype: "article".to_string(), + keywords: "hello, bye".to_string(), + citekey: "author_1999".to_string(), + abstract_text: "An abstract with multiple sentences. Here is the second".to_string(), + doi_url: "https://www.bibiman.org".to_string(), + filepath: "/home/file/path.pdf".to_string(), + }; let joined_vec = BibiSearch::convert_to_string(&bibvec); diff --git a/src/frontend/app.rs b/src/frontend/app.rs index 8d6454d..a035231 100644 --- a/src/frontend/app.rs +++ b/src/frontend/app.rs @@ -79,7 +79,7 @@ impl App { let biblio_data = BibiData::new(&main_biblio.bibliography, &main_biblio.citekeys); let tag_list = TagList::new(main_biblio.keyword_list.clone()); let search_struct = BibiSearch::default(); - let entry_table = EntryTable::from_iter(biblio_data.entry_list.bibentries.clone()); + let entry_table = EntryTable::new(&main_biblio.citekeys, &main_biblio.bibliography); let current_area = CurrentArea::EntryArea; Ok(Self { running, @@ -133,7 +133,8 @@ impl App { BibiData::new(&self.main_biblio.bibliography, &self.main_biblio.citekeys); // self.tag_list = TagList::from_iter(self.main_biblio.keyword_list.clone()); self.tag_list = TagList::new(self.main_biblio.keyword_list.clone()); - self.entry_table = EntryTable::from_iter(self.biblio_data.entry_list.bibentries.clone()); + self.entry_table = + EntryTable::new(&self.main_biblio.citekeys, &self.main_biblio.bibliography); } // Toggle moveable list between entries and tags @@ -157,7 +158,8 @@ impl App { } pub fn reset_current_list(&mut self) { - self.entry_table = EntryTable::from_iter(self.biblio_data.entry_list.bibentries.clone()); + self.entry_table = + EntryTable::new(&self.main_biblio.citekeys, &self.main_biblio.bibliography); self.tag_list = TagList::new(self.main_biblio.keyword_list.clone()); if let CurrentArea::TagArea = self.current_area { self.tag_list.tag_list_state.select(Some(0)) diff --git a/src/frontend/entries.rs b/src/frontend/entries.rs index 98604f9..95f6f84 100644 --- a/src/frontend/entries.rs +++ b/src/frontend/entries.rs @@ -17,7 +17,8 @@ use super::app::App; use super::tui::Tui; -use crate::backend::search::BibiSearch; +use crate::backend::{bib::BibiEntry, search::BibiSearch}; +use biblatex::Bibliography; use color_eyre::eyre::{Context, Ok, Result}; use core::panic; use editor_command::EditorBuilder; @@ -36,18 +37,49 @@ pub struct EntryTable { pub entry_info_scroll_state: ScrollbarState, } -impl FromIterator<Vec<String>> for EntryTable { - fn from_iter<T: IntoIterator<Item = Vec<String>>>(iter: T) -> Self { - let entry_table_items: Vec<EntryTableItem> = iter +// impl FromIterator<Vec<String>> for EntryTable { +// fn from_iter<T: IntoIterator<Item = Vec<String>>>(iter: T) -> Self { +// let entry_table_items: Vec<EntryTableItem> = iter +// .into_iter() +// .sorted() +// // 0: authors, 1: title, 2: date, 3: pubtype, 4: keywords, 5: citekey +// // 6: abstract, 7: doi/url, 8: pdf filepath +// // See backend/bib.rs BibiEntry impl +// .map(|i| { +// EntryTableItem::new( +// &i[0], &i[1], &i[2], &i[3], &i[4], &i[5], &i[6], &i[7], &i[8], +// ) +// }) +// .collect(); +// let entry_table_state = TableState::default().with_selected(0); +// let entry_scroll_state = ScrollbarState::new(entry_table_items.len()); +// let entry_info_scroll_state = ScrollbarState::default(); +// Self { +// entry_table_items, +// entry_table_at_search_start: Vec::new(), +// entry_table_state, +// entry_scroll_state, +// entry_info_scroll: 0, +// entry_info_scroll_state, +// } +// } +// } + +impl EntryTable { + pub fn new(citekeys: &Vec<String>, biblio: &Bibliography) -> Self { + let entry_table_items: Vec<EntryTableItem> = citekeys .into_iter() .sorted() - // 0: authors, 1: title, 2: date, 3: pubtype, 4: keywords, 5: citekey - // 6: abstract, 7: doi/url, 8: pdf filepath - // See backend/bib.rs BibiEntry impl - .map(|i| { - EntryTableItem::new( - &i[0], &i[1], &i[2], &i[3], &i[4], &i[5], &i[6], &i[7], &i[8], - ) + .map(|key| EntryTableItem { + authors: BibiEntry::get_authors(&key, &biblio), + title: BibiEntry::get_title(&key, &biblio), + year: BibiEntry::get_year(&key, &biblio), + pubtype: BibiEntry::get_pubtype(&key, &biblio), + keywords: BibiEntry::get_keywords(&key, &biblio), + citekey: key.clone(), + abstract_text: BibiEntry::get_abstract(&key, &biblio), + doi_url: BibiEntry::get_weblink(&key, &biblio), + filepath: BibiEntry::get_filepath(&key, &biblio), }) .collect(); let entry_table_state = TableState::default().with_selected(0); @@ -79,29 +111,29 @@ pub struct EntryTableItem { } impl EntryTableItem { - pub fn new( - authors: &str, - title: &str, - year: &str, - pubtype: &str, - keywords: &str, - citekey: &str, - abstract_text: &str, - doi_url: &str, - filepath: &str, - ) -> Self { - Self { - authors: authors.to_string(), - title: title.to_string(), - year: year.to_string(), - pubtype: pubtype.to_string(), - keywords: keywords.to_string(), - citekey: citekey.to_string(), - abstract_text: abstract_text.to_string(), - doi_url: doi_url.to_string(), - filepath: filepath.to_string(), - } - } + // pub fn new( + // authors: String, + // title: String, + // year: String, + // pubtype: String, + // keywords: String, + // citekey: String, + // abstract_text: String, + // doi_url: String, + // filepath: String, + // ) -> Self { + // Self { + // authors, + // title, + // year, + // pubtype, + // keywords, + // citekey, + // abstract_text, + // doi_url, + // filepath, + // } + // } // This functions decides which fields are rendered in the entry table // Fields which should be usable but not visible can be left out |
