Add machine family details in admin view.

This commit is contained in:
2020-05-26 01:48:05 +01:00
parent 96c7bc983e
commit 4b3d469065
6 changed files with 79 additions and 28 deletions

View File

@@ -2,7 +2,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web"> <Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup> <PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework> <TargetFramework>netcoreapp3.1</TargetFramework>
<Version>3.0.99.1182</Version> <Version>3.0.99.1185</Version>
<Company>Canary Islands Computer Museum</Company> <Company>Canary Islands Computer Museum</Company>
<Copyright>Copyright © 2003-2020 Natalia Portillo</Copyright> <Copyright>Copyright © 2003-2020 Natalia Portillo</Copyright>
<Product>Canary Islands Computer Museum Website</Product> <Product>Canary Islands Computer Museum Website</Product>
@@ -103,6 +103,9 @@
<Content Update="Pages\Admin\Details\License.razor"> <Content Update="Pages\Admin\Details\License.razor">
<ExcludeFromSingleFile>true</ExcludeFromSingleFile> <ExcludeFromSingleFile>true</ExcludeFromSingleFile>
</Content> </Content>
<Content Update="Pages\Admin\Details\MachineFamily.razor">
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
</Content>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<_ContentIncludedByDefault Remove="Areas\Admin\Views\BrowserTests\Delete.cshtml" /> <_ContentIncludedByDefault Remove="Areas\Admin\Views\BrowserTests\Delete.cshtml" />

View File

@@ -1,4 +1,4 @@
@{ @{
/****************************************************************************** /******************************************************************************
// MARECHAI: Master repository of computing history artifacts information // MARECHAI: Master repository of computing history artifacts information
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -29,31 +29,38 @@
// Copyright © 2003-2020 Natalia Portillo // Copyright © 2003-2020 Natalia Portillo
*******************************************************************************/ *******************************************************************************/
} }
@model Marechai.Database.Models.MachineFamily
@{ @page "/admin/machine_families/details/{Id:int}"
ViewData["Title"] = "Details"; @inherits OwningComponentBase<MachineFamiliesService>
} @inject IStringLocalizer<MachineFamiliesService> L
<h2>Details</h2> @inject CompaniesService CompaniesService
<div> @attribute [Authorize(Roles = "UberAdmin, Admin")]
<h4>Machine family</h4> <h3>@L["Machine family details"]</h3>
<hr /> <hr />
<dl class="dl-horizontal">
<dt> @if (!_loaded)
@Html.DisplayNameFor(model => model.Company) {
</dt> <p align="center">@L["Loading..."]</p>
<dd>
@Html.DisplayFor(model => model.Company.Name) return;
</dd> }
<dt>
@Html.DisplayNameFor(model => model.Name) <div>
</dt> <Field>
<dd> <FieldLabel>@L["Company"]</FieldLabel>
@Html.DisplayFor(model => model.Name) <Select Disabled="!_editable" TValue="int" @bind-SelectedValue="@_model.CompanyId">
</dd> @foreach (var company in _companies)
</dl> {
<SelectItem TValue="int" Value="@company.Id">@company.Name</SelectItem>
}
</Select>
</Field>
<Field>
<FieldLabel>@L["Name"]</FieldLabel>
<TextEdit ReadOnly="!_editable" @bind-Text="@_model.Name"/>
</Field>
</div> </div>
<div> <div>
<a asp-action="Edit" asp-route-id="@Model.Id" class="btn btn-primary">Edit</a> <span class="btn btn-primary">@L["Edit"]</span>
<a asp-action="Index" class="btn btn-secondary">Back to List</a> <a href="/admin/machine_families" class="btn btn-secondary">@L["Back to list"]</a>
</div> </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 MachineFamily
{
List<CompanyViewModel> _companies;
bool _editable;
bool _loaded;
Database.Models.MachineFamily _model;
[Parameter]
public int Id { get; set; }
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if(_loaded)
return;
_loaded = true;
if(Id <= 0)
return;
_companies = await CompaniesService.GetAsync();
_model = await Service.GetAsync(Id);
StateHasChanged();
}
}
}

View File

@@ -69,9 +69,7 @@
@item.Name @item.Name
</td> </td>
<td> <td>
<span class="btn btn-primary"> <a class="btn btn-primary" href="/admin/machine_families/details/@item.Id">@L["Details"]</a>
@L["Details"]
</span>
<span class="btn btn-secondary"> <span class="btn btn-secondary">
@L["Edit"] @L["Edit"]
</span> </span>

View File

@@ -162,4 +162,12 @@
<value>Cancelar</value> <value>Cancelar</value>
<comment>Cancel</comment> <comment>Cancel</comment>
</data> </data>
<data name="Machine family details" xml:space="preserve">
<value>Detalles de familia de máquinas</value>
<comment>Machine family details</comment>
</data>
<data name="Back to list" xml:space="preserve">
<value>Volver a la lista</value>
<comment>Back to list</comment>
</data>
</root> </root>

View File

@@ -20,6 +20,8 @@ namespace Marechai.Services
Id = m.Id, Company = m.Company.Name, Name = m.Name Id = m.Id, Company = m.Company.Name, Name = m.Name
}).ToListAsync(); }).ToListAsync();
public async Task<MachineFamily> GetAsync(int id) => await _context.MachineFamilies.FindAsync(id);
public async Task DeleteAsync(int id) public async Task DeleteAsync(int id)
{ {
MachineFamily item = await _context.MachineFamilies.FindAsync(id); MachineFamily item = await _context.MachineFamilies.FindAsync(id);