From e721ca280e7904625489708f43f846f5e12c7154 Mon Sep 17 00:00:00 2001 From: Michael Leon Putra Widhi <leonmichael463@gmail.com> Date: Sat, 7 Oct 2023 00:10:27 +0700 Subject: [PATCH] feat : adaptive numbers of product, refactor : scheme and styling --- scripts/client/pages/home/index.php | 2 +- scripts/client/public/css/pages/product.css | 22 +++++++++++++++++++ scripts/client/public/js/login.js | 4 ++-- scripts/client/public/js/product.js | 2 ++ scripts/client/public/js/signup.js | 4 ++-- scripts/index.html | 3 +-- .../app/controllers/ProductController.php | 2 +- 7 files changed, 31 insertions(+), 8 deletions(-) diff --git a/scripts/client/pages/home/index.php b/scripts/client/pages/home/index.php index 4b3def1..1794436 100644 --- a/scripts/client/pages/home/index.php +++ b/scripts/client/pages/home/index.php @@ -35,7 +35,7 @@ </div> </div> </div> - <div class="listTitle">Showing 14 items...</div> + <div class="listTitle">Showing <input class="numsie" type="text" id="numsofObj" value="" placeholder="0" readonly> items...</div> <div id="queryResultProduct" class="queryResultProduct"></div> <div class="pagination" id="pagenumProduct"></div> </div> diff --git a/scripts/client/public/css/pages/product.css b/scripts/client/public/css/pages/product.css index de1eef0..81534f7 100644 --- a/scripts/client/public/css/pages/product.css +++ b/scripts/client/public/css/pages/product.css @@ -8,6 +8,26 @@ row-gap: 0.25vh; } +#numsofObj { + background-color: inherit; + font-size: 1.5rem; + width: 1.7rem; + color: white; + border: none; + justify-items: center; + text-align: center; +} + +#numsofObj::placeholder { + background-color: inherit; + font-size: 1.5rem; + width: 1.7rem; + color: white; + border: none; + justify-items: center; + text-align: center; +} + .productMenu { width: 100%; display: flex; @@ -38,6 +58,8 @@ font-size: 1.5rem; align-items: center; margin-bottom: 1.5rem; + display: inline; + white-space: nowrap; } @media only screen and (max-width: 768px) { diff --git a/scripts/client/public/js/login.js b/scripts/client/public/js/login.js index 96f4ef3..689a8bb 100644 --- a/scripts/client/public/js/login.js +++ b/scripts/client/public/js/login.js @@ -10,10 +10,10 @@ document.getElementById('login-form').addEventListener('submit', function(event) console.log(this.responseText); if (this.responseText == "Login successful.") { alert("Login success!"); - window.location.href = "http://localhost:8000/client/pages/home"; + window.location.href = "http://localhost:8000/pages/home"; } else { alert("Invalid username or password. Please try again."); - window.location.href = "http://localhost:8000/client/pages/login"; + window.location.href = "http://localhost:8000/pages/login"; } } }; diff --git a/scripts/client/public/js/product.js b/scripts/client/public/js/product.js index 7bc9a7a..541c5f4 100644 --- a/scripts/client/public/js/product.js +++ b/scripts/client/public/js/product.js @@ -81,7 +81,9 @@ function selectProduct(numPage) { let res = JSON.parse(this.responseText); currentPageProduct = numPage; if (res['status']) { + console.log(res['data']['total']); products = res['data']; + document.querySelector("#numsofObj").value = String(res['data']['total']); totalPageProduct = res['data']['pages']; clearProduct(); appendData(products['products'], "queryResultProduct"); diff --git a/scripts/client/public/js/signup.js b/scripts/client/public/js/signup.js index 311930a..eb0d007 100644 --- a/scripts/client/public/js/signup.js +++ b/scripts/client/public/js/signup.js @@ -52,10 +52,10 @@ document.getElementById('register-form').addEventListener('submit', function(eve console.log(res); if (res["status"]) { alert("Account created!"); - window.location.href = "http://localhost:8000/client/pages/login"; + window.location.href = "http://localhost:8000/pages/login"; } else { alert("Username already exists! Failed to create account!"); - window.location.href = "http://localhost:8000/client/pages/signup" + window.location.href = "http://localhost:8000/pages/signup" } } }; diff --git a/scripts/index.html b/scripts/index.html index f28166d..51686ca 100644 --- a/scripts/index.html +++ b/scripts/index.html @@ -1,8 +1,7 @@ <!DOCTYPE HTML5> <head> <meta charset="utf-8" /> - <link rel="icon" /> - <meta name="viewport" content="width=device-width, initial-scale=1" /> + <link rel="icon" type="image/png" href="http://localhost:8000/public/images/logo.png"> <meta http-equiv="refresh" content="3;url=http://localhost:8000/pages/home" /> <link rel="stylesheet" href="http://localhost:8000/public/css/globals.css"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"> diff --git a/scripts/server/app/controllers/ProductController.php b/scripts/server/app/controllers/ProductController.php index 804148b..4f39c3c 100644 --- a/scripts/server/app/controllers/ProductController.php +++ b/scripts/server/app/controllers/ProductController.php @@ -196,7 +196,7 @@ class ProductController extends Controller { // Pagination if ($res) { - json_response_success(array("products" => $res, "pages" => ceil($total/$limit_page))); + json_response_success(array("products" => $res, "pages" => ceil($total/$limit_page), "total" => $total)); } else { json_response_fail(PRODUCT_NOT_FOUND); } -- GitLab