Merge Branch v1.7.0 into main (#348)

This commit is contained in:
Michael Green
2024-04-16 11:54:28 +10:00
committed by GitHub
parent 080a823cda
commit f85109abd2
5 changed files with 122 additions and 92 deletions

View File

@@ -43,7 +43,7 @@ namespace gaseous_server.Controllers
[MapToApiVersion("1.0")]
[HttpGet]
[ProducesResponseType(typeof(List<Game>), StatusCodes.Status200OK)]
public ActionResult Game(
public async Task<ActionResult> Game(
string name = "",
string platform = "",
string genre = "",
@@ -303,7 +303,7 @@ namespace gaseous_server.Controllers
[ProducesResponseType(typeof(Game), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[ResponseCache(CacheProfileName = "5Minute")]
public ActionResult Game(long GameId)
public async Task<ActionResult> Game(long GameId)
{
try
{
@@ -331,7 +331,7 @@ namespace gaseous_server.Controllers
[ProducesResponseType(typeof(List<AlternativeName>), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[ResponseCache(CacheProfileName = "7Days")]
public ActionResult GameAlternativeNames(long GameId)
public async Task<ActionResult> GameAlternativeNames(long GameId)
{
try
{
@@ -364,7 +364,7 @@ namespace gaseous_server.Controllers
[ProducesResponseType(typeof(List<AgeRatings.GameAgeRating>), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[ResponseCache(CacheProfileName = "7Days")]
public ActionResult GameAgeClassification(long GameId)
public async Task<ActionResult> GameAgeClassification(long GameId)
{
try
{
@@ -397,7 +397,7 @@ namespace gaseous_server.Controllers
[ProducesResponseType(typeof(List<Artwork>), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[ResponseCache(CacheProfileName = "7Days")]
public ActionResult GameArtwork(long GameId)
public async Task<ActionResult> GameArtwork(long GameId)
{
try
{
@@ -428,7 +428,7 @@ namespace gaseous_server.Controllers
[ProducesResponseType(typeof(Artwork), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[ResponseCache(CacheProfileName = "7Days")]
public ActionResult GameArtwork(long GameId, long ArtworkId)
public async Task<ActionResult> GameArtwork(long GameId, long ArtworkId)
{
try
{
@@ -464,7 +464,7 @@ namespace gaseous_server.Controllers
[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<ActionResult> GameCoverImage(long GameId, long ArtworkId, Communications.IGDBAPI_ImageSize size, string ImageName)
{
try
{
@@ -531,7 +531,7 @@ namespace gaseous_server.Controllers
[ProducesResponseType(typeof(Cover), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[ResponseCache(CacheProfileName = "7Days")]
public ActionResult GameCover(long GameId)
public async Task<ActionResult> GameCover(long GameId)
{
try
{
@@ -566,7 +566,7 @@ namespace gaseous_server.Controllers
[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<ActionResult> GameCoverImage(long GameId, Communications.IGDBAPI_ImageSize size, string imagename = "")
{
try
{
@@ -693,7 +693,7 @@ namespace gaseous_server.Controllers
[ProducesResponseType(typeof(List<Genre>), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[ResponseCache(CacheProfileName = "7Days")]
public ActionResult GameGenre(long GameId)
public async Task<ActionResult> GameGenre(long GameId)
{
try
{
@@ -731,7 +731,7 @@ namespace gaseous_server.Controllers
[ProducesResponseType(typeof(List<Dictionary<string, object>>), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[ResponseCache(CacheProfileName = "7Days")]
public ActionResult GameInvolvedCompanies(long GameId)
public async Task<ActionResult> GameInvolvedCompanies(long GameId)
{
try
{
@@ -776,7 +776,7 @@ namespace gaseous_server.Controllers
[ProducesResponseType(typeof(Dictionary<string, object>), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[ResponseCache(CacheProfileName = "7Days")]
public ActionResult GameInvolvedCompanies(long GameId, long CompanyId)
public async Task<ActionResult> GameInvolvedCompanies(long GameId, long CompanyId)
{
try
{
@@ -818,7 +818,7 @@ namespace gaseous_server.Controllers
[Route("{GameId}/companies/{CompanyId}/image")]
[ProducesResponseType(typeof(FileStreamResult), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public ActionResult GameCompanyImage(long GameId, long CompanyId)
public async Task<ActionResult> GameCompanyImage(long GameId, long CompanyId)
{
try
{
@@ -863,7 +863,7 @@ namespace gaseous_server.Controllers
[Route("{GameId}/platforms")]
[ProducesResponseType(typeof(List<KeyValuePair<long, string>>), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public ActionResult GamePlatforms(long GameId)
public async Task<ActionResult> GamePlatforms(long GameId)
{
try
{
@@ -882,7 +882,7 @@ namespace gaseous_server.Controllers
[ProducesResponseType(typeof(List<ReleaseDate>), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[ResponseCache(CacheProfileName = "7Days")]
public ActionResult GameReleaseDates(long GameId)
public async Task<ActionResult> GameReleaseDates(long GameId)
{
try
{
@@ -943,7 +943,7 @@ namespace gaseous_server.Controllers
[ProducesResponseType(typeof(Classes.Roms.GameRomItem), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
//[ResponseCache(CacheProfileName = "5Minute")]
public ActionResult GameRom(long GameId, long RomId)
public async Task<ActionResult> GameRom(long GameId, long RomId)
{
try
{
@@ -972,7 +972,7 @@ namespace gaseous_server.Controllers
[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<ActionResult> GameRomRename(long GameId, long RomId, long NewPlatformId, long NewGameId)
{
try
{
@@ -1002,7 +1002,7 @@ namespace gaseous_server.Controllers
[Route("{GameId}/roms/{RomId}")]
[ProducesResponseType(typeof(Classes.Roms.GameRomItem), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public ActionResult GameRomDelete(long GameId, long RomId)
public async Task<ActionResult> GameRomDelete(long GameId, long RomId)
{
try
{
@@ -1034,7 +1034,7 @@ namespace gaseous_server.Controllers
[Route("{GameId}/roms/{RomId}/file")]
[ProducesResponseType(typeof(FileStreamResult), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public ActionResult GameRomFile(long GameId, long RomId)
public async Task<ActionResult> GameRomFile(long GameId, long RomId)
{
try
{
@@ -1073,7 +1073,7 @@ namespace gaseous_server.Controllers
[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<ActionResult> GameRomFile(long GameId, long RomId, string FileName)
{
try
{
@@ -1172,7 +1172,7 @@ namespace gaseous_server.Controllers
[Route("{GameId}/romgroup")]
[ProducesResponseType(typeof(Classes.RomMediaGroup.GameRomMediaGroupItem), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public ActionResult NewGameRomGroup(long GameId, long PlatformId, [FromBody] List<long> RomIds)
public async Task<ActionResult> NewGameRomGroup(long GameId, long PlatformId, [FromBody] List<long> RomIds)
{
try
{
@@ -1233,7 +1233,7 @@ namespace gaseous_server.Controllers
[Route("{GameId}/romgroup/{RomGroupId}")]
[ProducesResponseType(typeof(Classes.RomMediaGroup.GameRomMediaGroupItem), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public ActionResult GameRomGroupDelete(long GameId, long RomGroupId)
public async Task<ActionResult> GameRomGroupDelete(long GameId, long RomGroupId)
{
try
{
@@ -1266,7 +1266,7 @@ namespace gaseous_server.Controllers
[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<ActionResult> GameRomGroupFile(long GameId, long RomGroupId, string filename = "")
{
try
{
@@ -1311,7 +1311,7 @@ namespace gaseous_server.Controllers
[Route("search")]
[ProducesResponseType(typeof(List<Game>), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public ActionResult GameSearch(long RomId = 0, string SearchString = "")
public async Task<ActionResult> GameSearch(long RomId = 0, string SearchString = "")
{
try
{
@@ -1352,7 +1352,7 @@ namespace gaseous_server.Controllers
[ProducesResponseType(typeof(List<Screenshot>), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[ResponseCache(CacheProfileName = "7Days")]
public ActionResult GameScreenshot(long GameId)
public async Task<ActionResult> GameScreenshot(long GameId)
{
try
{
@@ -1383,7 +1383,7 @@ namespace gaseous_server.Controllers
[ProducesResponseType(typeof(Screenshot), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[ResponseCache(CacheProfileName = "7Days")]
public ActionResult GameScreenshot(long GameId, long ScreenshotId)
public async Task<ActionResult> GameScreenshot(long GameId, long ScreenshotId)
{
try
{
@@ -1417,7 +1417,7 @@ namespace gaseous_server.Controllers
[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<ActionResult> GameScreenshotImage(long GameId, long ScreenshotId, Communications.IGDBAPI_ImageSize Size, string ImageName)
{
try
{
@@ -1468,7 +1468,7 @@ namespace gaseous_server.Controllers
[ProducesResponseType(typeof(List<GameVideo>), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[ResponseCache(CacheProfileName = "7Days")]
public ActionResult GameVideo(long GameId)
public async Task<ActionResult> GameVideo(long GameId)
{
try
{

View File

@@ -593,23 +593,29 @@ FROM
// build alpha list
Dictionary<string, int> AlphaList = new Dictionary<string, int>();
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("#"))
{
AlphaList.Add("#", 1);
}
}
if (!AlphaList.ContainsKey(firstChar))
else
{
AlphaList.Add(firstChar, CurrentPage);
}
if (NextPageIndex == i)
{
NextPageIndex += pageSize;
CurrentPage += 1;
if (!AlphaList.ContainsKey(firstChar))
{
AlphaList.Add(firstChar, CurrentPage);
}
if (NextPageIndex == i + 1)
{
NextPageIndex += pageSize;
CurrentPage += 1;
}
}
}

View File

@@ -72,6 +72,11 @@
</table>
</td>
</tr>
<tr>
<td>
<strong>Note</strong>: The page will need to be reloaded for changes to take effect.
</td>
</tr>
<tr>
<td style="text-align: right;">
<button id="profile_pref_ok" value="OK" onclick="SavePrefs();">OK</button>
@@ -221,7 +226,7 @@
if (getQueryString('page', 'string') == 'home' || getQueryString('page', 'string') == undefined) {
setCookie('games_library_last_page', 1);
location.reload();
//location.reload();
}
closeDialog();

View File

@@ -405,7 +405,7 @@ function executeFilter1_1(pageNumber, pageSize) {
if (!pageSize) {
switch (pageMode) {
case "infinite":
pageSize = 5;
pageSize = 30;
break;
case "paged":
default:

View File

@@ -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);
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;
}
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 (!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);
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);
}
}
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';
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 {