add persons page, quote count helpers, remove photo count UI for now
This commit is contained in:
@@ -74,6 +74,18 @@ impl Person {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_in_quote_count(&self) -> Result<i64, PersonError> {
|
||||||
|
Ok(database::conn()?
|
||||||
|
.prepare(
|
||||||
|
r#"
|
||||||
|
SELECT COUNT(DISTINCT l.quote_id) AS quote_count
|
||||||
|
FROM lines l WHERE l.name_id IN (
|
||||||
|
SELECT id FROM names WHERE person_id = ?1
|
||||||
|
);"#,
|
||||||
|
)?
|
||||||
|
.query_one((self.id,), |r| Ok(r.get(0)?))?)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn get_all_names(&self) -> Result<Vec<Name>, PersonError> {
|
pub fn get_all_names(&self) -> Result<Vec<Name>, PersonError> {
|
||||||
Ok(database::conn()?
|
Ok(database::conn()?
|
||||||
.prepare("SELECT id, is_primary, person_id, created_by, name FROM names WHERE person_id = ?1")?
|
.prepare("SELECT id, is_primary, person_id, created_by, name FROM names WHERE person_id = ?1")?
|
||||||
|
|||||||
@@ -52,6 +52,11 @@ impl Tag {
|
|||||||
None => Err(TagError::NoTagWithId(id)),
|
None => Err(TagError::NoTagWithId(id)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
pub fn get_tagged_quotes_count(&self) -> Result<i64, TagError> {
|
||||||
|
Ok(database::conn()?
|
||||||
|
.prepare("SELECT COUNT(*) FROM quote_tags WHERE tag_id = ?1")?
|
||||||
|
.query_one((self.id,), |r| Ok(r.get(0)?))?)
|
||||||
|
}
|
||||||
pub fn get_by_name(name: TagName) -> Result<Tag, TagError> {
|
pub fn get_by_name(name: TagName) -> Result<Tag, TagError> {
|
||||||
let res = database::conn()?
|
let res = database::conn()?
|
||||||
.prepare("SELECT id, tagname FROM tags WHERE tagname = ?1")?
|
.prepare("SELECT id, tagname FROM tags WHERE tagname = ?1")?
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ const LINKS: &[(&str, &str, &str, bool)] = &[
|
|||||||
("Dashboard", "/dashboard", icons::LAYOUT_DASHBOARD, false),
|
("Dashboard", "/dashboard", icons::LAYOUT_DASHBOARD, false),
|
||||||
("Quotes", "#quotes", icons::SCROLL_TEXT, false),
|
("Quotes", "#quotes", icons::SCROLL_TEXT, false),
|
||||||
("Photos", "#photos", icons::FILE_IMAGE, false),
|
("Photos", "#photos", icons::FILE_IMAGE, false),
|
||||||
("Persons", "#persons", icons::CONTACT, false),
|
("Persons", "/persons", icons::CONTACT, false),
|
||||||
("Tags", "/tags", icons::TAG, false),
|
("Tags", "/tags", icons::TAG, false),
|
||||||
("Users", "/users", icons::USERS, true),
|
("Users", "/users", icons::USERS, true),
|
||||||
("Logs", "#logs", icons::CLIPBOARD_CLOCK, true),
|
("Logs", "#logs", icons::CLIPBOARD_CLOCK, true),
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ use maud::{DOCTYPE, Markup, html};
|
|||||||
pub mod dashboard;
|
pub mod dashboard;
|
||||||
pub mod index;
|
pub mod index;
|
||||||
pub mod login;
|
pub mod login;
|
||||||
|
pub mod persons;
|
||||||
pub mod tags;
|
pub mod tags;
|
||||||
pub mod users;
|
pub mod users;
|
||||||
|
|
||||||
@@ -15,6 +16,7 @@ pub fn pages() -> Router {
|
|||||||
.route("/users", get(users::page))
|
.route("/users", get(users::page))
|
||||||
.route("/users/{id}", get(users::profile::page))
|
.route("/users/{id}", get(users::profile::page))
|
||||||
.route("/tags", get(tags::page))
|
.route("/tags", get(tags::page))
|
||||||
|
.route("/persons", get(persons::page))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn base(title: &str, inner: Markup) -> Markup {
|
pub fn base(title: &str, inner: Markup) -> Markup {
|
||||||
|
|||||||
71
src/web/pages/persons.rs
Normal file
71
src/web/pages/persons.rs
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
use axum::{
|
||||||
|
extract::Request,
|
||||||
|
response::{IntoResponse, Response},
|
||||||
|
};
|
||||||
|
use maud::{PreEscaped, html};
|
||||||
|
|
||||||
|
use crate::{
|
||||||
|
persons::Person,
|
||||||
|
users::{
|
||||||
|
User,
|
||||||
|
auth::{AuthError, UserAuthenticate},
|
||||||
|
},
|
||||||
|
web::{components::nav::nav, icons, pages::base},
|
||||||
|
};
|
||||||
|
|
||||||
|
pub async fn page(req: Request) -> Result<Response, AuthError> {
|
||||||
|
let u = User::authenticate(req.headers())?;
|
||||||
|
|
||||||
|
Ok(base(
|
||||||
|
"Persons | Mnemosyne",
|
||||||
|
html!(
|
||||||
|
(nav(u.as_ref(), req.uri().path()))
|
||||||
|
|
||||||
|
@if let Some(_) = u {
|
||||||
|
div class="mx-auto max-w-4xl px-2 my-4" {
|
||||||
|
p class="flex items-center gap-2" {
|
||||||
|
span class="text-neutral-500" {(PreEscaped(icons::CONTACT))}
|
||||||
|
span class="text-2xl font-semibold font-lora" {"Persons"}
|
||||||
|
}
|
||||||
|
p class="text-neutral-500 text-sm font-light" {
|
||||||
|
@if let Ok(c) = Person::total_count() {
|
||||||
|
(c) " persons in total."
|
||||||
|
} @else {
|
||||||
|
"Could not get total person count."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@if let Ok(persons) = Person::get_all() {
|
||||||
|
div class="max-w-4xl mx-auto mt-4 flex gap-2" {
|
||||||
|
@for person in &persons {
|
||||||
|
div class="rounded px-4 py-2 bg-neutral-200/10 border border-neutral-200/15 flex items-center" {
|
||||||
|
span class="text-neutral-400 mr-1" {"~"}
|
||||||
|
span class="text-sm" {(person.primary_name)}
|
||||||
|
div class="w-px h-2/3 my-auto mx-2 bg-neutral-200/15" {}
|
||||||
|
div class="text-xs flex items-center" {
|
||||||
|
(
|
||||||
|
if let Ok(i) = person.get_in_quote_count() {
|
||||||
|
i.to_string()
|
||||||
|
} else {
|
||||||
|
"?".to_string()
|
||||||
|
}
|
||||||
|
) span class="*:size-3 ml-1 text-neutral-400" {(PreEscaped(icons::SCROLL_TEXT))}
|
||||||
|
// div class="ml-2" {}
|
||||||
|
// "4" span class="*:size-3 ml-1 text-neutral-400" {(PreEscaped(icons::FILE_IMAGE))}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@if persons.is_empty() {
|
||||||
|
p class="text-center p-2" {"No persons yet."}
|
||||||
|
}
|
||||||
|
} @else {
|
||||||
|
p class="text-red-400 text-center" {"Failed to load persons."}
|
||||||
|
}
|
||||||
|
} @else {
|
||||||
|
p class="text-center p-2" {"You must be logged in to view this page."}
|
||||||
|
}
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.into_response())
|
||||||
|
}
|
||||||
@@ -43,9 +43,15 @@ pub async fn page(req: Request) -> Result<Response, AuthError> {
|
|||||||
span class="text-sm" {(tag.name)}
|
span class="text-sm" {(tag.name)}
|
||||||
div class="w-px h-2/3 my-auto mx-2 bg-neutral-200/15" {}
|
div class="w-px h-2/3 my-auto mx-2 bg-neutral-200/15" {}
|
||||||
div class="text-xs flex items-center" {
|
div class="text-xs flex items-center" {
|
||||||
"10" span class="*:size-3 ml-1 text-neutral-400" {(PreEscaped(icons::SCROLL_TEXT))}
|
(
|
||||||
div class="ml-2" {}
|
if let Ok(i) = tag.get_tagged_quotes_count() {
|
||||||
"4" span class="*:size-3 ml-1 text-neutral-400" {(PreEscaped(icons::FILE_IMAGE))}
|
i.to_string()
|
||||||
|
} else {
|
||||||
|
"?".to_string()
|
||||||
|
}
|
||||||
|
) span class="*:size-3 ml-1 text-neutral-400" {(PreEscaped(icons::SCROLL_TEXT))}
|
||||||
|
// div class="ml-2" {}
|
||||||
|
// "0" span class="*:size-3 ml-1 text-neutral-400" {(PreEscaped(icons::FILE_IMAGE))}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user