From aefa31b84ebe81718f1b42fbd52e5f82f5808e71 Mon Sep 17 00:00:00 2001 From: Bat Date: Sat, 12 May 2018 17:55:25 +0100 Subject: [PATCH] Add a few (ugly) badges to the user page --- src/routes/user.rs | 5 ++++- static/main.css | 10 ++++++++++ templates/users/details.tera | 38 +++++++++++++++++++++++++----------- 3 files changed, 41 insertions(+), 12 deletions(-) diff --git a/src/routes/user.rs b/src/routes/user.rs index 653e1c92..6907bd76 100644 --- a/src/routes/user.rs +++ b/src/routes/user.rs @@ -23,6 +23,8 @@ fn me(user: User) -> Redirect { fn details(name: String, conn: DbConn, account: Option) -> Template { let user = User::find_by_fqn(&*conn, name).unwrap(); let recents = Post::get_recents_for_author(&*conn, &user, 5); + let user_id = user.id.clone(); + Template::render("users/details", json!({ "user": serde_json::to_value(user).unwrap(), "account": account, @@ -33,7 +35,8 @@ fn details(name: String, conn: DbConn, account: Option) -> Template { "url": p.compute_id(&*conn), "date": p.creation_date.timestamp() }) - }).collect::>() + }).collect::>(), + "is_self": account.map(|a| a.id == user_id).unwrap_or(false) })) } diff --git a/static/main.css b/static/main.css index 1901af38..9b5f9ee9 100644 --- a/static/main.css +++ b/static/main.css @@ -91,3 +91,13 @@ textarea { min-height: 200px; resize: vertical; } + +.badge { + font-size: 12pt; + background: white; + color: #7a28cb; + border: 1px solid #7a28cb; + border-radius: 3px; + padding: 5px 10px; + margin: 0px 10px; +} diff --git a/templates/users/details.tera b/templates/users/details.tera index 717d41e4..7cf5a8f1 100644 --- a/templates/users/details.tera +++ b/templates/users/details.tera @@ -5,17 +5,33 @@ {% endblock title %} {% block content %} -

{{ user.display_name }}

-
- {{ user.summary | safe }} -
- -

Latest articles

-{% for article in recents %}
-

{{ article.post.title }}

-

{{ article.post.content | escape | truncate(length=200) }}…

-

By {{ article.author.display_name }} ⋅ {{ article.date | date(format="%B %e") }}

+

+ {{ user.display_name }} + {% if user.is_admin %} + Admin + {% endif %} + + {% if is_self %} + It is you + {% endif %} +

+ + {% if is_self %} + Edit your profile + {% endif %}
-{% endfor %} + +
+ {{ user.summary | safe }} +
+ +

Latest articles

+ {% for article in recents %} +
+

{{ article.post.title }}

+

{{ article.post.content | escape | truncate(length=200) }}…

+

By {{ article.author.display_name }} ⋅ {{ article.date | date(format="%B %e") }}

+
+ {% endfor %} {% endblock content %}