From d4cbbae20a2f3f92172c81f8e2fff4df0580a3b3 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sun, 24 May 2020 17:19:13 +0100 Subject: [PATCH] Move people admin index to Blazor. --- Marechai/Areas/Admin/Views/Home/Index.cshtml | 2 - .../Areas/Admin/Views/People/Index.cshtml | 76 -------- Marechai/Marechai.csproj | 5 +- Marechai/Pages/Admin/Index.razor | 3 + Marechai/Pages/Admin/People.razor | 131 +++++++++++++ .../Resources/Services/AdminService.es.resx | 4 + .../Resources/Services/PeopleService.es.resx | 173 ++++++++++++++++++ Marechai/Services/PeopleService.cs | 26 +++ Marechai/Services/Register.cs | 1 + Marechai/ViewModels/PersonViewModel.cs | 21 +++ 10 files changed, 363 insertions(+), 79 deletions(-) delete mode 100644 Marechai/Areas/Admin/Views/People/Index.cshtml create mode 100644 Marechai/Pages/Admin/People.razor create mode 100644 Marechai/Resources/Services/PeopleService.es.resx create mode 100644 Marechai/Services/PeopleService.cs create mode 100644 Marechai/ViewModels/PersonViewModel.cs diff --git a/Marechai/Areas/Admin/Views/Home/Index.cshtml b/Marechai/Areas/Admin/Views/Home/Index.cshtml index e19fca53..e5d450b5 100644 --- a/Marechai/Areas/Admin/Views/Home/Index.cshtml +++ b/Marechai/Areas/Admin/Views/Home/Index.cshtml @@ -48,8 +48,6 @@
News
- People -
Processors by machines
Processors diff --git a/Marechai/Areas/Admin/Views/People/Index.cshtml b/Marechai/Areas/Admin/Views/People/Index.cshtml deleted file mode 100644 index dfa940f2..00000000 --- a/Marechai/Areas/Admin/Views/People/Index.cshtml +++ /dev/null @@ -1,76 +0,0 @@ -@model IEnumerable - -@{ - ViewData["Title"] = "People"; -} -

People

-

- Create new -

- - - - - - - - - - - - - - - @foreach (var item in Model) - { - - - - - - - - - - - } - -
- @Html.DisplayNameFor(model => model.FullName) - - @Html.DisplayNameFor(model => model.CountryOfBirth) - - @Html.DisplayNameFor(model => model.BirthDate) - - @Html.DisplayNameFor(model => model.DeathDate) - - @Html.DisplayNameFor(model => model.Webpage) - - @Html.DisplayNameFor(model => model.Twitter) - - @Html.DisplayNameFor(model => model.Facebook) -
- @Html.DisplayFor(modelItem => item.FullName) - - @Html.DisplayFor(modelItem => item.CountryOfBirth.Name) - - @Html.DisplayFor(modelItem => item.BirthDate) - - @Html.DisplayFor(modelItem => item.DeathDate) - - @Html.DisplayFor(modelItem => item.Webpage) - - @if (item.Twitter != null) - { - @Html.DisplayFor(modelItem => item.Twitter) - } - - @if (item.Facebook != null) - { - @Html.DisplayFor(modelItem => item.Facebook) - } - - Details - Edit - Delete -
\ No newline at end of file diff --git a/Marechai/Marechai.csproj b/Marechai/Marechai.csproj index ee0369cf..71d954ab 100644 --- a/Marechai/Marechai.csproj +++ b/Marechai/Marechai.csproj @@ -2,7 +2,7 @@ netcoreapp3.1 - 3.0.99.1060 + 3.0.99.1061 Canary Islands Computer Museum Copyright © 2003-2020 Natalia Portillo Canary Islands Computer Museum Website @@ -67,6 +67,9 @@ true + + true + <_ContentIncludedByDefault Remove="Areas\Admin\Views\BrowserTests\Delete.cshtml" /> diff --git a/Marechai/Pages/Admin/Index.razor b/Marechai/Pages/Admin/Index.razor index d2b8464c..d43309a9 100644 --- a/Marechai/Pages/Admin/Index.razor +++ b/Marechai/Pages/Admin/Index.razor @@ -65,6 +65,9 @@
  • @L["Machines"]
  • +
  • + @L["People"] +
  • diff --git a/Marechai/Pages/Admin/People.razor b/Marechai/Pages/Admin/People.razor new file mode 100644 index 00000000..7f673319 --- /dev/null +++ b/Marechai/Pages/Admin/People.razor @@ -0,0 +1,131 @@ +@{ +/****************************************************************************** +// MARECHAI: Master repository of computing history artifacts information +// ---------------------------------------------------------------------------- +// +// Filename : People.razor +// Author(s) : Natalia Portillo +// +// --[ Description ] ---------------------------------------------------------- +// +// List of people +// +// --[ 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 "/admin/people" +@inherits OwningComponentBase +@inject IStringLocalizer L +@attribute [Authorize(Roles = "UberAdmin, Admin")] +

    @L["People"]

    +@if (_people is null) +{ +

    @L["Loading..."]

    + + return; +} +

    + + @L["Create new"] + +

    + + + + + + + + + + + + + + + @foreach (var item in _people) + { + + + + + + + + + + + } + +
    + @L["Known name"] + + @L["Country of birth"] + + @L["Birth date"] + + @L["Date of death"] + + @L["Webpage"] + + @L["Twitter"] + + @L["Facebook"] +
    + @item.FullName + + @item.CountryOfBirth + + @($"{item.BirthDate:d}") + + @($"{item.DeathDate:d}") + + @item.Webpage + + @if (item.Twitter != null) + { + @item.Twitter + } + + @if (item.Facebook != null) + { + @item.Facebook + } + + + @L["Details"] + + + @L["Edit"] + + + @L["Delete"] + +
    + +@code +{ + List _people; + + protected override async Task OnInitializedAsync() + { + _people = await Service.GetAsync(); + } +} \ No newline at end of file diff --git a/Marechai/Resources/Services/AdminService.es.resx b/Marechai/Resources/Services/AdminService.es.resx index 2fac4361..33194631 100644 --- a/Marechai/Resources/Services/AdminService.es.resx +++ b/Marechai/Resources/Services/AdminService.es.resx @@ -186,4 +186,8 @@ Máquinas Machines. + + Gente + People. + \ No newline at end of file diff --git a/Marechai/Resources/Services/PeopleService.es.resx b/Marechai/Resources/Services/PeopleService.es.resx new file mode 100644 index 00000000..35a7c312 --- /dev/null +++ b/Marechai/Resources/Services/PeopleService.es.resx @@ -0,0 +1,173 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + Gente + People + + + Cargando... + Message that appears while data is being loaded from database + + + Nombre conocido + Known name + + + País de nacimiento + Country of birth + + + Fecha de nacimiento + Birth date + + + Fecha de fallecimiento + Date of death + + + Página web + Webpage + + + Twitter + Twitter + + + Facebook + Facebook + + + Crear nueva + Create new + + + Detalles + Details + + + Editar + Edit + + + Eliminar + Delete + + \ No newline at end of file diff --git a/Marechai/Services/PeopleService.cs b/Marechai/Services/PeopleService.cs new file mode 100644 index 00000000..def993b2 --- /dev/null +++ b/Marechai/Services/PeopleService.cs @@ -0,0 +1,26 @@ +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Marechai.Database.Models; +using Marechai.ViewModels; +using Microsoft.EntityFrameworkCore; + +namespace Marechai.Services +{ + public class PeopleService + { + readonly MarechaiContext _context; + + public PeopleService(MarechaiContext context) => _context = context; + + public async Task> GetAsync() => + await _context.People.OrderBy(p => p.DisplayName).ThenBy(p => p.Alias).ThenBy(p => p.Name). + ThenBy(p => p.Surname).Select(p => new PersonViewModel + { + Id = p.Id, Name = p.Name, Surname = p.Surname, CountryOfBirth = p.CountryOfBirth.Name, + BirthDate = p.BirthDate, DeathDate = p.DeathDate, Webpage = p.Webpage, + Twitter = p.Twitter, Facebook = p.Facebook, Photo = p.Photo, Alias = p.Alias, + DisplayName = p.DisplayName + }).ToListAsync(); + } +} \ No newline at end of file diff --git a/Marechai/Services/Register.cs b/Marechai/Services/Register.cs index 9583ca82..a2492658 100644 --- a/Marechai/Services/Register.cs +++ b/Marechai/Services/Register.cs @@ -55,6 +55,7 @@ namespace Marechai.Services services.AddScoped(); services.AddScoped(); services.AddScoped(); + services.AddScoped(); } } } \ No newline at end of file diff --git a/Marechai/ViewModels/PersonViewModel.cs b/Marechai/ViewModels/PersonViewModel.cs new file mode 100644 index 00000000..459baa64 --- /dev/null +++ b/Marechai/ViewModels/PersonViewModel.cs @@ -0,0 +1,21 @@ +using System; + +namespace Marechai.ViewModels +{ + public class PersonViewModel : BaseViewModel + { + public string Name { get; set; } + public string Surname { get; set; } + public string CountryOfBirth { get; set; } + public DateTime BirthDate { get; set; } + public DateTime? DeathDate { get; set; } + public string Webpage { get; set; } + public string Twitter { get; set; } + public string Facebook { get; set; } + public Guid Photo { get; set; } + public string Alias { get; set; } + public string DisplayName { get; set; } + + public string FullName => DisplayName ?? Alias ?? $"{Name} {Surname}"; + } +} \ No newline at end of file