From 374dd9b36dec8d122078cb7ef10dd912fef32460 Mon Sep 17 00:00:00 2001 From: lukeflo Date: Thu, 17 Oct 2024 13:49:52 +0200 Subject: testwise rewrite entry table parsing --- src/frontend/entries.rs | 100 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 66 insertions(+), 34 deletions(-) (limited to 'src/frontend/entries.rs') 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> for EntryTable { - fn from_iter>>(iter: T) -> Self { - let entry_table_items: Vec = iter +// impl FromIterator> for EntryTable { +// fn from_iter>>(iter: T) -> Self { +// let entry_table_items: Vec = 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, biblio: &Bibliography) -> Self { + let entry_table_items: Vec = 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 -- cgit v1.2.3