Files
marechai/Marechai/Pages/Admin/Details/Screen.razor
2020-12-20 21:34:13 +00:00

264 lines
9.9 KiB
Plaintext

@{
/******************************************************************************
// MARECHAI: Master repository of computing history artifacts information
// ----------------------------------------------------------------------------
//
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// --[ License ] --------------------------------------------------------------
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
// ----------------------------------------------------------------------------
// Copyright © 2003-2020 Natalia Portillo
*******************************************************************************/
}
@page "/admin/screens/details/{Id:int}"
@page "/admin/screens/edit/{Id:int}"
@page "/admin/screens/create"
@using Marechai.Database.Models
@inherits OwningComponentBase<ScreensService>
@inject IStringLocalizer<ScreensService> L
@inject ResolutionsService ResolutionsService
@inject NavigationManager NavigationManager
@inject ResolutionsByScreenService ResolutionsByScreenService
@inject UserManager<ApplicationUser> UserManager
@inject AuthenticationStateProvider AuthenticationStateProvider
@attribute [Authorize(Roles = "UberAdmin, Admin")]
<h3>@L["Screen details"]</h3>
<hr />
@if(!_loaded)
{
<p align="center">@L["Loading..."]</p>
return;
}
<div>
@if(_editing || _model.Width.HasValue)
{
<Field>
<FieldLabel>@L["Width (mm)"]</FieldLabel>
@if(_editing)
{
<Check @bind-Checked="@_unknownWidth" @TValue="bool">@L["Unknown (width)"]</Check>
}
@if(!_editing ||
!_unknownWidth)
{
<Validation Validator="@ValidateDoubleBiggerThanZero">
<NumericEdit @bind-Value="@_model.Width" Decimals="2" Disabled="!_editing" @TValue="double?">
<Feedback>
<ValidationError>@L["Please enter a valid width in millimeters."]</ValidationError>
</Feedback>
</NumericEdit>
</Validation>
}
</Field>
}
@if(_editing || _model.Height.HasValue)
{
<Field>
<FieldLabel>@L["Height (mm)"]</FieldLabel>
@if(_editing)
{
<Check @bind-Checked="@_unknownHeight" @TValue="bool">@L["Unknown (height)"]</Check>
}
@if(!_editing ||
!_unknownHeight)
{
<Validation Validator="@ValidateDoubleBiggerThanZero">
<NumericEdit @bind-Value="@_model.Height" Decimals="2" Disabled="!_editing" @TValue="double?">
<Feedback>
<ValidationError>@L["Please enter a valid height in millimeters."]</ValidationError>
</Feedback>
</NumericEdit>
</Validation>
}
</Field>
}
<Field>
<FieldLabel>@L["Diagonal (inches)"]</FieldLabel>
<Validation Validator="@ValidateDoubleBiggerThanZero">
<NumericEdit @bind-Value="@_model.Diagonal" Decimals="2" Disabled="!_editing" @TValue="double">
<Feedback>
<ValidationError>@L["Please enter a correct diagonal size in inches."]</ValidationError>
</Feedback>
</NumericEdit>
</Validation>
</Field>
@if(_editing || _model.EffectiveColors.HasValue)
{
<Field>
<FieldLabel>@L["Effective colors"]</FieldLabel>
@if(_editing)
{
<Check @bind-Checked="@_unknownColors" @TValue="bool">@L["Unknown (effective colors)"]</Check>
}
@if(!_editing ||
!_unknownColors)
{
<Validation Validator="@ValidateLongBiggerThanZero">
<NumericEdit @bind-Value="@_model.EffectiveColors" Decimals="0" Disabled="!_editing" @TValue="long?">
<Feedback>
<ValidationError>@L["Please enter a number of effective colors."]</ValidationError>
</Feedback>
</NumericEdit>
</Validation>
}
</Field>
}
@if(_editing || _model.Type != null)
{
<Field>
<FieldLabel>@L["Type"]</FieldLabel>
@if(_editing)
{
<Check @bind-Checked="@_unknownType" @TValue="bool">@L["Unknown (type)"]</Check>
}
@if(!_editing ||
!_unknownType)
{
<Validation Validator="@ValidateType">
<TextEdit @bind-Text="@_model.Type" ReadOnly="!_editing">
<Feedback>
<ValidationError>@L["Please enter a valid screen type."]</ValidationError>
</Feedback>
</TextEdit>
</Validation>
}
</Field>
}
<Field>
<FieldLabel>@L["Native resolution"]</FieldLabel>
<Select @bind-SelectedValue="@_model.NativeResolutionId" Disabled="!_editing" @TValue="int">
@foreach(var resolution in _resolutions)
{
<SelectItem @TValue="int" Value="@resolution.Id">@resolution.ToString()</SelectItem>
}
</Select>
</Field>
</div>
<div>
@if(!_editing)
{
<Button Clicked="@OnEditClicked" Color="Color.Primary">@L["Edit"]</Button>
}
else
{
<Button Clicked="@OnSaveClicked" Color="Color.Success">@L["Save"]</Button>
<Button Clicked="@OnCancelClicked" Color="Color.Danger">@L["Cancel"]</Button>
}
<a class="btn btn-secondary" href="/admin/screens">@L["Back to list"]</a>
</div>
@if(!_editing)
{
<hr />
<h3>@L["Resolutions supported by this screen"]</h3>
<Button Clicked="OnAddResolutionClick" Color="Color.Success" Disabled="_addingResolution">@L["Add new (resolution by screen)"]</Button>
@if(_addingResolution)
{
<div>
<Field>
<FieldLabel>@L["Resolutions"]</FieldLabel>
<Select @bind-SelectedValue="@_addingResolutionId" Disabled="_savingResolution" @TValue="int?">
@foreach(var resolution in _resolutions)
{
@if(resolution.Id != _model.NativeResolutionId &&
_screenResolutions.All(r => r.ResolutionId != resolution.Id))
{
<SelectItem @TValue="int?" Value="@resolution.Id">@resolution</SelectItem>
}
}
</Select>
<Button Clicked="@CancelAddResolution" Color="Color.Primary" Disabled="@_savingResolution">@L["Cancel"]</Button>
<Button Clicked="@ConfirmAddResolution" Color="Color.Success" Disabled="@_savingResolution">@L["Add"]</Button>
</Field>
</div>
}
@if(_screenResolutions?.Count > 0)
{
<div>
<table class="table table-striped">
<thead>
<tr>
<th>
@L["Width"]
</th>
<th>
@L["Height"]
</th>
<th>
@L["Colors"]
</th>
<th>
@L["Palette"]
</th>
<th>
@L["Chars"]
</th>
<th>
@L["Grayscale"]
</th>
<th></th>
</tr>
</thead>
<tbody>
@foreach(var item in _screenResolutions)
{
<tr>
<td>
@item.Resolution.Width
</td>
<td>
@item.Resolution.Height
</td>
<td>
@item.Resolution.Colors
</td>
<td>
@item.Resolution.Palette
</td>
<td>
@item.Resolution.Chars
</td>
<td>
@item.Resolution.Grayscale
</td>
<td>
<Button Clicked="() => {ShowResolutionDeleteModal(item.Id);}" Color="Color.Danger" Disabled="@_addingResolution">@L["Delete"]</Button>
</td>
</tr>
}
</tbody>
</table>
</div>
}
<Modal Closing="@ModalClosing" IsCentered="true" ref="_frmDelete">
<ModalBackdrop />
<ModalContent Centered="true">
<ModalHeader>
<ModalTitle>@_deleteTitle</ModalTitle>
<CloseButton Clicked="@HideModal" />
</ModalHeader>
<ModalBody>
<Text>@_deleteText</Text>
</ModalBody>
<ModalFooter>
<Button Clicked="@HideModal" Color="Color.Primary" Disabled="@_deleteInProgress">@L["Cancel"]</Button>
<Button Clicked="@ConfirmDelete" Color="Color.Danger" Disabled="@_deleteInProgress">@L["Delete"]</Button>
</ModalFooter>
</ModalContent>
</Modal>}