mirror of
https://github.com/claunia/marechai.git
synced 2025-12-16 19:14:25 +00:00
Add people to book admin page.
This commit is contained in:
@@ -40,6 +40,8 @@
|
||||
@inject BooksByMachineFamilyService BooksByMachineFamilyService
|
||||
@inject MachinesService MachinesService
|
||||
@inject BooksByMachineService BooksByMachineService
|
||||
@inject DocumentPeopleService PeopleService
|
||||
@inject PeopleByBookService PeopleByBookService
|
||||
@inject NavigationManager NavigationManager
|
||||
@inject IWebHostEnvironment Host
|
||||
@inject IJSRuntime JSRuntime
|
||||
@@ -282,6 +284,69 @@
|
||||
</div>
|
||||
}
|
||||
|
||||
<hr />
|
||||
<h3>@L["People involved in this book"]</h3>
|
||||
<Button Color="Color.Success" Clicked="OnAddPersonClick" Disabled="_addingPerson">@L["Add new (person)"]</Button>
|
||||
@if (_addingPerson)
|
||||
{
|
||||
<div>
|
||||
<Field>
|
||||
<FieldLabel>@L["Person"]</FieldLabel>
|
||||
<Select Disabled="_savingPerson" TValue="int?" @bind-SelectedValue="@_addingPersonId">
|
||||
@foreach (var person in _people)
|
||||
{
|
||||
<SelectItem TValue="int?" Value="@person.Id">@person.FullName</SelectItem>
|
||||
}
|
||||
</Select>
|
||||
</Field>
|
||||
<Field>
|
||||
<FieldLabel>@L["Role"]</FieldLabel>
|
||||
<Select Disabled="!_editing" TValue="string" @bind-SelectedValue="@_addingPersonRoleId">
|
||||
@foreach (var role in _roles)
|
||||
{
|
||||
<SelectItem TValue="string" Value="@role.Id">@role.Name</SelectItem>
|
||||
}
|
||||
</Select>
|
||||
</Field>
|
||||
<Button Color="Color.Primary" Clicked="@CancelAddPerson" Disabled="@_savingPerson">@L["Cancel"]</Button>
|
||||
<Button Color="Color.Success" Clicked="@ConfirmAddPerson" Disabled="@_savingPerson">@L["Add"]</Button>
|
||||
</div>
|
||||
}
|
||||
@if (_bookPeople?.Count > 0)
|
||||
{
|
||||
<div>
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>
|
||||
@L["Person"]
|
||||
</th>
|
||||
<th>
|
||||
@L["Role"]
|
||||
</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var item in _bookPeople)
|
||||
{
|
||||
<tr>
|
||||
<td>
|
||||
@item.FullName
|
||||
</td>
|
||||
<td>
|
||||
@item.Role
|
||||
</td>
|
||||
<td>
|
||||
<Button Color="Color.Danger" Clicked="() => {ShowPersonDeleteModal(item.Id);}" Disabled="@_addingPerson">@L["Delete"]</Button>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
}
|
||||
|
||||
<hr />
|
||||
<h3>@L["Machine families this book talks about"]</h3>
|
||||
<Button Color="Color.Success" Clicked="OnAddFamilyClick" Disabled="_addingMachineFamily">@L["Add new (machine family)"]</Button>
|
||||
@@ -377,7 +442,7 @@
|
||||
</table>
|
||||
</div>
|
||||
}
|
||||
|
||||
|
||||
<Modal @ref="_frmDelete" IsCentered="true" Closing="@ModalClosing">
|
||||
<ModalBackdrop />
|
||||
<ModalContent Centered="true">
|
||||
|
||||
@@ -38,39 +38,48 @@ namespace Marechai.Pages.Admin.Details
|
||||
{
|
||||
public partial class Book
|
||||
{
|
||||
bool _addingCompany;
|
||||
int? _addingCompanyId;
|
||||
string _addingCompanyRoleId;
|
||||
bool _addingMachine;
|
||||
bool _addingMachineFamily;
|
||||
int? _addingMachineFamilyId;
|
||||
int? _addingMachineId;
|
||||
bool _addingCompany;
|
||||
int? _addingCompanyId;
|
||||
string _addingCompanyRoleId;
|
||||
bool _addingMachine;
|
||||
bool _addingMachineFamily;
|
||||
int? _addingMachineFamilyId;
|
||||
int? _addingMachineId;
|
||||
|
||||
bool _addingPerson;
|
||||
int? _addingPersonId;
|
||||
string _addingPersonRoleId;
|
||||
AuthenticationState _authState;
|
||||
List<CompanyByBookViewModel> _bookCompanies;
|
||||
List<BookByMachineFamilyViewModel> _bookMachineFamilies;
|
||||
List<BookByMachineViewModel> _bookMachines;
|
||||
List<PersonByBookViewModel> _bookPeople;
|
||||
List<DocumentCompanyViewModel> _companies;
|
||||
List<Iso31661Numeric> _countries;
|
||||
bool _creating;
|
||||
BookByMachineViewModel _currentBookByMachine;
|
||||
BookByMachineFamilyViewModel _currentBookByMachineFamily;
|
||||
CompanyByBookViewModel _currentCompanyByBook;
|
||||
PersonByBookViewModel _currentPersonByBook;
|
||||
bool _deleteInProgress;
|
||||
string _deleteText;
|
||||
string _deleteTitle;
|
||||
bool _deletingBookByMachine;
|
||||
bool _deletingBookByMachineFamily;
|
||||
bool _deletingCompanyByBook;
|
||||
bool _deletingPersonByBook;
|
||||
bool _editing;
|
||||
Modal _frmDelete;
|
||||
bool _loaded;
|
||||
List<MachineFamilyViewModel> _machineFamilies;
|
||||
List<MachineViewModel> _machines;
|
||||
BookViewModel _model;
|
||||
List<DocumentPersonViewModel> _people;
|
||||
List<DocumentRoleViewModel> _roles;
|
||||
bool _savingCompany;
|
||||
bool _savingMachine;
|
||||
bool _savingMachineFamily;
|
||||
bool _savingPerson;
|
||||
bool _unknownCountry;
|
||||
bool _unknownEdition;
|
||||
bool _unknownIsbn;
|
||||
@@ -108,6 +117,8 @@ namespace Marechai.Pages.Admin.Details
|
||||
_bookMachineFamilies = await BooksByMachineFamilyService.GetByBook(Id);
|
||||
_addingMachineId = _machines.First().Id;
|
||||
_bookMachines = await BooksByMachineService.GetByBook(Id);
|
||||
_addingPersonRoleId = _roles.First().Id;
|
||||
_bookPeople = await PeopleByBookService.GetByBook(Id);
|
||||
|
||||
_editing = _creating || NavigationManager.ToBaseRelativePath(NavigationManager.Uri).ToLowerInvariant().
|
||||
StartsWith("admin/books/edit/",
|
||||
@@ -304,6 +315,8 @@ namespace Marechai.Pages.Admin.Details
|
||||
_currentBookByMachineFamily = null;
|
||||
_deletingBookByMachine = false;
|
||||
_currentBookByMachine = null;
|
||||
_deletingPersonByBook = false;
|
||||
_currentPersonByBook = null;
|
||||
}
|
||||
|
||||
void HideModal() => _frmDelete.Hide();
|
||||
@@ -316,6 +329,8 @@ namespace Marechai.Pages.Admin.Details
|
||||
await ConfirmDeleteBookByMachineFamily();
|
||||
else if(_deletingBookByMachine)
|
||||
await ConfirmDeleteBookByMachine();
|
||||
else if(_deletingPersonByBook)
|
||||
await ConfirmDeletePersonByBook();
|
||||
}
|
||||
|
||||
async Task ConfirmDeleteCompanyByBook()
|
||||
@@ -506,5 +521,88 @@ namespace Marechai.Pages.Admin.Details
|
||||
// Tell we finished loading
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
void OnAddPersonClick()
|
||||
{
|
||||
_addingPerson = true;
|
||||
_savingPerson = false;
|
||||
_addingPersonId = _people.First().Id;
|
||||
}
|
||||
|
||||
void CancelAddPerson()
|
||||
{
|
||||
_addingPerson = false;
|
||||
_savingPerson = false;
|
||||
_addingPersonId = null;
|
||||
}
|
||||
|
||||
async Task ConfirmAddPerson()
|
||||
{
|
||||
if(_addingPersonId is null ||
|
||||
_addingPersonId <= 0)
|
||||
{
|
||||
CancelAddPerson();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
_savingPerson = true;
|
||||
|
||||
// Yield thread to let UI to update
|
||||
await Task.Yield();
|
||||
|
||||
await PeopleByBookService.CreateAsync(_addingPersonId.Value, Id, _addingPersonRoleId,
|
||||
(await UserManager.GetUserAsync(_authState.User)).Id);
|
||||
|
||||
_bookPeople = await PeopleByBookService.GetByBook(Id);
|
||||
|
||||
_addingPerson = false;
|
||||
_savingPerson = false;
|
||||
_addingPersonId = null;
|
||||
|
||||
// Yield thread to let UI to update
|
||||
await Task.Yield();
|
||||
|
||||
// Tell we finished loading
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
void ShowPersonDeleteModal(long itemId)
|
||||
{
|
||||
_currentPersonByBook = _bookPeople.FirstOrDefault(n => n.Id == itemId);
|
||||
_deletingPersonByBook = true;
|
||||
_deleteTitle = L["Delete person from this book"];
|
||||
|
||||
_deleteText =
|
||||
string.Format(L["Are you sure you want to delete the person {0} with role {1} from this book?"],
|
||||
_currentPersonByBook?.FullName, _currentPersonByBook?.Role);
|
||||
|
||||
_frmDelete.Show();
|
||||
}
|
||||
|
||||
async Task ConfirmDeletePersonByBook()
|
||||
{
|
||||
if(_currentPersonByBook is null)
|
||||
return;
|
||||
|
||||
_deleteInProgress = true;
|
||||
|
||||
// Yield thread to let UI to update
|
||||
await Task.Yield();
|
||||
|
||||
await PeopleByBookService.DeleteAsync(_currentPersonByBook.Id,
|
||||
(await UserManager.GetUserAsync(_authState.User)).Id);
|
||||
|
||||
_bookPeople = await PeopleByBookService.GetByBook(Id);
|
||||
|
||||
_deleteInProgress = false;
|
||||
_frmDelete.Hide();
|
||||
|
||||
// Yield thread to let UI to update
|
||||
await Task.Yield();
|
||||
|
||||
// Tell we finished loading
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -167,4 +167,19 @@
|
||||
<data name="Machines this book talks about" xml:space="preserve">
|
||||
<value>Machines this book talks about</value>
|
||||
</data>
|
||||
<data name="People involved in this book" xml:space="preserve">
|
||||
<value>People involved in this book</value>
|
||||
</data>
|
||||
<data name="Add new (person)" xml:space="preserve">
|
||||
<value>Add new</value>
|
||||
</data>
|
||||
<data name="Person" xml:space="preserve">
|
||||
<value>Person</value>
|
||||
</data>
|
||||
<data name="Delete person from this book" xml:space="preserve">
|
||||
<value>Delete person from this book</value>
|
||||
</data>
|
||||
<data name="Are you sure you want to delete the person {0} with role {1} from this book?" xml:space="preserve">
|
||||
<value>Are you sure you want to delete the person {0} with role {1} from this book?</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -283,4 +283,19 @@
|
||||
<data name="Machines this book talks about" xml:space="preserve">
|
||||
<value>Máquinas sobre las que habla este libro</value>
|
||||
</data>
|
||||
<data name="People involved in this book" xml:space="preserve">
|
||||
<value>Personas involucradas en este libro</value>
|
||||
</data>
|
||||
<data name="Add new (person)" xml:space="preserve">
|
||||
<value>Añadir nueva</value>
|
||||
</data>
|
||||
<data name="Person" xml:space="preserve">
|
||||
<value>Persona</value>
|
||||
</data>
|
||||
<data name="Delete person from this book" xml:space="preserve">
|
||||
<value>Eliminar persona de este libro</value>
|
||||
</data>
|
||||
<data name="Are you sure you want to delete the person {0} with role {1} from this book?" xml:space="preserve">
|
||||
<value>¿Estás seguro de eliminar la persona {0} con el rol {1} de este libro?</value>
|
||||
</data>
|
||||
</root>
|
||||
82
Marechai/Services/PeopleByBookService.cs
Normal file
82
Marechai/Services/PeopleByBookService.cs
Normal file
@@ -0,0 +1,82 @@
|
||||
/******************************************************************************
|
||||
// MARECHAI: Master repository of computing history artifacts information
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// --[ 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;
|
||||
|
||||
namespace Marechai.Services
|
||||
{
|
||||
public class PeopleByBookService
|
||||
{
|
||||
readonly MarechaiContext _context;
|
||||
|
||||
public PeopleByBookService(MarechaiContext context) => _context = context;
|
||||
|
||||
public async Task<List<PersonByBookViewModel>> GetByBook(long bookId) =>
|
||||
(await _context.PeopleByBooks.Where(p => p.BookId == bookId).Select(p => new PersonByBookViewModel
|
||||
{
|
||||
Id = p.Id,
|
||||
Name = p.Person.Name,
|
||||
Surname = p.Person.Surname,
|
||||
Alias = p.Person.Alias,
|
||||
DisplayName = p.Person.DisplayName,
|
||||
PersonId = p.PersonId,
|
||||
RoleId = p.RoleId,
|
||||
Role = p.Role.Name,
|
||||
BookId = p.BookId
|
||||
}).ToListAsync()).OrderBy(p => p.FullName).ThenBy(p => p.Role).ToList();
|
||||
|
||||
public async Task DeleteAsync(long id, string userId)
|
||||
{
|
||||
PeopleByBook item = await _context.PeopleByBooks.FindAsync(id);
|
||||
|
||||
if(item is null)
|
||||
return;
|
||||
|
||||
_context.PeopleByBooks.Remove(item);
|
||||
|
||||
await _context.SaveChangesWithUserAsync(userId);
|
||||
}
|
||||
|
||||
public async Task<long> CreateAsync(int personId, long bookId, string roleId, string userId)
|
||||
{
|
||||
var item = new PeopleByBook
|
||||
{
|
||||
PersonId = personId,
|
||||
BookId = bookId,
|
||||
RoleId = roleId
|
||||
};
|
||||
|
||||
await _context.PeopleByBooks.AddAsync(item);
|
||||
await _context.SaveChangesWithUserAsync(userId);
|
||||
|
||||
return item.Id;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -91,6 +91,7 @@ namespace Marechai.Services
|
||||
services.AddScoped<BooksByMachineService>();
|
||||
services.AddScoped<DocumentsByMachineService>();
|
||||
services.AddScoped<MagazinesByMachineService>();
|
||||
services.AddScoped<PeopleByBookService>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -33,5 +33,7 @@ namespace Marechai.ViewModels
|
||||
public string Alias { get; set; }
|
||||
public string Surname { get; set; }
|
||||
public string DisplayName { get; set; }
|
||||
|
||||
public string FullName => DisplayName ?? Alias ?? $"{Name} {Surname}";
|
||||
}
|
||||
}
|
||||
41
Marechai/ViewModels/PersonByBookViewModel.cs
Normal file
41
Marechai/ViewModels/PersonByBookViewModel.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
/******************************************************************************
|
||||
// MARECHAI: Master repository of computing history artifacts information
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// --[ 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.ViewModels
|
||||
{
|
||||
public class PersonByBookViewModel : BaseViewModel<long>
|
||||
{
|
||||
public int PersonId { get; set; }
|
||||
public long BookId { get; set; }
|
||||
public string RoleId { get; set; }
|
||||
public string Role { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Alias { get; set; }
|
||||
public string Surname { get; set; }
|
||||
public string DisplayName { get; set; }
|
||||
|
||||
public string FullName => DisplayName ?? Alias ?? $"{Name} {Surname}";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user