Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pagination to task index page #5

Open
yammmt opened this issue May 3, 2020 · 1 comment
Open

Add pagination to task index page #5

yammmt opened this issue May 3, 2020 · 1 comment
Assignees
Labels
enhancement New feature or request minor Minor issue: not critical

Comments

@yammmt
Copy link
Owner

yammmt commented May 3, 2020

It would be helpful if I have lots of tasks.

@yammmt yammmt added enhancement New feature or request minor Minor issue: not critical labels May 3, 2020
@yammmt yammmt self-assigned this May 6, 2020
@yammmt
Copy link
Owner Author

yammmt commented Apr 25, 2021

For DB side, limit and offset method provided by QueryDsl works fine. For example:

const TASK_PAGE_SIDZE: i64 = 5;

impl<'a, 'b> IndexContext<'a, 'b> {
    pub fn err(conn: &DbConn, msg: &'a str) -> IndexContext<'static, 'a> {
        IndexContext{ msg: Some(("warning", msg)), tasks: Task::all(conn), labels: Label::all(conn) }
    }

    pub fn raw(conn: &DbConn, msg: Option<(&'a str, &'b str)>, offset: i64) -> IndexContext<'a, 'b> {
        IndexContext{
            msg,
            tasks: Task::with_offset_and_limit(conn, offset, TASK_PAGE_SIZE),
            labels: Label::all(conn)
        }
    }
}

And Bulma provides pagination style too (document). I could implement pagination with them.


However, I have to think of current routes:

#[get("/")]
pub fn index(msg: Option<FlashMessage>, conn: DbConn) -> Template {

#[get("/<id>")]
pub fn edit(id: i32, msg: Option<FlashMessage>, conn: DbConn) -> Template {

If I want to keep the current URL, the pagination URL seems to be /page/1 or so. But this seems a little crazy for me. For me, /<number> should be the page number of the pagination, and instead /task/<number> should be the individual task page. How about the other sites on Internet? 🤔

Note that there are multiple HTTP methods for the /<number> route. Don't forget to see the src/routes/task.rs file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request minor Minor issue: not critical
Projects
None yet
Development

No branches or pull requests

1 participant