Move news admin index to Blazor.

This commit is contained in:
2020-05-24 17:39:37 +01:00
parent d4cbbae20a
commit 2d18733439
7 changed files with 78 additions and 23 deletions

View File

@@ -2,7 +2,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<Version>3.0.99.1061</Version>
<Version>3.0.99.1062</Version>
<Company>Canary Islands Computer Museum</Company>
<Copyright>Copyright © 2003-2020 Natalia Portillo</Copyright>
<Product>Canary Islands Computer Museum Website</Product>
@@ -70,6 +70,9 @@
<Content Update="Pages\Admin\People.razor">
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
</Content>
<Content Update="Pages\Admin\News.razor">
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
</Content>
</ItemGroup>
<ItemGroup>
<_ContentIncludedByDefault Remove="Areas\Admin\Views\BrowserTests\Delete.cshtml" />

View File

@@ -68,6 +68,9 @@
<li>
<a href="/admin/people">@L["People"]</a>
</li>
<li>
<a href="/admin/news">@L["News"]</a>
</li>
</ul>
</div>
<div class="content">

View File

@@ -1,14 +1,14 @@
@{
/******************************************************************************
@{
/******************************************************************************
// MARECHAI: Master repository of computing history artifacts information
// ----------------------------------------------------------------------------
//
// Filename : Index.cshtml
// Filename : News.razor
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// --[ Description ] ----------------------------------------------------------
//
// Admin view index
// List of news
//
// --[ License ] --------------------------------------------------------------
//
@@ -29,46 +29,63 @@
// Copyright © 2003-2020 Natalia Portillo
*******************************************************************************/
}
@model IEnumerable<Marechai.Database.Models.News>
@{
ViewData["Title"] = "News (Admin)";
@page "/admin/news"
@using Marechai.Database.Models
@inherits OwningComponentBase<NewsService>
@inject IStringLocalizer<NewsService> L
@attribute [Authorize(Roles = "UberAdmin, Admin")]
<h3>@L["News"]</h3>
@if (_news is null)
{
<p>@L["Loading..."]</p>
return;
}
<h2>News</h2>
<table class="table">
<thead>
<tr>
<th>
@Html.DisplayNameFor(model => model.Date)
@L["Date"]
</th>
<th>
@Html.DisplayNameFor(model => model.Type)
@L["Type"]
</th>
<th>
@Html.DisplayNameFor(model => model.AddedId)
@L["Affected ID"]
</th>
<th></th>
</tr>
</thead>
<tbody>
@foreach (var item in Model)
@foreach (var item in _news)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Date)
@item.Timestamp
</td>
<td>
@Html.DisplayFor(modelItem => item.Type)
@item.Type
</td>
<td>
@Html.DisplayFor(modelItem => item.AddedId)
@item.AffectedId
</td>
<td>
<a asp-action="Delete" asp-route-id="@item.Id" class="btn btn-danger">
Delete
</a>
<span class="btn btn-danger">
@L["Delete"]
</span>
</td>
</tr>
}
</tbody>
</table>
</table>
@code
{
List<NewsViewModel> _news;
protected override async Task OnInitializedAsync()
{
_news = await Service.GetAsync();
}
}

View File

@@ -190,4 +190,8 @@
<value>Gente</value>
<comment>People.</comment>
</data>
<data name="News" xml:space="preserve">
<value>Noticias</value>
<comment>News.</comment>
</data>
</root>

View File

@@ -154,4 +154,20 @@
<value>Videoconsola actualizada en la colección</value>
<comment>Updated console in collection</comment>
</data>
<data name="Loading..." xml:space="preserve">
<value>Cargando...</value>
<comment>Loading...</comment>
</data>
<data name="Date" xml:space="preserve">
<value>Noticias</value>
<comment>News</comment>
</data>
<data name="Type" xml:space="preserve">
<value>Tipo</value>
<comment>Type</comment>
</data>
<data name="Affected ID" xml:space="preserve">
<value>ID afectado</value>
<comment>Affected ID</comment>
</data>
</root>

View File

@@ -30,9 +30,11 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Marechai.Database;
using Marechai.Database.Models;
using Marechai.ViewModels;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Localization;
namespace Marechai.Services
@@ -48,6 +50,12 @@ namespace Marechai.Services
_l = localizer;
}
public async Task<List<NewsViewModel>> GetAsync() => await _context.News.OrderByDescending(n => n.Date).
Select(n => new NewsViewModel
{
Id = n.Id, Timestamp = n.Date, Type = n.Type, AffectedId = n.AddedId
}).ToListAsync();
public List<NewsViewModel> GetNews()
{
List<NewsViewModel> news = new List<NewsViewModel>();

View File

@@ -29,11 +29,14 @@
*******************************************************************************/
using System;
using Marechai.Database;
namespace Marechai.ViewModels
{
public sealed class NewsViewModel
public sealed class NewsViewModel : BaseViewModel<int>
{
public NewsViewModel() { }
public NewsViewModel(int affectedId, string text, DateTime timestamp, string controller, string itemName)
{
AffectedId = affectedId;
@@ -43,10 +46,11 @@ namespace Marechai.ViewModels
ItemName = itemName;
}
public int AffectedId { get; }
public NewsType Type { get; set; }
public int AffectedId { get; set; }
public string Controller { get; }
public string ItemName { get; }
public string Text { get; }
public DateTime Timestamp { get; }
public DateTime Timestamp { get; set; }
}
}