Move machines admin index to Blazor.

This commit is contained in:
2020-05-24 15:28:47 +01:00
parent ecdc4210d2
commit 4aabb169f9
8 changed files with 162 additions and 4 deletions

View File

@@ -42,8 +42,6 @@
<br /> <br />
<a asp-controller="InstructionSetExtensionsByProcessor">Instruction set extensions by processor</a> <a asp-controller="InstructionSetExtensionsByProcessor">Instruction set extensions by processor</a>
<br /> <br />
<a asp-controller="Machines">Machines</a>
<br />
<a asp-controller="MachinePhotos">Machine photos</a> <a asp-controller="MachinePhotos">Machine photos</a>
<br /> <br />
<a asp-controller="MemoryByMachines">Memory by machines</a> <a asp-controller="MemoryByMachines">Memory by machines</a>

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.1059</Version> <Version>3.0.99.1060</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>
@@ -64,6 +64,9 @@
<Content Update="Pages\Admin\MachineFamilies.razor"> <Content Update="Pages\Admin\MachineFamilies.razor">
<ExcludeFromSingleFile>true</ExcludeFromSingleFile> <ExcludeFromSingleFile>true</ExcludeFromSingleFile>
</Content> </Content>
<Content Update="Pages\Admin\Machines.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

@@ -62,6 +62,9 @@
<li> <li>
<a href="/admin/machine_families">@L["Machine families"]</a> <a href="/admin/machine_families">@L["Machine families"]</a>
</li> </li>
<li>
<a href="/admin/machines">@L["Machines"]</a>
</li>
</ul> </ul>
</div> </div>
<div class="content"> <div class="content">

View File

@@ -0,0 +1,119 @@
@{
/******************************************************************************
// MARECHAI: Master repository of computing history artifacts information
// ----------------------------------------------------------------------------
//
// Filename : Machines.razor
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// --[ Description ] ----------------------------------------------------------
//
// List of machines
//
// --[ 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/machines"
@inherits OwningComponentBase<MachinesService>
@inject IStringLocalizer<MachinesService> L
@attribute [Authorize(Roles = "UberAdmin, Admin")]
<h3>@L["Machines"]</h3>
@if (_machines is null)
{
<p>@L["Loading..."]</p>
return;
}
<p>
<span class="btn btn-primary">
@L["Create new"]
</span>
</p>
<table class="table">
<thead>
<tr>
<th>
@L["Company"]
</th>
<th>
@L["Family"]
</th>
<th>
@L["Name"]
</th>
<th>
@L["Model"]
</th>
<th>
@L["Introduced"]
</th>
<th>
@L["Type"]
</th>
<th></th>
</tr>
</thead>
<tbody>
@foreach (var item in _machines)
{
<tr>
<td>
@item.Company
</td>
<td>
@item.Family
</td>
<td>
@item.Name
</td>
<td>
@item.Model
</td>
<td>
@item.IntroducedView
</td>
<td>
@item.Type
</td>
<td>
<span class="btn btn-primary">
@L["Details"]
</span>
<span class="btn btn-secondary">
@L["Edit"]
</span>
<span class="btn btn-danger">
@L["Delete"]
</span>
</td>
</tr>
}
</tbody>
</table>
@code
{
List<MachineViewModel> _machines;
protected override async Task OnInitializedAsync()
{
_machines = await Service.GetAsync();
}
}

View File

@@ -182,4 +182,8 @@
<value>Familias de máquinas</value> <value>Familias de máquinas</value>
<comment>Machine families.</comment> <comment>Machine families.</comment>
</data> </data>
<data name="Machines" xml:space="preserve">
<value>Máquinas</value>
<comment>Machines.</comment>
</data>
</root> </root>

View File

@@ -430,4 +430,20 @@
<value>{0} con una capacidad norminal de {1}</value> <value>{0} con una capacidad norminal de {1}</value>
<comment>{0} is storage type, {1} is nominal capacity number formatted with above bytes or bps prefixes</comment> <comment>{0} is storage type, {1} is nominal capacity number formatted with above bytes or bps prefixes</comment>
</data> </data>
<data name="Type" xml:space="preserve">
<value>Tipo</value>
<comment>Type</comment>
</data>
<data name="Introduced" xml:space="preserve">
<value>Introducida en</value>
<comment>Introduced</comment>
</data>
<data name="Name" xml:space="preserve">
<value>Nombre</value>
<comment>Name</comment>
</data>
<data name="Company" xml:space="preserve">
<value>Compañía</value>
<comment>Company</comment>
</data>
</root> </root>

View File

@@ -1,4 +1,5 @@
using System.Linq; using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Marechai.Database.Models; using Marechai.Database.Models;
using Marechai.ViewModels; using Marechai.ViewModels;
@@ -18,6 +19,14 @@ namespace Marechai.Services
_l = localizer; _l = localizer;
} }
public async Task<List<MachineViewModel>> GetAsync() =>
await _context.Machines.OrderBy(m => m.Company.Name).ThenBy(m => m.Name).ThenBy(m => m.Family.Name).
Select(m => new MachineViewModel
{
Id = m.Id, Company = m.Company.Name, Name = m.Name, Model = m.Model,
Introduced = m.Introduced, Type = m.Type, Family = m.Family.Name
}).ToListAsync();
public async Task<MachineViewModel> GetMachine(int id) public async Task<MachineViewModel> GetMachine(int id)
{ {
Machine machine = await _context.Machines.FindAsync(id); Machine machine = await _context.Machines.FindAsync(id);

View File

@@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using Marechai.Database;
namespace Marechai.ViewModels namespace Marechai.ViewModels
{ {
@@ -18,5 +19,10 @@ namespace Marechai.ViewModels
public List<ProcessorViewModel> Processors { get; set; } public List<ProcessorViewModel> Processors { get; set; }
public List<SoundSynthViewModel> SoundSynthesizers { get; set; } public List<SoundSynthViewModel> SoundSynthesizers { get; set; }
public List<StorageViewModel> Storage { get; set; } public List<StorageViewModel> Storage { get; set; }
public string Company { get; set; }
public MachineType Type { get; set; }
public string Family { get; set; }
public string IntroducedView =>
Introduced?.Year == 1000 ? "Prototype" : Introduced?.ToShortDateString() ?? "Unknown";
} }
} }