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:
@@ -1,70 +0,0 @@
|
||||
@model Marechai.Database.Models.Screen
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "Edit";
|
||||
}
|
||||
<h1>Edit</h1>
|
||||
<h4>Screen</h4>
|
||||
<hr />
|
||||
<div class="row">
|
||||
<div class="col-md-4">
|
||||
<form asp-action="Edit">
|
||||
<div asp-validation-summary="ModelOnly" class="text-danger">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label asp-for="Diagonal" class="control-label">
|
||||
</label>
|
||||
<input asp-for="Diagonal" class="form-control" />
|
||||
<span asp-validation-for="Diagonal" class="text-danger">
|
||||
</span>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label asp-for="Width" class="control-label">
|
||||
</label>
|
||||
<input asp-for="Width" class="form-control" />
|
||||
<span asp-validation-for="Width" class="text-danger">
|
||||
</span>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label asp-for="Height" class="control-label">
|
||||
</label>
|
||||
<input asp-for="Height" class="form-control" />
|
||||
<span asp-validation-for="Height" class="text-danger">
|
||||
</span>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label asp-for="NativeResolution" class="control-label">
|
||||
</label>
|
||||
<select asp-for="NativeResolutionId" class="form-control" asp-items="ViewBag.NativeResolutionId">
|
||||
</select>
|
||||
<span asp-validation-for="NativeResolutionId" class="text-danger">
|
||||
</span>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label asp-for="EffectiveColors" class="control-label">
|
||||
</label>
|
||||
<input asp-for="EffectiveColors" class="form-control" />
|
||||
<span asp-validation-for="EffectiveColors" class="text-danger">
|
||||
</span>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label asp-for="Type" class="control-label">
|
||||
</label>
|
||||
<input asp-for="Type" class="form-control" />
|
||||
<span asp-validation-for="Type" class="text-danger">
|
||||
</span>
|
||||
</div>
|
||||
<input type="hidden" asp-for="Id" />
|
||||
<div class="form-group">
|
||||
<input class="btn btn-primary" type="submit" value="Save" />
|
||||
<a asp-action="Index" class="btn btn-secondary">
|
||||
Back to List
|
||||
</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@section Scripts {
|
||||
@{ await Html.RenderPartialAsync("_ValidationScriptsPartial"); }
|
||||
}
|
||||
@@ -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>
|
||||
|
||||
137
Marechai/Resources/Services/ScreensService.en.resx
Normal file
137
Marechai/Resources/Services/ScreensService.en.resx
Normal file
@@ -0,0 +1,137 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- ReSharper disable MarkupTextTypo -->
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name="Unknown (width)" xml:space="preserve">
|
||||
<value>Unknown</value>
|
||||
<comment>Unknown, referring to a screen width in millimeters</comment>
|
||||
</data>
|
||||
<data name="Unknown (height)" xml:space="preserve">
|
||||
<value>Unknown</value>
|
||||
<comment>Unknown, referring to a screen height in millimeters</comment>
|
||||
</data>
|
||||
<data name="Unknown (effective colors)" xml:space="preserve">
|
||||
<value>Unknown</value>
|
||||
<comment>Unknown, referring to a screen effective colors</comment>
|
||||
</data>
|
||||
<data name="Unknown (type)" xml:space="preserve">
|
||||
<value>Unknown</value>
|
||||
<comment>Unknown, referring to a screen type</comment>
|
||||
</data>
|
||||
</root>
|
||||
@@ -194,4 +194,48 @@
|
||||
<value>Diagonal (pulgadas)</value>
|
||||
<comment>Diagonal (inches)</comment>
|
||||
</data>
|
||||
<data name="Save" xml:space="preserve">
|
||||
<value>Guardar</value>
|
||||
<comment>Save</comment>
|
||||
</data>
|
||||
<data name="Unknown (width)" xml:space="preserve">
|
||||
<value>Desconocido</value>
|
||||
<comment>Unknown, referring to a screen width in millimeters</comment>
|
||||
</data>
|
||||
<data name="Unknown (height)" xml:space="preserve">
|
||||
<value>Desconocido</value>
|
||||
<comment>Unknown, referring to a screen height in millimeters</comment>
|
||||
</data>
|
||||
<data name="Unknown (effective colors)" xml:space="preserve">
|
||||
<value>Desconocidos</value>
|
||||
<comment>Unknown, referring to a screen effective colors</comment>
|
||||
</data>
|
||||
<data name="Unknown (type)" xml:space="preserve">
|
||||
<value>Desconocido</value>
|
||||
<comment>Unknown, referring to a screen type</comment>
|
||||
</data>
|
||||
<data name="Please enter a valid width in millimeters." xml:space="preserve">
|
||||
<value>Por favor introduce un ancho válido en milímetros</value>
|
||||
<comment>Please enter a valid width in millimeters.</comment>
|
||||
</data>
|
||||
<data name="Please enter a valid height in millimeters." xml:space="preserve">
|
||||
<value>Por favor introduce una altura válida en milímetros</value>
|
||||
<comment>Please enter a valid height in millimeters.</comment>
|
||||
</data>
|
||||
<data name="Please enter a correct diagonal size in inches." xml:space="preserve">
|
||||
<value>Por favor introduce una diagonal válida en pulgadas</value>
|
||||
<comment>Please enter a correct diagonal size in inches.</comment>
|
||||
</data>
|
||||
<data name="Please enter a number of effective colors." xml:space="preserve">
|
||||
<value>Por favor introduce un número válido de colores efectivos</value>
|
||||
<comment>Please enter a number of effective colors.</comment>
|
||||
</data>
|
||||
<data name="Please enter a valid screen type." xml:space="preserve">
|
||||
<value>Por favor introduce un tipo de pantalla válido</value>
|
||||
<comment>Please enter a valid screen type.</comment>
|
||||
</data>
|
||||
<data name="Screen type cannot be bigger than 256 characters." xml:space="preserve">
|
||||
<value>El tipo de pantalla no puede tener más de 256 caracteres.</value>
|
||||
<comment>Screen type cannot be bigger than 256 characters.</comment>
|
||||
</data>
|
||||
</root>
|
||||
@@ -2,6 +2,8 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Marechai.Database.Models;
|
||||
using Marechai.ViewModels;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Marechai.Services
|
||||
{
|
||||
@@ -15,7 +17,40 @@ namespace Marechai.Services
|
||||
ThenBy(s => s.EffectiveColors).ThenBy(s => s.NativeResolution.ToString()).
|
||||
ThenBy(s => s.Type).ThenBy(s => s.Size).ToList();
|
||||
|
||||
public async Task<Screen> GetAsync(int id) => await _context.Screens.FindAsync(id);
|
||||
public async Task<ScreenViewModel> GetAsync(int id) =>
|
||||
await _context.Screens.Where(s => s.Id == id).Select(s => new ScreenViewModel
|
||||
{
|
||||
Diagonal = s.Diagonal, EffectiveColors = s.EffectiveColors, Height = s.Height, Id = s.Id,
|
||||
NativeResolution = new ResolutionViewModel
|
||||
{
|
||||
Chars = s.NativeResolution.Chars, Colors = s.NativeResolution.Colors,
|
||||
Grayscale = s.NativeResolution.Grayscale, Height = s.NativeResolution.Height,
|
||||
Id = s.NativeResolution.Id, Palette = s.NativeResolution.Palette, Width = s.NativeResolution.Width
|
||||
},
|
||||
NativeResolutionId = s.NativeResolutionId, Type = s.Type, Width = s.Width
|
||||
}).FirstOrDefaultAsync();
|
||||
|
||||
public async Task UpdateAsync(ScreenViewModel viewModel)
|
||||
{
|
||||
Screen model = await _context.Screens.FindAsync(viewModel.Id);
|
||||
|
||||
if(model is null)
|
||||
return;
|
||||
|
||||
Resolution nativeResolution = await _context.Resolutions.FindAsync(viewModel.NativeResolutionId);
|
||||
|
||||
if(nativeResolution is null)
|
||||
return;
|
||||
|
||||
model.Diagonal = viewModel.Diagonal;
|
||||
model.EffectiveColors = viewModel.EffectiveColors;
|
||||
model.Height = viewModel.Height;
|
||||
model.NativeResolutionId = viewModel.NativeResolutionId;
|
||||
model.Type = viewModel.Type;
|
||||
model.Width = viewModel.Width;
|
||||
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
|
||||
public async Task DeleteAsync(int id)
|
||||
{
|
||||
|
||||
@@ -28,19 +28,28 @@ namespace Marechai.Shared
|
||||
e.Status = ValidationStatus.Success;
|
||||
}
|
||||
|
||||
public static void ValidateNullableDoubleBiggerThanZero(ValidatorEventArgs e)
|
||||
public static void ValidateDoubleBiggerThanZero(ValidatorEventArgs e, double minValue = 0, double maxValue = double.MaxValue)
|
||||
{
|
||||
if(!(e.Value is double item) ||
|
||||
item < 0)
|
||||
item < minValue || item > maxValue)
|
||||
e.Status = ValidationStatus.Error;
|
||||
else
|
||||
e.Status = ValidationStatus.Success;
|
||||
}
|
||||
|
||||
public static void ValidateNullableIntegerBiggerThanZero(ValidatorEventArgs e)
|
||||
public static void ValidateIntegerBiggerThanZero(ValidatorEventArgs e, int minValue = 0, int maxValue = int.MaxValue)
|
||||
{
|
||||
if(!(e.Value is int item) ||
|
||||
item < 0)
|
||||
item < minValue || item > maxValue)
|
||||
e.Status = ValidationStatus.Error;
|
||||
else
|
||||
e.Status = ValidationStatus.Success;
|
||||
}
|
||||
|
||||
public static void ValidateLongBiggerThanZero(ValidatorEventArgs e, long minValue = 0, long maxValue = long.MaxValue)
|
||||
{
|
||||
if(!(e.Value is long item) ||
|
||||
item < minValue || item > maxValue)
|
||||
e.Status = ValidationStatus.Error;
|
||||
else
|
||||
e.Status = ValidationStatus.Success;
|
||||
|
||||
31
Marechai/ViewModels/ScreenViewModel.cs
Normal file
31
Marechai/ViewModels/ScreenViewModel.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace Marechai.ViewModels
|
||||
{
|
||||
public class ScreenViewModel : BaseViewModel<int>
|
||||
{
|
||||
public double? Width { get; set; }
|
||||
public double? Height { get; set; }
|
||||
public double Diagonal { get; set; }
|
||||
public int NativeResolutionId { get; set; }
|
||||
public ResolutionViewModel NativeResolution { get; set; }
|
||||
public long? EffectiveColors { get; set; }
|
||||
public string Type { get; set; }
|
||||
|
||||
[NotMapped]
|
||||
public long? Colors => EffectiveColors ?? NativeResolution.Colors;
|
||||
|
||||
[NotMapped]
|
||||
public string Size
|
||||
{
|
||||
get
|
||||
{
|
||||
if(Width != null &&
|
||||
Height != null)
|
||||
return$"{Width}x{Height} mm";
|
||||
|
||||
return"Unknown";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user