Advanced level searches and visual fixes (#307)

Co-authored-by: Jayden <jvyden@jvyden.xyz>
This commit is contained in:
Josh 2022-05-14 14:58:15 -05:00 committed by GitHub
commit fb6f8a5c83
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 3 deletions

View file

@ -28,6 +28,10 @@
</div> </div>
<input type="submit" class="ui blue button"> <input type="submit" class="ui blue button">
</form> </form>
@if (Model.Comments.Count > 0)
{
<div class="ui divider"></div>
}
} }
@for(int i = 0; i < Model.Comments.Count; i++) @for(int i = 0; i < Model.Comments.Count; i++)

View file

@ -79,8 +79,9 @@
{ {
int count = Model.Reviews.Count; int count = Model.Reviews.Count;
<p>There @(count == 1 ? "is" : "are") @count review@(count == 1 ? "" : "s").</p> <p>There @(count == 1 ? "is" : "are") @count review@(count == 1 ? "" : "s").</p>
}
<div class="ui divider"></div> <div class="ui divider"></div>
}
@for(int i = 0; i < Model.Reviews.Count; i++) @for(int i = 0; i < Model.Reviews.Count; i++)
{ {
@ -147,7 +148,7 @@
else else
{ {
{ {
<p>@review.Text</p> <p>@HttpUtility.HtmlDecode(review.Text)</p>
} }
} }
} }

View file

@ -2,8 +2,10 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using LBPUnion.ProjectLighthouse.Pages.Layouts; using LBPUnion.ProjectLighthouse.Pages.Layouts;
using LBPUnion.ProjectLighthouse.Types;
using LBPUnion.ProjectLighthouse.Types.Levels; using LBPUnion.ProjectLighthouse.Types.Levels;
using LBPUnion.ProjectLighthouse.Types.Settings; using LBPUnion.ProjectLighthouse.Types.Settings;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
@ -31,6 +33,27 @@ public class SlotsPage : BaseLayout
{ {
if (string.IsNullOrWhiteSpace(name)) name = ""; if (string.IsNullOrWhiteSpace(name)) name = "";
string? targetAuthor = null;
GameVersion? targetGame = null;
StringBuilder finalSearch = new();
foreach (string part in name.Split(" "))
{
if (part.Contains("by:"))
{
targetAuthor = part.Replace("by:", "");
} else if (part.Contains("game:"))
{
if (part.Contains('1')) targetGame = GameVersion.LittleBigPlanet1;
else if (part.Contains('2')) targetGame = GameVersion.LittleBigPlanet2;
else if (part.Contains('3')) targetGame = GameVersion.LittleBigPlanet3;
else if (part.Contains('v')) targetGame = GameVersion.LittleBigPlanetVita;
}
else
{
finalSearch.Append(part);
}
}
this.SearchValue = name.Trim(); this.SearchValue = name.Trim();
this.SlotCount = await this.Database.Slots.CountAsync(p => p.Name.Contains(this.SearchValue)); this.SlotCount = await this.Database.Slots.CountAsync(p => p.Name.Contains(this.SearchValue));
@ -41,12 +64,16 @@ public class SlotsPage : BaseLayout
if (this.PageNumber < 0 || this.PageNumber >= this.PageAmount) return this.Redirect($"/slots/{Math.Clamp(this.PageNumber, 0, this.PageAmount - 1)}"); if (this.PageNumber < 0 || this.PageNumber >= this.PageAmount) return this.Redirect($"/slots/{Math.Clamp(this.PageNumber, 0, this.PageAmount - 1)}");
this.Slots = await this.Database.Slots.Include(p => p.Creator) this.Slots = await this.Database.Slots.Include(p => p.Creator)
.Where(p => p.Name.Contains(this.SearchValue)) .Where(p => p.Name.Contains(finalSearch.ToString()))
.Where(p => p.Creator != null && (targetAuthor == null || string.Equals(p.Creator.Username.ToLower(), targetAuthor.ToLower())))
.Where(p => targetGame == null || p.GameVersion == targetGame)
.OrderByDescending(p => p.FirstUploaded) .OrderByDescending(p => p.FirstUploaded)
.Skip(pageNumber * ServerStatics.PageSize) .Skip(pageNumber * ServerStatics.PageSize)
.Take(ServerStatics.PageSize) .Take(ServerStatics.PageSize)
.ToListAsync(); .ToListAsync();
this.SlotCount = this.Slots.Count;
return this.Page(); return this.Page();
} }
} }