From 2e9fe9177713f6138547b3923ca4cb037ddd5a5b Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Fri, 22 May 2020 01:08:12 +0100 Subject: [PATCH] Move computers index to Blazor. --- Marechai/Controllers/ComputerController.cs | 15 - Marechai/Marechai.csproj | 2 +- Marechai/Pages/Computers/Index.razor | 261 ++++++++++++++++++ .../Services/ComputersService.es.resx | 157 +++++++++++ Marechai/Services/ComputersService.cs | 66 +++++ Marechai/Services/Register.cs | 1 + Marechai/Views/Computer/Index.cshtml | 236 ---------------- 7 files changed, 486 insertions(+), 252 deletions(-) create mode 100644 Marechai/Pages/Computers/Index.razor create mode 100644 Marechai/Resources/Services/ComputersService.es.resx create mode 100644 Marechai/Services/ComputersService.cs delete mode 100644 Marechai/Views/Computer/Index.cshtml diff --git a/Marechai/Controllers/ComputerController.cs b/Marechai/Controllers/ComputerController.cs index 5b021282..29a23638 100644 --- a/Marechai/Controllers/ComputerController.cs +++ b/Marechai/Controllers/ComputerController.cs @@ -47,21 +47,6 @@ namespace Marechai.Controllers _context = context; } - public IActionResult Index() - { - ViewBag.ItemCount = _context.Machines.Count(m => m.Type == MachineType.Computer); - - ViewBag.MinYear = _context. - Machines.Where(t => t.Type == MachineType.Computer && t.Introduced.HasValue && - t.Introduced.Value.Year > 1000).Min(t => t.Introduced.Value.Year); - - ViewBag.MaxYear = _context. - Machines.Where(t => t.Type == MachineType.Computer && t.Introduced.HasValue && - t.Introduced.Value.Year > 1000).Max(t => t.Introduced.Value.Year); - - return View(); - } - public IActionResult ByLetter(char id) { // ToUpper() diff --git a/Marechai/Marechai.csproj b/Marechai/Marechai.csproj index 0529e217..72912381 100644 --- a/Marechai/Marechai.csproj +++ b/Marechai/Marechai.csproj @@ -2,7 +2,7 @@ netcoreapp3.1 - 3.0.99.962 + 3.0.99.964 Canary Islands Computer Museum Copyright © 2003-2020 Natalia Portillo Canary Islands Computer Museum Website diff --git a/Marechai/Pages/Computers/Index.razor b/Marechai/Pages/Computers/Index.razor new file mode 100644 index 00000000..ef1e7927 --- /dev/null +++ b/Marechai/Pages/Computers/Index.razor @@ -0,0 +1,261 @@ +@{ +/****************************************************************************** +// MARECHAI: Master repository of computing history artifacts information +// ---------------------------------------------------------------------------- +// +// Filename : Index.razor +// Author(s) : Natalia Portillo +// +// --[ Description ] ---------------------------------------------------------- +// +// Computers index +// +// --[ 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 +*******************************************************************************/ +} + +@page "/computers" +@inherits OwningComponentBase +@inject IStringLocalizer L + +@if (!_loaded) +{ + @L["Loading..."] +} + +

+ @L["Here you can consult our database."] +
+ @L["In this database you can find technical information as well as computers history, catalogued by companies, alfabetically and by release date."] +
+ @string.Format(L["{0} computers actually catalogued in the database."], _computers) +

+

+
+
+ @L["Search by companies"] +
+ + Q + + + W + + + E + + + R + + + T + + + Y + + + U + + + I + + + O + + + P + +
+ + A + + + S + + + D + + + F + + + G + + + H + + + J + + + K + + + L + +
+ + Z + + + X + + + C + + + V + + + B + + + N + + + M + +
+ + @L["All companies"] + +

+

+ @L["Alphabetically search"] +
+ + Q + + + W + + + E + + + R + + + T + + + Y + + + U + + + I + + + O + + + P + +
+ + A + + + S + + + D + + + F + + + G + + + H + + + J + + + K + + + L + +
+ + Z + + + X + + + C + + + V + + + B + + + N + + + M + +
+ + @L["All computers"] + +

+

+ @L["Search by year"] +
+ @{ var counter = 0; } + @for (int i = _minYear; i <= _maxYear; i++) + { + { + counter++; + } + + @i + + if (counter % 8 == 0) + { +
+ } + } +

+ +@code +{ + bool _loaded; + int _computers; + int _minYear; + int _maxYear; + + protected override async Task OnInitializedAsync() + { + _computers = await Service.GetComputersCountAsync(); + _minYear = await Service.GetMinimumYearAsync(); + _maxYear = await Service.GetMaximumYearAsync(); + + _loaded = true; + } +} diff --git a/Marechai/Resources/Services/ComputersService.es.resx b/Marechai/Resources/Services/ComputersService.es.resx new file mode 100644 index 00000000..78eb6dd2 --- /dev/null +++ b/Marechai/Resources/Services/ComputersService.es.resx @@ -0,0 +1,157 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Cargando... + Message that appears while data is being loaded from database + + + Aquí puedes consultar nuestra base de datos. + Introduction to search + + + En esta base de datos puedes encontrar información técnica así como historia de los ordenadores, catalogados por compañía, alfabéticamente y por fecha de introducción. + Introduction to database + + + {0} ordenadores catalogados en la base de datos + computers in database, {0} number + + + Buscar por compañías + Search by companies + + + Todas las compañías + All companies + + + Búsqueda alfabética + Search alphabetically + + + Todos los ordenadores + All computers + + + Búsqueda por año + Search by year + + \ No newline at end of file diff --git a/Marechai/Services/ComputersService.cs b/Marechai/Services/ComputersService.cs new file mode 100644 index 00000000..4cb2b8e4 --- /dev/null +++ b/Marechai/Services/ComputersService.cs @@ -0,0 +1,66 @@ +/****************************************************************************** +// MARECHAI: Master repository of computing history artifacts information +// ---------------------------------------------------------------------------- +// +// Filename : ComputersService.cs +// Author(s) : Natalia Portillo +// +// --[ Description ] ---------------------------------------------------------- +// +// Computers service +// +// --[ 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 System.Threading.Tasks; +using Marechai.Database; +using Marechai.Database.Models; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Localization; + +namespace Marechai.Services +{ + public class ComputersService + { + readonly MarechaiContext _context; + readonly IStringLocalizer _l; + + public ComputersService(MarechaiContext context, IStringLocalizer localizer) + { + _context = context; + _l = localizer; + } + + public async Task GetComputersCountAsync() => + await _context.Machines.CountAsync(c => c.Type == MachineType.Computer); + + public Task GetMinimumYearAsync() => _context. + Machines.Where(t => t.Type == MachineType.Computer && + t.Introduced.HasValue && + t.Introduced.Value.Year > 1000). + MinAsync(t => t.Introduced.Value.Year); + + public Task GetMaximumYearAsync() => _context. + Machines.Where(t => t.Type == MachineType.Computer && + t.Introduced.HasValue && + t.Introduced.Value.Year > 1000). + MaxAsync(t => t.Introduced.Value.Year); + } +} \ No newline at end of file diff --git a/Marechai/Services/Register.cs b/Marechai/Services/Register.cs index 99fafc3a..c6c70fe6 100644 --- a/Marechai/Services/Register.cs +++ b/Marechai/Services/Register.cs @@ -43,6 +43,7 @@ namespace Marechai.Services // TODO: Use reflection services.AddScoped(); services.AddScoped(); + services.AddScoped(); } } } \ No newline at end of file diff --git a/Marechai/Views/Computer/Index.cshtml b/Marechai/Views/Computer/Index.cshtml deleted file mode 100644 index d32ad7ed..00000000 --- a/Marechai/Views/Computer/Index.cshtml +++ /dev/null @@ -1,236 +0,0 @@ -@{ - /****************************************************************************** -// MARECHAI: Master repository of computing history artifacts information -// ---------------------------------------------------------------------------- -// -// Filename : Contact.cshtml -// Author(s) : Natalia Portillo -// -// --[ Description ] ---------------------------------------------------------- -// -// Contact page -// -// --[ 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 -*******************************************************************************/ - - ViewData["Title"] = "Computers"; -} -

- Here you can consult our database. -
- In this database you can find technical information as well as computers history, catalogued by companies, alfabetically and by release date. -
- @ViewBag.ItemCount computers actually catalogued in the database. -

-

-
-
- Search by companies -
- - Q - - - W - - - E - - - R - - - T - - - Y - - - U - - - I - - - O - - - P - -
- - A - - - S - - - D - - - F - - - G - - - H - - - J - - - K - - - L - -
- - Z - - - X - - - C - - - V - - - B - - - N - - - M - -
- - All companies - -

-

- Alfabetically search -
- - Q - - - W - - - E - - - R - - - T - - - Y - - - U - - - I - - - O - - - P - -
- - A - - - S - - - D - - - F - - - G - - - H - - - J - - - K - - - L - -
- - Z - - - X - - - C - - - V - - - B - - - N - - - M - -
- - All computers - -

-

- Search by year -
- @{ var counter = 0; } - @for (int i = ViewBag.MinYear; i <= ViewBag.MaxYear; i++) - { - { - counter++; - } - - @i - - if (counter % 8 == 0) - { -
- } - } -

\ No newline at end of file