Add Recent Transactions pagination and table view to with filtering
Convert the Recent Transactions card from a list view to a paginated table with enhanced filtering capabilities for super users. Frontend changes: - Replace q-list with q-table for better data presentation - Add pagination with configurable page size (default: 20 items) - Add transaction filter dropdown for super users to filter by username - Define table columns: Status, Date, Description, User, Amount, Fiat, Reference - Implement prev/next page navigation with page info display - Add filter controls with clear filter button Backend changes (views_api.py): - Add pagination support with limit/offset parameters - Add filter_user_id parameter for filtering by user (super user only) - Enrich transaction entries with user_id and username from account lookups - Return paginated response with total count and pagination metadata Database changes (crud.py): - Update get_all_journal_entries() to support offset parameter - Update get_journal_entries_by_user() to support offset parameter - Add count_all_journal_entries() for total count - Add count_journal_entries_by_user() for user-specific count This improves the Recent Transactions UX by providing better organization, easier navigation through large transaction lists, and the ability for admins to filter transactions by user.
This commit is contained in:
parent
093cecbff2
commit
f3d0d8652b
3 changed files with 172 additions and 47 deletions
38
views_api.py
38
views_api.py
|
|
@ -267,10 +267,12 @@ async def api_get_user_entries(
|
|||
wallet: WalletTypeInfo = Depends(require_invoice_key),
|
||||
limit: int = 20,
|
||||
offset: int = 0,
|
||||
filter_user_id: str = None,
|
||||
) -> dict:
|
||||
"""Get journal entries that affect the current user's accounts"""
|
||||
from lnbits.settings import settings as lnbits_settings
|
||||
from .crud import count_all_journal_entries, count_journal_entries_by_user
|
||||
from lnbits.core.crud.users import get_user
|
||||
from .crud import count_all_journal_entries, count_journal_entries_by_user, get_account
|
||||
|
||||
# If super user, show all journal entries
|
||||
if wallet.wallet.user == lnbits_settings.super_user:
|
||||
|
|
@ -280,8 +282,40 @@ async def api_get_user_entries(
|
|||
entries = await get_journal_entries_by_user(wallet.wallet.user, limit, offset)
|
||||
total = await count_journal_entries_by_user(wallet.wallet.user)
|
||||
|
||||
# Filter by user_id if specified (super user only)
|
||||
if filter_user_id and wallet.wallet.user == lnbits_settings.super_user:
|
||||
entries = [e for e in entries if any(
|
||||
line.account_id in [acc["id"] for acc in await db.fetchall(
|
||||
"SELECT id FROM accounts WHERE user_id = :user_id",
|
||||
{"user_id": filter_user_id}
|
||||
)]
|
||||
for line in e.lines
|
||||
)]
|
||||
total = len(entries)
|
||||
|
||||
# Enrich entries with username information
|
||||
enriched_entries = []
|
||||
for entry in entries:
|
||||
# Find user_id from entry lines (look for user-specific accounts)
|
||||
entry_user_id = None
|
||||
entry_username = None
|
||||
|
||||
for line in entry.lines:
|
||||
account = await get_account(line.account_id)
|
||||
if account and account.user_id:
|
||||
entry_user_id = account.user_id
|
||||
user = await get_user(account.user_id)
|
||||
entry_username = user.username if user and user.username else account.user_id[:16] + "..."
|
||||
break
|
||||
|
||||
enriched_entries.append({
|
||||
**entry.dict(),
|
||||
"user_id": entry_user_id,
|
||||
"username": entry_username,
|
||||
})
|
||||
|
||||
return {
|
||||
"entries": entries,
|
||||
"entries": enriched_entries,
|
||||
"total": total,
|
||||
"limit": limit,
|
||||
"offset": offset,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue