Move all database logic in machine view out of the view into the controller.

This commit is contained in:
2020-05-22 04:43:44 +01:00
parent 113b9fbad8
commit b3414bde1d
9 changed files with 359 additions and 152 deletions

View File

@@ -3,12 +3,12 @@
// MARECHAI: Master repository of computing history artifacts information
// ----------------------------------------------------------------------------
//
// Filename : Index.cshtml
// Filename : View.razor
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// --[ Description ] ----------------------------------------------------------
//
// Index page (and news)
// Shows a machine information
//
// --[ License ] --------------------------------------------------------------
//
@@ -32,9 +32,8 @@
}
@page "/machine/{Id:int}"
@using Marechai.Database.Models
@using Marechai.Database
@using Marechai.Database
@inherits OwningComponentBase<MachinesService>
@inject IStringLocalizer<MachinesService> L
@inject IWebHostEnvironment Host
@@ -54,17 +53,17 @@
}
<p align="center">
@if (_machine.Company.LastLogo != null &&
File.Exists(Path.Combine(Host.WebRootPath, "assets/logos", _machine.Company.LastLogo.Guid + ".svg")))
@if (_machine.CompanyLogo != null &&
File.Exists(Path.Combine(Host.WebRootPath, "assets/logos", _machine.CompanyLogo + ".svg")))
{
<picture>
<source type="image/svg+xml" srcset="/assets/logos/@(_machine.Company.LastLogo.Guid).svg">
<source type="image/webp" srcset="/assets/logos/webp/1x/@(_machine.Company.LastLogo.Guid).webp,
/assets/logos/webp/2x/@(_machine.Company.LastLogo.Guid).webp 2x,
/assets/logos/webp/3x/@(_machine.Company.LastLogo.Guid).webp 3x">
<img srcset="/assets/logos/png/1x/@(_machine.Company.LastLogo.Guid).png,
/assets/logos/png/2x/@(_machine.Company.LastLogo.Guid).png 2x,
/assets/logos/png/3x/@(_machine.Company.LastLogo.Guid).png 3x" src="/assets/logos/png/1x/@(_machine.Company.LastLogo.Guid).png" alt="" height="auto" width="auto" style="max-height: 256px; max-width: 256px" />
<source type="image/svg+xml" srcset="/assets/logos/@(_machine.CompanyLogo).svg">
<source type="image/webp" srcset="/assets/logos/webp/1x/@(_machine.CompanyLogo).webp,
/assets/logos/webp/2x/@(_machine.CompanyLogo).webp 2x,
/assets/logos/webp/3x/@(_machine.CompanyLogo).webp 3x">
<img srcset="/assets/logos/png/1x/@(_machine.CompanyLogo).png,
/assets/logos/png/2x/@(_machine.CompanyLogo).png 2x,
/assets/logos/png/3x/@(_machine.CompanyLogo).png 3x" src="/assets/logos/png/1x/@(_machine.CompanyLogo).png" alt="" height="auto" width="auto" style="max-height: 256px; max-width: 256px" />
</picture>
}
</p>
@@ -78,8 +77,8 @@
</b>
}
<b>
<a asp-controller="Company" asp-action="View" asp-route-id="@_machine.Company.Id">
@_machine.Company.Name</a> @_machine.Name</b>
<a href="/company/@_machine.CompanyId">
@_machine.CompanyName</a> @_machine.Name</b>
<table width="100%">
@if (_machine.Introduced.HasValue &&
@@ -97,7 +96,7 @@
</td>
</tr>
}
@if (_machine.Family != null)
@if (_machine.FamilyId != null)
{
<tr>
<th scope=row width="37%">
@@ -106,8 +105,8 @@
</div>
</th>
<td width="63%">
<a asp-controller="Computer" asp-action="ByFamily" asp-route-id="@_machine.Family.Id">
@_machine.Family.Name</a>
<a href="/machines/family/@_machine.FamilyId">
@_machine.FamilyName</a>
</td>
</tr>
}
@@ -135,17 +134,17 @@
<td>
<table>
@{ counter = 0; }
@foreach (var processorByMachine in _machine.Processors)
@foreach (var processor in _machine.Processors)
{
<tr>
<td>
@if (processorByMachine.Speed > 0)
@if (processor.Speed > 0)
{
@(processorByMachine.Processor.GprSize > 0 ? $"{processorByMachine.Processor.Name} @ {processorByMachine.Speed}Mhz ({processorByMachine.Processor.GprSize} bits)" : $"{processorByMachine.Processor.Name} @ {processorByMachine.Speed}Mhz")
@(processor.GprSize > 0 ? $"{processor.Name} @ {processor.Speed}Mhz ({processor.GprSize} bits)" : $"{processor.Name} @ {processor.Speed}Mhz")
}
else
{
@($"{processorByMachine.Processor.Name}")
@($"{processor.Name}")
}
<a aria-controls="@($"cpuInfo{counter}")" aria-expanded="false" class="btn btn-link" data-toggle="collapse" href="@($"#cpuInfo{counter}")">
+info
@@ -153,87 +152,87 @@
<div class="collapse" id="@($"cpuInfo{counter}")">
<div class="card card-body">
<table>
@if (processorByMachine.Processor.ModelCode != null &&
processorByMachine.Processor.ModelCode != processorByMachine.Processor.Name)
@if (processor.ModelCode != null &&
processor.ModelCode != processor.Name)
{
<tr>
<td>Model</td>
<td>@processorByMachine.Processor.ModelCode</td>
<td>@processor.ModelCode</td>
</tr>
}
<tr>
<td>Manufacturer</td>
<td>
<a asp-controller=Company asp-action=View asp-route-id=@processorByMachine.Processor.Company.Id>
@processorByMachine.Processor.Company.Name</a>
<a href="/processors/company/@processor.CompanyId">
@processor.CompanyName</a>
</td>
</tr>
@if (processorByMachine.Processor.Introduced != DateTime.MinValue)
@if (processor.Introduced != null)
{
<tr>
<td>Introduction date</td>
<td>@($"{processorByMachine.Processor.Introduced:yyyy}")</td>
<td>@($"{processor.Introduced:yyyy}")</td>
</tr>
}
@if (processorByMachine.Processor.InstructionSet != null)
@if (processor.InstructionSet != null)
{
<tr>
<td>Instruction set</td>
<td>@processorByMachine.Processor.InstructionSet.Name</td>
<td>@processor.InstructionSet</td>
</tr>
}
@if (processorByMachine.Processor.Speed > 0)
@if (processor.Speed > 0)
{
<tr>
<td>Nominal speed</td>
<td>@processorByMachine.Processor.Speed MHz</td>
<td>@processor.Speed MHz</td>
</tr>
}
@if (processorByMachine.Processor.Gprs > 0 ||
processorByMachine.Processor.Fprs > 0 ||
processorByMachine.Processor.SimdRegisters > 0)
@if (processor.Gprs > 0 ||
processor.Fprs > 0 ||
processor.SimdRegisters > 0)
{
<tr>
<td>Registers</td>
<td>
<table>
@if (processorByMachine.Processor.Gprs > 0)
@if (processor.Gprs > 0)
{
<tr>
<td>
@processorByMachine.Processor.Gprs general purpose registers of @processorByMachine.Processor.GprSize bits
@if (processorByMachine.Processor.FprSize > 0 &&
processorByMachine.Processor.Fprs == 0)
@processor.Gprs general purpose registers of @processor.GprSize bits
@if (processor.FprSize > 0 &&
processor.Fprs == 0)
{
@($", that can be used as floating point registers of {processorByMachine.Processor.FprSize}")
@($", that can be used as floating point registers of {processor.FprSize}")
}
@if (processorByMachine.Processor.SimdSize > 0 &&
processorByMachine.Processor.SimdRegisters == 0)
@if (processor.SimdSize > 0 &&
processor.SimdRegisters == 0)
{
@($", that can be used as SIMD registers of {processorByMachine.Processor.FprSize}")
@($", that can be used as SIMD registers of {processor.FprSize}")
}
</td>
</tr>
}
@if (processorByMachine.Processor.Fprs > 0)
@if (processor.Fprs > 0)
{
<tr>
<td>
@processorByMachine.Processor.Fprs floating-point registers of @processorByMachine.Processor.FprSize bits
@if (processorByMachine.Processor.SimdSize > 0 &&
processorByMachine.Processor.SimdRegisters == 0)
@processor.Fprs floating-point registers of @processor.FprSize bits
@if (processor.SimdSize > 0 &&
processor.SimdRegisters == 0)
{
@($", that can be used as SIMD registers of {processorByMachine.Processor.FprSize}")
@($", that can be used as SIMD registers of {processor.FprSize}")
}
</td>
</tr>
}
@if (processorByMachine.Processor.SimdRegisters > 0)
@if (processor.SimdRegisters > 0)
{
<tr>
<td>
@processorByMachine.Processor.SimdRegisters
<abbr title="Single instruction, multiple data">SIMD</abbr>registers of @processorByMachine.Processor.SimdSize bits
@processor.SimdRegisters
<abbr title="Single instruction, multiple data">SIMD</abbr>registers of @processor.SimdSize bits
</td>
</tr>
}
@@ -241,48 +240,48 @@
</td>
</tr>
}
@if (processorByMachine.Processor.Cores > 1)
@if (processor.Cores > 1)
{
<tr>
<td>Multi-core</td>
<td>@processorByMachine.Processor.Cores cores</td>
<td>@processor.Cores cores</td>
</tr>
}
@if (processorByMachine.Processor.Cores > 1)
@if (processor.ThreadsPerCore > 1)
{
<tr>
<td>
<abbr title="Simultaneous multithreading">SMT</abbr>
</td>
<td>
@processorByMachine.Processor.ThreadsPerCore threads
@if (processorByMachine.Processor.Cores > 1)
@processor.ThreadsPerCore threads
@if (processor.Cores > 1)
{
@(" per core")
}
</td>
</tr>
}
@if (processorByMachine.Processor.DataBus > 0 ||
processorByMachine.Processor.AddrBus > 0)
@if (processor.DataBus > 0 ||
processor.AddrBus > 0)
{
<tr>
<td>Bus</td>
<td>
<table>
@if (processorByMachine.Processor.DataBus > 0)
@if (processor.DataBus > 0)
{
<tr>
<td>
@processorByMachine.Processor.DataBus-bit data
@processor.DataBus-bit data
</td>
</tr>
}
@if (processorByMachine.Processor.AddrBus > 0)
@if (processor.AddrBus > 0)
{
<tr>
<td>
@processorByMachine.Processor.AddrBus-bit address
@processor.AddrBus-bit address
</td>
</tr>
}
@@ -291,44 +290,44 @@
</tr>
}
@if (processorByMachine.Processor.L1Instruction > 0 ||
processorByMachine.Processor.L1Data > 0 ||
processorByMachine.Processor.L2 > 0 ||
processorByMachine.Processor.L2 > 0)
@if (processor.L1Instruction > 0 ||
processor.L1Data > 0 ||
processor.L2 > 0 ||
processor.L2 > 0)
{
<tr>
<td>Cache</td>
<td>
<table>
@if (processorByMachine.Processor.L1Instruction > 0)
@if (processor.L1Instruction > 0)
{
<tr>
<td>
@(processorByMachine.Processor.L1Data < 0 ? $"{processorByMachine.Processor.L1Instruction}KiB combined instruction-data L1" : $"{processorByMachine.Processor.L1Instruction}KiB instruction L1")
@(processor.L1Data < 0 ? $"{processor.L1Instruction}KiB combined instruction-data L1" : $"{processor.L1Instruction}KiB instruction L1")
</td>
</tr>
}
@if (processorByMachine.Processor.L1Data > 0)
@if (processor.L1Data > 0)
{
<tr>
<td>
@($"{processorByMachine.Processor.L1Data}KiB data L1")
@($"{processor.L1Data}KiB data L1")
</td>
</tr>
}
@if (processorByMachine.Processor.L2 > 0)
@if (processor.L2 > 0)
{
<tr>
<td>
@($"{processorByMachine.Processor.L2}KiB L2")
@($"{processor.L2}KiB L2")
</td>
</tr>
}
@if (processorByMachine.Processor.L3 > 0)
@if (processor.L3 > 0)
{
<tr>
<td>
@($"{processorByMachine.Processor.L3}KiB L3")
@($"{processor.L3}KiB L3")
</td>
</tr>
}
@@ -336,49 +335,49 @@
</td>
</tr>
}
@if (processorByMachine.Processor.Package != null)
@if (processor.Package != null)
{
<tr>
<td>Package</td>
<td>@processorByMachine.Processor.Package</td>
<td>@processor.Package</td>
</tr>
}
@if (processorByMachine.Processor.Process != null ||
processorByMachine.Processor.ProcessNm > 0)
@if (processor.Process != null ||
processor.ProcessNm > 0)
{
<tr>
<td>Manufacturing process</td>
<td>
@if (processorByMachine.Processor.Process != null &&
processorByMachine.Processor.ProcessNm > 0)
@if (processor.Process != null &&
processor.ProcessNm > 0)
{
@processorByMachine.Processor.Process
@processor.Process
@("@")
@(processorByMachine.Processor.ProcessNm > 100 ? $"{processorByMachine.Processor.ProcessNm / 100}µm" : $"{processorByMachine.Processor.ProcessNm}nm")
@(processor.ProcessNm > 100 ? $"{processor.ProcessNm / 100}µm" : $"{processor.ProcessNm}nm")
}
else if (processorByMachine.Processor.ProcessNm > 0)
else if (processor.ProcessNm > 0)
{
@(processorByMachine.Processor.ProcessNm > 100 ? $"{processorByMachine.Processor.ProcessNm / 100}µm" : $"{processorByMachine.Processor.ProcessNm}nm")
@(processor.ProcessNm > 100 ? $"{processor.ProcessNm / 100}µm" : $"{processor.ProcessNm}nm")
}
else
{
@processorByMachine.Processor.Process
@processor.Process
}
</td>
</tr>
}
@if (processorByMachine.Processor.DieSize > 0)
@if (processor.DieSize > 0)
{
<tr>
<td>Die size</td>
<td>@processorByMachine.Processor.DieSize mm&sup2;</td>
<td>@processor.DieSize mm&sup2;</td>
</tr>
}
@if (processorByMachine.Processor.Transistors > 0)
@if (processor.Transistors > 0)
{
<tr>
<td>Transistors</td>
<td>@processorByMachine.Processor.Transistors</td>
<td>@processor.Transistors</td>
</tr>
}
</table>
@@ -469,9 +468,9 @@
<td>
<table>
@{ counter = 0; }
@foreach (var gpuByMachine in _machine.Gpus)
@foreach (var gpu in _machine.Gpus)
{
if (gpuByMachine.Gpu.Id == -2)
if (gpu.Id == -2)
{
<td>
Framebuffer
@@ -489,78 +488,78 @@
else
{
<td>
@($"{gpuByMachine.Gpu.Name}")
@($"{gpu.Name}")
<a aria-controls="@($"gpuInfo{counter}")" aria-expanded="false" class="btn btn-link" data-toggle="collapse" href="@($"#gpuInfo{counter}")">
+info
</a>
<div class="collapse" id="@($"gpuInfo{counter}")">
<div class="card card-body">
<table>
@if (gpuByMachine.Gpu.ModelCode != null &&
gpuByMachine.Gpu.ModelCode != gpuByMachine.Gpu.Name)
@if (gpu.ModelCode != null &&
gpu.ModelCode != gpu.Name)
{
<tr>
<td>Model</td>
<td>@gpuByMachine.Gpu.ModelCode</td>
<td>@gpu.ModelCode</td>
</tr>
}
<tr>
<td>Manufacturer</td>
<td>
<a asp-controller=Company asp-action=View asp-route-id=@gpuByMachine.Gpu.Company.Id>
@gpuByMachine.Gpu.Company.Name</a>
<a href="/gpus/company/@gpu.CompanyId">
@gpu.Company</a>
</td>
</tr>
@if (gpuByMachine.Gpu.Introduced != DateTime.MinValue)
@if (gpu.Introduced != null)
{
<tr>
<td>Introduction date</td>
<td>@($"{gpuByMachine.Gpu.Introduced:yyyy}")</td>
<td>@($"{gpu.Introduced:yyyy}")</td>
</tr>
}
@if (gpuByMachine.Gpu.Package != null)
@if (gpu.Package != null)
{
<tr>
<td>Package</td>
<td>@gpuByMachine.Gpu.Package</td>
<td>@gpu.Package</td>
</tr>
}
@if (gpuByMachine.Gpu.Process != null ||
gpuByMachine.Gpu.ProcessNm > 0)
@if (gpu.Process != null ||
gpu.ProcessNm > 0)
{
<tr>
<td>Manufacturing process</td>
<td>
@if (gpuByMachine.Gpu.Process != null &&
gpuByMachine.Gpu.ProcessNm > 0)
@if (gpu.Process != null &&
gpu.ProcessNm > 0)
{
@gpuByMachine.Gpu.Process
@gpu.Process
@("@")
@(gpuByMachine.Gpu.ProcessNm > 100 ? $"{gpuByMachine.Gpu.ProcessNm / 100}µm" : $"{gpuByMachine.Gpu.ProcessNm}nm")
@(gpu.ProcessNm > 100 ? $"{gpu.ProcessNm / 100}µm" : $"{gpu.ProcessNm}nm")
}
else if (gpuByMachine.Gpu.ProcessNm > 0)
else if (gpu.ProcessNm > 0)
{
@(gpuByMachine.Gpu.ProcessNm > 100 ? $"{gpuByMachine.Gpu.ProcessNm / 100}µm" : $"{gpuByMachine.Gpu.ProcessNm}nm")
@(gpu.ProcessNm > 100 ? $"{gpu.ProcessNm / 100}µm" : $"{gpu.ProcessNm}nm")
}
else
{
@gpuByMachine.Gpu.Process
@gpu.Process
}
</td>
</tr>
}
@if (gpuByMachine.Gpu.DieSize > 0)
@if (gpu.DieSize > 0)
{
<tr>
<td>Die size</td>
<td>@gpuByMachine.Gpu.DieSize mm&sup2;</td>
<td>@gpu.DieSize mm&sup2;</td>
</tr>
}
@if (gpuByMachine.Gpu.Transistors > 0)
@if (gpu.Transistors > 0)
{
<tr>
<td>Transistors</td>
<td>@gpuByMachine.Gpu.Transistors</td>
<td>@gpu.Transistors</td>
</tr>
}
</table>
@@ -574,7 +573,7 @@
</td>
</tr>
}
@if (_machine.Sound.Count > 0)
@if (_machine.SoundSynthetizers.Count > 0)
{
<tr>
<th scope=row>
@@ -585,10 +584,10 @@
<td>
<table>
@{ counter = 0; }
@foreach (var soundByMachine in _machine.Sound)
@foreach (var sound in _machine.SoundSynthetizers)
{
<tr>
@if (soundByMachine.SoundSynth.Id == -2)
@if (sound.Id == -2)
{
<td>
Software
@@ -606,104 +605,104 @@
else
{
<td>
@($"{soundByMachine.SoundSynth.Name}")
@($"{sound.Name}")
<a aria-controls="@($"synthInfo{counter}")" aria-expanded="false" class="btn btn-link" data-toggle="collapse" href="@($"#synthInfo{counter}")">
+info
</a>
<div class="collapse" id="@($"synthInfo{counter}")">
<div class="card card-body">
<table>
@if (soundByMachine.SoundSynth.ModelCode != null &&
soundByMachine.SoundSynth.ModelCode != soundByMachine.SoundSynth.Name)
@if (sound.ModelCode != null &&
sound.ModelCode != sound.Name)
{
<tr>
<td>Model</td>
<td>@soundByMachine.SoundSynth.ModelCode</td>
<td>@sound.ModelCode</td>
</tr>
}
@if (soundByMachine.SoundSynth.Company != null)
@if (sound.CompanyId != null)
{
<tr>
<td>Manufacturer</td>
<td>
<a asp-controller=Company asp-action=View asp-route-id=@soundByMachine.SoundSynth.Company.Id>
@soundByMachine.SoundSynth.Company.Name</a>
<a href="/soundsynths/company/@sound.CompanyId">
@sound.CompanyName</a>
</td>
</tr>
}
@if (soundByMachine.SoundSynth.Introduced != DateTime.MinValue)
@if (sound.Introduced != null)
{
<tr>
<td>Introduction date</td>
<td>@($"{soundByMachine.SoundSynth.Introduced:yyyy}")</td>
<td>@($"{sound.Introduced:yyyy}")</td>
</tr>
}
@if (soundByMachine.SoundSynth.Voices != 0 ||
soundByMachine.SoundSynth.SquareWave != 0 ||
soundByMachine.SoundSynth.WhiteNoise != 0)
@if (sound.Voices != 0 ||
sound.SquareWave != 0 ||
sound.WhiteNoise != 0)
{
<tr>
<td>Generators</td>
<td>
<table>
@if (soundByMachine.SoundSynth.Voices != 0)
@if (sound.Voices != 0)
{
<tr>
<td>@soundByMachine.SoundSynth.Voices voices</td>
<td>@sound.Voices voices</td>
</tr>
}
@if (soundByMachine.SoundSynth.SquareWave != 0)
@if (sound.SquareWave != 0)
{
<tr>
<td>@soundByMachine.SoundSynth.SquareWave square wave</td>
<td>@sound.SquareWave square wave</td>
</tr>
}
@if (soundByMachine.SoundSynth.WhiteNoise != 0)
@if (sound.WhiteNoise != 0)
{
<tr>
<td>@soundByMachine.SoundSynth.WhiteNoise white noise</td>
<td>@sound.WhiteNoise white noise</td>
</tr>
}
</table>
</td>
</tr>
}
@if (soundByMachine.SoundSynth.Depth != 0 ||
soundByMachine.SoundSynth.Frequency > 0)
@if (sound.Depth != 0 ||
sound.Frequency > 0)
{
<tr>
<td>Sample rate</td>
<td>
<table>
@if (soundByMachine.SoundSynth.Depth != 0 &&
soundByMachine.SoundSynth.Frequency > 0)
@if (sound.Depth != 0 &&
sound.Frequency > 0)
{
<tr>
<td>@soundByMachine.SoundSynth.Depth bits at @(soundByMachine.SoundSynth.Frequency > 1000 ? $"{soundByMachine.SoundSynth.Frequency / 1000}KHz" : $"{soundByMachine.SoundSynth.Frequency}Hz")</td>
<td>@sound.Depth bits at @(sound.Frequency > 1000 ? $"{sound.Frequency / 1000}KHz" : $"{sound.Frequency}Hz")</td>
</tr>
}
else if (soundByMachine.SoundSynth.Depth != 0)
else if (sound.Depth != 0)
{
<tr>
<td>@soundByMachine.SoundSynth.Depth bits</td>
<td>@sound.Depth bits</td>
</tr>
}
else
{
<tr>
<td>@(soundByMachine.SoundSynth.Frequency > 1000 ? $"{soundByMachine.SoundSynth.Frequency / 1000}KHz" : $"{soundByMachine.SoundSynth.Frequency}Hz")</td>
<td>@(sound.Frequency > 1000 ? $"{sound.Frequency / 1000}KHz" : $"{sound.Frequency}Hz")</td>
</tr>
}
</table>
</td>
</tr>
}
@if (soundByMachine.SoundSynth.Type != 0)
@if (sound.Type != 0)
{
<tr>
<td>Synthetizer type</td>
<td>
@soundByMachine.SoundSynth.Type
@sound.Type
</td>
</tr>
}
@@ -811,7 +810,7 @@
[Parameter]
public int Id { get; set; }
Machine _machine;
MachineViewModel _machine;
bool _loaded;
protected override async Task OnInitializedAsync()