From c9e749f811b16f7ec352d2aa8773105af046fad8 Mon Sep 17 00:00:00 2001
From: lukeflo
Date: Mon, 7 Oct 2024 16:15:49 +0200
Subject: add func for entry items, UI enhancement
- add functions to get url/doi and filepath
- get values for entry info from structs not by calling funcs again
---
src/backend/bib.rs | 15 ++++++++-----
src/backend/search.rs | 29 ++++++++++++++++++++++++-
src/frontend/entries.rs | 18 ++++++++++++++-
src/frontend/ui.rs | 58 ++++++++++++++++++++++++++++++++-----------------
4 files changed, 93 insertions(+), 27 deletions(-)
(limited to 'src')
diff --git a/src/backend/bib.rs b/src/backend/bib.rs
index 957adb1..3e0e844 100644
--- a/src/backend/bib.rs
+++ b/src/backend/bib.rs
@@ -15,10 +15,10 @@
// along with this program. If not, see .
/////
-use std::{fs, path::PathBuf};
-
use biblatex::{self, Bibliography};
use biblatex::{ChunksExt, Type};
+use color_eyre::eyre::ErrReport;
+use std::{fs, path::PathBuf};
// Set necessary fields
// TODO: can surely be made more efficient/simpler
@@ -128,6 +128,8 @@ pub struct BibiEntry {
pub pubtype: String,
pub keywords: String,
pub citekey: String,
+ pub weblink: String,
+ pub filepath: String,
}
impl BibiEntry {
@@ -139,6 +141,9 @@ impl BibiEntry {
Self::get_pubtype(&citekey, &biblio),
Self::get_keywords(&citekey, &biblio),
citekey.to_string(),
+ Self::get_abstract(&citekey, &biblio),
+ Self::get_weblink(&citekey, &biblio),
+ Self::get_filepath(&citekey, &biblio),
]
}
@@ -265,13 +270,13 @@ impl BibiEntry {
}
}
- pub fn get_filepath(citekey: &str, biblio: &Bibliography) -> PathBuf {
+ pub fn get_filepath(citekey: &str, biblio: &Bibliography) -> String {
if let true = biblio.get(&citekey).unwrap().file().is_ok() {
let file = biblio.get(&citekey).unwrap().file().unwrap();
- file.into()
+ file
} else {
let file = "".to_string();
- file.into()
+ file
}
}
}
diff --git a/src/backend/search.rs b/src/backend/search.rs
index 7319acc..2c11355 100644
--- a/src/backend/search.rs
+++ b/src/backend/search.rs
@@ -26,7 +26,7 @@ impl Default for BibiSearch {
impl BibiSearch {
// Stringify inner Vec by joining/concat
fn convert_to_string(inner_vec: &Vec) -> String {
- inner_vec.join(" ")
+ inner_vec[0..6].join(" ")
}
// Return a filtered entry list
@@ -89,3 +89,30 @@ impl BibiSearch {
filtered_list
}
}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn test_vector_join() {
+ let bibvec = vec![
+ "Author".to_string(),
+ "Title".to_string(),
+ "1999".to_string(),
+ "article".to_string(),
+ "hello, bye".to_string(),
+ "author_1999".to_string(),
+ "An abstract with multiple sentences. Sometimes thats necessary".to_string(),
+ "www.bibiman.org".to_string(),
+ "/home/file/path.pdf".to_string(),
+ ];
+
+ let joined_vec = BibiSearch::convert_to_string(&bibvec);
+
+ assert_eq!(
+ joined_vec,
+ "Author Title 1999 article hello, bye author_1999"
+ )
+ }
+}
diff --git a/src/frontend/entries.rs b/src/frontend/entries.rs
index c532bf0..8eadfa2 100644
--- a/src/frontend/entries.rs
+++ b/src/frontend/entries.rs
@@ -29,7 +29,14 @@ impl FromIterator> for EntryTable {
let entry_table_items = iter
.into_iter()
.sorted()
- .map(|i| EntryTableItem::new(&i[0], &i[1], &i[2], &i[3], &i[4], &i[5]))
+ // 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);
Self {
@@ -55,6 +62,9 @@ pub struct EntryTableItem {
pub pubtype: String,
pub keywords: String,
pub citekey: String,
+ pub abstract_text: String,
+ pub doi_url: String,
+ pub filepath: String,
}
impl EntryTableItem {
@@ -65,6 +75,9 @@ impl EntryTableItem {
pubtype: &str,
keywords: &str,
citekey: &str,
+ abstract_text: &str,
+ doi_url: &str,
+ filepath: &str,
) -> Self {
Self {
authors: authors.to_string(),
@@ -73,6 +86,9 @@ impl EntryTableItem {
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(),
}
}
diff --git a/src/frontend/ui.rs b/src/frontend/ui.rs
index 3246145..4920b81 100644
--- a/src/frontend/ui.rs
+++ b/src/frontend/ui.rs
@@ -232,48 +232,66 @@ impl App {
pub fn render_selected_item(&mut self, area: Rect, buf: &mut Buffer) {
// We get the info depending on the item's state.
- // TODO: Implement logic showin informations for selected entry:
let style_value = Style::new().bold().fg(TEXT_FG_COLOR);
+ let style_value_sec = Style::new()
+ .add_modifier(Modifier::ITALIC)
+ .fg(TEXT_FG_COLOR);
let lines = {
+ let idx = self.entry_table.entry_table_state.selected().unwrap();
+ let cur_entry = &self.entry_table.entry_table_items[idx];
// if self.entry_table.entry_table_items.len() > 0 {
if self.entry_table.entry_table_state.selected().is_some() {
let mut lines = vec![];
lines.push(Line::from(vec![
Span::styled("Authors: ", style_value),
Span::styled(
- String::from(BibiEntry::get_authors(
- &self.get_selected_citekey(),
- &self.main_biblio.bibliography,
- )),
+ // String::from(BibiEntry::get_authors(
+ // &self.get_selected_citekey(),
+ // &self.main_biblio.bibliography,
+ // )),
+ // Style::new().green(),
+ cur_entry.authors.clone(),
Style::new().green(),
),
]));
lines.push(Line::from(vec![
Span::styled("Title: ", style_value),
Span::styled(
- String::from(BibiEntry::get_title(
- &self.get_selected_citekey(),
- &self.main_biblio.bibliography,
- )),
+ // String::from(BibiEntry::get_title(
+ // &self.get_selected_citekey(),
+ // &self.main_biblio.bibliography,
+ // )),
+ // Style::new().magenta(),
+ cur_entry.title.clone(),
Style::new().magenta(),
),
]));
lines.push(Line::from(vec![
Span::styled("Year: ", style_value),
- Span::styled(
- String::from(BibiEntry::get_year(
- &self.get_selected_citekey(),
- &self.main_biblio.bibliography,
- )),
- Style::new().light_magenta(),
- ),
+ Span::styled(cur_entry.year.clone(), Style::new().light_magenta()),
]));
+ if !cur_entry.doi_url.is_empty() {
+ lines.push(Line::raw(""));
+ lines.push(Line::from(vec![
+ Span::styled("DOI/URL: ", style_value_sec),
+ Span::styled(
+ cur_entry.doi_url.clone(),
+ Style::default().fg(TEXT_FG_COLOR).underlined(),
+ ),
+ ]));
+ }
+ if !cur_entry.filepath.is_empty() {
+ lines.push(Line::from(vec![
+ Span::styled("File: ", style_value_sec),
+ Span::styled(
+ cur_entry.filepath.clone(),
+ Style::default().fg(TEXT_FG_COLOR),
+ ),
+ ]));
+ }
lines.push(Line::from(""));
lines.push(Line::from(vec![Span::styled(
- String::from(BibiEntry::get_abstract(
- &self.get_selected_citekey(),
- &self.main_biblio.bibliography,
- )),
+ cur_entry.abstract_text.clone(),
Style::default().fg(TEXT_FG_COLOR),
)]));
lines
--
cgit v1.2.3