diff --git a/web-app/django/VIM/apps/instruments/static/instruments/css/pagination.css b/web-app/django/VIM/apps/instruments/static/instruments/css/pagination.css new file mode 100644 index 0000000..2f385c5 --- /dev/null +++ b/web-app/django/VIM/apps/instruments/static/instruments/css/pagination.css @@ -0,0 +1,40 @@ +input[type="number"] { + border: 1px solid #9EB384; + border-radius: 4px; + padding: 5px; + width: 50px; + color: #435334; + margin: 0 0.3rem; +} + +input[type="number"]:hover { + border: 1px solid #435334; + color: #435334; +} + +input[type="number"]:focus { + border: 1px solid #435334; + box-shadow: 0 0 5px #9EB384; + outline: none; +} + +.btn-check:checked + .btn { + color: #435334; + border: none; + padding: 0.1rem 0.2rem; +} + +.btn-check:not(:checked) + .btn { + color: #9EB384; + border: none; + padding: 0.1rem 0.2rem; +} + +.text-start, .text-end { + color: #435334; + margin: 0 0.3rem; +} + +.col-form-label { + color: #435334; +} \ No newline at end of file diff --git a/web-app/django/VIM/apps/instruments/static/instruments/js/PaginationTools.js b/web-app/django/VIM/apps/instruments/static/instruments/js/PaginationTools.js index 28795e3..d31ed15 100644 --- a/web-app/django/VIM/apps/instruments/static/instruments/js/PaginationTools.js +++ b/web-app/django/VIM/apps/instruments/static/instruments/js/PaginationTools.js @@ -1,66 +1,77 @@ -const paginationModal = document.getElementById("paginationModal"); const instrumentNumElement = document.getElementById('instrumentNum'); const instrumentNum = instrumentNumElement.getAttribute('data-instrument-num'); - -const savePaginationBtn = document.getElementById("save-pagination-setting"); -const paginateByInput = document.getElementById("pagination-range"); const pageNumInput = document.getElementById("page-num"); -const rangeValue = document.getElementById("range-value"); - const pageBtns = document.querySelectorAll(".page-link"); +const optionRadios = document.querySelectorAll(".option-radio"); updatePaginationSetting(); -function setPaginationSetting(paginateBy, pageNum) { +function updatePaginationSetting() { + const url = new URL(window.location.href); + const page = url.searchParams.get("page") || 1; + const paginateBy = url.searchParams.get("paginate_by") || 20; + setPage(page); + setPaginateBy(paginateBy); + pageNumInput.max = Math.ceil(instrumentNum / paginateBy); +} + +function setPaginateBy(paginateBy) { localStorage.setItem("paginate_by", paginateBy); - localStorage.setItem("page", pageNum); } -function getPaginationSetting() { - return { - paginate_by: localStorage.getItem("paginate_by"), - page: localStorage.getItem("page") - }; +function setPage(pageNum) { + localStorage.setItem("page", pageNum); } -function updatePaginationSetting() { - currentPaginateBy = getPaginationSetting().paginate_by || 20; - currentPageNum = getPaginationSetting().page || 1; - paginateByInput.value = currentPaginateBy; - pageNumInput.value = currentPageNum; +function getPaginateBy() { + return localStorage.getItem("paginate_by"); } -function pageNumInputValidation() { - maxPageNum = Math.ceil(instrumentNum / paginateByInput.value); - if (pageNumInput.value < 1) { - pageNumInput.value = 1; - } else if (pageNumInput.value > maxPageNum) { - pageNumInput.value = maxPageNum; - } +function getPage() { + return localStorage.getItem("page"); } -paginateByInput.addEventListener("input", function () { - rangeValue.textContent = this.value; - maxPageNum = Math.ceil(instrumentNum / this.value); - if (pageNumInput.value > maxPageNum) { - pageNumInput.value = maxPageNum; +optionRadios.forEach(function(radio) { + if (radio.id == getPaginateBy()) { + radio.checked = true; } - pageNumInput.max = maxPageNum; }); -savePaginationBtn.addEventListener("click", () => { - pageNumInputValidation(); - const url = new URL(window.location.href); - url.searchParams.set("paginate_by", paginateByInput.value); - url.searchParams.set("page", pageNumInput.value); - window.location.href = url.href; - setPaginationSetting(paginateByInput.value, pageNumInput.value); - updatePaginationSetting(); +optionRadios.forEach(function(radio) { + radio.addEventListener("change", function() { + if (radio.checked) { + const selectedOptionInt = parseInt(radio.id); + setPaginateBy(selectedOptionInt); + maxPageNum = Math.ceil(instrumentNum / getPaginateBy()); + validPageNum = Math.min(Math.max(getPage(), 1), maxPageNum); + if (validPageNum !== getPage()) { + setPage(validPageNum); + } + refreshPage(); + } + }); +}); + +pageNumInput.addEventListener("keydown", function(event) { + if (event.key === "Enter") { + maxPageNum = Math.ceil(instrumentNum / getPaginateBy()); + validPageNum = Math.min(Math.max(pageNumInput.value, 1), maxPageNum); + pageNumInput.value = validPageNum; + pageNumInput.max = maxPageNum; + setPage(validPageNum); + refreshPage(); + } }); pageBtns.forEach((btn) => { btn.addEventListener("click", () => { - paginate_by = localStorage.getItem("paginate_by"); - btn.href = btn.href + "&paginate_by=" + paginate_by; + btn.href = btn.href + "&paginate_by=" + getPaginateBy(); }); -}); \ No newline at end of file +}); + +function refreshPage() { + const url = new URL(window.location.href); + url.searchParams.set("page", getPage()); + url.searchParams.set("paginate_by", getPaginateBy()); + window.location.href = url.href; +} \ No newline at end of file diff --git a/web-app/django/VIM/apps/instruments/templates/instruments/includes/pageSetting.html b/web-app/django/VIM/apps/instruments/templates/instruments/includes/pageSetting.html deleted file mode 100644 index a280c0a..0000000 --- a/web-app/django/VIM/apps/instruments/templates/instruments/includes/pageSetting.html +++ /dev/null @@ -1,148 +0,0 @@ - - - - \ No newline at end of file diff --git a/web-app/django/VIM/apps/instruments/templates/instruments/index.html b/web-app/django/VIM/apps/instruments/templates/instruments/index.html index 389bbdc..c4e1020 100644 --- a/web-app/django/VIM/apps/instruments/templates/instruments/index.html +++ b/web-app/django/VIM/apps/instruments/templates/instruments/index.html @@ -7,8 +7,9 @@ {% block css_files %} + {% endblock %} - + {% block content %}
@@ -93,10 +94,6 @@

INSTRUMENT LIST

- - {% include "instruments/includes/pageSetting.html" %} @@ -110,48 +107,83 @@

INSTRUMENT LIST


+
+ + Showing {{ page_obj.start_index }} to {{ page_obj.end_index }} of {{ page_obj.paginator.count }} entries + +
+ View + + + + + + + + + per page +
+
{% include "instruments/includes/masonryView.html" %} {% comment %} {% include "instruments/includes/listView.html" %} {% endcomment %} {% include "instruments/includes/stdView.html" %}
- -
- +
+
+ + +