From f65408a64dd72dd2d7b99e512698cb513e9248c0 Mon Sep 17 00:00:00 2001 From: Michael Green <84688932+michael-j-green@users.noreply.github.com> Date: Mon, 29 Jan 2024 18:08:09 +1100 Subject: [PATCH] Game library should return to the page it was on after a page navigation or refresh Fixes #253 * Game library should return to the page it was on after a page navigation or refresh Fixes #253 --- gaseous-server/wwwroot/pages/home.html | 2 +- .../wwwroot/scripts/filterformating.js | 23 +++++++++++++++---- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/gaseous-server/wwwroot/pages/home.html b/gaseous-server/wwwroot/pages/home.html index f0ff2b7..397f51f 100644 --- a/gaseous-server/wwwroot/pages/home.html +++ b/gaseous-server/wwwroot/pages/home.html @@ -43,7 +43,7 @@ var scrollerElement = document.getElementById('games_filter_scroller'); formatFilterPanel(scrollerElement, result); - executeFilter1_1(); + //executeFilter1_1(); }); $('#games_library_orderby_select').select2(); diff --git a/gaseous-server/wwwroot/scripts/filterformating.js b/gaseous-server/wwwroot/scripts/filterformating.js index 7369bb4..58267bc 100644 --- a/gaseous-server/wwwroot/scripts/filterformating.js +++ b/gaseous-server/wwwroot/scripts/filterformating.js @@ -110,16 +110,30 @@ function formatFilterPanel(containerElement, result) { // set order by values var orderByCookie = getCookie('games_library_orderby_select'); if (orderByCookie) { - document.getElementById('games_library_orderby_select').value = orderByCookie; + var orderBySelector = document.getElementById('games_library_orderby_select'); + $(orderBySelector).select2('destroy'); + $(orderBySelector).val(orderByCookie).select2(); } var orderByDirectionCookie = getCookie('games_library_orderby_direction_select'); if (orderByDirectionCookie) { - document.getElementById('games_library_orderby_direction_select').value = orderByDirectionCookie; + var orderByDirectionSelector = document.getElementById('games_library_orderby_direction_select'); + $(orderByDirectionSelector).select2('destroy'); + $(orderByDirectionSelector).val(orderByDirectionCookie).select2(); } containerElement.appendChild(targetElement); containerElement.appendChild(buttonsDiv); + + console.log('Filter generated - execute filter'); + var pageNumber = undefined; + if (getCookie('games_library_last_page') == "") { + pageNumber = undefined; + } else { + pageNumber = Number(getCookie('games_library_last_page')); + } + + executeFilter1_1(pageNumber); } function buildFilterPanel(targetElement, headerString, friendlyHeaderString, valueList, showToggle, initialDisplay) { @@ -381,10 +395,10 @@ function executeFilter1_1(pageNumber, pageSize) { var model; // get order by - var orderBy = document.getElementById('games_library_orderby_select').value; + var orderBy = $('#games_library_orderby_select').val(); setCookie('games_library_orderby_select', orderBy); var orderByDirection = true; - var orderByDirectionSelect = document.getElementById('games_library_orderby_direction_select').value; + var orderByDirectionSelect = $('#games_library_orderby_direction_select').val(); if (orderByDirectionSelect == "Ascending") { orderByDirection = true; } else { @@ -553,6 +567,7 @@ function executeFilter1_1(pageNumber, pageSize) { 'POST', function (result) { var gameElement = document.getElementById('games_library'); + setCookie('games_library_last_page', pageNumber); formatGamesPanel(gameElement, result, pageNumber, pageSize, true); }, function (error) {