mirror of
https://github.com/claunia/marechai.git
synced 2025-12-16 19:14:25 +00:00
Move companies by letter to Blazor.
This commit is contained in:
@@ -1,88 +0,0 @@
|
||||
/******************************************************************************
|
||||
// MARECHAI: Master repository of computing history artifacts information
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : CompanyController.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// Company 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 <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
// Copyright © 2003-2020 Natalia Portillo
|
||||
*******************************************************************************/
|
||||
|
||||
using System.Linq;
|
||||
using Marechai.Database.Models;
|
||||
using Marechai.ViewModels;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Marechai.Controllers
|
||||
{
|
||||
public class CompanyController : Controller
|
||||
{
|
||||
readonly MarechaiContext _context;
|
||||
readonly IWebHostEnvironment hostingEnvironment;
|
||||
|
||||
public CompanyController(IWebHostEnvironment env, MarechaiContext context)
|
||||
{
|
||||
hostingEnvironment = env;
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public IActionResult ByLetter(char id)
|
||||
{
|
||||
// ToUpper()
|
||||
if(id >= 'a' &&
|
||||
id <= 'z')
|
||||
id -= (char)32;
|
||||
|
||||
// Check if not letter
|
||||
if(id < 'A' ||
|
||||
id > 'Z')
|
||||
id = '\0';
|
||||
|
||||
ViewBag.Letter = id;
|
||||
|
||||
ViewBag.WebRootPath = hostingEnvironment.WebRootPath;
|
||||
|
||||
if(id == '\0')
|
||||
return RedirectToAction(nameof(Index));
|
||||
|
||||
return View(_context.Companies.Include(c => c.Logos).Where(c => c.Name.StartsWith(id)).OrderBy(c => c.Name).
|
||||
Select(c => new CompanyViewModel
|
||||
{
|
||||
Id = c.Id, LastLogo = c.Logos.OrderByDescending(l => l.Year).FirstOrDefault().Guid,
|
||||
Name = c.Name
|
||||
}).ToList());
|
||||
}
|
||||
|
||||
public IActionResult Index()
|
||||
{
|
||||
ViewBag.WebRootPath = hostingEnvironment.WebRootPath;
|
||||
|
||||
return View(_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
|
||||
}).ToList());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<Version>3.0.99.954</Version>
|
||||
<Version>3.0.99.961</Version>
|
||||
<Company>Canary Islands Computer Museum</Company>
|
||||
<Copyright>Copyright © 2003-2020 Natalia Portillo</Copyright>
|
||||
<Product>Canary Islands Computer Museum Website</Product>
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
|
||||
@page "/companies"
|
||||
@page "/companies/country/{CountryId:int}"
|
||||
@page "/companies/{StartingCharacter}"
|
||||
@inherits OwningComponentBase<CompaniesService>
|
||||
@inject IStringLocalizer<CompaniesService> L
|
||||
@inject IWebHostEnvironment Host
|
||||
@@ -62,6 +63,12 @@
|
||||
<br />
|
||||
}
|
||||
|
||||
@if (_character.HasValue)
|
||||
{
|
||||
<b>@string.Format(L["Companies which name starts with {0}."], _character)</b>
|
||||
<br />
|
||||
}
|
||||
|
||||
@if (_companies.Any())
|
||||
{
|
||||
<p>
|
||||
@@ -98,20 +105,46 @@
|
||||
@code
|
||||
{
|
||||
[Parameter]
|
||||
public int? CountryId{get;set;}
|
||||
public int? CountryId { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public string StartingCharacter { get; set; }
|
||||
|
||||
List<CompanyViewModel> _companies;
|
||||
string _countryName;
|
||||
char? _character;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
if (CountryId.HasValue)
|
||||
_character = null;
|
||||
if (!string.IsNullOrWhiteSpace(StartingCharacter) &&
|
||||
StartingCharacter.Length == 1)
|
||||
{
|
||||
_character = StartingCharacter[0];
|
||||
|
||||
// ToUpper()
|
||||
if (_character >= 'a' &&
|
||||
_character <= 'z')
|
||||
_character -= (char)32;
|
||||
|
||||
|
||||
// Check if not letter or number
|
||||
if (_character < '0' ||
|
||||
(_character > '9' && _character < 'A') ||
|
||||
_character > 'Z')
|
||||
_character = null;
|
||||
}
|
||||
|
||||
if (_character.HasValue)
|
||||
_companies = await Service.GetCompaniesByLetterAsync(_character.Value);
|
||||
|
||||
if (CountryId.HasValue && _companies is null)
|
||||
{
|
||||
_countryName = await Service.GetCountryNameAsync(CountryId.Value);
|
||||
|
||||
if (_countryName != null)
|
||||
{
|
||||
_companies = await Service.GetCompaniesByCountryAsync(CountryId.Value);
|
||||
_companies = await Service.GetCompaniesByCountryAsync(CountryId.Value);
|
||||
}
|
||||
else
|
||||
CountryId = null;
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
*******************************************************************************/
|
||||
}
|
||||
|
||||
@page "/companies/{Id:int}"
|
||||
@page "/company/{Id:int}"
|
||||
@using Marechai.Database.Models
|
||||
@using Marechai.Database
|
||||
|
||||
@@ -159,7 +159,7 @@
|
||||
if (_soldTo != null)
|
||||
{
|
||||
<td>
|
||||
<a href="/companies/@_soldTo.Id">
|
||||
<a href="/company/@_soldTo.Id">
|
||||
@string.Format(L["Company sold to {0} on {1}."], _soldTo.Name, _company.Sold.Value.ToLongDateString())</a>
|
||||
</td>
|
||||
}
|
||||
@@ -173,7 +173,7 @@
|
||||
if (_soldTo != null)
|
||||
{
|
||||
<td>
|
||||
<a href="/companies/@_soldTo.Id">
|
||||
<a href="/company/@_soldTo.Id">
|
||||
@string.Format(L["Company sold to {0} on an unknown date."], _soldTo.Name)</a>
|
||||
</td>
|
||||
}
|
||||
@@ -189,7 +189,7 @@
|
||||
if (_soldTo != null)
|
||||
{
|
||||
<td>
|
||||
<a href="/companies/@_soldTo.Id">@string.Format(L["Company merged on {0} to form {1}."], _company.Sold.Value.ToLongDateString(), _soldTo.Name)</a>
|
||||
<a href="/company/@_soldTo.Id">@string.Format(L["Company merged on {0} to form {1}."], _company.Sold.Value.ToLongDateString(), _soldTo.Name)</a>
|
||||
</td>
|
||||
}
|
||||
else
|
||||
@@ -202,7 +202,7 @@
|
||||
if (_soldTo != null)
|
||||
{
|
||||
<td>
|
||||
<a href="/companies/@_soldTo.Id">@string.Format(L["Company merged on an unknown date to form {0}."], _soldTo.Name)</a>
|
||||
<a href="/company/@_soldTo.Id">@string.Format(L["Company merged on an unknown date to form {0}."], _soldTo.Name)</a>
|
||||
</td>
|
||||
}
|
||||
else
|
||||
@@ -237,7 +237,7 @@
|
||||
if (_soldTo != null)
|
||||
{
|
||||
<td>
|
||||
<a href="/companies/@_soldTo.Id">@string.Format(L["Company renamed to {0} on {1}."], _soldTo.Name, _company.Sold.Value.ToLongDateString())</a>
|
||||
<a href="/company/@_soldTo.Id">@string.Format(L["Company renamed to {0} on {1}."], _soldTo.Name, _company.Sold.Value.ToLongDateString())</a>
|
||||
</td>
|
||||
}
|
||||
else
|
||||
@@ -250,7 +250,7 @@
|
||||
if (_soldTo != null)
|
||||
{
|
||||
<td>
|
||||
<a href="/companies/@_soldTo.Id">
|
||||
<a href="/company/@_soldTo.Id">
|
||||
@string.Format(L["Company renamed to {0} on an unknown date."], _soldTo.Name)</a>
|
||||
</td>
|
||||
}
|
||||
|
||||
@@ -250,4 +250,8 @@
|
||||
<value>Compañías fundadas en {0}.</value>
|
||||
<comment>Companies founded in, {0} country name</comment>
|
||||
</data>
|
||||
<data name="Companies which name starts with {0}." xml:space="preserve">
|
||||
<value>Compañías cuyo nombre empieza por {0}.</value>
|
||||
<comment>Companies with {0}, a single character, as the start of the name</comment>
|
||||
</data>
|
||||
</root>
|
||||
@@ -103,5 +103,22 @@ namespace Marechai.Services
|
||||
Guid,
|
||||
Name = c.Name
|
||||
}).ToListAsync();
|
||||
|
||||
public Task<List<CompanyViewModel>> GetCompaniesByLetterAsync(char id) => _context.
|
||||
Companies.Include(c => c.Logos).
|
||||
Where(c => EF.Functions.Like(c.Name,
|
||||
$"{id}%")).
|
||||
OrderBy(c => c.Name).
|
||||
Select(c => new CompanyViewModel
|
||||
{
|
||||
Id = c.Id,
|
||||
LastLogo = c.
|
||||
Logos.
|
||||
OrderByDescending(l =>
|
||||
l.
|
||||
Year).
|
||||
FirstOrDefault().Guid,
|
||||
Name = c.Name
|
||||
}).ToListAsync();
|
||||
}
|
||||
}
|
||||
@@ -1,75 +0,0 @@
|
||||
@{
|
||||
/******************************************************************************
|
||||
// MARECHAI: Master repository of computing history artifacts information
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : ByLetter.cshtml
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// Lists companies by letter (or all)
|
||||
//
|
||||
// --[ 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"] = "Companies";
|
||||
}
|
||||
@using System.IO
|
||||
@model IEnumerable<Marechai.ViewModels.CompanyViewModel>
|
||||
<p>Search results:</p>
|
||||
<p align="center">
|
||||
@if (ViewBag.Letter != '\0')
|
||||
{
|
||||
<b>@ViewBag.Letter</b>
|
||||
<br />
|
||||
}
|
||||
|
||||
@if (Model.Any())
|
||||
{
|
||||
<p>
|
||||
@Model.Count() companies found in the database.
|
||||
<br />
|
||||
@foreach (var company in Model)
|
||||
{
|
||||
<a asp-controller="Company" asp-action="View" asp-route-id="@company.Id">
|
||||
@if (company.LastLogo != null &&
|
||||
File.Exists(System.IO.Path.Combine(ViewBag.WebRootPath, "assets/logos", company.LastLogo + ".svg")))
|
||||
{
|
||||
<picture>
|
||||
<source type="image/svg+xml" srcset="/assets/logos/@(company.LastLogo).svg">
|
||||
<source type="image/webp" srcset="/assets/logos/thumbs/webp/1x/@(company.LastLogo).webp,
|
||||
/assets/logos/thumbs/webp/2x/@(company.LastLogo).webp 2x,
|
||||
/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" />
|
||||
</picture>
|
||||
}
|
||||
@company.Name
|
||||
</a>
|
||||
<br />
|
||||
}
|
||||
</p>
|
||||
}
|
||||
else
|
||||
{
|
||||
<p>There are no companies found in the database that start with this letter.</p>
|
||||
}
|
||||
</p>
|
||||
Reference in New Issue
Block a user