Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement checkboxes in slot settings to toggle various slot properties #1063

Merged
merged 7 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions ProjectLighthouse.Servers.Website/Pages/SlotSettingsPage.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@
<div class="field" style="display: flex; justify-content: center; align-items: center;">
<div>
<div>
<img src=@(isAdventure ? "/assets/advSlotCardOverlay.png" : "/assets/slotCardOverlay.png") style="min-width: @(size)px; width: @(size)px; height: @(size)px; pointer-events: none; position: absolute; z-index: 3;">

Check warning on line 41 in ProjectLighthouse.Servers.Website/Pages/SlotSettingsPage.cshtml

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Missing required 'alt' attribute

Missing required 'alt' attribute

Check notice on line 41 in ProjectLighthouse.Servers.Website/Pages/SlotSettingsPage.cshtml

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Important tags or attributes missing (<img> should specify alternative text)

should specify alternative text
<img src="~/assets/slotCardBackground.png" style="min-width: @(size)px; width: @(size)px; height: @(size)px; position: absolute; z-index: 1; @(adventureStyle)">

Check warning on line 42 in ProjectLighthouse.Servers.Website/Pages/SlotSettingsPage.cshtml

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Path error

Path '$PROJECT_DIR$/ProjectLighthouse.Servers.Website/assets/slotCardBackground.png' is not found

Check warning on line 42 in ProjectLighthouse.Servers.Website/Pages/SlotSettingsPage.cshtml

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Path error

Path '$PROJECT_DIR$/ProjectLighthouse.Servers.Website/assets' is not found

Check warning on line 42 in ProjectLighthouse.Servers.Website/Pages/SlotSettingsPage.cshtml

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Missing required 'alt' attribute

Missing required 'alt' attribute

Check notice on line 42 in ProjectLighthouse.Servers.Website/Pages/SlotSettingsPage.cshtml

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Important tags or attributes missing (<img> should specify alternative text)

should specify alternative text
<img id="slotIcon" class="cardIcon slotCardIcon" src="/gameAssets/@Model.Slot.IconHash" style="min-width: @(size)px; width: @(size)px; height: @(size)px; position: relative; z-index: 2; @(adventureStyle)"

Check warning on line 43 in ProjectLighthouse.Servers.Website/Pages/SlotSettingsPage.cshtml

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Missing required 'alt' attribute

Missing required 'alt' attribute

Check notice on line 43 in ProjectLighthouse.Servers.Website/Pages/SlotSettingsPage.cshtml

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Important tags or attributes missing (<img> should specify alternative text)

should specify alternative text
onerror="this.onerror='';this.src='/gameAssets/@ServerConfiguration.Instance.WebsiteConfiguration.MissingIconHash'">
</div>
<div class="ui fitted divider hidden"></div>
Expand All @@ -60,6 +60,33 @@
<label style="text-align: left" for="description">Description</label>
<textarea name="description" id="description" spellcheck="false" placeholder="Description">@HttpUtility.HtmlDecode(Model.Slot.Description)</textarea>
</div>
<div class="ui divider"></div>
<label class="ui button @(Model.Slot.InitiallyLocked ? "selected" : "")" style="margin-bottom: 1em;" for="checkboxInitiallyLocked">
<i class="lock icon"></i>
Locked
<input type="checkbox" name="initiallyLocked" id="checkboxInitiallyLocked" style="margin-left: 5px;" onchange="onCheckboxChange(this)" @(Model.Slot.InitiallyLocked ? "checked" : "") value="true">
</label>
<label class="ui button @(Model.Slot.Shareable == 1 ? "selected" : "")" style="margin-bottom: 1em;" for="checkboxShareable">
<i class="check icon"></i>
Copyable
<input type="checkbox" name="shareable" id="checkboxShareable" style="margin-left: 5px;" onchange="onCheckboxChange(this)" @(Model.Slot.Shareable == 1 ? "checked" : "") value="1">
</label>
@if (Model.Slot.GameVersion != GameVersion.LittleBigPlanet1)
{
<label class="ui button @(Model.Slot.SubLevel ? "selected" : "")" style="margin-bottom: 1em;" for="checkboxSubLevel">
<i class="arrow circle down icon"></i>
Sub Level
<input type="checkbox" name="subLevel" id="checkboxSubLevel" style="margin-left: 5px;" onchange="onCheckboxChange(this)" @(Model.Slot.SubLevel ? "checked" : "") value="true">
</label>
}
else
{
<label class="ui button @(Model.Slot.Lbp1Only ? "selected" : "")" style="margin-bottom: 1em;" for="checkboxLbp1Only">
<i class="eye icon"></i>
LBP1 Only
<input type="checkbox" name="lbp1Only" id="checkboxLbp1Only" style="margin-left: 5px;" onchange="onCheckboxChange(this)" @(Model.Slot.Lbp1Only ? "checked" : "") value="true">
</label>
}
@if (Model.Slot.GameVersion != GameVersion.LittleBigPlanet1)
{
<div class="field">
Expand Down Expand Up @@ -106,6 +133,14 @@
function onHoverStart(btn){
generateRandomSkew(btn);
}
function onCheckboxChange(checkbox) {
const label = checkbox.parentElement;
if (checkbox.checked) {
label.classList.add('selected');
} else {
label.classList.remove('selected');
}
}
function generateRandomSkew(element){
let rand = Math.random() * 6 - 3;
element.style.setProperty("--skew", "rotate(" + rand + "deg)");
Expand Down
32 changes: 30 additions & 2 deletions ProjectLighthouse.Servers.Website/Pages/SlotSettingsPage.cshtml.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#nullable enable

Check warning on line 1 in ProjectLighthouse.Servers.Website/Pages/SlotSettingsPage.cshtml.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Redundant nullable directive

Redundant nullable directive
using LBPUnion.ProjectLighthouse.Configuration;
using LBPUnion.ProjectLighthouse.Database;
using LBPUnion.ProjectLighthouse.Files;
using LBPUnion.ProjectLighthouse.Helpers;
using LBPUnion.ProjectLighthouse.Servers.Website.Pages.Layouts;
using LBPUnion.ProjectLighthouse.Types.Entities.Level;
using LBPUnion.ProjectLighthouse.Types.Users;
using LBPUnion.ProjectLighthouse.Types.Filter;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
Expand All @@ -15,17 +16,28 @@
{

public SlotEntity? Slot;
public SlotSettingsPage(DatabaseContext database) : base(database)

Check notice on line 19 in ProjectLighthouse.Servers.Website/Pages/SlotSettingsPage.cshtml.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Convert constructor into primary constructor

Convert into primary constructor
{}

public async Task<IActionResult> OnPost([FromRoute] int slotId, [FromForm] string? avatar, [FromForm] string? name, [FromForm] string? description, string? labels)
public async Task<IActionResult> OnPost
(
[FromRoute] int slotId,
[FromForm] string? avatar,
[FromForm] string? name,
[FromForm] string? description,
[FromForm] string? labels,
[FromForm] bool initiallyLocked,
[FromForm] int shareable,
[FromForm] bool subLevel,
[FromForm] bool lbp1Only
)
{
this.Slot = await this.Database.Slots.FirstOrDefaultAsync(u => u.SlotId == slotId);

Check notice on line 35 in ProjectLighthouse.Servers.Website/Pages/SlotSettingsPage.cshtml.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Query can return incomplete data for related entities

Query can return incomplete data for related entities
if (this.Slot == null) return this.NotFound();

if (this.User == null) return this.Redirect("~/slot/" + slotId);

if (!this.User.IsModerator && this.User != this.Slot.Creator) return this.Redirect("~/slot/" + slotId);

Check warning on line 40 in ProjectLighthouse.Servers.Website/Pages/SlotSettingsPage.cshtml.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Usage of navigational property can return incomplete data

Usage of navigational property can return incomplete data

// Deny request if in read-only mode
if (ServerConfiguration.Instance.UserGeneratedContentLimits.ReadOnlyMode)
Expand Down Expand Up @@ -56,6 +68,22 @@
this.Slot.AuthorLabels = labels;
}

if (this.Slot.InitiallyLocked != initiallyLocked) this.Slot.InitiallyLocked = initiallyLocked;

if (this.Slot.Shareable != shareable) this.Slot.Shareable = shareable;

if (this.Slot.SubLevel != subLevel)
{
if (this.Slot.GameVersion != GameVersion.LittleBigPlanet1)
this.Slot.SubLevel = subLevel;
}

if (this.Slot.Lbp1Only != lbp1Only)
{
if (this.Slot.GameVersion == GameVersion.LittleBigPlanet1)
this.Slot.Lbp1Only = lbp1Only;
}

// ReSharper disable once InvertIf
if (this.Database.ChangeTracker.HasChanges())
{
Expand All @@ -77,4 +105,4 @@

return this.Page();
}
}
}
Loading