Skip to content

Commit

Permalink
Implement checkboxes in slot settings to toggle various slot properti…
Browse files Browse the repository at this point in the history
…es (#1063)

* Implement checkboxes in slot settings to toggle various slot properties

* Fix UI inconsistencies in checkboxes

* Update ProjectLighthouse.Servers.Website/Pages/SlotSettingsPage.cshtml

Co-authored-by: Josh <[email protected]>

* Update ProjectLighthouse.Servers.Website/Pages/SlotSettingsPage.cshtml

Co-authored-by: Josh <[email protected]>

* Fix missing end quote and add extra margin

* Update SlotSettingsPage.cshtml.cs

Resolve file conflict

---------

Co-authored-by: Josh <[email protected]>
  • Loading branch information
FeTetra and Slendy authored Dec 11, 2024
1 parent f059b20 commit 8b8756e
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 2 deletions.
35 changes: 35 additions & 0 deletions ProjectLighthouse.Servers.Website/Pages/SlotSettingsPage.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,33 @@ function onSubmit(){
<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 onSubmit(){
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
Expand Up @@ -5,6 +5,7 @@
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 @@ -18,7 +19,18 @@ public class SlotSettingsPage : BaseLayout
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();
Expand Down Expand Up @@ -56,6 +68,22 @@ public async Task<IActionResult> OnPost([FromRoute] int slotId, [FromForm] strin
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 @@ public async Task<IActionResult> OnGet([FromRoute] int slotId)

return this.Page();
}
}
}

0 comments on commit 8b8756e

Please sign in to comment.