Move companies index to Blazor.

This commit is contained in:
2020-05-21 20:25:47 +01:00
parent 0ff6b0b5c3
commit 307bb245ac
14 changed files with 252 additions and 72 deletions

View File

@@ -30,7 +30,7 @@
using System.Linq;
using Marechai.Database.Models;
using Marechai.Models;
using Marechai.ViewModels;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;

View File

@@ -2,7 +2,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<Version>3.0.99.937</Version>
<Version>3.0.99.944</Version>
<Company>Canary Islands Computer Museum</Company>
<Copyright>Copyright © 2003-2020 Natalia Portillo</Copyright>
<Product>Canary Islands Computer Museum Website</Product>
@@ -112,9 +112,6 @@
</Content>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="Resources\Services\NewsService.es.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>NewsService.es.Designer.cs</LastGenOutput>
</EmbeddedResource>
<EmbeddedResource Update="Resources\**\*.es.resx" />
</ItemGroup>
</Project>

View File

@@ -1,11 +0,0 @@
using System;
namespace Marechai.Models
{
public class CompanyViewModel
{
public int Id;
public Guid? LastLogo;
public string Name;
}
}

View File

@@ -1,39 +0,0 @@
/******************************************************************************
// MARECHAI: Master repository of computing history artifacts information
// ----------------------------------------------------------------------------
//
// Filename : ErrorViewModel.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// --[ Description ] ----------------------------------------------------------
//
// Error view model
//
// --[ 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
*******************************************************************************/
namespace Marechai.Models
{
public class ErrorViewModel
{
public string RequestId { get; set; }
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
}
}

View File

@@ -1,9 +1,9 @@
@{
/******************************************************************************
@{
/******************************************************************************
// MARECHAI: Master repository of computing history artifacts information
// ----------------------------------------------------------------------------
//
// Filename : Index.cshtml
// Filename : Index.razor
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// --[ Description ] ----------------------------------------------------------
@@ -28,22 +28,31 @@
// ----------------------------------------------------------------------------
// Copyright © 2003-2020 Natalia Portillo
*******************************************************************************/
ViewData["Title"] = "Companies";
}
@using System.IO
@model IEnumerable<CompanyViewModel>
@page "/companies"
@inherits OwningComponentBase<CompaniesService>
@inject IStringLocalizer<CompaniesService> L
@inject IWebHostEnvironment Host
@if (_companies is null)
{
<p align="center">@L["Loading..."]</p>
return;
}
<p align="center">
@if (Model.Any())
@if (_companies.Any())
{
<p>
@Model.Count() companies found in the database.
@string.Format(L["{0} companies found in the database."], _companies.Count())
<br />
@foreach (var company in Model)
@foreach (var company in _companies)
{
<a asp-controller="Company" asp-action="View" asp-route-id="@company.Id">
<a href="/companies/@company.Id">
@if (company.LastLogo != null &&
File.Exists(System.IO.Path.Combine(ViewBag.WebRootPath, "assets/logos", company.LastLogo + ".svg")))
File.Exists(Path.Combine(Host.WebRootPath, "assets/logos", company.LastLogo + ".svg")))
{
<picture>
<source type="image/svg+xml" srcset="/assets/logos/@(company.LastLogo).svg">
@@ -52,7 +61,7 @@
/assets/logos/thumbs/webp/3x/@(company.LastLogo).webp 3x">
<img srcset="/assets/logos/thumbs/png/1x/@(company.LastLogo).png,
/assets/logos/thumbs/png/2x/@(company.LastLogo).png 2x,
/assets/logos/thumbs/png/3x/@(company.LastLogo).png 3x" src="/assets/logos/thumbs/png/1x@(company.LastLogo).png" ) alt="" height="auto" width="auto" style="max-height: 32px; max-width: 128px" />
/assets/logos/thumbs/png/3x/@(company.LastLogo).png 3x" src="/assets/logos/thumbs/png/1x@(company.LastLogo).png" alt="" height="auto" width="auto" style="max-height: 32px; max-width: 128px" />
</picture>
}
@company.Name
@@ -65,4 +74,13 @@
{
<p>There are no companies in the database.</p>
}
</p>
</p>
@code
{
List<CompanyViewModel> _companies;
protected override async Task OnInitializedAsync()
{
_companies = await Service.GetCompaniesAsync();
}
}

View File

@@ -0,0 +1,129 @@
<?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="{0} companies found in the database." xml:space="preserve">
<value>{0} compañías en la base de datos.</value>
<comment>How many companies are in the database, {0} is a number</comment>
</data>
</root>

View File

@@ -146,4 +146,8 @@
<value>Contacto</value>
<comment>Contact</comment>
</data>
<data name="Companies" xml:space="preserve">
<value>Compañías</value>
<comment>Companies</comment>
</data>
</root>

View File

@@ -0,0 +1,63 @@
/******************************************************************************
// MARECHAI: Master repository of computing history artifacts information
// ----------------------------------------------------------------------------
//
// Filename : CompaniesService.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// --[ Description ] ----------------------------------------------------------
//
// Companies 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.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Marechai.Database.Models;
using Marechai.ViewModels;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Localization;
namespace Marechai.Services
{
public class CompaniesService
{
readonly MarechaiContext _context;
readonly IStringLocalizer<CompaniesService> _l;
public CompaniesService(MarechaiContext context, IStringLocalizer<CompaniesService> localizer)
{
_context = context;
_l = localizer;
}
public Task<List<CompanyViewModel>> GetCompaniesAsync() => _context.
Companies.Include(c => c.Logos).OrderBy(c => c.Name).
Select(c => new CompanyViewModel
{
Id = c.Id,
LastLogo = c.
Logos.OrderByDescending(l => l.Year).
FirstOrDefault().Guid,
Name = c.Name
}).ToListAsync();
}
}

View File

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

View File

@@ -14,6 +14,11 @@
<span class="fa fa-newspaper" aria-hidden="true"></span>&nbsp;@L["News"]
</NavLink>
</li>
<li class="nav-item px-3">
<NavLink class="nav-link" href="companies">
<span class="fa fa-building" aria-hidden="true"></span>&nbsp;@L["Companies"]
</NavLink>
</li>
</ul>
</div>

View File

@@ -0,0 +1,11 @@
using System;
namespace Marechai.ViewModels
{
public class CompanyViewModel
{
public int Id { get; set; }
public Guid? LastLogo { get; set; }
public string Name { get; set; }
}
}

View File

@@ -32,7 +32,7 @@
ViewData["Title"] = "Companies";
}
@using System.IO
@model IEnumerable<CompanyViewModel>
@model IEnumerable<Marechai.ViewModels.CompanyViewModel>
<p align="center">
@if (ViewBag.Iso3166 != null)
{

View File

@@ -32,7 +32,7 @@
ViewData["Title"] = "Companies";
}
@using System.IO
@model IEnumerable<CompanyViewModel>
@model IEnumerable<Marechai.ViewModels.CompanyViewModel>
<p>Search results:</p>
<p align="center">
@if (ViewBag.Letter != '\0')

View File

@@ -10,3 +10,5 @@
@using Marechai.Services
@using Marechai.ViewModels
@using Microsoft.Extensions.Localization
@using System.IO
@using Microsoft.AspNetCore.Hosting