Add pagination links

This commit is contained in:
Bat 2018-07-25 14:29:34 +02:00
parent 5549e4d0e5
commit 04dac6f87f
8 changed files with 47 additions and 1 deletions

View File

@ -339,3 +339,9 @@ msgstr ""
msgid "Optional"
msgstr ""
#, fuzzy
msgid "One article in this blog"
msgid_plural "{{ count }} articles in this blog"
msgstr[0] "Du bist kein Autor in diesem Blog."
msgstr[1] "Du bist kein Autor in diesem Blog."

View File

@ -332,3 +332,8 @@ msgstr ""
msgid "Optional"
msgstr ""
msgid "One article in this blog"
msgid_plural "{{ count }} articles in this blog"
msgstr[0] ""
msgstr[1] ""

View File

@ -335,3 +335,9 @@ msgstr ""
msgid "Optional"
msgstr "Optionnel"
#, fuzzy
msgid "One article in this blog"
msgid_plural "{{ count }} articles in this blog"
msgstr[0] "{{ count }} aut⋅eur⋅rice dans ce blog : "
msgstr[1] "{{ count }} aut⋅eur⋅rice⋅s dans ce blog : "

View File

@ -343,5 +343,12 @@ msgstr ""
msgid "Optional"
msgstr "Nieobowiązkowe"
#, fuzzy
msgid "One article in this blog"
msgid_plural "{{ count }} articles in this blog"
msgstr[0] "Ten blog ma jednego autora: "
msgstr[1] "Ten blog ma {{ count }} autorów: "
msgstr[2] "Ten blog ma {{ count }} autorów: "
#~ msgid "Logowanie"
#~ msgstr "Zaloguj się"

View File

@ -34,7 +34,9 @@ fn paginated_details(name: String, conn: DbConn, user: Option<User>, page: Page)
"posts": posts.into_iter().map(|p| p.to_json(&*conn)).collect::<Vec<serde_json::Value>>(),
"authors": authors.into_iter().map(|u| u.to_json(&*conn)).collect::<Vec<serde_json::Value>>(),
"n_authors": authors.len(),
"n_articles": articles.len()
"n_articles": articles.len(),
"page": page.page,
"n_pages": Page::total(articles.len() as i32)
}))
})
}

View File

@ -61,6 +61,15 @@ impl Page {
}
}
/// Computes the total number of pages needed to display n_items
pub fn total(n_items: i32) -> i32 {
if n_items % ITEMS_PER_PAGE == 0 {
n_items / ITEMS_PER_PAGE
} else {
(n_items / ITEMS_PER_PAGE) + 1
}
}
pub fn limits(&self) -> (i32, i32) {
((self.page - 1) * ITEMS_PER_PAGE, self.page * ITEMS_PER_PAGE)
}

View File

@ -36,5 +36,6 @@
{{ macros::post_card(article=article) }}
{% endfor %}
</div>
{{ macros::paginate(page=page, total=n_pages) }}
</section>
{% endblock content %}

View File

@ -35,3 +35,13 @@
{% endif %}
<input type="{{ type }}" id="{{ name }}" name="{{ name }}" value="{{ form[name] | default(value="") }}" {{ props | safe }}/>
{% endmacro input %}
{% macro paginate(page, total, previous="Previous page", next="Next page") %}
<div class="pagination">
{% if page != 1 %}
<a href="?page={{ page - 1 }}">{{ previous | _ }}</a>
{% endif %}
{% if page < total %}
<a href="?page={{ page + 1 }}">{{ next | _ }}</a>
{% endif %}
</div>
{% endmacro %}