ProjectLighthouse/ProjectLighthouse.Servers.Website/Pages/SlotsPage.cshtml.cs
koko 6558d09c8d
Implement profile and level privacy settings (#841)
* Create interactions management page and basic GET logic

* Fix client side query and add blocked count as well as comments nitpick

* Implement basic backend logic for interactions management

* Remove errant null/whitespace checks and add border to blocked users partials

* Implement user page's respect to profile privacy settings

* Fix issue where user can't view their own profile if privacy settings are tightened

* Fix other issues with profile access

* Remove excess conditional expression from PSN privtype check

* Check if access is allowed within request handler and hide bio/RA if private

* Fix PSN privacy level check

* Display private users in search and add base UI class to level lock icon

* Rename everything from interactions to privacy for clarity

* Dagg requested an eyeball

Co-authored-by: vilijur <69403080+vilijur@users.noreply.github.com>

* Clarify profile settings page title

* Implement level privacy settings

* Formatting nitpicks within UserPrivacyPage

* Add discard changes buttons

* Apply suggestion from code review

* Consolidate privacy settings areas together

* Grammar nitpick for comments enable/disable dropdown

* Remove un-needed blue UI segment

* Allow mods to issue disable comments case regardless of privacy settings

Also addresses a few frontend and backend nitpicks left unaddressed by previous commits

* Remove limiting AND operator expression

* Grammar clarity on disable comments button

* Add missing hidden button divider under Wipe Earth Decorations

* No eyeball -m88youngling

Removes eyeball from actual privacy settings page to match styling

* Use long-text description for privacy type dropdowns

* Use long-text description for comments toggle dropdown

* Implement slot page privacy

* Grammar nitpicks with Daggintosh

* Daggintosh grammar review second edition

* Once again put request handler arguments on one line

* Rename LevelsPrivate variable to SlotsPrivate for internal consistency

* Fix issue with PSN slot privacy type

* Un-break comments

* Apply most of the suggestions from code review

* Correct form dropdown values for privacy types

* Potentially fix broken privacy type extension

* Slightly rework access calculation extension method

* Fix issues with if statements

* Apply suggestions from code review

* Make everything translatable

---------

Co-authored-by: vilijur <69403080+vilijur@users.noreply.github.com>
2023-07-22 21:49:56 +00:00

82 lines
No EOL
2.9 KiB
C#

#nullable enable
using System.Text;
using LBPUnion.ProjectLighthouse.Configuration;
using LBPUnion.ProjectLighthouse.Database;
using LBPUnion.ProjectLighthouse.Servers.Website.Pages.Layouts;
using LBPUnion.ProjectLighthouse.Types.Entities.Level;
using LBPUnion.ProjectLighthouse.Types.Levels;
using LBPUnion.ProjectLighthouse.Types.Users;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
namespace LBPUnion.ProjectLighthouse.Servers.Website.Pages;
public class SlotsPage : BaseLayout
{
public int PageAmount;
public int PageNumber;
public int SlotCount;
public List<SlotEntity> Slots = new();
public string? SearchValue;
public SlotsPage(DatabaseContext database) : base(database)
{}
public async Task<IActionResult> OnGet([FromRoute] int pageNumber, [FromQuery] string? 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).Append(' ');
}
}
this.SearchValue = name.Trim();
string trimmedSearch = finalSearch.ToString().Trim();
IQueryable<SlotEntity> slots = this.Database.Slots.Include(p => p.Creator)
.Where(p => p.Type == SlotType.User && !p.Hidden)
.Where(p => p.Name.Contains(trimmedSearch))
.Where(p => p.Creator != null && (targetAuthor == null || string.Equals(p.Creator.Username.ToLower(), targetAuthor.ToLower())))
.Where(p => p.Creator != null && (!p.SubLevel || p.Creator == this.User))
.Where(p => targetGame == null || p.GameVersion == targetGame);
this.SlotCount = await slots.CountAsync();
this.PageNumber = pageNumber;
this.PageAmount = Math.Max(1, (int)Math.Ceiling((double)this.SlotCount / ServerStatics.PageSize));
if (this.PageNumber < 0 || this.PageNumber >= this.PageAmount) return this.Redirect($"/slots/{Math.Clamp(this.PageNumber, 0, this.PageAmount - 1)}");
this.Slots = await slots
.OrderByDescending(p => p.FirstUploaded)
.Skip(pageNumber * ServerStatics.PageSize)
.Take(ServerStatics.PageSize)
.ToListAsync();
return this.Page();
}
}