better way to know whether this is the last page
This commit is contained in:
parent
cd553608a5
commit
4c33b63f97
|
@ -5,7 +5,7 @@ from flask_login import login_required, current_user
|
||||||
|
|
||||||
from app import alias_utils
|
from app import alias_utils
|
||||||
from app.api.serializer import get_alias_infos_with_pagination_v3, get_alias_info_v3
|
from app.api.serializer import get_alias_infos_with_pagination_v3, get_alias_info_v3
|
||||||
from app.config import ALIAS_LIMIT
|
from app.config import ALIAS_LIMIT, PAGE_LIMIT
|
||||||
from app.dashboard.base import dashboard_bp
|
from app.dashboard.base import dashboard_bp
|
||||||
from app.db import Session
|
from app.db import Session
|
||||||
from app.extensions import limiter
|
from app.extensions import limiter
|
||||||
|
@ -161,21 +161,20 @@ def index():
|
||||||
directory_id = int(alias_filter[len("directory:") :])
|
directory_id = int(alias_filter[len("directory:") :])
|
||||||
|
|
||||||
alias_infos = get_alias_infos_with_pagination_v3(
|
alias_infos = get_alias_infos_with_pagination_v3(
|
||||||
current_user, page, query, sort, alias_filter, mailbox_id, directory_id
|
|
||||||
)
|
|
||||||
# to know whether there's alias on the next page
|
|
||||||
next_page_alias = get_alias_infos_with_pagination_v3(
|
|
||||||
current_user,
|
current_user,
|
||||||
page + 1, # next page
|
page,
|
||||||
query,
|
query,
|
||||||
sort,
|
sort,
|
||||||
alias_filter,
|
alias_filter,
|
||||||
mailbox_id,
|
mailbox_id,
|
||||||
directory_id,
|
directory_id,
|
||||||
page_limit=1, # only load 1 alias
|
# load 1 alias more to know whether this is the last page
|
||||||
|
page_limit=PAGE_LIMIT + 1,
|
||||||
)
|
)
|
||||||
|
|
||||||
last_page = len(next_page_alias) == 0
|
last_page = len(alias_infos) <= PAGE_LIMIT
|
||||||
|
# remove the last alias that's added to know whether this is the last page
|
||||||
|
alias_infos = alias_infos[:PAGE_LIMIT]
|
||||||
|
|
||||||
# add highlighted alias in case it's not included
|
# add highlighted alias in case it's not included
|
||||||
if highlight_alias_id and highlight_alias_id not in [
|
if highlight_alias_id and highlight_alias_id not in [
|
||||||
|
|
|
@ -536,7 +536,7 @@
|
||||||
<div class="col">
|
<div class="col">
|
||||||
<nav aria-label="Alias navigation">
|
<nav aria-label="Alias navigation">
|
||||||
<ul class="pagination">
|
<ul class="pagination">
|
||||||
<li class="page-item">
|
<li class="page-item mr-1">
|
||||||
<a class="btn btn-outline-primary {% if page == 0 %}disabled{% endif %}"
|
<a class="btn btn-outline-primary {% if page == 0 %}disabled{% endif %}"
|
||||||
href="{{ url_for('dashboard.index', page=page-1, query=query, sort=sort, filter=filter) }}">
|
href="{{ url_for('dashboard.index', page=page-1, query=query, sort=sort, filter=filter) }}">
|
||||||
Previous</a>
|
Previous</a>
|
||||||
|
|
Loading…
Reference in a new issue