Add pagination links
This commit is contained in:
		
							parent
							
								
									5549e4d0e5
								
							
						
					
					
						commit
						04dac6f87f
					
				
							
								
								
									
										6
									
								
								po/de.po
									
									
									
									
									
								
							
							
						
						
									
										6
									
								
								po/de.po
									
									
									
									
									
								
							| @ -339,3 +339,9 @@ msgstr "" | |||||||
| 
 | 
 | ||||||
| msgid "Optional" | msgid "Optional" | ||||||
| msgstr "" | 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." | ||||||
|  | |||||||
							
								
								
									
										5
									
								
								po/en.po
									
									
									
									
									
								
							
							
						
						
									
										5
									
								
								po/en.po
									
									
									
									
									
								
							| @ -332,3 +332,8 @@ msgstr "" | |||||||
| 
 | 
 | ||||||
| msgid "Optional" | msgid "Optional" | ||||||
| msgstr "" | msgstr "" | ||||||
|  | 
 | ||||||
|  | msgid "One article in this blog" | ||||||
|  | msgid_plural "{{ count }} articles in this blog" | ||||||
|  | msgstr[0] "" | ||||||
|  | msgstr[1] "" | ||||||
|  | |||||||
							
								
								
									
										6
									
								
								po/fr.po
									
									
									
									
									
								
							
							
						
						
									
										6
									
								
								po/fr.po
									
									
									
									
									
								
							| @ -335,3 +335,9 @@ msgstr "" | |||||||
| 
 | 
 | ||||||
| msgid "Optional" | msgid "Optional" | ||||||
| msgstr "Optionnel" | 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 : " | ||||||
|  | |||||||
							
								
								
									
										7
									
								
								po/pl.po
									
									
									
									
									
								
							
							
						
						
									
										7
									
								
								po/pl.po
									
									
									
									
									
								
							| @ -343,5 +343,12 @@ msgstr "" | |||||||
| msgid "Optional" | msgid "Optional" | ||||||
| msgstr "Nieobowiązkowe" | 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" | #~ msgid "Logowanie" | ||||||
| #~ msgstr "Zaloguj się" | #~ msgstr "Zaloguj się" | ||||||
|  | |||||||
| @ -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>>(), |             "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>>(), |             "authors": authors.into_iter().map(|u| u.to_json(&*conn)).collect::<Vec<serde_json::Value>>(), | ||||||
|             "n_authors": authors.len(), |             "n_authors": authors.len(), | ||||||
|             "n_articles": articles.len() |             "n_articles": articles.len(), | ||||||
|  |             "page": page.page, | ||||||
|  |             "n_pages": Page::total(articles.len() as i32) | ||||||
|         })) |         })) | ||||||
|     })    
 |     })    
 | ||||||
| } | } | ||||||
|  | |||||||
| @ -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) { |     pub fn limits(&self) -> (i32, i32) { | ||||||
|         ((self.page - 1) * ITEMS_PER_PAGE, self.page * ITEMS_PER_PAGE) |         ((self.page - 1) * ITEMS_PER_PAGE, self.page * ITEMS_PER_PAGE) | ||||||
|     } |     } | ||||||
|  | |||||||
| @ -36,5 +36,6 @@ | |||||||
|                 {{ macros::post_card(article=article) }} |                 {{ macros::post_card(article=article) }} | ||||||
|             {% endfor %} |             {% endfor %} | ||||||
|         </div> |         </div> | ||||||
|  |         {{ macros::paginate(page=page, total=n_pages) }} | ||||||
|     </section> |     </section> | ||||||
| {% endblock content %} | {% endblock content %} | ||||||
|  | |||||||
| @ -35,3 +35,13 @@ | |||||||
|     {% endif %} |     {% endif %} | ||||||
|     <input type="{{ type }}" id="{{ name }}" name="{{ name }}" value="{{ form[name] | default(value="") }}" {{ props | safe }}/> |     <input type="{{ type }}" id="{{ name }}" name="{{ name }}" value="{{ form[name] | default(value="") }}" {{ props | safe }}/> | ||||||
| {% endmacro input %} | {% 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 %} | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user