mirror of
https://github.com/claunia/marechai.git
synced 2025-12-16 19:14:25 +00:00
Add sound synthesizer editing in admin view.
This commit is contained in:
@@ -31,9 +31,11 @@
|
||||
}
|
||||
|
||||
@page "/admin/sound_synths/details/{Id:int}"
|
||||
@page "/admin/sound_synths/edit/{Id:int}"
|
||||
@inherits OwningComponentBase<SoundSynthsService>
|
||||
@inject IStringLocalizer<SoundSynthsService> L
|
||||
@inject CompaniesService CompaniesService
|
||||
@inject NavigationManager NavigationManager
|
||||
@attribute [Authorize(Roles = "UberAdmin, Admin")]
|
||||
<h3>@L["Sound synthesizer details"]</h3>
|
||||
<hr />
|
||||
@@ -46,80 +48,209 @@
|
||||
}
|
||||
|
||||
<div>
|
||||
@if (_editable || _model.CompanyId != null)
|
||||
@if (_editing || _model.CompanyId != null)
|
||||
{
|
||||
<Field>
|
||||
<FieldLabel>@L["Company"]</FieldLabel>
|
||||
<Select Disabled="!_editable" TValue="int?" @bind-SelectedValue="@_model.CompanyId">
|
||||
@foreach (var company in _companies)
|
||||
{
|
||||
<SelectItem TValue="int?" Value="@company.Id">@company.Name</SelectItem>
|
||||
}
|
||||
</Select>
|
||||
@if (_editing)
|
||||
{
|
||||
<Check TValue="bool" @bind-Checked="@_unknownCompany">@L["Unknown (company)"]</Check>
|
||||
}
|
||||
@if (!_editing ||
|
||||
!_unknownCompany)
|
||||
{
|
||||
<Select Disabled="!_editing" TValue="int?" @bind-SelectedValue="@_model.CompanyId">
|
||||
@foreach (var company in _companies)
|
||||
{
|
||||
<SelectItem TValue="int?" Value="@company.Id">@company.Name</SelectItem>
|
||||
}
|
||||
</Select>
|
||||
}
|
||||
</Field>
|
||||
}
|
||||
<Field>
|
||||
<FieldLabel>@L["Name"]</FieldLabel>
|
||||
<TextEdit Disabled="!_editable" @bind-Text="@_model.Name"/>
|
||||
<TextEdit Disabled="!_editing" @bind-Text="@_model.Name"/>
|
||||
</Field>
|
||||
@if (_editable || _model.ModelCode != null)
|
||||
@if (_editing || _model.ModelCode != null)
|
||||
{
|
||||
<Field>
|
||||
<FieldLabel>@L["Model code"]</FieldLabel>
|
||||
<TextEdit Disabled="!_editable" @bind-Text="@_model.ModelCode"/>
|
||||
@if (_editing)
|
||||
{
|
||||
<Check TValue="bool" @bind-Checked="@_unknownModelCode">@L["Unknown (model code)"]</Check>
|
||||
}
|
||||
@if (!_editing ||
|
||||
!_unknownModelCode)
|
||||
{
|
||||
<Validation Validator="@ValidateModelCode">
|
||||
<TextEdit Disabled="!_editing" @bind-Text="@_model.ModelCode">
|
||||
<Feedback>
|
||||
<ValidationError>@L["Please enter a valid model code."]</ValidationError>
|
||||
</Feedback>
|
||||
</TextEdit>
|
||||
</Validation>
|
||||
}
|
||||
</Field>
|
||||
}
|
||||
@if (_editable || _model.Introduced.HasValue)
|
||||
@if (_editing || _model.Introduced.HasValue)
|
||||
{
|
||||
<Field>
|
||||
<FieldLabel>@L["Introduced"]</FieldLabel>
|
||||
<DateEdit Disabled="!_editable" TValue="DateTime?" @bind-Date="@_model.Introduced"/>
|
||||
</Field>
|
||||
@if (_editing)
|
||||
{
|
||||
<Check TValue="bool" Disabled="_prototype" @bind-Checked="@_unknownIntroduced">@L["Unknown (introduction date)"]</Check>
|
||||
<Check TValue="bool" Disabled="_unknownIntroduced" @bind-Checked="@_prototype">@L["Prototype"]</Check>
|
||||
}
|
||||
@if (!_editing ||
|
||||
(!_prototype && !_unknownIntroduced))
|
||||
{
|
||||
<Validation Validator="@ValidateIntroduced">
|
||||
<DateEdit Disabled="!_editing" TValue="DateTime?" @bind-Date="@_model.Introduced">
|
||||
<Feedback>
|
||||
<ValidationError>@L["Please enter an introduction date."]</ValidationError>
|
||||
</Feedback>
|
||||
</DateEdit>
|
||||
</Validation>
|
||||
}
|
||||
</Field>
|
||||
}
|
||||
@if (_editable || _model.Voices.HasValue)
|
||||
@if (_editing || _model.Voices.HasValue)
|
||||
{
|
||||
<Field>
|
||||
<FieldLabel>@L["Digitized voices"]</FieldLabel>
|
||||
<NumericEdit Disabled="!_editable" TValue="int?" Decimals="0" @bind-Value="@_model.Voices"/>
|
||||
</Field>
|
||||
@if (_editing)
|
||||
{
|
||||
<Check TValue="bool" @bind-Checked="@_unknownVoices">@L["Unknown (voices)"]</Check>
|
||||
}
|
||||
@if (!_editing ||
|
||||
!_unknownVoices)
|
||||
{
|
||||
<Validation Validator="@ValidateNullableIntegerBiggerThanZero">
|
||||
<NumericEdit Disabled="!_editing" TValue="int?" Decimals="0" @bind-Value="@_model.Voices" >
|
||||
<Feedback>
|
||||
<ValidationError>@L["Please enter a valid number of voices."]</ValidationError>
|
||||
</Feedback>
|
||||
</NumericEdit>
|
||||
</Validation>
|
||||
}
|
||||
</Field>
|
||||
}
|
||||
@if (_editable || _model.Frequency.HasValue)
|
||||
@if (_editing || _model.Frequency.HasValue)
|
||||
{
|
||||
<Field>
|
||||
<FieldLabel>@L["Sample rate (Hz)"]</FieldLabel>
|
||||
<NumericEdit Disabled="!_editable" TValue="double?" Decimals="0" @bind-Value="@_model.Frequency"/>
|
||||
</Field>
|
||||
@if (_editing)
|
||||
{
|
||||
<Check TValue="bool" @bind-Checked="@_unknownSampleRate">@L["Unknown (sample rate)"]</Check>
|
||||
}
|
||||
@if (!_editing ||
|
||||
!_unknownSampleRate)
|
||||
{
|
||||
<Validation Validator="@ValidateNullableDoubleBiggerThanZero">
|
||||
<NumericEdit Disabled="!_editing" TValue="double?" Decimals="0" @bind-Value="@_model.Frequency" >
|
||||
<Feedback>
|
||||
<ValidationError>@L["Please enter a valid sample rate."]</ValidationError>
|
||||
</Feedback>
|
||||
</NumericEdit>
|
||||
</Validation>
|
||||
}
|
||||
</Field>
|
||||
}
|
||||
@if (_editable || _model.Depth.HasValue)
|
||||
@if (_editing || _model.Depth.HasValue)
|
||||
{
|
||||
<Field>
|
||||
<FieldLabel>@L["Sample resolution (bits)"]</FieldLabel>
|
||||
<NumericEdit Disabled="!_editable" TValue="int?" Decimals="0" @bind-Value="@_model.Depth"/>
|
||||
</Field>
|
||||
@if (_editing)
|
||||
{
|
||||
<Check TValue="bool" @bind-Checked="@_unknownSampleResolution">@L["Unknown (sample resolution)"]</Check>
|
||||
}
|
||||
@if (!_editing ||
|
||||
!_unknownSampleResolution)
|
||||
{
|
||||
<Validation Validator="@ValidateNullableIntegerBiggerThanZero">
|
||||
<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>
|
||||
</Feedback>
|
||||
</NumericEdit>
|
||||
</Validation>
|
||||
}
|
||||
</Field>
|
||||
}
|
||||
@if (_editable || _model.SquareWave.HasValue)
|
||||
@if (_editing || _model.SquareWave.HasValue)
|
||||
{
|
||||
<Field>
|
||||
<FieldLabel>@L["Square wave channels"]</FieldLabel>
|
||||
<NumericEdit Disabled="!_editable" TValue="int?" Decimals="0" @bind-Value="@_model.SquareWave"/>
|
||||
</Field>
|
||||
@if (_editing)
|
||||
{
|
||||
<Check TValue="bool" @bind-Checked="@_unknownSquareWaveChannels">@L["Unknown (square wave channels)"]</Check>
|
||||
}
|
||||
@if (!_editing ||
|
||||
!_unknownSquareWaveChannels)
|
||||
{
|
||||
<Validation Validator="@ValidateNullableIntegerBiggerThanZero">
|
||||
<NumericEdit Disabled="!_editing" TValue="int?" Decimals="0" @bind-Value="@_model.SquareWave" >
|
||||
<Feedback>
|
||||
<ValidationError>@L["Please enter a valid number of square wave channels."]</ValidationError>
|
||||
</Feedback>
|
||||
</NumericEdit>
|
||||
</Validation>
|
||||
}
|
||||
</Field>
|
||||
}
|
||||
@if (_editable || _model.WhiteNoise.HasValue)
|
||||
@if (_editing || _model.WhiteNoise.HasValue)
|
||||
{
|
||||
<Field>
|
||||
<FieldLabel>@L["White noise channels"]</FieldLabel>
|
||||
<NumericEdit Disabled="!_editable" TValue="int?" Decimals="0" @bind-Value="@_model.WhiteNoise"/>
|
||||
</Field>
|
||||
@if (_editing)
|
||||
{
|
||||
<Check TValue="bool" @bind-Checked="@_unknownWhiteNoiseChannels">@L["Unknown (white noise channels)"]</Check>
|
||||
}
|
||||
@if (!_editing ||
|
||||
!_unknownWhiteNoiseChannels)
|
||||
{
|
||||
<Validation Validator="@ValidateNullableIntegerBiggerThanZero">
|
||||
<NumericEdit Disabled="!_editing" TValue="int?" Decimals="0" @bind-Value="@_model.WhiteNoise" >
|
||||
<Feedback>
|
||||
<ValidationError>@L["Please enter a valid number of white noise channels."]</ValidationError>
|
||||
</Feedback>
|
||||
</NumericEdit>
|
||||
</Validation>
|
||||
}
|
||||
</Field>
|
||||
}
|
||||
@if (_editable || _model.Type.HasValue)
|
||||
@if (_editing || _model.Type.HasValue)
|
||||
{
|
||||
<Field>
|
||||
<FieldLabel>@L["Type"]</FieldLabel>
|
||||
<NumericEdit Disabled="!_editable" TValue="int?" Decimals="0" @bind-Value="@_model.Type"/>
|
||||
</Field>
|
||||
@if (_editing)
|
||||
{
|
||||
<Check TValue="bool" @bind-Checked="@_unknownType">@L["Unknown (type)"]</Check>
|
||||
}
|
||||
@if (!_editing ||
|
||||
!_unknownType)
|
||||
{
|
||||
<Validation Validator="@ValidateNullableIntegerBiggerThanZero">
|
||||
<NumericEdit Disabled="!_editing" TValue="int?" Decimals="0" @bind-Value="@_model.Type" >
|
||||
<Feedback>
|
||||
<ValidationError>@L["Please enter a valid sound synthesizer type."]</ValidationError>
|
||||
</Feedback>
|
||||
</NumericEdit>
|
||||
</Validation>
|
||||
}
|
||||
</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/sound_synths" 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,20 @@ namespace Marechai.Pages.Admin.Details
|
||||
{
|
||||
public partial class SoundSynth
|
||||
{
|
||||
List<CompanyViewModel> _companies;
|
||||
bool _editable;
|
||||
bool _loaded;
|
||||
Database.Models.SoundSynth _model;
|
||||
List<CompanyViewModel> _companies;
|
||||
bool _editing;
|
||||
bool _loaded;
|
||||
SoundSynthViewModel _model;
|
||||
bool _prototype;
|
||||
bool _unknownCompany;
|
||||
bool _unknownIntroduced;
|
||||
bool _unknownModelCode;
|
||||
bool _unknownSampleRate;
|
||||
bool _unknownSampleResolution;
|
||||
bool _unknownSquareWaveChannels;
|
||||
bool _unknownType;
|
||||
bool _unknownVoices;
|
||||
bool _unknownWhiteNoiseChannels;
|
||||
[Parameter]
|
||||
public int Id { get; set; }
|
||||
|
||||
@@ -27,7 +40,109 @@ namespace Marechai.Pages.Admin.Details
|
||||
_companies = await CompaniesService.GetAsync();
|
||||
_model = await Service.GetAsync(Id);
|
||||
|
||||
_editing = NavigationManager.ToBaseRelativePath(NavigationManager.Uri).ToLowerInvariant().
|
||||
StartsWith("admin/sound_synths/edit/", StringComparison.InvariantCulture);
|
||||
|
||||
if(_editing)
|
||||
SetCheckboxes();
|
||||
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
void SetCheckboxes()
|
||||
{
|
||||
_unknownCompany = !_model.CompanyId.HasValue;
|
||||
_unknownModelCode = string.IsNullOrWhiteSpace(_model.ModelCode);
|
||||
_unknownIntroduced = !_model.Introduced.HasValue;
|
||||
_prototype = _model.Introduced?.Year == 1000;
|
||||
_unknownVoices = !_model.Voices.HasValue;
|
||||
_unknownSampleRate = !_model.Frequency.HasValue;
|
||||
_unknownSampleResolution = !_model.Depth.HasValue;
|
||||
_unknownSquareWaveChannels = !_model.SquareWave.HasValue;
|
||||
_unknownWhiteNoiseChannels = !_model.WhiteNoise.HasValue;
|
||||
_unknownType = !_model.Type.HasValue;
|
||||
}
|
||||
|
||||
void OnEditClicked()
|
||||
{
|
||||
_editing = true;
|
||||
SetCheckboxes();
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
async void OnCancelClicked()
|
||||
{
|
||||
_editing = false;
|
||||
_model = await Service.GetAsync(Id);
|
||||
SetCheckboxes();
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
async void OnSaveClicked()
|
||||
{
|
||||
if(_unknownCompany)
|
||||
_model.CompanyId = null;
|
||||
else if(_model.CompanyId < 0)
|
||||
return;
|
||||
|
||||
if(_unknownModelCode)
|
||||
_model.ModelCode = null;
|
||||
else if(string.IsNullOrWhiteSpace(_model.ModelCode))
|
||||
return;
|
||||
|
||||
if(_unknownIntroduced)
|
||||
_model.Introduced = null;
|
||||
else if(_prototype)
|
||||
_model.Introduced = new DateTime(1000, 1, 1);
|
||||
else if(_model.Introduced >= DateTime.UtcNow.Date)
|
||||
return;
|
||||
|
||||
if(_unknownVoices)
|
||||
_model.Voices = null;
|
||||
else if(_model.Voices < 0)
|
||||
return;
|
||||
|
||||
if(_unknownSampleRate)
|
||||
_model.Frequency = null;
|
||||
else if(_model.Frequency < 0)
|
||||
return;
|
||||
|
||||
if(_unknownSampleResolution)
|
||||
_model.Depth = null;
|
||||
else if(_model.Depth < 0)
|
||||
return;
|
||||
|
||||
if(_unknownSquareWaveChannels)
|
||||
_model.SquareWave = null;
|
||||
else if(_model.SquareWave < 0)
|
||||
return;
|
||||
|
||||
if(_unknownWhiteNoiseChannels)
|
||||
_model.WhiteNoise = null;
|
||||
else if(_model.WhiteNoise < 0)
|
||||
return;
|
||||
|
||||
if(_unknownType)
|
||||
_model.Type = null;
|
||||
else if(_model.Type < 0)
|
||||
return;
|
||||
|
||||
_editing = false;
|
||||
await Service.UpdateAsync(_model);
|
||||
_model = await Service.GetAsync(Id);
|
||||
SetCheckboxes();
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
void ValidateModelCode(ValidatorEventArgs e) =>
|
||||
Validators.ValidateStringWithMaxLength(e, L["Model code must be 45 characters or less."], 45);
|
||||
|
||||
void ValidateIntroduced(ValidatorEventArgs e) => Validators.ValidateIntroducedDate(e);
|
||||
|
||||
void ValidateNullableIntegerBiggerThanZero(ValidatorEventArgs e) =>
|
||||
Validators.ValidateNullableIntegerBiggerThanZero(e);
|
||||
|
||||
void ValidateNullableDoubleBiggerThanZero(ValidatorEventArgs e) =>
|
||||
Validators.ValidateNullableDoubleBiggerThanZero(e);
|
||||
}
|
||||
}
|
||||
@@ -88,9 +88,7 @@
|
||||
</td>
|
||||
<td>
|
||||
<a class="btn btn-primary" href="/admin/sound_synths/details/@item.Id">@L["Details"]</a>
|
||||
<span class="btn btn-secondary">
|
||||
@L["Edit"]
|
||||
</span>
|
||||
<a class="btn btn-secondary" href="/admin/sound_synths/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