aboutsummaryrefslogtreecommitdiff
path: root/src/frontend/entries.rs
diff options
context:
space:
mode:
authorlukeflo2024-10-17 13:49:52 +0200
committerlukeflo2024-10-17 13:49:52 +0200
commit374dd9b36dec8d122078cb7ef10dd912fef32460 (patch)
tree57c829626f5654ed2811b08cf652396dac017244 /src/frontend/entries.rs
parentd54b08f8fbe372afdd9b4bc3e366555ebdef4372 (diff)
downloadbibiman-374dd9b36dec8d122078cb7ef10dd912fef32460.tar.gz
bibiman-374dd9b36dec8d122078cb7ef10dd912fef32460.zip
testwise rewrite entry table parsing
Diffstat (limited to 'src/frontend/entries.rs')
-rw-r--r--src/frontend/entries.rs100
1 files changed, 66 insertions, 34 deletions
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