mirror of
https://github.com/claunia/marechai.git
synced 2025-12-16 19:14:25 +00:00
Add screen editing in admin view.
This commit is contained in:
@@ -31,9 +31,11 @@
|
||||
}
|
||||
|
||||
@page "/admin/screens/details/{Id:int}"
|
||||
@page "/admin/screens/edit/{Id:int}"
|
||||
@inherits OwningComponentBase<ScreensService>
|
||||
@inject IStringLocalizer<ScreensService> L
|
||||
@inject ResolutionsService ResolutionsService
|
||||
@inject NavigationManager NavigationManager
|
||||
@attribute [Authorize(Roles = "UberAdmin, Admin")]
|
||||
<h3>@L["Screen details"]</h3>
|
||||
<hr />
|
||||
@@ -46,41 +48,104 @@
|
||||
}
|
||||
|
||||
<div>
|
||||
@if (_editable || _model.Width.HasValue)
|
||||
@if (_editing || _model.Width.HasValue)
|
||||
{
|
||||
<Field>
|
||||
<FieldLabel>@L["Width (mm)"]</FieldLabel>
|
||||
<NumericEdit Disabled="!_editable" TValue="double?" Decimals="2" @bind-Value="@_model.Width"/>
|
||||
@if (_editing)
|
||||
{
|
||||
<Check TValue="bool" @bind-Checked="@_unknownWidth">@L["Unknown (width)"]</Check>
|
||||
}
|
||||
@if (!_editing ||
|
||||
!_unknownWidth)
|
||||
{
|
||||
<Validation Validator="@ValidateDoubleBiggerThanZero">
|
||||
<NumericEdit Disabled="!_editing" TValue="double?" Decimals="2" @bind-Value="@_model.Width" >
|
||||
<Feedback>
|
||||
<ValidationError>@L["Please enter a valid width in millimeters."]</ValidationError>
|
||||
</Feedback>
|
||||
</NumericEdit>
|
||||
</Validation>
|
||||
}
|
||||
</Field>
|
||||
}
|
||||
@if (_editable || _model.Height.HasValue)
|
||||
@if (_editing || _model.Height.HasValue)
|
||||
{
|
||||
<Field>
|
||||
<FieldLabel>@L["Height (mm)"]</FieldLabel>
|
||||
<NumericEdit Disabled="!_editable" TValue="double?" Decimals="0" @bind-Value="@_model.Height"/>
|
||||
@if (_editing)
|
||||
{
|
||||
<Check TValue="bool" @bind-Checked="@_unknownHeight">@L["Unknown (height)"]</Check>
|
||||
}
|
||||
@if (!_editing ||
|
||||
!_unknownHeight)
|
||||
{
|
||||
<Validation Validator="@ValidateDoubleBiggerThanZero">
|
||||
<NumericEdit Disabled="!_editing" TValue="double?" Decimals="2" @bind-Value="@_model.Height" >
|
||||
<Feedback>
|
||||
<ValidationError>@L["Please enter a valid height in millimeters."]</ValidationError>
|
||||
</Feedback>
|
||||
</NumericEdit>
|
||||
</Validation>
|
||||
}
|
||||
<NumericEdit Disabled="!_editing" TValue="double?" Decimals="2" @bind-Value="@_model.Height"/>
|
||||
</Field>
|
||||
}
|
||||
<Field>
|
||||
<FieldLabel>@L["Diagonal (inches)"]</FieldLabel>
|
||||
<NumericEdit Disabled="!_editable" TValue="double" Decimals="2" @bind-Value="@_model.Diagonal"/>
|
||||
<Validation Validator="@ValidateDoubleBiggerThanZero">
|
||||
<NumericEdit Disabled="!_editing" TValue="long" Decimals="2" @bind-Value="@_model.Diagonal" >
|
||||
<Feedback>
|
||||
<ValidationError>@L["Please enter a correct diagonal size in inches."]</ValidationError>
|
||||
</Feedback>
|
||||
</NumericEdit>
|
||||
</Validation>
|
||||
</Field>
|
||||
@if (_editable || _model.EffectiveColors.HasValue)
|
||||
@if (_editing || _model.EffectiveColors.HasValue)
|
||||
{
|
||||
<Field>
|
||||
<FieldLabel>@L["Effective colors"]</FieldLabel>
|
||||
<NumericEdit Disabled="!_editable" TValue="long?" Decimals="0" @bind-Value="@_model.EffectiveColors"/>
|
||||
@if (_editing)
|
||||
{
|
||||
<Check TValue="bool" @bind-Checked="@_unknownColors">@L["Unknown (effective colors)"]</Check>
|
||||
}
|
||||
@if (!_editing ||
|
||||
!_unknownColors)
|
||||
{
|
||||
<Validation Validator="@ValidateLongBiggerThanZero">
|
||||
<NumericEdit Disabled="!_editing" TValue="long?" Decimals="0" @bind-Value="@_model.EffectiveColors" >
|
||||
<Feedback>
|
||||
<ValidationError>@L["Please enter a number of effective colors."]</ValidationError>
|
||||
</Feedback>
|
||||
</NumericEdit>
|
||||
</Validation>
|
||||
}
|
||||
</Field>
|
||||
}
|
||||
@if (_editable || _model.Type != null)
|
||||
@if (_editing || _model.Type != null)
|
||||
{
|
||||
<Field>
|
||||
<FieldLabel>@L["Type"]</FieldLabel>
|
||||
<TextEdit ReadOnly="!_editable" @bind-Text="@_model.Type" />
|
||||
@if (_editing)
|
||||
{
|
||||
<Check TValue="bool" @bind-Checked="@_unknownType">@L["Unknown (type)"]</Check>
|
||||
}
|
||||
@if (!_editing ||
|
||||
!_unknownType)
|
||||
{
|
||||
<Validation Validator="@ValidateType">
|
||||
<TextEdit ReadOnly="!_editing" @bind-Text="@_model.Type">
|
||||
<Feedback>
|
||||
<ValidationError>@L["Please enter a valid screen type."]</ValidationError>
|
||||
</Feedback>
|
||||
</TextEdit>
|
||||
</Validation>
|
||||
}
|
||||
</Field>
|
||||
}
|
||||
<Field>
|
||||
<FieldLabel>@L["Native resolution"]</FieldLabel>
|
||||
<Select Disabled="!_editable" TValue="int" @bind-SelectedValue="@_model.NativeResolutionId">
|
||||
<Select Disabled="!_editing" TValue="int" @bind-SelectedValue="@_model.NativeResolutionId">
|
||||
@foreach (var resolution in _resolutions)
|
||||
{
|
||||
<SelectItem TValue="int" Value="@resolution.Id">@resolution.ToString()</SelectItem>
|
||||
@@ -89,6 +154,14 @@
|
||||
</Field>
|
||||
</div>
|
||||
<div>
|
||||
<span class="btn btn-primary">@L["Edit"]</span>
|
||||
@if (!_editing)
|
||||
{
|
||||
<Button Color="Color.Primary" Clicked="@OnEditClicked">@L["Edit"]</Button>
|
||||
}
|
||||
else
|
||||
{
|
||||
<Button Color="Color.Success" Clicked="@OnSaveClicked">@L["Save"]</Button>
|
||||
<Button Color="Color.Danger" Clicked="@OnCancelClicked">@L["Cancel"]</Button>
|
||||
}
|
||||
<a href="/admin/screens" class="btn btn-secondary">@L["Back to list"]</a>
|
||||
</div>
|
||||
@@ -1,5 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Blazorise;
|
||||
using Marechai.Shared;
|
||||
using Marechai.ViewModels;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
|
||||
@@ -7,10 +10,14 @@ namespace Marechai.Pages.Admin.Details
|
||||
{
|
||||
public partial class Screen
|
||||
{
|
||||
bool _editable;
|
||||
bool _editing;
|
||||
bool _loaded;
|
||||
Database.Models.Screen _model;
|
||||
ScreenViewModel _model;
|
||||
List<ResolutionViewModel> _resolutions;
|
||||
bool _unknownColors;
|
||||
bool _unknownHeight;
|
||||
bool _unknownType;
|
||||
bool _unknownWidth;
|
||||
[Parameter]
|
||||
public int Id { get; set; }
|
||||
|
||||
@@ -27,7 +34,73 @@ namespace Marechai.Pages.Admin.Details
|
||||
_resolutions = await ResolutionsService.GetAsync();
|
||||
_model = await Service.GetAsync(Id);
|
||||
|
||||
_editing = NavigationManager.ToBaseRelativePath(NavigationManager.Uri).ToLowerInvariant().
|
||||
StartsWith("admin/screens/edit/", StringComparison.InvariantCulture);
|
||||
|
||||
if(_editing)
|
||||
SetCheckboxes();
|
||||
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
void SetCheckboxes()
|
||||
{
|
||||
_unknownWidth = !_model.Width.HasValue;
|
||||
_unknownType = string.IsNullOrWhiteSpace(_model.Type);
|
||||
_unknownHeight = !_model.Height.HasValue;
|
||||
_unknownColors = !_model.Colors.HasValue;
|
||||
}
|
||||
|
||||
void OnEditClicked()
|
||||
{
|
||||
_editing = true;
|
||||
SetCheckboxes();
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
async void OnCancelClicked()
|
||||
{
|
||||
_editing = false;
|
||||
_model = await Service.GetAsync(Id);
|
||||
SetCheckboxes();
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
async void OnSaveClicked()
|
||||
{
|
||||
if(_unknownWidth)
|
||||
_model.Width = null;
|
||||
else if(_model.Width < 0)
|
||||
return;
|
||||
|
||||
if(_unknownHeight)
|
||||
_model.Height = null;
|
||||
else if(_model.Height < 0)
|
||||
return;
|
||||
|
||||
if(_unknownType)
|
||||
_model.Type = null;
|
||||
else if(string.IsNullOrWhiteSpace(_model.Type))
|
||||
return;
|
||||
|
||||
if(_unknownColors)
|
||||
_model.EffectiveColors = null;
|
||||
else if(_model.EffectiveColors < 0)
|
||||
return;
|
||||
|
||||
_editing = false;
|
||||
await Service.UpdateAsync(_model);
|
||||
_model = await Service.GetAsync(Id);
|
||||
SetCheckboxes();
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
void ValidateDoubleBiggerThanZero(ValidatorEventArgs e) =>
|
||||
Validators.ValidateDoubleBiggerThanZero(e, 1, 131072);
|
||||
|
||||
void ValidateLongBiggerThanZero(ValidatorEventArgs e) => Validators.ValidateLongBiggerThanZero(e, 2);
|
||||
|
||||
void ValidateType(ValidatorEventArgs e) =>
|
||||
Validators.ValidateStringWithMaxLength(e, L["Screen type cannot be bigger than 256 characters."], 256);
|
||||
}
|
||||
}
|
||||
@@ -126,7 +126,7 @@
|
||||
@if (!_editing ||
|
||||
!_unknownVoices)
|
||||
{
|
||||
<Validation Validator="@ValidateNullableIntegerBiggerThanZero">
|
||||
<Validation Validator="@ValidateIntegerBiggerThanZero">
|
||||
<NumericEdit Disabled="!_editing" TValue="int?" Decimals="0" @bind-Value="@_model.Voices" >
|
||||
<Feedback>
|
||||
<ValidationError>@L["Please enter a valid number of voices."]</ValidationError>
|
||||
@@ -147,7 +147,7 @@
|
||||
@if (!_editing ||
|
||||
!_unknownSampleRate)
|
||||
{
|
||||
<Validation Validator="@ValidateNullableDoubleBiggerThanZero">
|
||||
<Validation Validator="@ValidateDoubleBiggerThanZero">
|
||||
<NumericEdit Disabled="!_editing" TValue="double?" Decimals="0" @bind-Value="@_model.Frequency" >
|
||||
<Feedback>
|
||||
<ValidationError>@L["Please enter a valid sample rate."]</ValidationError>
|
||||
@@ -168,7 +168,7 @@
|
||||
@if (!_editing ||
|
||||
!_unknownSampleResolution)
|
||||
{
|
||||
<Validation Validator="@ValidateNullableIntegerBiggerThanZero">
|
||||
<Validation Validator="@ValidateIntegerBiggerThanZero">
|
||||
<NumericEdit Disabled="!_editing" TValue="int?" Decimals="0" @bind-Value="@_model.Depth" >
|
||||
<Feedback>
|
||||
<ValidationError>@L["Please enter a valid number of bits for sample resolution."]</ValidationError>
|
||||
@@ -189,7 +189,7 @@
|
||||
@if (!_editing ||
|
||||
!_unknownSquareWaveChannels)
|
||||
{
|
||||
<Validation Validator="@ValidateNullableIntegerBiggerThanZero">
|
||||
<Validation Validator="@ValidateIntegerBiggerThanZero">
|
||||
<NumericEdit Disabled="!_editing" TValue="int?" Decimals="0" @bind-Value="@_model.SquareWave" >
|
||||
<Feedback>
|
||||
<ValidationError>@L["Please enter a valid number of square wave channels."]</ValidationError>
|
||||
@@ -210,7 +210,7 @@
|
||||
@if (!_editing ||
|
||||
!_unknownWhiteNoiseChannels)
|
||||
{
|
||||
<Validation Validator="@ValidateNullableIntegerBiggerThanZero">
|
||||
<Validation Validator="@ValidateIntegerBiggerThanZero">
|
||||
<NumericEdit Disabled="!_editing" TValue="int?" Decimals="0" @bind-Value="@_model.WhiteNoise" >
|
||||
<Feedback>
|
||||
<ValidationError>@L["Please enter a valid number of white noise channels."]</ValidationError>
|
||||
@@ -231,7 +231,7 @@
|
||||
@if (!_editing ||
|
||||
!_unknownType)
|
||||
{
|
||||
<Validation Validator="@ValidateNullableIntegerBiggerThanZero">
|
||||
<Validation Validator="@ValidateIntegerBiggerThanZero">
|
||||
<NumericEdit Disabled="!_editing" TValue="int?" Decimals="0" @bind-Value="@_model.Type" >
|
||||
<Feedback>
|
||||
<ValidationError>@L["Please enter a valid sound synthesizer type."]</ValidationError>
|
||||
|
||||
@@ -139,10 +139,8 @@ namespace Marechai.Pages.Admin.Details
|
||||
|
||||
void ValidateIntroduced(ValidatorEventArgs e) => Validators.ValidateIntroducedDate(e);
|
||||
|
||||
void ValidateNullableIntegerBiggerThanZero(ValidatorEventArgs e) =>
|
||||
Validators.ValidateNullableIntegerBiggerThanZero(e);
|
||||
void ValidateIntegerBiggerThanZero(ValidatorEventArgs e) => Validators.ValidateIntegerBiggerThanZero(e);
|
||||
|
||||
void ValidateNullableDoubleBiggerThanZero(ValidatorEventArgs e) =>
|
||||
Validators.ValidateNullableDoubleBiggerThanZero(e);
|
||||
void ValidateDoubleBiggerThanZero(ValidatorEventArgs e) => Validators.ValidateDoubleBiggerThanZero(e);
|
||||
}
|
||||
}
|
||||
@@ -82,9 +82,7 @@
|
||||
</td>
|
||||
<td>
|
||||
<a class="btn btn-primary" href="/admin/screens/details/@item.Id">@L["Details"]</a>
|
||||
<span class="btn btn-secondary">
|
||||
@L["Edit"]
|
||||
</span>
|
||||
<a class="btn btn-secondary" href="/admin/screens/edit/@item.Id">@L["Edit"]</a>
|
||||
<Button Color="Color.Danger" Clicked="() => {ShowModal(item.Id);}">@L["Delete"]</Button>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
Reference in New Issue
Block a user