fix: adjust domain accessors and template adapter for Askama compatibility
This commit is contained in:
@@ -7,6 +7,7 @@ edition = "2024"
|
|||||||
askama = { version = "0.16.0" }
|
askama = { version = "0.16.0" }
|
||||||
|
|
||||||
serde = { workspace = true }
|
serde = { workspace = true }
|
||||||
|
chrono = { workspace = true }
|
||||||
|
|
||||||
domain = { workspace = true }
|
domain = { workspace = true }
|
||||||
application = { workspace = true }
|
application = { workspace = true }
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ struct UsersTemplate<'a> {
|
|||||||
#[template(path = "profile.html")]
|
#[template(path = "profile.html")]
|
||||||
struct ProfileTemplate<'a> {
|
struct ProfileTemplate<'a> {
|
||||||
ctx: &'a HtmlPageContext,
|
ctx: &'a HtmlPageContext,
|
||||||
profile_user_email: &'a str,
|
profile_display_name: String,
|
||||||
stats: &'a UserStats,
|
stats: &'a UserStats,
|
||||||
view: &'a str,
|
view: &'a str,
|
||||||
entries: Option<&'a Paginated<DiaryEntry>>,
|
entries: Option<&'a Paginated<DiaryEntry>>,
|
||||||
@@ -79,6 +79,7 @@ struct HeatmapCell {
|
|||||||
bg_style: String,
|
bg_style: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
fn relative_time(dt: chrono::NaiveDateTime) -> String {
|
fn relative_time(dt: chrono::NaiveDateTime) -> String {
|
||||||
let now = chrono::Utc::now().naive_utc();
|
let now = chrono::Utc::now().naive_utc();
|
||||||
let diff = now.signed_duration_since(dt);
|
let diff = now.signed_duration_since(dt);
|
||||||
@@ -192,9 +193,11 @@ impl HtmlRenderer for AskamaHtmlRenderer {
|
|||||||
let heatmap = data.history.as_deref()
|
let heatmap = data.history.as_deref()
|
||||||
.map(|h| build_heatmap(h))
|
.map(|h| build_heatmap(h))
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
|
let profile_display_name = data.profile_user_email
|
||||||
|
.split('@').next().unwrap_or(&data.profile_user_email).to_string();
|
||||||
ProfileTemplate {
|
ProfileTemplate {
|
||||||
ctx: &data.ctx,
|
ctx: &data.ctx,
|
||||||
profile_user_email: &data.profile_user_email,
|
profile_display_name,
|
||||||
stats: &data.stats,
|
stats: &data.stats,
|
||||||
view: &data.view,
|
view: &data.view,
|
||||||
entries: data.entries.as_ref(),
|
entries: data.entries.as_ref(),
|
||||||
|
|||||||
@@ -8,6 +8,12 @@ pub struct HtmlPageContext {
|
|||||||
pub register_enabled: bool,
|
pub register_enabled: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl HtmlPageContext {
|
||||||
|
pub fn is_current_user(&self, id: Uuid) -> bool {
|
||||||
|
self.user_id == Some(id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub struct LoginPageData<'a> {
|
pub struct LoginPageData<'a> {
|
||||||
pub ctx: HtmlPageContext,
|
pub ctx: HtmlPageContext,
|
||||||
pub error: Option<&'a str>,
|
pub error: Option<&'a str>,
|
||||||
|
|||||||
@@ -193,6 +193,11 @@ impl Review {
|
|||||||
pub fn created_at(&self) -> &NaiveDateTime {
|
pub fn created_at(&self) -> &NaiveDateTime {
|
||||||
&self.created_at
|
&self.created_at
|
||||||
}
|
}
|
||||||
|
/// Returns [star1_filled, star2_filled, ..., star5_filled]
|
||||||
|
pub fn stars(&self) -> [bool; 5] {
|
||||||
|
let r = self.rating.value();
|
||||||
|
[r >= 1, r >= 2, r >= 3, r >= 4, r >= 5]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
@@ -306,6 +311,9 @@ impl UserSummary {
|
|||||||
pub fn avg_rating_display(&self) -> String {
|
pub fn avg_rating_display(&self) -> String {
|
||||||
self.avg_rating.map(|r| format!("{:.1}", r)).unwrap_or_else(|| "—".to_string())
|
self.avg_rating.map(|r| format!("{:.1}", r)).unwrap_or_else(|| "—".to_string())
|
||||||
}
|
}
|
||||||
|
pub fn initial(&self) -> char {
|
||||||
|
self.display_name().chars().next().unwrap_or('?').to_ascii_uppercase()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
@@ -344,6 +352,12 @@ pub struct MonthlyRating {
|
|||||||
pub count: i64,
|
pub count: i64,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl MonthlyRating {
|
||||||
|
pub fn bar_height_pct(&self) -> i64 {
|
||||||
|
(self.avg_rating / 5.0 * 100.0) as i64
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct DirectorStat {
|
pub struct DirectorStat {
|
||||||
pub director: String,
|
pub director: String,
|
||||||
|
|||||||
Reference in New Issue
Block a user