Add screen details in admin view.

This commit is contained in:
2020-05-26 04:36:42 +01:00
parent 3d2f0b7183
commit a10fbda825
7 changed files with 151 additions and 55 deletions

View File

@@ -1,50 +0,0 @@
@model Marechai.Database.Models.Screen
@{
ViewData["Title"] = "Details";
}
<h1>Details</h1>
<div>
<h4>Screen</h4>
<hr />
<dl class="row">
<dt class="col-sm-2">
@Html.DisplayNameFor(model => model.Diagonal)
</dt>
<dd class="col-sm-10">
@Html.DisplayFor(model => model.Diagonal)
</dd>
<dt class="col-sm-2">
@Html.DisplayNameFor(model => model.Size)
</dt>
<dd class="col-sm-10">
@Html.DisplayFor(model => model.Size)
</dd>
<dt class="col-sm-2">
@Html.DisplayNameFor(model => model.NativeResolution)
</dt>
<dd class="col-sm-10">
@Model.NativeResolution.ToString()
</dd>
<dt class="col-sm-2">
@Html.DisplayNameFor(model => model.EffectiveColors)
</dt>
<dd class="col-sm-10">
@Html.DisplayFor(model => model.EffectiveColors)
</dd>
<dt class="col-sm-2">
@Html.DisplayNameFor(model => model.Type)
</dt>
<dd class="col-sm-10">
@Html.DisplayFor(model => model.Type)
</dd>
</dl>
</div>
<div>
<a asp-action="Edit" asp-route-id="@Model.Id" class="btn btn-primary">
Edit
</a>
<a asp-action="Index" class="btn btn-secondary">
Back to List
</a>
</div>

View File

@@ -2,7 +2,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<Version>3.0.99.1193</Version>
<Version>3.0.99.1195</Version>
<Company>Canary Islands Computer Museum</Company>
<Copyright>Copyright © 2003-2020 Natalia Portillo</Copyright>
<Product>Canary Islands Computer Museum Website</Product>

View File

@@ -0,0 +1,94 @@
@{
/******************************************************************************
// MARECHAI: Master repository of computing history artifacts information
// ----------------------------------------------------------------------------
//
// Filename : Details.cshtml
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// --[ Description ] ----------------------------------------------------------
//
// Admin view details
//
// --[ 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}"
@inherits OwningComponentBase<ScreensService>
@inject IStringLocalizer<ScreensService> L
@inject ResolutionsService ResolutionsService
@attribute [Authorize(Roles = "UberAdmin, Admin")]
<h3>@L["Screen details"]</h3>
<hr />
@if (!_loaded)
{
<p align="center">@L["Loading..."]</p>
return;
}
<div>
@if (_editable || _model.Width.HasValue)
{
<Field>
<FieldLabel>@L["Width (mm)"]</FieldLabel>
<NumericEdit Disabled="!_editable" TValue="double?" Decimals="2" @bind-Value="@_model.Width"/>
</Field>
}
@if (_editable || _model.Height.HasValue)
{
<Field>
<FieldLabel>@L["Height (mm)"]</FieldLabel>
<NumericEdit Disabled="!_editable" TValue="double?" Decimals="0" @bind-Value="@_model.Height"/>
</Field>
}
<Field>
<FieldLabel>@L["Diagonal (inches)"]</FieldLabel>
<NumericEdit Disabled="!_editable" TValue="double" Decimals="2" @bind-Value="@_model.Diagonal"/>
</Field>
@if (_editable || _model.EffectiveColors.HasValue)
{
<Field>
<FieldLabel>@L["Effective colors"]</FieldLabel>
<NumericEdit Disabled="!_editable" TValue="long?" Decimals="0" @bind-Value="@_model.EffectiveColors"/>
</Field>
}
@if (_editable || _model.Type != null)
{
<Field>
<FieldLabel>@L["Type"]</FieldLabel>
<TextEdit ReadOnly="!_editable" @bind-Text="@_model.Type" />
</Field>
}
<Field>
<FieldLabel>@L["Native resolution"]</FieldLabel>
<Select Disabled="!_editable" TValue="int" @bind-SelectedValue="@_model.NativeResolutionId">
@foreach (var resolution in _resolutions)
{
<SelectItem TValue="int" Value="@resolution.Id">@resolution.ToString()</SelectItem>
}
</Select>
</Field>
</div>
<div>
<span class="btn btn-primary">@L["Edit"]</span>
<a href="/admin/screens" class="btn btn-secondary">@L["Back to list"]</a>
</div>

View File

@@ -0,0 +1,33 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Marechai.ViewModels;
using Microsoft.AspNetCore.Components;
namespace Marechai.Pages.Admin.Details
{
public partial class Screen
{
bool _editable;
bool _loaded;
Database.Models.Screen _model;
List<ResolutionViewModel> _resolutions;
[Parameter]
public int Id { get; set; }
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if(_loaded)
return;
_loaded = true;
if(Id <= 0)
return;
_resolutions = await ResolutionsService.GetAsync();
_model = await Service.GetAsync(Id);
StateHasChanged();
}
}
}

View File

@@ -31,7 +31,6 @@
}
@page "/admin/screens"
@using Marechai.Database.Models
@inherits OwningComponentBase<ScreensService>
@inject IStringLocalizer<ScreensService> L
@attribute [Authorize(Roles = "UberAdmin, Admin")]
@@ -82,9 +81,7 @@
@item.Type
</td>
<td>
<span class="btn btn-primary">
@L["Details"]
</span>
<a class="btn btn-primary" href="/admin/screens/details/@item.Id">@L["Details"]</a>
<span class="btn btn-secondary">
@L["Edit"]
</span>

View File

@@ -174,4 +174,24 @@
<value>Cancelar</value>
<comment>Cancel</comment>
</data>
<data name="Screen details" xml:space="preserve">
<value>Detalles de pantalla</value>
<comment>Screen details</comment>
</data>
<data name="Back to list" xml:space="preserve">
<value>Volver a la lista</value>
<comment>Back to list</comment>
</data>
<data name="Width (mm)" xml:space="preserve">
<value>Ancho (mm)</value>
<comment>Width (mm)</comment>
</data>
<data name="Height (mm)" xml:space="preserve">
<value>Alto (mm)</value>
<comment>Height (mm)</comment>
</data>
<data name="Diagonal (inches)" xml:space="preserve">
<value>Diagonal (pulgadas)</value>
<comment>Diagonal (inches)</comment>
</data>
</root>

View File

@@ -15,6 +15,8 @@ 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 DeleteAsync(int id)
{
Screen item = await _context.Screens.FindAsync(id);