From 16207edb77eef75903a007df6b2bd84cb4d5b943 Mon Sep 17 00:00:00 2001
From: Alexander_Kabui
Date: Tue, 10 Sep 2024 17:58:59 +0300
Subject: Implement client side pagination for history page.
---
gn2/wqflask/templates/gnqa_search_history.html | 24 ++++++++++++++++++++++++
gn2/wqflask/views.py | 13 ++++++++++++-
2 files changed, 36 insertions(+), 1 deletion(-)
diff --git a/gn2/wqflask/templates/gnqa_search_history.html b/gn2/wqflask/templates/gnqa_search_history.html
index 8d54ad80..c12e7c93 100644
--- a/gn2/wqflask/templates/gnqa_search_history.html
+++ b/gn2/wqflask/templates/gnqa_search_history.html
@@ -47,6 +47,30 @@
{% endfor %}
+
+
+
diff --git a/gn2/wqflask/views.py b/gn2/wqflask/views.py
index bb086a84..ec252cab 100644
--- a/gn2/wqflask/views.py
+++ b/gn2/wqflask/views.py
@@ -16,6 +16,7 @@ import random
import requests
import sys
import traceback
+import math
import uuid
import xlsxwriter
@@ -331,10 +332,20 @@ def get_gnqa_records():
**{"status_code": resp.status_code,
**resp.json()})
+ def get_chunk(items, page, size):
+ start_idx = ((page-1) * size)
+ end_idx = (page*size)
+ return iter(items[start_idx:end_idx])
+
def _success_(resp):
response = resp.json()
+ page = int(request.args.get("page", 1))
+ pagination_size = int(request.args.get("max_size", 10))
+ prev_n_queries = get_chunk(response, page, pagination_size)
return render_template("gnqa_search_history.html",
- prev_queries=response)
+ prev_queries=prev_n_queries,
+ num_pages=math.ceil(len(response)/pagination_size),
+ current=page)
token = session_info()["user"]["token"].either(
lambda err: err, lambda tok: tok["access_token"])
response_url = "/api/llm/search/records"
--
cgit v1.2.3