diff --git a/Marechai/Controllers/MachineController.cs b/Marechai/Controllers/MachineController.cs deleted file mode 100644 index 2f2b923e..00000000 --- a/Marechai/Controllers/MachineController.cs +++ /dev/null @@ -1,56 +0,0 @@ -/****************************************************************************** -// MARECHAI: Master repository of computing history artifacts information -// ---------------------------------------------------------------------------- -// -// Filename : ConsoleController.cs -// Author(s) : Natalia Portillo -// -// --[ Description ] ---------------------------------------------------------- -// -// Machine controller -// -// --[ 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 . -// -// ---------------------------------------------------------------------------- -// Copyright © 2003-2020 Natalia Portillo -*******************************************************************************/ - -using System.Linq; -using Marechai.Database.Models; -using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Mvc; - -namespace Marechai.Controllers -{ - public class MachineController : Controller - { - readonly MarechaiContext _context; - readonly IWebHostEnvironment hostingEnvironment; - - public MachineController(IWebHostEnvironment env, MarechaiContext context) - { - hostingEnvironment = env; - _context = context; - } - - public IActionResult View(int id) - { - ViewBag.WebRootPath = hostingEnvironment.WebRootPath; - - return View(_context.Machines.FirstOrDefault(m => m.Id == id)); - } - } -} \ No newline at end of file diff --git a/Marechai/Marechai.csproj b/Marechai/Marechai.csproj index a7cce348..2a3121ce 100644 --- a/Marechai/Marechai.csproj +++ b/Marechai/Marechai.csproj @@ -2,7 +2,7 @@ netcoreapp3.1 - 3.0.99.966 + 3.0.99.969 Canary Islands Computer Museum Copyright © 2003-2020 Natalia Portillo Canary Islands Computer Museum Website diff --git a/Marechai/Pages/Companies/View.razor b/Marechai/Pages/Companies/View.razor index d16dd418..4df819db 100644 --- a/Marechai/Pages/Companies/View.razor +++ b/Marechai/Pages/Companies/View.razor @@ -320,7 +320,7 @@
@foreach (var computer in _computers) { - + @computer.Name
} @@ -350,7 +350,7 @@
@foreach (var console in _consoles) { - + @console.Name
} diff --git a/Marechai/Views/Machine/View.cshtml b/Marechai/Pages/Machines/View.razor similarity index 92% rename from Marechai/Views/Machine/View.cshtml rename to Marechai/Pages/Machines/View.razor index feaa63a5..834d9d7b 100644 --- a/Marechai/Views/Machine/View.cshtml +++ b/Marechai/Pages/Machines/View.razor @@ -1,5 +1,5 @@ -@{ - /****************************************************************************** +@{ +/****************************************************************************** // MARECHAI: Master repository of computing history artifacts information // ---------------------------------------------------------------------------- // @@ -28,43 +28,62 @@ // ---------------------------------------------------------------------------- // Copyright © 2003-2020 Natalia Portillo *******************************************************************************/ - // TODO: Resolutions - ViewData["Title"] = "Computer"; +// TODO: Resolutions } -@using System.IO + +@page "/machine/{Id:int}" +@using Marechai.Database.Models @using Marechai.Database -@model Marechai.Database.Models.Machine + +@inherits OwningComponentBase +@inject IStringLocalizer L +@inject IWebHostEnvironment Host + +@if (!_loaded) +{ +

@L["Loading..."]

+ + return; +} + +@if (_machine is null) +{ +

@L["Machine not found in database"]

+ + return; +} +

- @if (Model.Company.LastLogo != null && - File.Exists(System.IO.Path.Combine(ViewBag.WebRootPath, "assets/logos", Model.Company.LastLogo.Guid + ".svg"))) + @if (_machine.Company.LastLogo != null && + File.Exists(Path.Combine(Host.WebRootPath, "assets/logos", _machine.Company.LastLogo.Guid + ".svg"))) { - - - + + + }

@{ var counter = 0; } -@if (Model.Introduced.HasValue && - Model.Introduced.Value.Year == 1000) +@if (_machine.Introduced.HasValue && + _machine.Introduced.Value.Year == 1000) {
PROTOTYPE
} - - @Model.Company.Name @Model.Name + + @_machine.Company.Name @_machine.Name -@if (Model.Introduced.HasValue && - Model.Introduced.Value.Year != 1000) +@if (_machine.Introduced.HasValue && + _machine.Introduced.Value.Year != 1000) { } -@if (Model.Family != null) +@if (_machine.Family != null) { } -@if (Model.Model != null) +@if (_machine.Model != null) { } -@if (Model.Processors.Count > 0) +@if (_machine.Processors.Count > 0) {
@@ -73,12 +92,12 @@ - - @Model.Introduced.Value.ToLongDateString() + + @_machine.Introduced.Value.ToLongDateString()
@@ -87,12 +106,12 @@ - - @Model.Family.Name + + @_machine.Family.Name
@@ -101,11 +120,11 @@ - @Model.Model + @_machine.Model
@@ -116,7 +135,7 @@ @{ counter = 0; } - @foreach (var processorByMachine in Model.Processors) + @foreach (var processorByMachine in _machine.Processors) { } -@if (Model.Memory != null && - Model.Memory.Count > 0) +@if (_machine.Memory != null && + _machine.Memory.Count > 0) {
@@ -233,7 +252,7 @@ {
- SMT + SMT @processorByMachine.Processor.ThreadsPerCore threads @@ -374,8 +393,8 @@
@@ -385,7 +404,7 @@ - @foreach (var memory in Model.Memory) + @foreach (var memory in _machine.Memory) { string memValue; if (memory.Size > 1073741824) @@ -439,7 +458,7 @@ } -@if (Model.Gpus.Count > 0) +@if (_machine.Gpus.Count > 0) {
@@ -450,7 +469,7 @@ @{ counter = 0; } - @foreach (var gpuByMachine in Model.Gpus) + @foreach (var gpuByMachine in _machine.Gpus) { if (gpuByMachine.Gpu.Id == -2) { @@ -555,7 +574,7 @@ } -@if (Model.Sound.Count > 0) +@if (_machine.Sound.Count > 0) {
@@ -566,7 +585,7 @@ @{ counter = 0; } - @foreach (var soundByMachine in Model.Sound) + @foreach (var soundByMachine in _machine.Sound) { @if (soundByMachine.SoundSynth.Id == -2) @@ -700,7 +719,7 @@ } -@if (Model.Storage.Count > 0) +@if (_machine.Storage.Count > 0) {
@@ -710,7 +729,7 @@ - @foreach (var storage in Model.Storage) + @foreach (var storage in _machine.Storage) { string capString = null; @@ -782,7 +801,23 @@ }
-@if (File.Exists(System.IO.Path.Combine(ViewBag.WebRootPath, "assets/photos/computers", Model.Id + ".jpg"))) +@if (File.Exists(Path.Combine(Host.WebRootPath, "assets/photos/computers", _machine.Id + ".jpg"))) { - + +} + +@code +{ + [Parameter] + public int Id { get; set; } + + Machine _machine; + bool _loaded; + + protected override async Task OnInitializedAsync() + { + _machine = await Service.GetMachine(Id); + + _loaded = true; + } } \ No newline at end of file diff --git a/Marechai/Services/MachinesService.cs b/Marechai/Services/MachinesService.cs new file mode 100644 index 00000000..d4640250 --- /dev/null +++ b/Marechai/Services/MachinesService.cs @@ -0,0 +1,20 @@ +using System.Threading.Tasks; +using Marechai.Database.Models; +using Microsoft.Extensions.Localization; + +namespace Marechai.Services +{ + public class MachinesService + { + readonly MarechaiContext _context; + readonly IStringLocalizer _l; + + public MachinesService(MarechaiContext context, IStringLocalizer localizer) + { + _context = context; + _l = localizer; + } + + public async Task GetMachine(int id) => await _context.Machines.FindAsync(id); + } +} \ No newline at end of file diff --git a/Marechai/Services/NewsService.cs b/Marechai/Services/NewsService.cs index b565f267..5b7eaf63 100644 --- a/Marechai/Services/NewsService.cs +++ b/Marechai/Services/NewsService.cs @@ -62,49 +62,49 @@ namespace Marechai.Services switch(@new.Type) { case NewsType.NewComputerInDb: - news.Add(new NewsViewModel(@new.AddedId, _l["New computer in database"], @new.Date, "Machine", + news.Add(new NewsViewModel(@new.AddedId, _l["New computer in database"], @new.Date, "machine", $"{machine.Company.Name} {machine.Name}")); break; case NewsType.NewConsoleInDb: - news.Add(new NewsViewModel(@new.AddedId, _l["New console in database"], @new.Date, "Machine", + news.Add(new NewsViewModel(@new.AddedId, _l["New console in database"], @new.Date, "machine", $"{machine.Company.Name} {machine.Name}")); break; case NewsType.NewComputerInCollection: - news.Add(new NewsViewModel(@new.AddedId, _l["New computer in collection"], @new.Date, "Machine", + news.Add(new NewsViewModel(@new.AddedId, _l["New computer in collection"], @new.Date, "machine", $"{machine.Company.Name} {machine.Name}")); break; case NewsType.NewConsoleInCollection: - news.Add(new NewsViewModel(@new.AddedId, _l["New console in collection"], @new.Date, "Machine", + news.Add(new NewsViewModel(@new.AddedId, _l["New console in collection"], @new.Date, "machine", $"{machine.Company.Name} {machine.Name}")); break; case NewsType.UpdatedComputerInDb: news.Add(new NewsViewModel(@new.AddedId, _l["Updated computer in database"], @new.Date, - "Machine", $"{machine.Company.Name} {machine.Name}")); + "machine", $"{machine.Company.Name} {machine.Name}")); break; case NewsType.UpdatedConsoleInDb: news.Add(new NewsViewModel(@new.AddedId, _l["Updated console in database"], @new.Date, - "Machine", $"{machine.Company.Name} {machine.Name}")); + "machine", $"{machine.Company.Name} {machine.Name}")); break; case NewsType.UpdatedComputerInCollection: news.Add(new NewsViewModel(@new.AddedId, _l["Updated computer in collection"], @new.Date, - "Machine", $"{machine.Company.Name} {machine.Name}")); + "machine", $"{machine.Company.Name} {machine.Name}")); break; case NewsType.UpdatedConsoleInCollection: news.Add(new NewsViewModel(@new.AddedId, _l["Updated console in collection"], @new.Date, - "Machine", $"{machine.Company.Name} {machine.Name}")); + "machine", $"{machine.Company.Name} {machine.Name}")); break; diff --git a/Marechai/Services/Register.cs b/Marechai/Services/Register.cs index fed4aa62..666f9f43 100644 --- a/Marechai/Services/Register.cs +++ b/Marechai/Services/Register.cs @@ -45,6 +45,7 @@ namespace Marechai.Services services.AddScoped(); services.AddScoped(); services.AddScoped(); + services.AddScoped(); } } } \ No newline at end of file