windjammer_ui/components/generated/
pagination.rs1#![allow(clippy::all)]
2#![allow(noop_method_call)]
3use super::traits::Renderable;
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq)]
6pub struct Pagination {
7 pub current_page: i32,
8 pub total_pages: i32,
9 pub show_first_last: bool,
10 pub show_prev_next: bool,
11}
12
13impl Pagination {
14 #[inline]
15 pub fn new(current_page: i32, total_pages: i32) -> Pagination {
16 Pagination {
17 current_page,
18 total_pages,
19 show_first_last: true,
20 show_prev_next: true,
21 }
22 }
23 #[inline]
24 pub fn show_first_last(mut self, show: bool) -> Pagination {
25 self.show_first_last = show;
26 self
27 }
28 #[inline]
29 pub fn show_prev_next(mut self, show: bool) -> Pagination {
30 self.show_prev_next = show;
31 self
32 }
33}
34
35impl Renderable for Pagination {
36 #[inline]
37 fn render(self) -> String {
38 let mut html = "<nav class='wj-pagination'><ul>".to_string();
39 if self.show_first_last {
40 html = format!(
41 "{}<li class='wj-pagination-item'><a href='#'>«</a></li>",
42 html
43 );
44 }
45 if self.show_prev_next {
46 let prev_disabled = {
47 if self.current_page == 1 {
48 " disabled".to_string()
49 } else {
50 "".to_string()
51 }
52 };
53 html = format!(
54 "{}<li class='wj-pagination-item{}'><a href='#'>‹</a></li>",
55 html, prev_disabled
56 );
57 }
58 let mut page = 1;
59 while page <= self.total_pages {
60 let active = {
61 if page == self.current_page {
62 " active".to_string()
63 } else {
64 "".to_string()
65 }
66 };
67 html = format!(
68 "{}<li class='wj-pagination-item{}'><a href='#'>{}</a></li>",
69 html, active, page
70 );
71 page += 1;
72 }
73 if self.show_prev_next {
74 let next_disabled = {
75 if self.current_page == self.total_pages {
76 " disabled".to_string()
77 } else {
78 "".to_string()
79 }
80 };
81 html = format!(
82 "{}<li class='wj-pagination-item{}'><a href='#'>›</a></li>",
83 html, next_disabled
84 );
85 }
86 if self.show_first_last {
87 html = format!(
88 "{}<li class='wj-pagination-item'><a href='#'>»</a></li>",
89 html
90 );
91 }
92 format!("{}</ul></nav>", html)
93 }
94}