From 50256d954a026f7da3cce182717112e9c1d153f5 Mon Sep 17 00:00:00 2001
From: lukeflo
Date: Tue, 24 Sep 2024 22:50:50 +0200
Subject: bib backend structs
---
plainfile | 3 --
src/backend/bib.rs | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++--
src/frontend/app.rs | 54 +++++++++++++++++++++++++++++++++
3 files changed, 138 insertions(+), 5 deletions(-)
delete mode 100644 plainfile
diff --git a/plainfile b/plainfile
deleted file mode 100644
index 78481bb..0000000
--- a/plainfile
+++ /dev/null
@@ -1,3 +0,0 @@
-My first entry
-A second entry
-And a third one
diff --git a/src/backend/bib.rs b/src/backend/bib.rs
index 6e913fd..2aa6c8b 100644
--- a/src/backend/bib.rs
+++ b/src/backend/bib.rs
@@ -15,7 +15,7 @@
// along with this program. If not, see .
/////
-use biblatex::Bibliography;
+use biblatex::{Bibliography, ChunksExt, Type};
use std::{fs, path::PathBuf};
use super::cliargs::PosArgs;
@@ -56,5 +56,87 @@ impl BibiMain {
}
pub struct BibiData {
- pub citekey: Vec,
+ pub bibentries: Vec,
+}
+
+// Struct which has to be created for every entry of bibdatabase
+pub struct BibiEntry {
+ pub authors: String,
+ pub title: String,
+ pub year: String,
+ pub pubtype: String,
+ // pub keywords: Vec,
+ pub citekey: String,
+}
+
+// INFO & TODO: Iterator needs to process all citekeys (Vec) and should output another vector which holds every single entry as BibiEntry struct (Vec). Maybe the BibiEntry struct has to be wrapped inside a larger BibiEntryVec/BibiData struct or similar -> Iterator for BibiData!
+
+impl BibiEntry {
+ pub fn new(citekey: &str) -> Self {
+ Self {
+ authors: Self::get_authors(citekey),
+ title: Self::get_title(citekey),
+ year: Self::get_year(citekey),
+ pubtype: Self::get_pubtype(citekey),
+ // keywords: Self::get_keywords(citekey),
+ citekey: citekey.to_string(),
+ }
+ }
+
+ fn get_authors(citekey: &str) -> String {
+ let biblio = BibiMain::new().bibliography;
+ let authors = biblio.get(&citekey).unwrap().author().unwrap();
+ let authors = {
+ if authors.len() > 1 {
+ let authors = format!("{} et al.", authors[0].name);
+ authors
+ } else {
+ let authors = authors[0].name.to_string();
+ authors
+ }
+ };
+ authors
+ }
+
+ fn get_title(citekey: &str) -> String {
+ let biblio = BibiMain::new().bibliography;
+ let title = biblio
+ .get(&citekey)
+ .unwrap()
+ .title()
+ .unwrap()
+ .format_verbatim();
+ title
+ }
+
+ fn get_year(citekey: &str) -> String {
+ let biblio = BibiMain::new().bibliography;
+ let year = biblio
+ .get(&citekey)
+ .unwrap()
+ .date()
+ .unwrap()
+ .to_chunks()
+ .format_verbatim();
+
+ let year = &year[..4];
+ year.to_string()
+ }
+
+ fn get_pubtype(citekey: &str) -> String {
+ let biblio = BibiMain::new().bibliography;
+ let pubtype = biblio.get(&citekey).unwrap().entry_type.to_string();
+ pubtype
+ }
+
+ fn get_keywords(citekey: &str) -> String {
+ let biblio = BibiMain::new().bibliography;
+ let keywords = biblio
+ .get(&citekey)
+ .unwrap()
+ .keywords()
+ .unwrap()
+ .format_verbatim();
+ keywords
+ }
}
diff --git a/src/frontend/app.rs b/src/frontend/app.rs
index 0bee743..51a5aff 100644
--- a/src/frontend/app.rs
+++ b/src/frontend/app.rs
@@ -112,6 +112,23 @@ impl FromIterator<[String; 5]> for EntryTable {
}
}
+// // Also possible with vector. TODO: Decide whats better
+// impl FromIterator> for EntryTable {
+// fn from_iter>>(iter: T) -> Self {
+// // Has to be Vev
+// let entry_table_items = iter
+// .into_iter()
+// .sorted()
+// .map(|i| EntryTableItem::new(&i[0], &i[1], &i[2], &i[3], &i[4]))
+// .collect();
+// let entry_table_state = TableState::default().with_selected(0);
+// Self {
+// entry_table_items,
+// entry_table_state,
+// }
+// }
+// }
+
// Define list containing entries as table
#[derive(Debug)]
pub struct EntryTable {
@@ -209,6 +226,43 @@ impl Default for App {
"hurston_1919".to_string(),
],
];
+ // let iter = vec![
+ // vec![
+ // "Mrs. Doubtfire".to_string(),
+ // "A great book of great length".to_string(),
+ // "2003".to_string(),
+ // "book".to_string(),
+ // "doubtfire_2003".to_string(),
+ // ],
+ // vec![
+ // "Veye Tatah".to_string(),
+ // "Modern economy".to_string(),
+ // 1995.to_string(),
+ // "article".to_string(),
+ // "tatah_1995".to_string(),
+ // ],
+ // vec![
+ // "Joseph Conrad".to_string(),
+ // "Heart of Darkness".to_string(),
+ // 1899.to_string(),
+ // "book".to_string(),
+ // "conrad_1899".to_string(),
+ // ],
+ // vec![
+ // "Michelle-Rolpg Trouillot".to_string(),
+ // "Silencing the Past".to_string(),
+ // "1995".to_string(),
+ // "book".to_string(),
+ // "trouillot_1995".to_string(),
+ // ],
+ // vec![
+ // "Zora Neale Hurston".to_string(),
+ // "Barracoon".to_string(),
+ // "1919".to_string(),
+ // "book".to_string(),
+ // "hurston_1919".to_string(),
+ // ],
+ // ];
Self {
running: true,
tag_list: TagList::from_iter(lines),
--
cgit v1.2.3