diff --git a/src/views/live-preview/pages/logs/logs.vue b/src/views/live-preview/pages/logs/logs.vue index e5d3d97c7..9e1a75278 100644 --- a/src/views/live-preview/pages/logs/logs.vue +++ b/src/views/live-preview/pages/logs/logs.vue @@ -15,6 +15,11 @@ export default { DatePicker, }, setup() { + const searchPage = ref(); + const currentPage = ref(1); + const totalPages = ref(1); + const paginate = ref(20); + const page = ref(1); const pdfLoading = ref(false); const csvLoading = ref(false); const filterLoading = ref(false); @@ -23,6 +28,27 @@ export default { const logs = ref(); const startDate = ref(); const endDate = ref(); + + const visiblePages = computed(() => { + const pages = []; + if (totalPages.value <= 5) { + for (let i = 1; i <= totalPages.value; i++) { + pages.push(i); + } + } else { + let start = currentPage.value - 2; + let end = currentPage.value + 2; + + if (start < 1) start = 1; + if (end > totalPages.value) end = totalPages.value; + + for (let i = start; i <= end; i++) { + pages.push(i); + } + } + return pages; + }); + const exportFile = (param) => { if (param === "pdf") { console.log("pdf"); @@ -101,7 +127,7 @@ export default { selectedUser.value || "" }&start_date=${startDate.value || ""}&end_date=${ endDate.value || "" - }`, + }&paginate=${paginate.value || 10}&page=${page.value || 1}`, { headers: { "Content-Type": "application/json", @@ -111,13 +137,45 @@ export default { ) .then((resp) => { filterLoading.value = false; - logs.value = resp.data.data; + logs.value = resp.data.data.data; + currentPage.value = resp.data.data.current_page; + totalPages.value = resp.data.data.last_page; }) .catch(() => { filterLoading.value = false; }); }; + function handlePageInput() { + if (searchPage.value < 1) { + searchPage.value = 1; + } else if (searchPage.value > totalPages.value) { + searchPage.value = totalPages.value; + } + + if (searchPage.value >= 1 && searchPage.value <= totalPages.value) { + page.value = searchPage.value; + } + } + + watch(page, () => { + getLogs(); + }); + + const nextPage = () => { + if (currentPage.value < totalPages.value) { + page.value++; + getLogs(); + } + }; + + const prevPage = () => { + if (currentPage.value > 1) { + page.value--; + getLogs(); + } + }; + const handleLocationUpdate = () => { location.reload(); }; @@ -189,6 +247,15 @@ export default { pdfLoading, csvLoading, exportFile, + + currentPage, + totalPages, + nextPage, + prevPage, + page, + handlePageInput, + searchPage, + visiblePages, }; }, }; @@ -309,6 +376,78 @@ export default { + + +
+ +
+
+ +
+ +
+
+
@@ -333,4 +472,46 @@ export default { animation: spin 1s linear infinite; margin: 20px auto; /* Center the loader */ } +.search-number { + display: flex; + align-items: center; +} + +.search-number input { + width: 150px; + padding: 0.5rem; + font-size: 1rem; + border-radius: 0.375rem; + margin-bottom: 7px; + border: 1px solid #ced4da; + transition: border-color 0.3s ease, box-shadow 0.3s ease; +} + +.search-number input:focus { + border-color: #007bff; + box-shadow: 0 0 0 0.2rem rgba(38, 143, 255, 0.25); +} + +.search-number input::placeholder { + color: #6c757d; +} + +.search-number input:disabled { + background-color: #f8f9fa; + cursor: not-allowed; +} +.pagination { + display: flex; + flex-wrap: wrap; + gap: 5px; +} + +.page-item { + flex: 0 0 auto; +} + +.page-link { + cursor: pointer; + user-select: none; +}