mirror of
https://github.com/claunia/marechai.git
synced 2025-12-16 11:04:25 +00:00
Add machine families to book admin page.
This commit is contained in:
@@ -36,6 +36,8 @@
|
||||
@inject DocumentCompaniesService CompaniesService
|
||||
@inject DocumentRolesService DocumentRolesService
|
||||
@inject CompaniesByBookService CompaniesByBookService
|
||||
@inject MachineFamiliesService MachineFamiliesService
|
||||
@inject BooksByMachineFamilyService BooksByMachineFamilyService
|
||||
@inject NavigationManager NavigationManager
|
||||
@inject IWebHostEnvironment Host
|
||||
@inject IJSRuntime JSRuntime
|
||||
@@ -239,8 +241,8 @@
|
||||
}
|
||||
</Select>
|
||||
</Field>
|
||||
<Button Color="Color.Primary" Clicked="@CancelAddCpu" Disabled="@_savingCompany">@L["Cancel"]</Button>
|
||||
<Button Color="Color.Success" Clicked="@ConfirmAddCpu" Disabled="@_savingCompany">@L["Add"]</Button>
|
||||
<Button Color="Color.Primary" Clicked="@CancelAddCompany" Disabled="@_savingCompany">@L["Cancel"]</Button>
|
||||
<Button Color="Color.Success" Clicked="@ConfirmAddCompany" Disabled="@_savingCompany">@L["Add"]</Button>
|
||||
</div>
|
||||
}
|
||||
@if (_bookCompanies?.Count > 0)
|
||||
@@ -269,7 +271,55 @@
|
||||
@item.Role
|
||||
</td>
|
||||
<td>
|
||||
<Button Color="Color.Danger" Clicked="() => {ShowCpuDeleteModal(item.Id);}" Disabled="@_addingCompany">@L["Delete"]</Button>
|
||||
<Button Color="Color.Danger" Clicked="() => {ShowCompanyDeleteModal(item.Id);}" Disabled="@_addingCompany">@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>
|
||||
@if (_addingMachineFamily)
|
||||
{
|
||||
<div>
|
||||
<Field>
|
||||
<FieldLabel>@L["Family"]</FieldLabel>
|
||||
<Select Disabled="_savingMachineFamily" TValue="int?" @bind-SelectedValue="@_addingMachineFamilyId">
|
||||
@foreach (var family in _machineFamilies)
|
||||
{
|
||||
<SelectItem TValue="int?" Value="@family.Id">@family.Name</SelectItem>
|
||||
}
|
||||
</Select>
|
||||
</Field>
|
||||
<Button Color="Color.Primary" Clicked="@CancelAddFamily" Disabled="@_savingMachineFamily">@L["Cancel"]</Button>
|
||||
<Button Color="Color.Success" Clicked="@ConfirmAddFamily" Disabled="@_savingMachineFamily">@L["Add"]</Button>
|
||||
</div>
|
||||
}
|
||||
@if (_bookMachineFamilies?.Count > 0)
|
||||
{
|
||||
<div>
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>
|
||||
@L["Family"]
|
||||
</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var item in _bookMachineFamilies)
|
||||
{
|
||||
<tr>
|
||||
<td>
|
||||
@item.MachineFamily
|
||||
</td>
|
||||
<td>
|
||||
<Button Color="Color.Danger" Clicked="() => {ShowMachineFamilyDeleteModal(item.Id);}" Disabled="@_addingMachineFamily">@L["Delete"]</Button>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
|
||||
@@ -38,31 +38,38 @@ namespace Marechai.Pages.Admin.Details
|
||||
{
|
||||
public partial class Book
|
||||
{
|
||||
bool _addingCompany;
|
||||
int? _addingCompanyId;
|
||||
string _addingCompanyRoleId;
|
||||
AuthenticationState _authState;
|
||||
List<CompanyByBookViewModel> _bookCompanies;
|
||||
List<DocumentCompanyViewModel> _companies;
|
||||
List<Iso31661Numeric> _countries;
|
||||
bool _creating;
|
||||
CompanyByBookViewModel _currentCompanyByBook;
|
||||
bool _deleteInProgress;
|
||||
string _deleteText;
|
||||
string _deleteTitle;
|
||||
bool _deletingCompanyByBook;
|
||||
bool _editing;
|
||||
Modal _frmDelete;
|
||||
bool _loaded;
|
||||
BookViewModel _model;
|
||||
List<DocumentRoleViewModel> _roles;
|
||||
bool _savingCompany;
|
||||
bool _unknownCountry;
|
||||
bool _unknownEdition;
|
||||
bool _unknownIsbn;
|
||||
bool _unknownNativeTitle;
|
||||
bool _unknownPages;
|
||||
bool _unknownPublished;
|
||||
bool _addingCompany;
|
||||
int? _addingCompanyId;
|
||||
string _addingCompanyRoleId;
|
||||
bool _addingMachineFamily;
|
||||
int? _addingMachineFamilyId;
|
||||
AuthenticationState _authState;
|
||||
List<CompanyByBookViewModel> _bookCompanies;
|
||||
List<BookByMachineFamilyViewModel> _bookMachineFamilies;
|
||||
List<DocumentCompanyViewModel> _companies;
|
||||
List<Iso31661Numeric> _countries;
|
||||
bool _creating;
|
||||
BookByMachineFamilyViewModel _currentBookByMachineFamily;
|
||||
CompanyByBookViewModel _currentCompanyByBook;
|
||||
bool _deleteInProgress;
|
||||
string _deleteText;
|
||||
string _deleteTitle;
|
||||
bool _deletingBookByMachineFamily;
|
||||
bool _deletingCompanyByBook;
|
||||
bool _editing;
|
||||
Modal _frmDelete;
|
||||
bool _loaded;
|
||||
List<MachineFamilyViewModel> _machineFamilies;
|
||||
BookViewModel _model;
|
||||
List<DocumentRoleViewModel> _roles;
|
||||
bool _savingCompany;
|
||||
bool _savingMachineFamily;
|
||||
bool _unknownCountry;
|
||||
bool _unknownEdition;
|
||||
bool _unknownIsbn;
|
||||
bool _unknownNativeTitle;
|
||||
bool _unknownPages;
|
||||
bool _unknownPublished;
|
||||
|
||||
[Parameter]
|
||||
public long Id { get; set; }
|
||||
@@ -81,14 +88,16 @@ namespace Marechai.Pages.Admin.Details
|
||||
!_creating)
|
||||
return;
|
||||
|
||||
_countries = await CountriesService.GetAsync();
|
||||
_companies = await CompaniesService.GetAsync();
|
||||
_roles = await DocumentRolesService.GetEnabledAsync();
|
||||
_machineFamilies = await MachineFamiliesService.GetAsync();
|
||||
_model = _creating ? new BookViewModel() : await Service.GetAsync(Id);
|
||||
_authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
|
||||
_addingCompanyRoleId = _roles.First().Id;
|
||||
_bookCompanies = await CompaniesByBookService.GetByBook(Id);
|
||||
_countries = await CountriesService.GetAsync();
|
||||
_companies = await CompaniesService.GetAsync();
|
||||
_roles = await DocumentRolesService.GetEnabledAsync();
|
||||
_machineFamilies = await MachineFamiliesService.GetAsync();
|
||||
_model = _creating ? new BookViewModel() : await Service.GetAsync(Id);
|
||||
_authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
|
||||
_addingCompanyRoleId = _roles.First().Id;
|
||||
_bookCompanies = await CompaniesByBookService.GetByBook(Id);
|
||||
_addingMachineFamilyId = _machineFamilies.First().Id;
|
||||
_bookMachineFamilies = await BooksByMachineFamilyService.GetByBook(Id);
|
||||
|
||||
_editing = _creating || NavigationManager.ToBaseRelativePath(NavigationManager.Uri).ToLowerInvariant().
|
||||
StartsWith("admin/books/edit/",
|
||||
@@ -225,19 +234,19 @@ namespace Marechai.Pages.Admin.Details
|
||||
_addingCompanyId = _companies.First().Id;
|
||||
}
|
||||
|
||||
void CancelAddCpu()
|
||||
void CancelAddCompany()
|
||||
{
|
||||
_addingCompany = false;
|
||||
_savingCompany = false;
|
||||
_addingCompanyId = null;
|
||||
}
|
||||
|
||||
async Task ConfirmAddCpu()
|
||||
async Task ConfirmAddCompany()
|
||||
{
|
||||
if(_addingCompanyId is null ||
|
||||
_addingCompanyId <= 0)
|
||||
{
|
||||
CancelAddCpu();
|
||||
CancelAddCompany();
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -263,7 +272,7 @@ namespace Marechai.Pages.Admin.Details
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
void ShowCpuDeleteModal(long itemId)
|
||||
void ShowCompanyDeleteModal(long itemId)
|
||||
{
|
||||
_currentCompanyByBook = _bookCompanies.FirstOrDefault(n => n.Id == itemId);
|
||||
_deletingCompanyByBook = true;
|
||||
@@ -288,10 +297,12 @@ namespace Marechai.Pages.Admin.Details
|
||||
async void ConfirmDelete()
|
||||
{
|
||||
if(_deletingCompanyByBook)
|
||||
await ConfirmDeleteCpuByMachine();
|
||||
await ConfirmDeleteCompanyByBook();
|
||||
else if(_deletingBookByMachineFamily)
|
||||
await ConfirmDeleteBookByMachineFamily();
|
||||
}
|
||||
|
||||
async Task ConfirmDeleteCpuByMachine()
|
||||
async Task ConfirmDeleteCompanyByBook()
|
||||
{
|
||||
if(_currentCompanyByBook is null)
|
||||
return;
|
||||
@@ -315,5 +326,87 @@ namespace Marechai.Pages.Admin.Details
|
||||
// Tell we finished loading
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
void OnAddFamilyClick()
|
||||
{
|
||||
_addingMachineFamily = true;
|
||||
_savingMachineFamily = false;
|
||||
_addingMachineFamilyId = _machineFamilies.First().Id;
|
||||
}
|
||||
|
||||
void CancelAddFamily()
|
||||
{
|
||||
_addingMachineFamily = false;
|
||||
_savingMachineFamily = false;
|
||||
_addingMachineFamilyId = null;
|
||||
}
|
||||
|
||||
async Task ConfirmAddFamily()
|
||||
{
|
||||
if(_addingMachineFamilyId is null ||
|
||||
_addingMachineFamilyId <= 0)
|
||||
{
|
||||
CancelAddFamily();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
_savingMachineFamily = true;
|
||||
|
||||
// Yield thread to let UI to update
|
||||
await Task.Yield();
|
||||
|
||||
await BooksByMachineFamilyService.CreateAsync(_addingMachineFamilyId.Value, Id,
|
||||
(await UserManager.GetUserAsync(_authState.User)).Id);
|
||||
|
||||
_bookMachineFamilies = await BooksByMachineFamilyService.GetByBook(Id);
|
||||
|
||||
_addingMachineFamily = false;
|
||||
_savingMachineFamily = false;
|
||||
_addingMachineFamilyId = null;
|
||||
|
||||
// Yield thread to let UI to update
|
||||
await Task.Yield();
|
||||
|
||||
// Tell we finished loading
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
void ShowMachineFamilyDeleteModal(long itemId)
|
||||
{
|
||||
_currentBookByMachineFamily = _bookMachineFamilies.FirstOrDefault(n => n.Id == itemId);
|
||||
_deletingBookByMachineFamily = true;
|
||||
_deleteTitle = L["Delete machine family from this book"];
|
||||
|
||||
_deleteText = string.Format(L["Are you sure you want to delete the machine family {0} from this book?"],
|
||||
_currentBookByMachineFamily?.MachineFamily);
|
||||
|
||||
_frmDelete.Show();
|
||||
}
|
||||
|
||||
async Task ConfirmDeleteBookByMachineFamily()
|
||||
{
|
||||
if(_currentBookByMachineFamily is null)
|
||||
return;
|
||||
|
||||
_deleteInProgress = true;
|
||||
|
||||
// Yield thread to let UI to update
|
||||
await Task.Yield();
|
||||
|
||||
await BooksByMachineFamilyService.DeleteAsync(_currentBookByMachineFamily.Id,
|
||||
(await UserManager.GetUserAsync(_authState.User)).Id);
|
||||
|
||||
_bookMachineFamilies = await BooksByMachineFamilyService.GetByBook(Id);
|
||||
|
||||
_deleteInProgress = false;
|
||||
_frmDelete.Hide();
|
||||
|
||||
// Yield thread to let UI to update
|
||||
await Task.Yield();
|
||||
|
||||
// Tell we finished loading
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -137,4 +137,13 @@
|
||||
<data name="Are you sure you want to delete the company {0} with role {1} from this book?" xml:space="preserve">
|
||||
<value>Are you sure you want to delete the company {0} with role {1} from this book?</value>
|
||||
</data>
|
||||
<data name="Machine families this book talks about" xml:space="preserve">
|
||||
<value>Machine families this book talks about</value>
|
||||
</data>
|
||||
<data name="Add new (machine family)" xml:space="preserve">
|
||||
<value>Add new</value>
|
||||
</data>
|
||||
<data name="Family" xml:space="preserve">
|
||||
<value>Family</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -253,4 +253,13 @@
|
||||
<data name="Are you sure you want to delete the company {0} with role {1} from this book?" xml:space="preserve">
|
||||
<value>¿Estás seguro de eliminar la compañía {0} con el rol {1} de este libro?</value>
|
||||
</data>
|
||||
<data name="Machine families this book talks about" xml:space="preserve">
|
||||
<value>Familias de máquinas sobre las que habla este libro</value>
|
||||
</data>
|
||||
<data name="Add new (machine family)" xml:space="preserve">
|
||||
<value>Añadir nueva</value>
|
||||
</data>
|
||||
<data name="Family" xml:space="preserve">
|
||||
<value>Familia</value>
|
||||
</data>
|
||||
</root>
|
||||
77
Marechai/Services/BooksByMachineFamilyService.cs
Normal file
77
Marechai/Services/BooksByMachineFamilyService.cs
Normal file
@@ -0,0 +1,77 @@
|
||||
/******************************************************************************
|
||||
// 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 BooksByMachineFamilyService
|
||||
{
|
||||
readonly MarechaiContext _context;
|
||||
|
||||
public BooksByMachineFamilyService(MarechaiContext context) => _context = context;
|
||||
|
||||
public async Task<List<BookByMachineFamilyViewModel>> GetByBook(long bookId) =>
|
||||
await _context.BooksByMachineFamilies.Where(p => p.BookId == bookId).
|
||||
Select(p => new BookByMachineFamilyViewModel
|
||||
{
|
||||
Id = p.Id,
|
||||
BookId = p.BookId,
|
||||
MachineFamilyId = p.MachineFamilyId,
|
||||
MachineFamily = p.MachineFamily.Name
|
||||
}).OrderBy(p => p.MachineFamily).ThenBy(p => p.Book).ToListAsync();
|
||||
|
||||
public async Task DeleteAsync(long id, string userId)
|
||||
{
|
||||
BooksByMachineFamily item = await _context.BooksByMachineFamilies.FindAsync(id);
|
||||
|
||||
if(item is null)
|
||||
return;
|
||||
|
||||
_context.BooksByMachineFamilies.Remove(item);
|
||||
|
||||
await _context.SaveChangesWithUserAsync(userId);
|
||||
}
|
||||
|
||||
public async Task<long> CreateAsync(int machineFamilyId, long bookId, string userId)
|
||||
{
|
||||
var item = new BooksByMachineFamily
|
||||
{
|
||||
MachineFamilyId = machineFamilyId,
|
||||
BookId = bookId
|
||||
};
|
||||
|
||||
await _context.BooksByMachineFamilies.AddAsync(item);
|
||||
await _context.SaveChangesWithUserAsync(userId);
|
||||
|
||||
return item.Id;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -85,6 +85,7 @@ namespace Marechai.Services
|
||||
services.AddScoped<CompaniesBySoftwareVariantService>();
|
||||
services.AddScoped<CompaniesBySoftwareVersionService>();
|
||||
services.AddScoped<DocumentRolesService>();
|
||||
services.AddScoped<BooksByMachineFamilyService>();
|
||||
}
|
||||
}
|
||||
}
|
||||
35
Marechai/ViewModels/BookByMachineFamilyViewModel.cs
Normal file
35
Marechai/ViewModels/BookByMachineFamilyViewModel.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
/******************************************************************************
|
||||
// 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 BookByMachineFamilyViewModel : BaseViewModel<long>
|
||||
{
|
||||
public long BookId { get; set; }
|
||||
public string Book { get; set; }
|
||||
public int MachineFamilyId { get; set; }
|
||||
public string MachineFamily { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user