diff --git a/Marechai/Pages/Admin/Details/Document.razor b/Marechai/Pages/Admin/Details/Document.razor
index b849c07e..e08f3c5f 100644
--- a/Marechai/Pages/Admin/Details/Document.razor
+++ b/Marechai/Pages/Admin/Details/Document.razor
@@ -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 @@
}
+
+ @L["Machines this document talks about"]
+
+ @if (_addingMachine)
+ {
+
+
+ @L[""]
+
+
+
+
+
+ }
+ @if (_documentMachines?.Count > 0)
+ {
+
+
+
+
+ |
+ @L["Machine"]
+ |
+ |
+
+
+
+ @foreach (var item in _documentMachines)
+ {
+
+ |
+ @item.Machine
+ |
+
+
+ |
+
+ }
+
+
+
+ }
+
diff --git a/Marechai/Pages/Admin/Details/Document.razor.cs b/Marechai/Pages/Admin/Details/Document.razor.cs
index 08b24260..cf5235d5 100644
--- a/Marechai/Pages/Admin/Details/Document.razor.cs
+++ b/Marechai/Pages/Admin/Details/Document.razor.cs
@@ -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 _companies;
List _countries;
bool _creating;
CompanyByDocumentViewModel _currentCompanyByDocument;
+ DocumentByMachineViewModel _currentDocumentByMachine;
DocumentByMachineFamilyViewModel _currentDocumentByMachineFamily;
bool _deleteInProgress;
string _deleteText;
string _deleteTitle;
bool _deletingCompanyByDocument;
+ bool _deletingDocumentByMachine;
bool _deletingDocumentByMachineFamily;
List _documentCompanies;
List _documentMachineFamilies;
+ List _documentMachines;
bool _editing;
Modal _frmDelete;
bool _loaded;
List _machineFamilies;
+ List _machines;
DocumentViewModel _model;
List _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();
+ }
}
}
\ No newline at end of file
diff --git a/Marechai/Resources/Services/DocumentsService.en.resx b/Marechai/Resources/Services/DocumentsService.en.resx
index 31718fe9..999dbe02 100644
--- a/Marechai/Resources/Services/DocumentsService.en.resx
+++ b/Marechai/Resources/Services/DocumentsService.en.resx
@@ -122,4 +122,25 @@
Family
+
+ Delete machine family from this document
+
+
+ Are you sure you want to delete the machine family {0} from this document?
+
+
+ Delete machine from this document
+
+
+ Are you sure you want to delete the machine {0} from this document?
+
+
+ Machine
+
+
+ Add new
+
+
+ Machines this document talks about
+
\ No newline at end of file
diff --git a/Marechai/Resources/Services/DocumentsService.es.resx b/Marechai/Resources/Services/DocumentsService.es.resx
index b216652c..8a797a82 100644
--- a/Marechai/Resources/Services/DocumentsService.es.resx
+++ b/Marechai/Resources/Services/DocumentsService.es.resx
@@ -238,4 +238,25 @@
Familias de máquinas sobre las que habla este documento
+
+ Añadir nueva
+
+
+ ¿Estás seguro de eliminar la familia de máquinas {0} de este documento?
+
+
+ ¿Estás seguro de eliminar la máquina {0} de este documento?
+
+
+ Eliminar familia de máquinas de este documento
+
+
+ Eliminar máquina de este documento
+
+
+ Máquina
+
+
+ Máquinas sobre las que habla este documento
+
\ No newline at end of file
diff --git a/Marechai/Services/DocumentsByMachineService.cs b/Marechai/Services/DocumentsByMachineService.cs
new file mode 100644
index 00000000..cac585e6
--- /dev/null
+++ b/Marechai/Services/DocumentsByMachineService.cs
@@ -0,0 +1,77 @@
+/******************************************************************************
+// MARECHAI: Master repository of computing history artifacts information
+// ----------------------------------------------------------------------------
+//
+// Author(s) : Natalia Portillo
+//
+// --[ 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 .
+//
+// ----------------------------------------------------------------------------
+// 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> 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 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;
+ }
+ }
+}
\ No newline at end of file
diff --git a/Marechai/Services/Register.cs b/Marechai/Services/Register.cs
index 857a5862..333a4096 100644
--- a/Marechai/Services/Register.cs
+++ b/Marechai/Services/Register.cs
@@ -89,6 +89,7 @@ namespace Marechai.Services
services.AddScoped();
services.AddScoped();
services.AddScoped();
+ services.AddScoped();
}
}
}
\ No newline at end of file
diff --git a/Marechai/ViewModels/DocumentByMachineViewModel.cs b/Marechai/ViewModels/DocumentByMachineViewModel.cs
new file mode 100644
index 00000000..e0c9f244
--- /dev/null
+++ b/Marechai/ViewModels/DocumentByMachineViewModel.cs
@@ -0,0 +1,35 @@
+/******************************************************************************
+// MARECHAI: Master repository of computing history artifacts information
+// ----------------------------------------------------------------------------
+//
+// Author(s) : Natalia Portillo
+//
+// --[ 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 .
+//
+// ----------------------------------------------------------------------------
+// Copyright © 2003-2020 Natalia Portillo
+*******************************************************************************/
+
+namespace Marechai.ViewModels
+{
+ public class DocumentByMachineViewModel : BaseViewModel
+ {
+ public long DocumentId { get; set; }
+ public string Document { get; set; }
+ public int MachineId { get; set; }
+ public string Machine { get; set; }
+ }
+}
\ No newline at end of file