Implement checkboxes in slot settings to toggle various slot properties

This commit is contained in:
FeTetra 2024-09-10 16:24:21 -04:00 committed by FeTetra
commit 7839082c30
2 changed files with 57 additions and 1 deletions

View file

@ -60,6 +60,34 @@ 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 red label" for="initiallyLocked">
<i class="lock icon"></i>
Locked
<input type="checkbox" name="initiallyLocked" id="initiallyLocked" style="margin-left: 5px;" @(Model.Slot.InitiallyLocked ? "checked" : "") value="true">
</label>
<label class="ui green label" for="shareable">
<i class="check icon"></i>
Copyable
<input type="checkbox" name="shareable" id="shareable" style="margin-left: 5px;" @(Model.Slot.Shareable == 1 ? "checked" : "") value="1">
</label>
@if (Model.Slot.GameVersion != GameVersion.LittleBigPlanet1)
{
<label class="ui blue label" for="subLevel">
<i class="arrow circle down icon"></i>
Sub Level
<input type="checkbox" name="subLevel" id="subLevel" style="margin-left: 5px;" @(Model.Slot.SubLevel ? "checked" : "") value="true">
</label>
}
else
{
<label class="ui yellow label" for="lbp1Only">
<i class="eye icon"></i>
LBP1 Only
<input type="checkbox" name="lbp1Only" id="lbp1Only" style="margin-left: 5px;" @(Model.Slot.Lbp1Only ? "checked" : "") value="true">
</label>
}
<div class="ui divider fitted hidden"></div>
@if (Model.Slot.GameVersion != GameVersion.LittleBigPlanet1)
{
<div class="field">

View file

@ -5,6 +5,7 @@ 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 Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
@ -17,7 +18,18 @@ public class SlotSettingsPage : BaseLayout
public SlotSettingsPage(DatabaseContext database) : base(database)
{}
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);
if (this.Slot == null) return this.NotFound();
@ -55,6 +67,22 @@ public class SlotSettingsPage : BaseLayout
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())
{