diff --git a/gaseous-server/Controllers/V1.0/GamesController.cs b/gaseous-server/Controllers/V1.0/GamesController.cs index 1997e8b9..2482dccf 100644 --- a/gaseous-server/Controllers/V1.0/GamesController.cs +++ b/gaseous-server/Controllers/V1.0/GamesController.cs @@ -43,7 +43,7 @@ SignInManager signInManager [MapToApiVersion("1.0")] [HttpGet] [ProducesResponseType(typeof(List), StatusCodes.Status200OK)] - public ActionResult Game( + public async Task Game( string name = "", string platform = "", string genre = "", @@ -303,7 +303,7 @@ public static List GetGames( [ProducesResponseType(typeof(Game), StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status404NotFound)] [ResponseCache(CacheProfileName = "5Minute")] - public ActionResult Game(long GameId) + public async Task Game(long GameId) { try { @@ -331,7 +331,7 @@ public ActionResult Game(long GameId) [ProducesResponseType(typeof(List), StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status404NotFound)] [ResponseCache(CacheProfileName = "7Days")] - public ActionResult GameAlternativeNames(long GameId) + public async Task GameAlternativeNames(long GameId) { try { @@ -364,7 +364,7 @@ public ActionResult GameAlternativeNames(long GameId) [ProducesResponseType(typeof(List), StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status404NotFound)] [ResponseCache(CacheProfileName = "7Days")] - public ActionResult GameAgeClassification(long GameId) + public async Task GameAgeClassification(long GameId) { try { @@ -397,7 +397,7 @@ public ActionResult GameAgeClassification(long GameId) [ProducesResponseType(typeof(List), StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status404NotFound)] [ResponseCache(CacheProfileName = "7Days")] - public ActionResult GameArtwork(long GameId) + public async Task GameArtwork(long GameId) { try { @@ -428,7 +428,7 @@ public ActionResult GameArtwork(long GameId) [ProducesResponseType(typeof(Artwork), StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status404NotFound)] [ResponseCache(CacheProfileName = "7Days")] - public ActionResult GameArtwork(long GameId, long ArtworkId) + public async Task GameArtwork(long GameId, long ArtworkId) { try { @@ -464,7 +464,7 @@ public ActionResult GameArtwork(long GameId, long ArtworkId) [Route("{GameId}/artwork/{ArtworkId}/image/{size}/{ImageName}")] [ProducesResponseType(typeof(FileStreamResult), StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status404NotFound)] - public ActionResult GameCoverImage(long GameId, long ArtworkId, Communications.IGDBAPI_ImageSize size, string ImageName) + public async Task GameCoverImage(long GameId, long ArtworkId, Communications.IGDBAPI_ImageSize size, string ImageName) { try { @@ -531,7 +531,7 @@ public ActionResult GameCoverImage(long GameId, long ArtworkId, Communications.I [ProducesResponseType(typeof(Cover), StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status404NotFound)] [ResponseCache(CacheProfileName = "7Days")] - public ActionResult GameCover(long GameId) + public async Task GameCover(long GameId) { try { @@ -566,7 +566,7 @@ public ActionResult GameCover(long GameId) [Route("{GameId}/cover/image/{size}/{imagename}")] [ProducesResponseType(typeof(FileStreamResult), StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status404NotFound)] - public ActionResult GameCoverImage(long GameId, Communications.IGDBAPI_ImageSize size, string imagename = "") + public async Task GameCoverImage(long GameId, Communications.IGDBAPI_ImageSize size, string imagename = "") { try { @@ -693,7 +693,7 @@ public async Task GameSetFavouriteAsync(long GameId, bool favourit [ProducesResponseType(typeof(List), StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status404NotFound)] [ResponseCache(CacheProfileName = "7Days")] - public ActionResult GameGenre(long GameId) + public async Task GameGenre(long GameId) { try { @@ -731,7 +731,7 @@ public ActionResult GameGenre(long GameId) [ProducesResponseType(typeof(List>), StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status404NotFound)] [ResponseCache(CacheProfileName = "7Days")] - public ActionResult GameInvolvedCompanies(long GameId) + public async Task GameInvolvedCompanies(long GameId) { try { @@ -776,7 +776,7 @@ public ActionResult GameInvolvedCompanies(long GameId) [ProducesResponseType(typeof(Dictionary), StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status404NotFound)] [ResponseCache(CacheProfileName = "7Days")] - public ActionResult GameInvolvedCompanies(long GameId, long CompanyId) + public async Task GameInvolvedCompanies(long GameId, long CompanyId) { try { @@ -818,7 +818,7 @@ public ActionResult GameInvolvedCompanies(long GameId, long CompanyId) [Route("{GameId}/companies/{CompanyId}/image")] [ProducesResponseType(typeof(FileStreamResult), StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status404NotFound)] - public ActionResult GameCompanyImage(long GameId, long CompanyId) + public async Task GameCompanyImage(long GameId, long CompanyId) { try { @@ -863,7 +863,7 @@ public ActionResult GameCompanyImage(long GameId, long CompanyId) [Route("{GameId}/platforms")] [ProducesResponseType(typeof(List>), StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status404NotFound)] - public ActionResult GamePlatforms(long GameId) + public async Task GamePlatforms(long GameId) { try { @@ -882,7 +882,7 @@ public ActionResult GamePlatforms(long GameId) [ProducesResponseType(typeof(List), StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status404NotFound)] [ResponseCache(CacheProfileName = "7Days")] - public ActionResult GameReleaseDates(long GameId) + public async Task GameReleaseDates(long GameId) { try { @@ -943,7 +943,7 @@ public async Task GameRomAsync(long GameId, int pageNumber = 0, in [ProducesResponseType(typeof(Classes.Roms.GameRomItem), StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status404NotFound)] //[ResponseCache(CacheProfileName = "5Minute")] - public ActionResult GameRom(long GameId, long RomId) + public async Task GameRom(long GameId, long RomId) { try { @@ -972,7 +972,7 @@ public ActionResult GameRom(long GameId, long RomId) [Route("{GameId}/roms/{RomId}")] [ProducesResponseType(typeof(Classes.Roms.GameRomItem), StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status404NotFound)] - public ActionResult GameRomRename(long GameId, long RomId, long NewPlatformId, long NewGameId) + public async Task GameRomRename(long GameId, long RomId, long NewPlatformId, long NewGameId) { try { @@ -1002,7 +1002,7 @@ public ActionResult GameRomRename(long GameId, long RomId, long NewPlatformId, l [Route("{GameId}/roms/{RomId}")] [ProducesResponseType(typeof(Classes.Roms.GameRomItem), StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status404NotFound)] - public ActionResult GameRomDelete(long GameId, long RomId) + public async Task GameRomDelete(long GameId, long RomId) { try { @@ -1034,7 +1034,7 @@ public ActionResult GameRomDelete(long GameId, long RomId) [Route("{GameId}/roms/{RomId}/file")] [ProducesResponseType(typeof(FileStreamResult), StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status404NotFound)] - public ActionResult GameRomFile(long GameId, long RomId) + public async Task GameRomFile(long GameId, long RomId) { try { @@ -1073,7 +1073,7 @@ public ActionResult GameRomFile(long GameId, long RomId) [Route("{GameId}/roms/{RomId}/{FileName}")] [ProducesResponseType(typeof(FileStreamResult), StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status404NotFound)] - public ActionResult GameRomFile(long GameId, long RomId, string FileName) + public async Task GameRomFile(long GameId, long RomId, string FileName) { try { @@ -1172,7 +1172,7 @@ public async Task GetGameRomGroupAsync(long GameId) [Route("{GameId}/romgroup")] [ProducesResponseType(typeof(Classes.RomMediaGroup.GameRomMediaGroupItem), StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status404NotFound)] - public ActionResult NewGameRomGroup(long GameId, long PlatformId, [FromBody] List RomIds) + public async Task NewGameRomGroup(long GameId, long PlatformId, [FromBody] List RomIds) { try { @@ -1233,7 +1233,7 @@ public async Task GameRomGroupMembersAsync(long GameId, long RomGr [Route("{GameId}/romgroup/{RomGroupId}")] [ProducesResponseType(typeof(Classes.RomMediaGroup.GameRomMediaGroupItem), StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status404NotFound)] - public ActionResult GameRomGroupDelete(long GameId, long RomGroupId) + public async Task GameRomGroupDelete(long GameId, long RomGroupId) { try { @@ -1266,7 +1266,7 @@ public ActionResult GameRomGroupDelete(long GameId, long RomGroupId) [Route("{GameId}/romgroup/{RomGroupId}/{filename}")] [ProducesResponseType(typeof(FileStreamResult), StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status404NotFound)] - public ActionResult GameRomGroupFile(long GameId, long RomGroupId, string filename = "") + public async Task GameRomGroupFile(long GameId, long RomGroupId, string filename = "") { try { @@ -1311,7 +1311,7 @@ public ActionResult GameRomGroupFile(long GameId, long RomGroupId, string filena [Route("search")] [ProducesResponseType(typeof(List), StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status404NotFound)] - public ActionResult GameSearch(long RomId = 0, string SearchString = "") + public async Task GameSearch(long RomId = 0, string SearchString = "") { try { @@ -1352,7 +1352,7 @@ public ActionResult GameSearch(long RomId = 0, string SearchString = "") [ProducesResponseType(typeof(List), StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status404NotFound)] [ResponseCache(CacheProfileName = "7Days")] - public ActionResult GameScreenshot(long GameId) + public async Task GameScreenshot(long GameId) { try { @@ -1383,7 +1383,7 @@ public ActionResult GameScreenshot(long GameId) [ProducesResponseType(typeof(Screenshot), StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status404NotFound)] [ResponseCache(CacheProfileName = "7Days")] - public ActionResult GameScreenshot(long GameId, long ScreenshotId) + public async Task GameScreenshot(long GameId, long ScreenshotId) { try { @@ -1417,7 +1417,7 @@ public ActionResult GameScreenshot(long GameId, long ScreenshotId) [Route("{GameId}/screenshots/{ScreenshotId}/image/{size}/{ImageName}")] [ProducesResponseType(typeof(FileStreamResult), StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status404NotFound)] - public ActionResult GameScreenshotImage(long GameId, long ScreenshotId, Communications.IGDBAPI_ImageSize Size, string ImageName) + public async Task GameScreenshotImage(long GameId, long ScreenshotId, Communications.IGDBAPI_ImageSize Size, string ImageName) { try { @@ -1468,7 +1468,7 @@ public ActionResult GameScreenshotImage(long GameId, long ScreenshotId, Communic [ProducesResponseType(typeof(List), StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status404NotFound)] [ResponseCache(CacheProfileName = "7Days")] - public ActionResult GameVideo(long GameId) + public async Task GameVideo(long GameId) { try { diff --git a/gaseous-server/Controllers/V1.1/GamesController.cs b/gaseous-server/Controllers/V1.1/GamesController.cs index 67ce3727..50e2e191 100644 --- a/gaseous-server/Controllers/V1.1/GamesController.cs +++ b/gaseous-server/Controllers/V1.1/GamesController.cs @@ -593,23 +593,29 @@ LEFT JOIN // build alpha list Dictionary AlphaList = new Dictionary(); - int CurrentPage = 0; - int NextPageIndex = 0; + int CurrentPage = 1; + int NextPageIndex = pageSize; for (int i = 0; i < dbResponse.Rows.Count; i++) { string firstChar = dbResponse.Rows[i]["NameThe"].ToString().Substring(0, 1).ToUpperInvariant(); if (!"ABCDEFGHIJKLMNOPQRSTUVWXYZ".Contains(firstChar)) { - firstChar = "#"; - } - if (!AlphaList.ContainsKey(firstChar)) - { - AlphaList.Add(firstChar, CurrentPage); + if (!AlphaList.ContainsKey("#")) + { + AlphaList.Add("#", 1); + } } - if (NextPageIndex == i) + else { - NextPageIndex += pageSize; - CurrentPage += 1; + if (!AlphaList.ContainsKey(firstChar)) + { + AlphaList.Add(firstChar, CurrentPage); + } + if (NextPageIndex == i + 1) + { + NextPageIndex += pageSize; + CurrentPage += 1; + } } } diff --git a/gaseous-server/wwwroot/pages/dialogs/userprofile.html b/gaseous-server/wwwroot/pages/dialogs/userprofile.html index f2356950..81963323 100644 --- a/gaseous-server/wwwroot/pages/dialogs/userprofile.html +++ b/gaseous-server/wwwroot/pages/dialogs/userprofile.html @@ -72,6 +72,11 @@

Game Library

+ + + Note: The page will need to be reloaded for changes to take effect. + + @@ -221,7 +226,7 @@

Reset Password

if (getQueryString('page', 'string') == 'home' || getQueryString('page', 'string') == undefined) { setCookie('games_library_last_page', 1); - location.reload(); + //location.reload(); } closeDialog(); diff --git a/gaseous-server/wwwroot/scripts/filterformating.js b/gaseous-server/wwwroot/scripts/filterformating.js index 228d0518..a40f7149 100644 --- a/gaseous-server/wwwroot/scripts/filterformating.js +++ b/gaseous-server/wwwroot/scripts/filterformating.js @@ -405,7 +405,7 @@ function executeFilter1_1(pageNumber, pageSize) { if (!pageSize) { switch (pageMode) { case "infinite": - pageSize = 5; + pageSize = 30; break; case "paged": default: diff --git a/gaseous-server/wwwroot/scripts/gamesformating.js b/gaseous-server/wwwroot/scripts/gamesformating.js index 4e83f8e4..4b9b971a 100644 --- a/gaseous-server/wwwroot/scripts/gamesformating.js +++ b/gaseous-server/wwwroot/scripts/gamesformating.js @@ -77,52 +77,54 @@ function formatGamesPanel(targetElement, result, pageNumber, pageSize, forceScro break; case 'infinite': var gamePlaceholders = document.getElementsByName('GamePlaceholder'); - let currentPageValue = 0; - let nextPageThreshold = -1; - for (var i = 0; i < result.count; i++) { - if (i >= nextPageThreshold) { - // new page - currentPageValue ++; - nextPageThreshold = i + pageSize; - - if (currentPageValue > 0) { - if (!document.getElementById('pageFooterAnchor' + (currentPageValue - 1))) { - let newFooterPageAnchor = document.createElement('a'); - newFooterPageAnchor.id = 'pageFooterAnchor' + (currentPageValue - 1); - newFooterPageAnchor.setAttribute('name', 'pageAnchor' + (currentPageValue - 1)); - newFooterPageAnchor.className = 'pageFooterAnchor'; - newFooterPageAnchor.setAttribute('data-page', (currentPageValue - 1)); - newFooterPageAnchor.setAttribute('data-loaded', "0"); - targetElement.appendChild(newFooterPageAnchor); - } - } - if (!document.getElementById('pageAnchor' + currentPageValue)) { - let newPageAnchor = document.createElement('a'); - newPageAnchor.id = 'pageAnchor' + currentPageValue; - newPageAnchor.setAttribute('name', 'pageAnchor' + currentPageValue); - newPageAnchor.className = 'pageAnchor'; - newPageAnchor.setAttribute('data-page', currentPageValue); - newPageAnchor.setAttribute('data-loaded', "0"); - targetElement.appendChild(newPageAnchor); - } + let currentPage = 1; + let totalPages = Math.ceil(result.count / pageSize); + let startIndex = 0; + let endIndex = pageSize; + for (let p = currentPage; p < totalPages + 1; p++) { + //console.log("Page: " + p + " - StartIndex: " + startIndex + " - EndIndex: " + endIndex); + + let newPageAnchor = document.getElementById('pageAnchor' + p); + if (!newPageAnchor) { + newPageAnchor = document.createElement('span'); + newPageAnchor.id = 'pageAnchor' + p; + newPageAnchor.setAttribute('name', 'pageAnchor' + p); + newPageAnchor.className = 'pageAnchor'; + newPageAnchor.setAttribute('data-page', p); + newPageAnchor.setAttribute('data-loaded', "0"); + targetElement.appendChild(newPageAnchor); + } + + if (endIndex > result.count) { + endIndex = result.count; } - var placeHolderpresent = false; - for (var x = 0; x < gamePlaceholders.length; x++) { - if (gamePlaceholders[x].getAttribute('data-index') == i) { - placeHolderpresent = true; + for (let i = startIndex; i < endIndex; i++) { + var placeHolderpresent = false; + for (var x = 0; x < gamePlaceholders.length; x++) { + if (gamePlaceholders[x].getAttribute('data-index') == i) { + placeHolderpresent = true; + } + } + if (placeHolderpresent == false) { + var gamePlaceholder = document.createElement('div'); + gamePlaceholder.setAttribute('name', 'GamePlaceholder'); + gamePlaceholder.id = 'GamePlaceholder' + i; + gamePlaceholder.setAttribute('data-index', i); + gamePlaceholder.className = 'game_tile'; + newPageAnchor.appendChild(gamePlaceholder); } } - if (placeHolderpresent == false) { - var gamePlaceholder = document.createElement('div'); - gamePlaceholder.setAttribute('name', 'GamePlaceholder'); - gamePlaceholder.id = 'GamePlaceholder' + i; - gamePlaceholder.setAttribute('data-index', i); - gamePlaceholder.className = 'game_tile'; - targetElement.appendChild(gamePlaceholder); + + startIndex = endIndex; + endIndex = startIndex + pageSize; + + if (startIndex > result.count) { + break; } } + break; } @@ -160,6 +162,8 @@ function formatGamesPanel(targetElement, result, pageNumber, pageSize, forceScro break; } + + $(game).fadeIn(500); } var pager = document.getElementById('games_pager'); @@ -173,7 +177,7 @@ function formatGamesPanel(targetElement, result, pageNumber, pageSize, forceScro for (const [key, value] of Object.entries(result.alphaList)) { var letterPager = document.createElement('span'); letterPager.className = 'games_library_alpha_pager_letter'; - letterPager.setAttribute('onclick', 'document.location.hash = "#pageAnchor' + value + '"; executeFilter1_1(' + value + ');'); + letterPager.setAttribute('onclick', 'document.location.hash = "#pageAnchor' + (value) + '"; executeFilter1_1(' + (value) + ');'); letterPager.innerHTML = key; alphaPager.appendChild(letterPager); } @@ -289,8 +293,13 @@ function formatGamesPanel(targetElement, result, pageNumber, pageSize, forceScro $('.lazy').Lazy({ effect: 'show', - effectTime: 100, - visibleOnly: true + effectTime: 500, + visibleOnly: true, + defaultImage: '/images/unknowngame.png', + delay: 250, + afterLoad: function(element) { + //console.log(element[0].getAttribute('data-id')); + } }); } @@ -306,13 +315,24 @@ function isScrolledIntoView(elem) { } } +const elementIsVisibleInViewport = (el, partiallyVisible = false) => { + const { top, left, bottom, right } = el.getBoundingClientRect(); + const { innerHeight, innerWidth } = window; + return partiallyVisible + ? ((top > 0 && top < innerHeight) || + (bottom > 0 && bottom < innerHeight)) && + ((left > 0 && left < innerWidth) || (right > 0 && right < innerWidth)) + : top >= 0 && left >= 0 && bottom <= innerHeight && right <= innerWidth; + }; + function IsInView() { var pageMode = GetPreference('LibraryPagination', 'paged'); switch (pageMode) { case "paged": var loadElement = document.getElementById('games_library_loadmore'); if (loadElement) { - if (isScrolledIntoView(loadElement)) { + //if (isScrolledIntoView(loadElement)) { + if (elementIsVisibleInViewport(loadElement, true)) { var pageNumber = Number(document.getElementById('games_library_loadmore').getAttribute('data-pagenumber')); var pageSize = document.getElementById('games_library_loadmore').getAttribute('data-pagesize'); executeFilter1_1(pageNumber); @@ -326,17 +346,14 @@ function IsInView() { // load page let anchors = document.getElementsByClassName('pageAnchor'); - let footAnchors = document.getElementsByClassName('pageFooterAnchor'); for (let i = 0; i < anchors.length; i++) { - if (isScrolledIntoView(anchors[i]) && anchors[i].getAttribute('data-loaded') == "0") { - document.getElementById(anchors[i].id).setAttribute('data-loaded', "1"); - executeFilter1_1(Number(anchors[i].getAttribute('data-page'))); - } - } - for (let i = 0; i < footAnchors.length; i++) { - if (isScrolledIntoView(footAnchors[i]) && footAnchors[i].getAttribute('data-loaded') == "0") { - document.getElementById(footAnchors[i].id).setAttribute('data-loaded', "1"); - executeFilter1_1(Number(footAnchors[i].getAttribute('data-page'))); + //if (isScrolledIntoView(anchors[i])) { + if (elementIsVisibleInViewport(anchors[i], true)) { + if (anchors[i].getAttribute('data-loaded') == "0") { + console.log("Loading page: " + anchors[i].getAttribute('data-page')); + document.getElementById(anchors[i].id).setAttribute('data-loaded', "1"); + executeFilter1_1(Number(anchors[i].getAttribute('data-page'))); + } } } break; @@ -360,12 +377,14 @@ function renderGameIcon(gameObject, showTitle, showRatings, showClassification, gameBox.classList.add(...classes['game_tile']); } gameBox.setAttribute('onclick', 'window.location.href = "/index.html?page=game&id=' + gameObject.id + '";'); + gameBox.style.display = 'none'; var gameImageBox = document.createElement('div'); gameImageBox.classList.add(...classes['game_tile_box']); var gameImage = document.createElement('img'); gameImage.id = 'game_tile_cover_' + gameObject.id; + gameImage.setAttribute('data-id', gameObject.id); if (useSmallCover == true) { gameImage.classList.add(...classes['game_tile_image game_tile_image_small lazy']); } else {