Add a few (ugly) badges to the user page

This commit is contained in:
Bat 2018-05-12 17:55:25 +01:00
parent ea08718c23
commit aefa31b84e
3 changed files with 41 additions and 12 deletions

View File

@ -23,6 +23,8 @@ fn me(user: User) -> Redirect {
fn details(name: String, conn: DbConn, account: Option<User>) -> Template { fn details(name: String, conn: DbConn, account: Option<User>) -> Template {
let user = User::find_by_fqn(&*conn, name).unwrap(); let user = User::find_by_fqn(&*conn, name).unwrap();
let recents = Post::get_recents_for_author(&*conn, &user, 5); let recents = Post::get_recents_for_author(&*conn, &user, 5);
let user_id = user.id.clone();
Template::render("users/details", json!({ Template::render("users/details", json!({
"user": serde_json::to_value(user).unwrap(), "user": serde_json::to_value(user).unwrap(),
"account": account, "account": account,
@ -33,7 +35,8 @@ fn details(name: String, conn: DbConn, account: Option<User>) -> Template {
"url": p.compute_id(&*conn), "url": p.compute_id(&*conn),
"date": p.creation_date.timestamp() "date": p.creation_date.timestamp()
}) })
}).collect::<Vec<serde_json::Value>>() }).collect::<Vec<serde_json::Value>>(),
"is_self": account.map(|a| a.id == user_id).unwrap_or(false)
})) }))
} }

View File

@ -91,3 +91,13 @@ textarea {
min-height: 200px; min-height: 200px;
resize: vertical; resize: vertical;
} }
.badge {
font-size: 12pt;
background: white;
color: #7a28cb;
border: 1px solid #7a28cb;
border-radius: 3px;
padding: 5px 10px;
margin: 0px 10px;
}

View File

@ -5,17 +5,33 @@
{% endblock title %} {% endblock title %}
{% block content %} {% block content %}
<h1>{{ user.display_name }}</h1> <div>
<div> <h1>
{{ user.summary | safe }} {{ user.display_name }}
</div> {% if user.is_admin %}
<span class="badge">Admin</span>
{% endif %}
<h2>Latest articles</h2> {% if is_self %}
{% for article in recents %} <span class="badge">It is you</span>
{% endif %}
</h1>
{% if is_self %}
<a href="edit" class="button inline-block">Edit your profile</a>
{% endif %}
</div>
<div>
{{ user.summary | safe }}
</div>
<h2>Latest articles</h2>
{% for article in recents %}
<div> <div>
<h3><a href="{{ article.url }}">{{ article.post.title }}</a></h3> <h3><a href="{{ article.url }}">{{ article.post.title }}</a></h3>
<p>{{ article.post.content | escape | truncate(length=200) }}…</p> <p>{{ article.post.content | escape | truncate(length=200) }}…</p>
<p>By {{ article.author.display_name }} ⋅ {{ article.date | date(format="%B %e") }}</p> <p>By {{ article.author.display_name }} ⋅ {{ article.date | date(format="%B %e") }}</p>
</div> </div>
{% endfor %} {% endfor %}
{% endblock content %} {% endblock content %}