diff --git a/gaseous-server/Controllers/V1.0/GamesController.cs b/gaseous-server/Controllers/V1.0/GamesController.cs index b630429..0dfae0b 100644 --- a/gaseous-server/Controllers/V1.0/GamesController.cs +++ b/gaseous-server/Controllers/V1.0/GamesController.cs @@ -41,260 +41,6 @@ namespace gaseous_server.Controllers _signInManager = signInManager; } - [MapToApiVersion("1.0")] - [HttpGet] - [ProducesResponseType(typeof(List), StatusCodes.Status200OK)] - public async Task Game( - string name = "", - string platform = "", - string genre = "", - string gamemode = "", - string playerperspective = "", - string theme = "", - int minrating = -1, - int maxrating = -1, - bool sortdescending = false) - { - - return Ok(GetGames(name, platform, genre, gamemode, playerperspective, theme, minrating, maxrating, "Adult", true, true, sortdescending)); - } - - public static List GetGames( - string name = "", - string platform = "", - string genre = "", - string gamemode = "", - string playerperspective = "", - string theme = "", - int minrating = -1, - int maxrating = -1, - string ratinggroup = "Adult", - bool includenullrating = true, - bool sortbynamethe = false, - bool sortdescending = false) - { - string whereClause = ""; - string havingClause = ""; - Dictionary whereParams = new Dictionary(); - - List whereClauses = new List(); - List havingClauses = new List(); - - string tempVal = ""; - - if (name.Length > 0) - { - tempVal = "`Name` LIKE @Name"; - whereParams.Add("@Name", "%" + name + "%"); - havingClauses.Add(tempVal); - } - - if (minrating != -1) - { - string ratingTempMinVal = "totalRating >= @totalMinRating"; - whereParams.Add("@totalMinRating", minrating); - havingClauses.Add(ratingTempMinVal); - } - - if (maxrating != -1) - { - string ratingTempMaxVal = "totalRating <= @totalMaxRating"; - whereParams.Add("@totalMaxRating", maxrating); - havingClauses.Add(ratingTempMaxVal); - } - - if (platform.Length > 0) - { - tempVal = "view_Games_Roms.PlatformId IN ("; - string[] platformClauseItems = platform.Split(","); - for (int i = 0; i < platformClauseItems.Length; i++) - { - if (i > 0) - { - tempVal += ", "; - } - string platformLabel = "@Platform" + i; - tempVal += platformLabel; - whereParams.Add(platformLabel, platformClauseItems[i]); - } - tempVal += ")"; - whereClauses.Add(tempVal); - } - - if (genre.Length > 0) - { - tempVal = "Relation_Game_Genres.GenresId IN ("; - string[] genreClauseItems = genre.Split(","); - for (int i = 0; i < genreClauseItems.Length; i++) - { - if (i > 0) - { - tempVal += " AND "; - } - string genreLabel = "@Genre" + i; - tempVal += genreLabel; - whereParams.Add(genreLabel, genreClauseItems[i]); - } - tempVal += ")"; - whereClauses.Add(tempVal); - } - - if (gamemode.Length > 0) - { - tempVal = "Relation_Game_GameModes.GameModesId IN ("; - string[] gameModeClauseItems = gamemode.Split(","); - for (int i = 0; i < gameModeClauseItems.Length; i++) - { - if (i > 0) - { - tempVal += " AND "; - } - string gameModeLabel = "@GameMode" + i; - tempVal += gameModeLabel; - whereParams.Add(gameModeLabel, gameModeClauseItems[i]); - } - tempVal += ")"; - whereClauses.Add(tempVal); - } - - if (playerperspective.Length > 0) - { - tempVal = "Relation_Game_PlayerPerspectives.PlayerPerspectivesId IN ("; - string[] playerPerspectiveClauseItems = playerperspective.Split(","); - for (int i = 0; i < playerPerspectiveClauseItems.Length; i++) - { - if (i > 0) - { - tempVal += " AND "; - } - string playerPerspectiveLabel = "@PlayerPerspective" + i; - tempVal += playerPerspectiveLabel; - whereParams.Add(playerPerspectiveLabel, playerPerspectiveClauseItems[i]); - } - tempVal += ")"; - whereClauses.Add(tempVal); - } - - if (theme.Length > 0) - { - tempVal = "Relation_Game_Themes.ThemesId IN ("; - string[] themeClauseItems = theme.Split(","); - for (int i = 0; i < themeClauseItems.Length; i++) - { - if (i > 0) - { - tempVal += " AND "; - } - string themeLabel = "@Theme" + i; - tempVal += themeLabel; - whereParams.Add(themeLabel, themeClauseItems[i]); - } - tempVal += ")"; - whereClauses.Add(tempVal); - } - - if (ratinggroup.Length > 0) - { - List AgeClassificationsList = new List(); - foreach (string ratingGroup in ratinggroup.Split(',')) - { - AgeGroups.AgeRestrictionGroupings ageRestriction = (AgeGroups.AgeRestrictionGroupings)Enum.Parse(typeof(AgeGroups.AgeRestrictionGroupings), ratingGroup); - if (AgeGroups.AgeGroupings.ContainsKey(ageRestriction)) - { - List ageGroups = AgeGroups.AgeGroupings[ageRestriction]; - foreach (AgeGroups.AgeGroupItem ageGroup in ageGroups) - { - AgeClassificationsList.AddRange(ageGroup.AgeGroupItemValues); - } - } - } - - if (AgeClassificationsList.Count > 0) - { - tempVal = "(view_AgeRatings.Rating IN ("; - for (int i = 0; i < AgeClassificationsList.Count; i++) - { - if (i > 0) - { - tempVal += ", "; - } - string themeLabel = "@Rating" + i; - tempVal += themeLabel; - whereParams.Add(themeLabel, AgeClassificationsList[i]); - } - tempVal += ")"; - - tempVal += " OR "; - - if (includenullrating == true) - { - tempVal += "view_AgeRatings.Rating IS NULL"; - } - else - { - tempVal += "view_AgeRatings.Rating IS NOT NULL"; - } - tempVal += ")"; - - whereClauses.Add(tempVal); - } - } - - // build where clause - if (whereClauses.Count > 0) - { - whereClause = "WHERE "; - for (int i = 0; i < whereClauses.Count; i++) - { - if (i > 0) - { - whereClause += " AND "; - } - whereClause += whereClauses[i]; - } - } - - // build having clause - if (havingClauses.Count > 0) - { - havingClause = "HAVING "; - for (int i = 0; i < havingClauses.Count; i++) - { - if (i > 0) - { - havingClause += " AND "; - } - havingClause += havingClauses[i]; - } - } - - // order by clause - string orderByField = "Name"; - if (sortbynamethe == true) - { - orderByField = "NameThe"; - } - string orderByClause = "ORDER BY `" + orderByField + "` ASC"; - if (sortdescending == true) - { - orderByClause = "ORDER BY `" + orderByField + "` DESC"; - } - - Database db = new Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString); - string sql = "SELECT DISTINCT view_Games_Roms.GameId AS ROMGameId, Game.*, case when Game.`Name` like 'The %' then CONCAT(trim(substr(Game.`Name` from 4)), ', The') else Game.`Name` end as NameThe FROM view_Games_Roms LEFT JOIN Game ON Game.Id = view_Games_Roms.GameId LEFT JOIN Relation_Game_Genres ON Game.Id = Relation_Game_Genres.GameId LEFT JOIN Relation_Game_GameModes ON Game.Id = Relation_Game_GameModes.GameId LEFT JOIN Relation_Game_PlayerPerspectives ON Game.Id = Relation_Game_PlayerPerspectives.GameId LEFT JOIN Relation_Game_Themes ON Game.Id = Relation_Game_Themes.GameId LEFT JOIN (SELECT Relation_Game_AgeRatings.GameId, AgeRating.* FROM Relation_Game_AgeRatings JOIN AgeRating ON Relation_Game_AgeRatings.AgeRatingsId = AgeRating.Id) view_AgeRatings ON Game.Id = view_AgeRatings.GameId " + whereClause + " " + havingClause + " " + orderByClause; - - List RetVal = new List(); - - DataTable dbResponse = db.ExecuteCMD(sql, whereParams); - foreach (DataRow dr in dbResponse.Rows) - { - //RetVal.Add(Classes.Metadata.Games.GetGame((long)dr["ROMGameId"], false, false)); - RetVal.Add(Classes.Metadata.Games.GetGame(dr)); - } - - return RetVal; - } - [MapToApiVersion("1.0")] [MapToApiVersion("1.1")] [HttpGet] @@ -1046,6 +792,27 @@ namespace gaseous_server.Controllers } } + [MapToApiVersion("1.0")] + [MapToApiVersion("1.1")] + [HttpGet] + [Route("{MetadataMapId}/metadata")] + [ProducesResponseType(typeof(List), StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + public async Task GameMetadataSources(long MetadataMapId) + { + try + { + List metadataMapItems = Classes.MetadataManagement.GetMetadataMap(MetadataMapId).MetadataMapItems; + + // return metadataMapItems after first removing any items where sourceType = "TheGamesDb" + return Ok(metadataMapItems.Where(x => x.SourceType != HasheousClient.Models.MetadataSources.TheGamesDb).ToList()); + } + catch + { + return NotFound(); + } + } + [MapToApiVersion("1.0")] [MapToApiVersion("1.1")] [HttpGet] diff --git a/gaseous-server/Controllers/V1.1/GamesController.cs b/gaseous-server/Controllers/V1.1/GamesController.cs index 5072c57..aa9241c 100644 --- a/gaseous-server/Controllers/V1.1/GamesController.cs +++ b/gaseous-server/Controllers/V1.1/GamesController.cs @@ -553,8 +553,6 @@ FROM Favourites ON Game.MetadataMapId = Favourites.GameId AND Favourites.UserId = @userid " + whereClause + " " + havingClause + " " + orderByClause; List RetVal = new List(); - Console.WriteLine(sql); - DataTable dbResponse = db.ExecuteCMD(sql, whereParams, new Database.DatabaseMemoryCacheOptions(CacheEnabled: true, ExpirationSeconds: 60)); // get count diff --git a/gaseous-server/wwwroot/pages/game.html b/gaseous-server/wwwroot/pages/game.html index c670011..06e212c 100644 --- a/gaseous-server/wwwroot/pages/game.html +++ b/gaseous-server/wwwroot/pages/game.html @@ -104,12 +104,26 @@
Similar Games
+ - - - \ No newline at end of file + + \ No newline at end of file diff --git a/gaseous-server/wwwroot/pages/game.js b/gaseous-server/wwwroot/pages/game.js index df51641..7077141 100644 --- a/gaseous-server/wwwroot/pages/game.js +++ b/gaseous-server/wwwroot/pages/game.js @@ -16,6 +16,22 @@ function SetupPage() { // populate games page gameData = result; + switch (gameData.metadataSource) { + case "IGDB": + let attributionSection = document.getElementById('gamesmetadataprovider'); + attributionSection.style.display = 'block'; + + let attributionIcon = document.getElementById('metadata-attribution-icon'); + attributionIcon.setAttribute('src', '/images/IGDB_Logo.svg'); + + let attributionText = document.getElementById('metadata-attribution-text'); + attributionText.innerHTML = 'This game\'s metadata is provided by IGDB. Source Page'; + break; + + default: + break; + } + // get name var gameTitleLabel = document.getElementById('gametitle_label'); gameTitleLabel.innerHTML = result.name; @@ -27,7 +43,7 @@ function SetupPage() { if (gameData.total_rating_count) { var criticscorelabel = document.getElementById('gametitle_criticrating_label'); - criticscorelabel.innerHTML = ' User Rating
' + "based on " + gameData.total_rating_count + " votes
" + criticscorelabel.innerHTML = ' User Rating
' + "based on " + gameData.total_rating_count + " votes
" } } diff --git a/gaseous-server/wwwroot/styles/style.css b/gaseous-server/wwwroot/styles/style.css index 738fa53..91ecff4 100644 --- a/gaseous-server/wwwroot/styles/style.css +++ b/gaseous-server/wwwroot/styles/style.css @@ -3044,4 +3044,11 @@ button:not(.select2-selection__choice__remove):not(.select2-selection__clear):no max-width: 160px; width: 160px; white-space: normal; +} + +.metadata-attribution-icon { + width: 30px; + height: 30px; + margin-right: 5px; + filter: invert(1); } \ No newline at end of file