Move computers index to Blazor.

This commit is contained in:
2020-05-22 01:08:12 +01:00
parent 44ae0b38b2
commit 2e9fe91777
7 changed files with 486 additions and 252 deletions

View File

@@ -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()

View File

@@ -2,7 +2,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<Version>3.0.99.962</Version>
<Version>3.0.99.964</Version>
<Company>Canary Islands Computer Museum</Company>
<Copyright>Copyright © 2003-2020 Natalia Portillo</Copyright>
<Product>Canary Islands Computer Museum Website</Product>

View File

@@ -0,0 +1,261 @@
@{
/******************************************************************************
// MARECHAI: Master repository of computing history artifacts information
// ----------------------------------------------------------------------------
//
// Filename : Index.razor
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// --[ 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 <http://www.gnu.org/licenses/>.
//
// ----------------------------------------------------------------------------
// Copyright © 2003-2020 Natalia Portillo
*******************************************************************************/
}
@page "/computers"
@inherits OwningComponentBase<ComputersService>
@inject IStringLocalizer<ComputersService> L
@if (!_loaded)
{
@L["Loading..."]
}
<p>
@L["Here you can consult our database."]
<br />
@L["In this database you can find technical information as well as computers history, catalogued by companies, alfabetically and by release date."]
<br />
@string.Format(L["{0} computers actually catalogued in the database."], _computers)
</p>
<p>
<br>
<br>
@L["Search by companies"]
<br>
<a href="/companies/Q">
Q
</a>
<a href="/companies/W">
W
</a>
<a href="/companies/E">
E
</a>
<a href="/companies/R">
R
</a>
<a href="/companies/T">
T
</a>
<a href="/companies/Y">
Y
</a>
<a href="/companies/U">
U
</a>
<a href="/companies/I">
I
</a>
<a href="/companies/O">
O
</a>
<a href="/companies/P">
P
</a>
<br>
<a href="/companies/A">
A
</a>
<a href="/companies/S">
S
</a>
<a href="/companies/D">
D
</a>
<a href="/companies/F">
F
</a>
<a href="/companies/G">
G
</a>
<a href="/companies/H">
H
</a>
<a href="/companies/J">
J
</a>
<a href="/companies/K">
K
</a>
<a href="/companies/L">
L
</a>
<br>
<a href="/companies/Z">
Z
</a>
<a href="/companies/X">
X
</a>
<a href="/companies/C">
C
</a>
<a href="/companies/V">
V
</a>
<a href="/companies/B">
B
</a>
<a href="/companies/N">
N
</a>
<a href="/companies/M">
M
</a>
<br>
<a href="/companies">
@L["All companies"]
</a>
</p>
<p>
@L["Alphabetically search"]
<br>
<a href="/computers/Q">
Q
</a>
<a href="/computers/W">
W
</a>
<a href="/computers/E">
E
</a>
<a href="/computers/R">
R
</a>
<a href="/computers/T">
T
</a>
<a href="/computers/Y">
Y
</a>
<a href="/computers/U">
U
</a>
<a href="/computers/I">
I
</a>
<a href="/computers/O">
O
</a>
<a href="/computers/P">
P
</a>
<br>
<a href="/computers/A">
A
</a>
<a href="/computers/S">
S
</a>
<a href="/computers/D">
D
</a>
<a href="/computers/F">
F
</a>
<a href="/computers/G">
G
</a>
<a href="/computers/H">
H
</a>
<a href="/computers/J">
J
</a>
<a href="/computers/K">
K
</a>
<a href="/computers/L">
L
</a>
<br>
<a href="/computers/Z">
Z
</a>
<a href="/computers/X">
X
</a>
<a href="/computers/C">
C
</a>
<a href="/computers/V">
V
</a>
<a href="/computers/B">
B
</a>
<a href="/computers/N">
N
</a>
<a href="/computers/M">
M
</a>
<br>
<a href="/computers">
@L["All computers"]
</a>
</p>
<p>
@L["Search by year"]
<br>
@{ var counter = 0; }
@for (int i = _minYear; i <= _maxYear; i++)
{
{
counter++;
}
<a href="/computers/year/@i">
@i
</a>
if (counter % 8 == 0)
{
<br />
}
}
</p>
@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;
}
}

View File

@@ -0,0 +1,157 @@
<?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="Loading..." xml:space="preserve">
<value>Cargando...</value>
<comment>Message that appears while data is being loaded from database</comment>
</data>
<data name="Here you can consult our database." xml:space="preserve">
<value>Aquí puedes consultar nuestra base de datos.</value>
<comment>Introduction to search</comment>
</data>
<data name="In this database you can find technical information as well as computers history, catalogued by companies, alfabetically and by release date." xml:space="preserve">
<value>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.</value>
<comment>Introduction to database</comment>
</data>
<data name="{0} computers actually catalogued in the database." xml:space="preserve">
<value>{0} ordenadores catalogados en la base de datos</value>
<comment>computers in database, {0} number</comment>
</data>
<data name="Search by companies" xml:space="preserve">
<value>Buscar por compañías</value>
<comment>Search by companies</comment>
</data>
<data name="All companies" xml:space="preserve">
<value>Todas las compañías</value>
<comment>All companies</comment>
</data>
<data name="Alphabetically search" xml:space="preserve">
<value>Búsqueda alfabética</value>
<comment>Search alphabetically</comment>
</data>
<data name="All computers" xml:space="preserve">
<value>Todos los ordenadores</value>
<comment>All computers</comment>
</data>
<data name="Search by year" xml:space="preserve">
<value>Búsqueda por año</value>
<comment>Search by year</comment>
</data>
</root>

View File

@@ -0,0 +1,66 @@
/******************************************************************************
// MARECHAI: Master repository of computing history artifacts information
// ----------------------------------------------------------------------------
//
// Filename : ComputersService.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// --[ 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 <http://www.gnu.org/licenses/>.
//
// ----------------------------------------------------------------------------
// 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<ComputersService> _l;
public ComputersService(MarechaiContext context, IStringLocalizer<ComputersService> localizer)
{
_context = context;
_l = localizer;
}
public async Task<int> GetComputersCountAsync() =>
await _context.Machines.CountAsync(c => c.Type == MachineType.Computer);
public Task<int> 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<int> GetMaximumYearAsync() => _context.
Machines.Where(t => t.Type == MachineType.Computer &&
t.Introduced.HasValue &&
t.Introduced.Value.Year > 1000).
MaxAsync(t => t.Introduced.Value.Year);
}
}

View File

@@ -43,6 +43,7 @@ namespace Marechai.Services
// TODO: Use reflection
services.AddScoped<NewsService>();
services.AddScoped<CompaniesService>();
services.AddScoped<ComputersService>();
}
}
}

View File

@@ -1,236 +0,0 @@
@{
/******************************************************************************
// MARECHAI: Master repository of computing history artifacts information
// ----------------------------------------------------------------------------
//
// Filename : Contact.cshtml
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// --[ 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 <http://www.gnu.org/licenses/>.
//
// ----------------------------------------------------------------------------
// Copyright © 2003-2020 Natalia Portillo
*******************************************************************************/
ViewData["Title"] = "Computers";
}
<p>
Here you can consult our database.
<br />
In this database you can find technical information as well as computers history, catalogued by companies, alfabetically and by release date.
<br />
@ViewBag.ItemCount computers actually catalogued in the database.
</p>
<p>
<br>
<br>
Search by companies
<br>
<a asp-action="ByLetter" asp-controller="Company" asp-route-id="Q">
Q
</a>
<a asp-action="ByLetter" asp-controller="Company" asp-route-id="W">
W
</a>
<a asp-action="ByLetter" asp-controller="Company" asp-route-id="E">
E
</a>
<a asp-action="ByLetter" asp-controller="Company" asp-route-id="R">
R
</a>
<a asp-action="ByLetter" asp-controller="Company" asp-route-id="T">
T
</a>
<a asp-action="ByLetter" asp-controller="Company" asp-route-id="Y">
Y
</a>
<a asp-action="ByLetter" asp-controller="Company" asp-route-id="U">
U
</a>
<a asp-action="ByLetter" asp-controller="Company" asp-route-id="I">
I
</a>
<a asp-action="ByLetter" asp-controller="Company" asp-route-id="O">
O
</a>
<a asp-action="ByLetter" asp-controller="Company" asp-route-id="P">
P
</a>
<br>
<a asp-action="ByLetter" asp-controller="Company" asp-route-id="A">
A
</a>
<a asp-action="ByLetter" asp-controller="Company" asp-route-id="S">
S
</a>
<a asp-action="ByLetter" asp-controller="Company" asp-route-id="D">
D
</a>
<a asp-action="ByLetter" asp-controller="Company" asp-route-id="F">
F
</a>
<a asp-action="ByLetter" asp-controller="Company" asp-route-id="G">
G
</a>
<a asp-action="ByLetter" asp-controller="Company" asp-route-id="H">
H
</a>
<a asp-action="ByLetter" asp-controller="Company" asp-route-id="J">
J
</a>
<a asp-action="ByLetter" asp-controller="Company" asp-route-id="K">
K
</a>
<a asp-action="ByLetter" asp-controller="Company" asp-route-id="L">
L
</a>
<br>
<a asp-action="ByLetter" asp-controller="Company" asp-route-id="Z">
Z
</a>
<a asp-action="ByLetter" asp-controller="Company" asp-route-id="X">
X
</a>
<a asp-action="ByLetter" asp-controller="Company" asp-route-id="C">
C
</a>
<a asp-action="ByLetter" asp-controller="Company" asp-route-id="V">
V
</a>
<a asp-action="ByLetter" asp-controller="Company" asp-route-id="B">
B
</a>
<a asp-action="ByLetter" asp-controller="Company" asp-route-id="N">
N
</a>
<a asp-action="ByLetter" asp-controller="Company" asp-route-id="M">
M
</a>
<br>
<a asp-action="ByLetter" asp-controller="Company">
All companies
</a>
</p>
<p>
Alfabetically search
<br>
<a asp-action="ByLetter" asp-controller="Computer" asp-route-id="Q">
Q
</a>
<a asp-action="ByLetter" asp-controller="Computer" asp-route-id="W">
W
</a>
<a asp-action="ByLetter" asp-controller="Computer" asp-route-id="E">
E
</a>
<a asp-action="ByLetter" asp-controller="Computer" asp-route-id="R">
R
</a>
<a asp-action="ByLetter" asp-controller="Computer" asp-route-id="T">
T
</a>
<a asp-action="ByLetter" asp-controller="Computer" asp-route-id="Y">
Y
</a>
<a asp-action="ByLetter" asp-controller="Computer" asp-route-id="U">
U
</a>
<a asp-action="ByLetter" asp-controller="Computer" asp-route-id="I">
I
</a>
<a asp-action="ByLetter" asp-controller="Computer" asp-route-id="O">
O
</a>
<a asp-action="ByLetter" asp-controller="Computer" asp-route-id="P">
P
</a>
<br>
<a asp-action="ByLetter" asp-controller="Computer" asp-route-id="A">
A
</a>
<a asp-action="ByLetter" asp-controller="Computer" asp-route-id="S">
S
</a>
<a asp-action="ByLetter" asp-controller="Computer" asp-route-id="D">
D
</a>
<a asp-action="ByLetter" asp-controller="Computer" asp-route-id="F">
F
</a>
<a asp-action="ByLetter" asp-controller="Computer" asp-route-id="G">
G
</a>
<a asp-action="ByLetter" asp-controller="Computer" asp-route-id="H">
H
</a>
<a asp-action="ByLetter" asp-controller="Computer" asp-route-id="J">
J
</a>
<a asp-action="ByLetter" asp-controller="Computer" asp-route-id="K">
K
</a>
<a asp-action="ByLetter" asp-controller="Computer" asp-route-id="L">
L
</a>
<br>
<a asp-action="ByLetter" asp-controller="Computer" asp-route-id="Z">
Z
</a>
<a asp-action="ByLetter" asp-controller="Computer" asp-route-id="X">
X
</a>
<a asp-action="ByLetter" asp-controller="Computer" asp-route-id="C">
C
</a>
<a asp-action="ByLetter" asp-controller="Computer" asp-route-id="V">
V
</a>
<a asp-action="ByLetter" asp-controller="Computer" asp-route-id="B">
B
</a>
<a asp-action="ByLetter" asp-controller="Computer" asp-route-id="N">
N
</a>
<a asp-action="ByLetter" asp-controller="Computer" asp-route-id="M">
M
</a>
<br>
<a asp-action="ByLetter" asp-controller="Computer">
All computers
</a>
</p>
<p>
Search by year
<br>
@{ var counter = 0; }
@for (int i = ViewBag.MinYear; i <= ViewBag.MaxYear; i++)
{
{
counter++;
}
<a asp-action=ByYear asp-controller=Computer asp-route-id=@i>
@i
</a>
if (counter % 8 == 0)
{
<br />
}
}
</p>