mirror of
https://github.com/claunia/marechai.git
synced 2025-12-16 11:04:25 +00:00
Add machines to document admin page.
This commit is contained in:
@@ -38,6 +38,8 @@
|
||||
@inject CompaniesByDocumentService CompaniesByDocumentService
|
||||
@inject MachineFamiliesService MachineFamiliesService
|
||||
@inject DocumentsByMachineFamilyService DocumentsByMachineFamilyService
|
||||
@inject MachinesService MachinesService
|
||||
@inject DocumentsByMachineService DocumentsByMachineService
|
||||
@inject NavigationManager NavigationManager
|
||||
@inject IWebHostEnvironment Host
|
||||
@inject IJSRuntime JSRuntime
|
||||
@@ -254,6 +256,54 @@
|
||||
</div>
|
||||
}
|
||||
|
||||
<hr />
|
||||
<h3>@L["Machines this document talks about"]</h3>
|
||||
<Button Color="Color.Success" Clicked="OnAddMachineClick" Disabled="_addingMachine">@L["Add new (machine)"]</Button>
|
||||
@if (_addingMachine)
|
||||
{
|
||||
<div>
|
||||
<Field>
|
||||
<FieldLabel>@L[""]</FieldLabel>
|
||||
<Select Disabled="_savingMachine" TValue="int?" @bind-SelectedValue="@_addingMachineId">
|
||||
@foreach (var machine in _machines)
|
||||
{
|
||||
<SelectItem TValue="int?" Value="@machine.Id">@machine.Name</SelectItem>
|
||||
}
|
||||
</Select>
|
||||
</Field>
|
||||
<Button Color="Color.Primary" Clicked="@CancelAddMachine" Disabled="@_savingMachine">@L["Cancel"]</Button>
|
||||
<Button Color="Color.Success" Clicked="@ConfirmAddMachine" Disabled="@_savingMachine">@L["Add"]</Button>
|
||||
</div>
|
||||
}
|
||||
@if (_documentMachines?.Count > 0)
|
||||
{
|
||||
<div>
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>
|
||||
@L["Machine"]
|
||||
</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var item in _documentMachines)
|
||||
{
|
||||
<tr>
|
||||
<td>
|
||||
@item.Machine
|
||||
</td>
|
||||
<td>
|
||||
<Button Color="Color.Danger" Clicked="() => {ShowMachineDeleteModal(item.Id);}" Disabled="@_addingMachine">@L["Delete"]</Button>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
}
|
||||
|
||||
<Modal @ref="_frmDelete" IsCentered="true" Closing="@ModalClosing">
|
||||
<ModalBackdrop />
|
||||
<ModalContent Centered="true">
|
||||
|
||||
@@ -41,28 +41,35 @@ namespace Marechai.Pages.Admin.Details
|
||||
bool _addingCompany;
|
||||
int? _addingCompanyId;
|
||||
string _addingCompanyRoleId;
|
||||
bool _addingMachine;
|
||||
bool _addingMachineFamily;
|
||||
int? _addingMachineFamilyId;
|
||||
int? _addingMachineId;
|
||||
AuthenticationState _authState;
|
||||
List<DocumentCompanyViewModel> _companies;
|
||||
List<Iso31661Numeric> _countries;
|
||||
bool _creating;
|
||||
CompanyByDocumentViewModel _currentCompanyByDocument;
|
||||
DocumentByMachineViewModel _currentDocumentByMachine;
|
||||
DocumentByMachineFamilyViewModel _currentDocumentByMachineFamily;
|
||||
bool _deleteInProgress;
|
||||
string _deleteText;
|
||||
string _deleteTitle;
|
||||
bool _deletingCompanyByDocument;
|
||||
bool _deletingDocumentByMachine;
|
||||
bool _deletingDocumentByMachineFamily;
|
||||
List<CompanyByDocumentViewModel> _documentCompanies;
|
||||
List<DocumentByMachineFamilyViewModel> _documentMachineFamilies;
|
||||
List<DocumentByMachineViewModel> _documentMachines;
|
||||
bool _editing;
|
||||
Modal _frmDelete;
|
||||
bool _loaded;
|
||||
List<MachineFamilyViewModel> _machineFamilies;
|
||||
List<MachineViewModel> _machines;
|
||||
DocumentViewModel _model;
|
||||
List<DocumentRoleViewModel> _roles;
|
||||
bool _savingCompany;
|
||||
bool _savingMachine;
|
||||
bool _savingMachineFamily;
|
||||
bool _unknownCountry;
|
||||
bool _unknownNativeTitle;
|
||||
@@ -89,12 +96,15 @@ namespace Marechai.Pages.Admin.Details
|
||||
_companies = await CompaniesService.GetAsync();
|
||||
_roles = await DocumentRolesService.GetEnabledAsync();
|
||||
_machineFamilies = await MachineFamiliesService.GetAsync();
|
||||
_machines = await MachinesService.GetAsync();
|
||||
_model = _creating ? new DocumentViewModel() : await Service.GetAsync(Id);
|
||||
_authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
|
||||
_addingCompanyRoleId = _roles.First().Id;
|
||||
_documentCompanies = await CompaniesByDocumentService.GetByDocument(Id);
|
||||
_addingMachineFamilyId = _machineFamilies.First().Id;
|
||||
_documentMachineFamilies = await DocumentsByMachineFamilyService.GetByDocument(Id);
|
||||
_addingMachineId = _machines.First().Id;
|
||||
_documentMachines = await DocumentsByMachineService.GetByDocument(Id);
|
||||
|
||||
_editing = _creating || NavigationManager.ToBaseRelativePath(NavigationManager.Uri).ToLowerInvariant().
|
||||
StartsWith("admin/documents/edit/",
|
||||
@@ -241,6 +251,8 @@ namespace Marechai.Pages.Admin.Details
|
||||
_currentCompanyByDocument = null;
|
||||
_deletingDocumentByMachineFamily = false;
|
||||
_currentDocumentByMachineFamily = null;
|
||||
_deletingDocumentByMachine = false;
|
||||
_currentDocumentByMachine = null;
|
||||
}
|
||||
|
||||
void HideModal() => _frmDelete.Hide();
|
||||
@@ -251,6 +263,8 @@ namespace Marechai.Pages.Admin.Details
|
||||
await ConfirmDeleteCompanyByMachine();
|
||||
else if(_deletingDocumentByMachineFamily)
|
||||
await ConfirmDeleteDocumentByMachineFamily();
|
||||
else if(_deletingDocumentByMachine)
|
||||
await ConfirmDeleteDocumentByMachine();
|
||||
}
|
||||
|
||||
async Task ConfirmDeleteCompanyByMachine()
|
||||
@@ -359,5 +373,87 @@ namespace Marechai.Pages.Admin.Details
|
||||
// Tell we finished loading
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
void OnAddMachineClick()
|
||||
{
|
||||
_addingMachine = true;
|
||||
_savingMachine = false;
|
||||
_addingMachineId = _machines.First().Id;
|
||||
}
|
||||
|
||||
void CancelAddMachine()
|
||||
{
|
||||
_addingMachine = false;
|
||||
_savingMachine = false;
|
||||
_addingMachineId = null;
|
||||
}
|
||||
|
||||
async Task ConfirmAddMachine()
|
||||
{
|
||||
if(_addingMachineId is null ||
|
||||
_addingMachineId <= 0)
|
||||
{
|
||||
CancelAddMachine();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
_savingMachine = true;
|
||||
|
||||
// Yield thread to let UI to update
|
||||
await Task.Yield();
|
||||
|
||||
await DocumentsByMachineService.CreateAsync(_addingMachineId.Value, Id,
|
||||
(await UserManager.GetUserAsync(_authState.User)).Id);
|
||||
|
||||
_documentMachines = await DocumentsByMachineService.GetByDocument(Id);
|
||||
|
||||
_addingMachine = false;
|
||||
_savingMachine = false;
|
||||
_addingMachineId = null;
|
||||
|
||||
// Yield thread to let UI to update
|
||||
await Task.Yield();
|
||||
|
||||
// Tell we finished loading
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
void ShowMachineDeleteModal(long itemId)
|
||||
{
|
||||
_currentDocumentByMachine = _documentMachines.FirstOrDefault(n => n.Id == itemId);
|
||||
_deletingDocumentByMachine = true;
|
||||
_deleteTitle = L["Delete machine from this document"];
|
||||
|
||||
_deleteText = string.Format(L["Are you sure you want to delete the machine {0} from this document?"],
|
||||
_currentDocumentByMachine?.Machine);
|
||||
|
||||
_frmDelete.Show();
|
||||
}
|
||||
|
||||
async Task ConfirmDeleteDocumentByMachine()
|
||||
{
|
||||
if(_currentDocumentByMachine is null)
|
||||
return;
|
||||
|
||||
_deleteInProgress = true;
|
||||
|
||||
// Yield thread to let UI to update
|
||||
await Task.Yield();
|
||||
|
||||
await DocumentsByMachineService.DeleteAsync(_currentDocumentByMachine.Id,
|
||||
(await UserManager.GetUserAsync(_authState.User)).Id);
|
||||
|
||||
_documentMachines = await DocumentsByMachineService.GetByDocument(Id);
|
||||
|
||||
_deleteInProgress = false;
|
||||
_frmDelete.Hide();
|
||||
|
||||
// Yield thread to let UI to update
|
||||
await Task.Yield();
|
||||
|
||||
// Tell we finished loading
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -122,4 +122,25 @@
|
||||
<data name="Family" xml:space="preserve">
|
||||
<value>Family</value>
|
||||
</data>
|
||||
<data name="Delete machine family from this document" xml:space="preserve">
|
||||
<value>Delete machine family from this document</value>
|
||||
</data>
|
||||
<data name="Are you sure you want to delete the machine family {0} from this document?" xml:space="preserve">
|
||||
<value>Are you sure you want to delete the machine family {0} from this document?</value>
|
||||
</data>
|
||||
<data name="Delete machine from this document" xml:space="preserve">
|
||||
<value>Delete machine from this document</value>
|
||||
</data>
|
||||
<data name="Are you sure you want to delete the machine {0} from this document?" xml:space="preserve">
|
||||
<value>Are you sure you want to delete the machine {0} from this document?</value>
|
||||
</data>
|
||||
<data name="Machine" xml:space="preserve">
|
||||
<value>Machine</value>
|
||||
</data>
|
||||
<data name="Add new (machine)" xml:space="preserve">
|
||||
<value>Add new</value>
|
||||
</data>
|
||||
<data name="Machines this document talks about" xml:space="preserve">
|
||||
<value>Machines this document talks about</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -238,4 +238,25 @@
|
||||
<data name="Machine families this document talks about" xml:space="preserve">
|
||||
<value>Familias de máquinas sobre las que habla este documento</value>
|
||||
</data>
|
||||
<data name="Add new (machine)" xml:space="preserve">
|
||||
<value>Añadir nueva</value>
|
||||
</data>
|
||||
<data name="Are you sure you want to delete the machine family {0} from this document?" xml:space="preserve">
|
||||
<value>¿Estás seguro de eliminar la familia de máquinas {0} de este documento?</value>
|
||||
</data>
|
||||
<data name="Are you sure you want to delete the machine {0} from this document?" xml:space="preserve">
|
||||
<value>¿Estás seguro de eliminar la máquina {0} de este documento?</value>
|
||||
</data>
|
||||
<data name="Delete machine family from this document" xml:space="preserve">
|
||||
<value>Eliminar familia de máquinas de este documento</value>
|
||||
</data>
|
||||
<data name="Delete machine from this document" xml:space="preserve">
|
||||
<value>Eliminar máquina de este documento</value>
|
||||
</data>
|
||||
<data name="Machine" xml:space="preserve">
|
||||
<value>Máquina</value>
|
||||
</data>
|
||||
<data name="Machines this document talks about" xml:space="preserve">
|
||||
<value>Máquinas sobre las que habla este documento</value>
|
||||
</data>
|
||||
</root>
|
||||
77
Marechai/Services/DocumentsByMachineService.cs
Normal file
77
Marechai/Services/DocumentsByMachineService.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 DocumentsByMachineService
|
||||
{
|
||||
readonly MarechaiContext _context;
|
||||
|
||||
public DocumentsByMachineService(MarechaiContext context) => _context = context;
|
||||
|
||||
public async Task<List<DocumentByMachineViewModel>> GetByDocument(long bookId) =>
|
||||
await _context.DocumentsByMachines.Where(p => p.DocumentId == bookId).
|
||||
Select(p => new DocumentByMachineViewModel
|
||||
{
|
||||
Id = p.Id,
|
||||
DocumentId = p.DocumentId,
|
||||
MachineId = p.MachineId,
|
||||
Machine = p.Machine.Name
|
||||
}).OrderBy(p => p.Machine).ThenBy(p => p.Document).ToListAsync();
|
||||
|
||||
public async Task DeleteAsync(long id, string userId)
|
||||
{
|
||||
DocumentsByMachine item = await _context.DocumentsByMachines.FindAsync(id);
|
||||
|
||||
if(item is null)
|
||||
return;
|
||||
|
||||
_context.DocumentsByMachines.Remove(item);
|
||||
|
||||
await _context.SaveChangesWithUserAsync(userId);
|
||||
}
|
||||
|
||||
public async Task<long> CreateAsync(int machineId, long bookId, string userId)
|
||||
{
|
||||
var item = new DocumentsByMachine
|
||||
{
|
||||
MachineId = machineId,
|
||||
DocumentId = bookId
|
||||
};
|
||||
|
||||
await _context.DocumentsByMachines.AddAsync(item);
|
||||
await _context.SaveChangesWithUserAsync(userId);
|
||||
|
||||
return item.Id;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -89,6 +89,7 @@ namespace Marechai.Services
|
||||
services.AddScoped<DocumentsByMachineFamilyService>();
|
||||
services.AddScoped<MagazinesByMachineFamilyService>();
|
||||
services.AddScoped<BooksByMachineService>();
|
||||
services.AddScoped<DocumentsByMachineService>();
|
||||
}
|
||||
}
|
||||
}
|
||||
35
Marechai/ViewModels/DocumentByMachineViewModel.cs
Normal file
35
Marechai/ViewModels/DocumentByMachineViewModel.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 DocumentByMachineViewModel : BaseViewModel<long>
|
||||
{
|
||||
public long DocumentId { get; set; }
|
||||
public string Document { get; set; }
|
||||
public int MachineId { get; set; }
|
||||
public string Machine { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user