Add document person details in admin view.

This commit is contained in:
2020-05-25 20:41:02 +01:00
parent b3aac972eb
commit f3f2d30373
7 changed files with 153 additions and 55 deletions

View File

@@ -1,51 +0,0 @@
@model Marechai.Database.Models.DocumentPerson
@{
ViewData["Title"] = "Details";
}
<h1>Details</h1>
<div>
<h4>Document person</h4>
<hr />
<dl class="row">
<dt class="col-sm-2">
@Html.DisplayNameFor(model => model.Name)
</dt>
<dd class="col-sm-10">
@Html.DisplayFor(model => model.Name)
</dd>
<dt class="col-sm-2">
@Html.DisplayNameFor(model => model.Surname)
</dt>
<dd class="col-sm-10">
@Html.DisplayFor(model => model.Surname)
</dd>
<dt class="col-sm-2">
@Html.DisplayNameFor(model => model.Alias)
</dt>
<dd class="col-sm-10">
@Html.DisplayFor(model => model.Alias)
</dd>
<dt class="col-sm-2">
@Html.DisplayNameFor(model => model.DisplayName)
</dt>
<dd class="col-sm-10">
@Html.DisplayFor(model => model.DisplayName)
</dd>
<dt class="col-sm-2">
@Html.DisplayNameFor(model => model.Person)
</dt>
<dd class="col-sm-10">
<a asp-action="Details" asp-route-id="@Model.PersonId" asp-controller="People">
@Html.DisplayFor(modelItem => Model.Person.FullName)</a>
</dd>
</dl>
</div>
<div>
<a asp-action="Edit" asp-route-id="@Model.Id" class="btn btn-primary">
Edit
</a>
<a asp-action="Index" class="btn btn-secondary">
Back to List
</a>
</div>

View File

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

View File

@@ -0,0 +1,93 @@
@{
/******************************************************************************
// MARECHAI: Master repository of computing history artifacts information
// ----------------------------------------------------------------------------
//
// Filename : Details.cshtml
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// --[ Description ] ----------------------------------------------------------
//
// Admin view details
//
// --[ 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 "/admin/document_people/details/{Id:int}"
@inherits OwningComponentBase<DocumentPeopleService>
@inject IStringLocalizer<DocumentPeopleService> L
@inject PeopleService PeopleService
@attribute [Authorize(Roles = "UberAdmin, Admin")]
<h3>@L["Document person details"]</h3>
<hr />
@if (!_loaded)
{
<p align="center">@L["Loading..."]</p>
return;
}
<div>
@if (_editable || _model.Name != null)
{
<Field>
<FieldLabel>@L["Name"]</FieldLabel>
<TextEdit ReadOnly="!_editable" @bind-Text="@_model.Name" />
</Field>
}
@if (_editable || _model.Surname != null)
{
<Field>
<FieldLabel>@L["Surname"]</FieldLabel>
<TextEdit ReadOnly="!_editable" @bind-Text="@_model.Surname" />
</Field>
}
@if (_editable || _model.Alias != null)
{
<Field>
<FieldLabel>@L["Alias"]</FieldLabel>
<TextEdit ReadOnly="!_editable" @bind-Text="@_model.Alias" />
</Field>
}
@if (_editable || _model.DisplayName != null)
{
<Field>
<FieldLabel>@L["Display name"]</FieldLabel>
<TextEdit ReadOnly="!_editable" @bind-Text="@_model.DisplayName" />
</Field>
}
@if (_editable || _model.PersonId != null)
{
<Field>
<FieldLabel>@L["Linked person"]</FieldLabel>
<Select Disabled="!_editable" TValue="int?" @bind-SelectedValue="@_model.PersonId">
@foreach (var person in _people)
{
<SelectItem TValue="int?" Value="@person.Id">@person.DisplayName</SelectItem>
}
</Select>
</Field>
}
</div>
<div>
<span class="btn btn-primary">@L["Edit"]</span>
<a href="/admin/companies" class="btn btn-secondary">@L["Back to list"]</a>
</div>

View File

@@ -0,0 +1,33 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Marechai.ViewModels;
using Microsoft.AspNetCore.Components;
namespace Marechai.Pages.Admin.Details
{
public partial class DocumentPerson
{
bool _editable;
bool _loaded;
Database.Models.DocumentPerson _model;
List<PersonViewModel> _people;
[Parameter]
public int Id { get; set; }
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if(_loaded)
return;
_loaded = true;
if(Id <= 0)
return;
_people = await PeopleService.GetAsync();
_model = await Service.GetAsync(Id);
StateHasChanged();
}
}
}

View File

@@ -71,9 +71,7 @@
</a>
</td>
<td>
<span class="btn btn-primary">
@L["Details"]
</span>
<a class="btn btn-primary" href="/admin/document_people/details/@item.Id">@L["Details"]</a>
<span class="btn btn-secondary">
@L["Edit"]
</span>

View File

@@ -162,4 +162,24 @@
<value>Cancelar</value>
<comment>Cancel</comment>
</data>
<data name="Document person details" xml:space="preserve">
<value>Detalles de persona de documentos</value>
<comment>Document person details</comment>
</data>
<data name="Back to list" xml:space="preserve">
<value>Volver a la lista</value>
<comment>Back to list</comment>
</data>
<data name="Surname" xml:space="preserve">
<value>Apellido</value>
<comment>Surname</comment>
</data>
<data name="Display name" xml:space="preserve">
<value>Nombre para mostrar</value>
<comment>Display name</comment>
</data>
<data name="Alias" xml:space="preserve">
<value>Alias</value>
<comment>Alias</comment>
</data>
</root>

View File

@@ -24,6 +24,8 @@ namespace Marechai.Services
PersonId = d.PersonId
}).ToListAsync();
public async Task<DocumentPerson> GetAsync(int id) => await _context.DocumentPeople.FindAsync(id);
public async Task DeleteAsync(int id)
{
DocumentPerson item = await _context.DocumentPeople.FindAsync(id);