From 71fd9413e71aa34bdb18519c9cd6c76d7558f9e6 Mon Sep 17 00:00:00 2001 From: Thunder Date: Sun, 3 Mar 2024 08:43:11 +0700 Subject: [PATCH 1/2] Add paging for list order --- .../management/order/OrderServlet.java | 35 +++++- .../view/assets/js/validate/validator.js | 4 +- .../view/jsp/management/order/order.jsp | 112 +++++++++++------- 3 files changed, 102 insertions(+), 49 deletions(-) diff --git a/src/main/java/io/hardingadonis/saledock/controller/management/order/OrderServlet.java b/src/main/java/io/hardingadonis/saledock/controller/management/order/OrderServlet.java index 50b83b2..30d45de 100644 --- a/src/main/java/io/hardingadonis/saledock/controller/management/order/OrderServlet.java +++ b/src/main/java/io/hardingadonis/saledock/controller/management/order/OrderServlet.java @@ -11,6 +11,8 @@ @WebServlet(name = "OrderServlet", urlPatterns = {"/order"}) public class OrderServlet extends HttpServlet { + + final static int LIMIT = 10; @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) @@ -19,12 +21,26 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response) response.setContentType("text/html; charset=UTF-8"); List orders = Singleton.orderDAO.getAll(); + int count = Singleton.orderDAO.count(); - List reversedOrders = orders.stream() - .sorted(Comparator.comparing(Order::getID).reversed()) - .collect(Collectors.toList()); + int pageNum = getInteger(request.getParameter("page")); + int offset = pageNum; - request.setAttribute("orders", reversedOrders); + if (offset == -1){ + offset = 0; + pageNum = 1; + } else { + offset = (offset - 1)*LIMIT; + } + + List orderPaging = Singleton.orderDAO.pagination(offset, LIMIT); + int total = Singleton.orderDAO.totalPages(LIMIT); + + request.setAttribute("numOfOrder", count); + request.setAttribute("currentPage", pageNum); + request.setAttribute("totalPage", total); + request.setAttribute("limit", LIMIT); + request.setAttribute("orders", orderPaging); request.setAttribute("page", "order"); request.getRequestDispatcher("/view/jsp/management/order/order.jsp").forward(request, response); @@ -34,4 +50,15 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response) protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { } + + private static int getInteger(String parameter){ + if (parameter == null) { + return -1; + } + try { + return Integer.parseInt(parameter); + } catch (NumberFormatException e) { + return -1; + } + } } diff --git a/src/main/webapp/view/assets/js/validate/validator.js b/src/main/webapp/view/assets/js/validate/validator.js index 44cd0f6..47e27aa 100644 --- a/src/main/webapp/view/assets/js/validate/validator.js +++ b/src/main/webapp/view/assets/js/validate/validator.js @@ -1,4 +1,3 @@ - //Object 'Validator' function Validator(options) { @@ -250,5 +249,4 @@ function updateCKEditor() { if (typeof CKEDITOR !== 'undefined' && CKEDITOR.instances['description']) { CKEDITOR.instances['description'].updateElement(); } -} - +} \ No newline at end of file diff --git a/src/main/webapp/view/jsp/management/order/order.jsp b/src/main/webapp/view/jsp/management/order/order.jsp index b4c62ec..b4250f3 100644 --- a/src/main/webapp/view/jsp/management/order/order.jsp +++ b/src/main/webapp/view/jsp/management/order/order.jsp @@ -34,57 +34,85 @@

Quản lý đơn hàng

Thêm đơn hàng
-
-
- - - - - - - - - - - + +
+
+
Mã đặt hàngTên khách hàngTổng tiềnThao tác
+ - - - - + + + + + + + + + + + + + + + + + +
${order.code}${order.customer.name}${order.getTotalToString()} - - - + Mã đặt hàngTên khách hàngTổng tiềnThao tác
${order.code}${order.customer.name}${order.getTotalToString()} + + + + + + + - - +
+
+
+
+

+ Hiển thị ${requestScope.currentPage * requestScope.limit < requestScope.numOfOrder ? requestScope.currentPage * requestScope.limit : requestScope.numOfOrder} + trên ${requestScope.numOfOrder} đơn hàng +

+
+
+
-
-
-

Hiển thị 1 trong 1 đơn hàng

+ + +
  • + + + +
  • + + +
    -
    - +
    + + +
    +
    +

    + Không có đơn hàng nào để quản lí. +

    -
    +
    From cadb1dfafa5b0ea9d2d91cffdb75b7a7037c929e Mon Sep 17 00:00:00 2001 From: Thunder Date: Sun, 3 Mar 2024 14:18:37 +0700 Subject: [PATCH 2/2] Update format currency in list order --- src/main/webapp/view/jsp/management/order/order.jsp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/webapp/view/jsp/management/order/order.jsp b/src/main/webapp/view/jsp/management/order/order.jsp index b4250f3..4c4b0c0 100644 --- a/src/main/webapp/view/jsp/management/order/order.jsp +++ b/src/main/webapp/view/jsp/management/order/order.jsp @@ -40,10 +40,10 @@ - - - - + + + + @@ -51,7 +51,7 @@ - +
    Mã đặt hàngTên khách hàngTổng tiềnThao tácMã đặt hàngTên khách hàngTổng tiềnThao tác
    ${order.code} ${order.customer.name}${order.getTotalToString()}${order.getTotalToString()} ₫