Move processors admin index to Blazor.

This commit is contained in:
2020-05-24 17:59:47 +01:00
parent 2d18733439
commit 38c0558764
9 changed files with 280 additions and 58 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.1062</Version> <Version>3.0.99.1063</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>
@@ -73,6 +73,9 @@
<Content Update="Pages\Admin\News.razor"> <Content Update="Pages\Admin\News.razor">
<ExcludeFromSingleFile>true</ExcludeFromSingleFile> <ExcludeFromSingleFile>true</ExcludeFromSingleFile>
</Content> </Content>
<Content Update="Pages\Admin\Processors.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

@@ -71,6 +71,9 @@
<li> <li>
<a href="/admin/news">@L["News"]</a> <a href="/admin/news">@L["News"]</a>
</li> </li>
<li>
<a href="/admin/processors">@L["Processors"]</a>
</li>
</ul> </ul>
</div> </div>
<div class="content"> <div class="content">

View File

@@ -1,14 +1,14 @@
@{ @{
/****************************************************************************** /******************************************************************************
// MARECHAI: Master repository of computing history artifacts information // MARECHAI: Master repository of computing history artifacts information
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// //
// Filename : Index.cshtml // Filename : Processors.razor
// Author(s) : Natalia Portillo <claunia@claunia.com> // Author(s) : Natalia Portillo <claunia@claunia.com>
// //
// --[ Description ] ---------------------------------------------------------- // --[ Description ] ----------------------------------------------------------
// //
// Admin view index // List of processors
// //
// --[ License ] -------------------------------------------------------------- // --[ License ] --------------------------------------------------------------
// //
@@ -29,69 +29,86 @@
// Copyright © 2003-2020 Natalia Portillo // Copyright © 2003-2020 Natalia Portillo
*******************************************************************************/ *******************************************************************************/
} }
@model IEnumerable<Marechai.Areas.Admin.Models.ProcessorViewModel>
@{ @page "/admin/processors"
ViewData["Title"] = "Processors (Admin)"; @using Marechai.Database.Models
@inherits OwningComponentBase<ProcessorsService>
@inject IStringLocalizer<ProcessorsService> L
@attribute [Authorize(Roles = "UberAdmin, Admin")]
<h3>@L["Processors"]</h3>
@if (_processors is null)
{
<p>@L["Loading..."]</p>
return;
} }
<h2>Processors</h2>
<p> <p>
<a asp-action="Create" class="btn btn-primary"> <span class="btn btn-primary">
Create new @L["Create new"]
</a> </span>
</p> </p>
<table class="table"> <table class="table">
<thead> <thead>
<tr> <tr>
<th> <th>
@Html.DisplayNameFor(model => model.Company) @L["Company"]
</th> </th>
<th> <th>
@Html.DisplayNameFor(model => model.Name) @L["Name"]
</th> </th>
<th> <th>
@Html.DisplayNameFor(model => model.ModelCode) @L["Model code"]
</th> </th>
<th> <th>
@Html.DisplayNameFor(model => model.Introduced) @L["Introduced"]
</th> </th>
<th> <th>
@Html.DisplayNameFor(model => model.InstructionSet) @L["Instruction set"]
</th> </th>
<th></th> <th></th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@foreach (var item in Model) @foreach (var item in _processors)
{ {
<tr> <tr>
<td> <td>
@Html.DisplayFor(modelItem => item.Company) @item.CompanyName
</td> </td>
<td> <td>
@Html.DisplayFor(modelItem => item.Name) @item.Name
</td> </td>
<td> <td>
@Html.DisplayFor(modelItem => item.ModelCode) @item.ModelCode
</td> </td>
<td> <td>
@Html.DisplayFor(modelItem => item.IntroducedView) @item.IntroducedView
</td> </td>
<td> <td>
@Html.DisplayFor(modelItem => item.InstructionSet) @item.InstructionSet
</td> </td>
<td> <td>
<a asp-action="Details" asp-route-id="@item.Id" class="btn btn-primary"> <span class="btn btn-primary">
Details @L["Details"]
</a> </span>
<a asp-action="Edit" asp-route-id="@item.Id" class="btn btn-secondary"> <span class="btn btn-secondary">
Edit @L["Edit"]
</a> </span>
<a asp-action="Delete" asp-route-id="@item.Id" class="btn btn-danger"> <span class="btn btn-danger">
Delete @L["Delete"]
</a> </span>
</td> </td>
</tr> </tr>
} }
</tbody> </tbody>
</table> </table>
@code
{
List<ProcessorViewModel> _processors;
protected override async Task OnInitializedAsync()
{
_processors = await Service.GetAsync();
}
}

View File

@@ -194,4 +194,8 @@
<value>Noticias</value> <value>Noticias</value>
<comment>News.</comment> <comment>News.</comment>
</data> </data>
<data name="Processors" xml:space="preserve">
<value>Procesadores</value>
<comment>Processors.</comment>
</data>
</root> </root>

View File

@@ -0,0 +1,165 @@
<?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="Processors" xml:space="preserve">
<value>Procesadores</value>
<comment>Processors</comment>
</data>
<data name="Loading..." xml:space="preserve">
<value>Cargando...</value>
<comment>Message that appears while data is being loaded from database</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>
<data name="Introduced" xml:space="preserve">
<value>Introducido el</value>
<comment>Introduced</comment>
</data>
<data name="Model code" xml:space="preserve">
<value>Modelo</value>
<comment>Model code</comment>
</data>
<data name="Instruction set" xml:space="preserve">
<value>Arquitectura</value>
<comment>Instruction set</comment>
</data>
<data name="Create new" xml:space="preserve">
<value>Crear nuevo</value>
<comment>Create new</comment>
</data>
<data name="Details" xml:space="preserve">
<value>Detalles</value>
<comment>Details</comment>
</data>
<data name="Edit" xml:space="preserve">
<value>Editar</value>
<comment>Edit</comment>
</data>
<data name="Delete" xml:space="preserve">
<value>Eliminar</value>
<comment>Delete</comment>
</data>
</root>

View File

@@ -12,11 +12,14 @@ namespace Marechai.Services
{ {
readonly MarechaiContext _context; readonly MarechaiContext _context;
readonly IStringLocalizer<MachinesService> _l; readonly IStringLocalizer<MachinesService> _l;
readonly ProcessorsService _processorsService;
public MachinesService(MarechaiContext context, IStringLocalizer<MachinesService> localizer) public MachinesService(MarechaiContext context, IStringLocalizer<MachinesService> localizer,
ProcessorsService processorsService)
{ {
_context = context; _context = context;
_l = localizer; _l = localizer;
_processorsService = processorsService;
} }
public async Task<List<MachineViewModel>> GetAsync() => public async Task<List<MachineViewModel>> GetAsync() =>
@@ -80,28 +83,7 @@ namespace Marechai.Services
Type = m.Type, Usage = m.Usage, Size = m.Size, Speed = m.Speed Type = m.Type, Usage = m.Usage, Size = m.Size, Speed = m.Speed
}).ToListAsync(); }).ToListAsync();
model.Processors = await _context.ProcessorsByMachine.Where(p => p.MachineId == machine.Id). model.Processors = await _processorsService.GetByMachineAsync(machine.Id);
Select(p => new ProcessorViewModel
{
Name = p.Processor.Name, CompanyName = p.Processor.Company.Name,
CompanyId = p.Processor.Company.Id, ModelCode = p.Processor.ModelCode,
Introduced = p.Processor.Introduced, Speed = p.Speed,
Package = p.Processor.Package, Gprs = p.Processor.Gprs,
GprSize = p.Processor.GprSize, Fprs = p.Processor.Fprs,
FprSize = p.Processor.FprSize, Cores = p.Processor.Cores,
ThreadsPerCore = p.Processor.ThreadsPerCore,
Process = p.Processor.Process, ProcessNm = p.Processor.ProcessNm,
DieSize = p.Processor.DieSize, Transistors = p.Processor.Transistors,
DataBus = p.Processor.DataBus, AddrBus = p.Processor.AddrBus,
SimdRegisters = p.Processor.SimdRegisters,
SimdSize = p.Processor.SimdSize,
L1Instruction = p.Processor.L1Instruction,
L1Data = p.Processor.L1Data, L2 = p.Processor.L2, L3 = p.Processor.L3,
InstructionSet = p.Processor.InstructionSet.Name,
InstructionSetExtensions =
p.Processor.InstructionSetExtensions.
Select(e => e.Extension.Extension).ToList()
}).ToListAsync();
model.SoundSynthesizers = model.SoundSynthesizers =
await _context.SoundByMachine.Where(s => s.MachineId == machine.Id).Select(s => s.SoundSynth). await _context.SoundByMachine.Where(s => s.MachineId == machine.Id).Select(s => s.SoundSynth).

View File

@@ -0,0 +1,45 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Marechai.Database.Models;
using Marechai.ViewModels;
using Microsoft.EntityFrameworkCore;
namespace Marechai.Services
{
public class ProcessorsService
{
readonly MarechaiContext _context;
public ProcessorsService(MarechaiContext context) => _context = context;
public async Task<List<ProcessorViewModel>> GetAsync() =>
await _context.Processors.Select(p => new ProcessorViewModel
{
Name = p.Name, CompanyName = p.Company.Name, CompanyId = p.Company.Id, ModelCode = p.ModelCode,
Introduced = p.Introduced, Speed = p.Speed, Package = p.Package, Gprs = p.Gprs,
GprSize = p.GprSize, Fprs = p.Fprs, FprSize = p.FprSize, Cores = p.Cores,
ThreadsPerCore = p.ThreadsPerCore, Process = p.Process, ProcessNm = p.ProcessNm, DieSize = p.DieSize,
Transistors = p.Transistors, DataBus = p.DataBus, AddrBus = p.AddrBus, SimdRegisters = p.SimdRegisters,
SimdSize = p.SimdSize, L1Instruction = p.L1Instruction, L1Data = p.L1Data, L2 = p.L2,
L3 = p.L3, InstructionSet = p.InstructionSet.Name,
InstructionSetExtensions = p.InstructionSetExtensions.Select(e => e.Extension.Extension).ToList()
}).ToListAsync();
public async Task<List<ProcessorViewModel>> GetByMachineAsync(int machineId) =>
await _context.ProcessorsByMachine.Where(p => p.MachineId == machineId).Select(p => new ProcessorViewModel
{
Name = p.Processor.Name, CompanyName = p.Processor.Company.Name, CompanyId = p.Processor.Company.Id,
ModelCode = p.Processor.ModelCode, Introduced = p.Processor.Introduced, Speed = p.Speed,
Package = p.Processor.Package, Gprs = p.Processor.Gprs, GprSize = p.Processor.GprSize,
Fprs = p.Processor.Fprs, FprSize = p.Processor.FprSize, Cores = p.Processor.Cores,
ThreadsPerCore = p.Processor.ThreadsPerCore, Process = p.Processor.Process,
ProcessNm = p.Processor.ProcessNm, DieSize = p.Processor.DieSize, Transistors = p.Processor.Transistors,
DataBus = p.Processor.DataBus, AddrBus = p.Processor.AddrBus, SimdRegisters = p.Processor.SimdRegisters,
SimdSize = p.Processor.SimdSize, L1Instruction = p.Processor.L1Instruction, L1Data = p.Processor.L1Data,
L2 = p.Processor.L2, L3 = p.Processor.L3, InstructionSet = p.Processor.InstructionSet.Name,
InstructionSetExtensions =
p.Processor.InstructionSetExtensions.Select(e => e.Extension.Extension).ToList()
}).ToListAsync();
}
}

View File

@@ -56,6 +56,7 @@ namespace Marechai.Services
services.AddScoped<LicensesService>(); services.AddScoped<LicensesService>();
services.AddScoped<MachineFamiliesService>(); services.AddScoped<MachineFamiliesService>();
services.AddScoped<PeopleService>(); services.AddScoped<PeopleService>();
services.AddScoped<ProcessorsService>();
} }
} }
} }

View File

@@ -32,5 +32,7 @@ namespace Marechai.ViewModels
public string InstructionSet { get; set; } public string InstructionSet { get; set; }
public List<string> InstructionSetExtensions { get; set; } public List<string> InstructionSetExtensions { get; set; }
public int? CompanyId { get; set; } public int? CompanyId { get; set; }
public string IntroducedView => Introduced?.ToShortDateString() ?? "Unknown";
} }
} }