diff --git a/Marechai.Database/Models/CompaniesBySoftwareVersion.cs b/Marechai.Database/Models/CompaniesBySoftwareVersion.cs index 544ef7d4..fe9b6a66 100644 --- a/Marechai.Database/Models/CompaniesBySoftwareVersion.cs +++ b/Marechai.Database/Models/CompaniesBySoftwareVersion.cs @@ -35,5 +35,9 @@ namespace Marechai.Database.Models public virtual SoftwareVersion SoftwareVersion { get; set; } [Required] public virtual DocumentRole Role { get; set; } + + public string RoleId { get; set; } + public int CompanyId { get; set; } + public ulong SoftwareVersionId { get; set; } } } \ No newline at end of file diff --git a/Marechai.Database/Models/MarechaiContext.cs b/Marechai.Database/Models/MarechaiContext.cs index c57f910c..259539c7 100644 --- a/Marechai.Database/Models/MarechaiContext.cs +++ b/Marechai.Database/Models/MarechaiContext.cs @@ -126,6 +126,9 @@ namespace Marechai.Database.Models public virtual DbSet MasteringTexts { get; set; } public virtual DbSet MediaTagDumps { get; set; } public virtual DbSet SoftwareVariantByCompilationMedia { get; set; } + public virtual DbSet CompaniesBySoftwareFamilies { get; set; } + public virtual DbSet CompaniesBySoftwareVariants { get; set; } + public virtual DbSet CompaniesBySoftwareVersions { get; set; } protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { @@ -1839,6 +1842,8 @@ namespace Marechai.Database.Models modelBuilder.Entity(entity => { + entity.ToTable("CompaniesBySoftwareFamily"); + entity.HasOne(d => d.Company).WithMany(p => p.SoftwareFamilies).OnDelete(DeleteBehavior.Cascade); entity.HasOne(d => d.SoftwareFamily).WithMany(p => p.Companies).OnDelete(DeleteBehavior.Cascade); }); @@ -1864,6 +1869,8 @@ namespace Marechai.Database.Models modelBuilder.Entity(entity => { + entity.ToTable("CompaniesBySoftwareVersion"); + entity.HasOne(d => d.Company).WithMany(p => p.SoftwareVersions).OnDelete(DeleteBehavior.Cascade); entity.HasOne(d => d.SoftwareVersion).WithMany(p => p.Companies).OnDelete(DeleteBehavior.Cascade); }); @@ -1894,6 +1901,8 @@ namespace Marechai.Database.Models modelBuilder.Entity(entity => { + entity.ToTable("CompaniesBySoftwareVariant"); + entity.HasOne(d => d.Company).WithMany(p => p.SoftwareVariants).OnDelete(DeleteBehavior.Cascade); entity.HasOne(d => d.SoftwareVariant).WithMany(p => p.Companies).OnDelete(DeleteBehavior.Cascade); }); diff --git a/Marechai/Marechai.csproj b/Marechai/Marechai.csproj index 23e63ae5..7bc348be 100644 --- a/Marechai/Marechai.csproj +++ b/Marechai/Marechai.csproj @@ -2,7 +2,7 @@ netcoreapp3.1 - 4.0.0.1817 + 4.0.0.1820 Canary Islands Computer Museum Copyright © 2003-2020 Natalia Portillo Canary Islands Computer Museum Website diff --git a/Marechai/Pages/Admin/Details/SoftwareVersion.razor b/Marechai/Pages/Admin/Details/SoftwareVersion.razor index efd80de3..1b467933 100644 --- a/Marechai/Pages/Admin/Details/SoftwareVersion.razor +++ b/Marechai/Pages/Admin/Details/SoftwareVersion.razor @@ -34,6 +34,9 @@ @inject IStringLocalizer L @inject SoftwareFamiliesService SoftwareFamiliesService @inject LicensesService LicensesService +@inject CompaniesService CompaniesService +@inject DocumentRolesService DocumentRolesService +@inject CompaniesBySoftwareVersionService CompaniesBySoftwareVersionService @inject NavigationManager NavigationManager @inject IWebHostEnvironment Host @inject IJSRuntime JSRuntime @@ -187,3 +190,85 @@ } @L["Back to list"] +@if (!_editing) +{ +
+

@L["Companies involved in this software version"]

+ + @if (_addingCompany) + { +
+ + @L["Company"] + + + + @L["Role"] + + + + +
+ } + @if (_softwareVersionCompanies?.Count > 0) + { +
+ + + + + + + + + + @foreach (var item in _softwareVersionCompanies) + { + + + + + + } + +
+ @L["Company"] + + @L["Role"] +
+ @item.Company + + @item.Role + + +
+
+ } + + + + + + @_deleteTitle + + + + @_deleteText + + + + + + + +} \ No newline at end of file diff --git a/Marechai/Pages/Admin/Details/SoftwareVersion.razor.cs b/Marechai/Pages/Admin/Details/SoftwareVersion.razor.cs index 7b77bca4..37262255 100644 --- a/Marechai/Pages/Admin/Details/SoftwareVersion.razor.cs +++ b/Marechai/Pages/Admin/Details/SoftwareVersion.razor.cs @@ -25,6 +25,7 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Threading.Tasks; using Blazorise; using Marechai.Shared; @@ -36,20 +37,32 @@ namespace Marechai.Pages.Admin.Details { public partial class SoftwareVersion { - AuthenticationState _authState; - bool _creating; - bool _editing; - List _licenses; - bool _loaded; - SoftwareVersionViewModel _model; - List _softwareFamilies; - List _softwareVersions; - bool _unknownCodename; - bool _unknownIntroduced; - bool _unknownLicense; - - bool _unknownName; - bool _unknownPrevious; + bool _addingCompany; + int? _addingCompanyId; + string _addingCompanyRoleId; + AuthenticationState _authState; + List _companies; + bool _creating; + CompanyBySoftwareVersionViewModel _currentCompanyBySoftwareVersion; + bool _deleteInProgress; + string _deleteText; + string _deleteTitle; + bool _deletingCompanyBySoftwareVersion; + bool _editing; + Modal _frmDelete; + List _licenses; + bool _loaded; + SoftwareVersionViewModel _model; + List _roles; + bool _savingCompany; + List _softwareFamilies; + List _softwareVersionCompanies; + List _softwareVersions; + bool _unknownCodename; + bool _unknownIntroduced; + bool _unknownLicense; + bool _unknownName; + bool _unknownPrevious; [Parameter] public ulong Id { get; set; } @@ -69,11 +82,14 @@ namespace Marechai.Pages.Admin.Details !_creating) return; - _softwareVersions = await Service.GetAsync(); - _softwareFamilies = await SoftwareFamiliesService.GetAsync(); - _licenses = await LicensesService.GetAsync(); - _model = _creating ? new SoftwareVersionViewModel() : await Service.GetAsync(Id); - _authState = await AuthenticationStateProvider.GetAuthenticationStateAsync(); + _softwareVersions = await Service.GetAsync(); + _softwareFamilies = await SoftwareFamiliesService.GetAsync(); + _licenses = await LicensesService.GetAsync(); + _companies = await CompaniesService.GetAsync(); + _roles = await DocumentRolesService.GetEnabledAsync(); + _model = _creating ? new SoftwareVersionViewModel() : await Service.GetAsync(Id); + _authState = await AuthenticationStateProvider.GetAuthenticationStateAsync(); + _addingCompanyRoleId = _roles.First().Id; _editing = _creating || NavigationManager.ToBaseRelativePath(NavigationManager.Uri).ToLowerInvariant(). StartsWith("admin/software_versions/edit/", @@ -169,5 +185,103 @@ namespace Marechai.Pages.Admin.Details Validators.ValidateString(e, L["Version must be smaller than 256 characters."], 256); void ValidateIntroduced(ValidatorEventArgs e) => Validators.ValidateDate(e); + + void OnAddCompanyClick() + { + _addingCompany = true; + _savingCompany = false; + _addingCompanyId = _companies.First().Id; + } + + void CancelAddCpu() + { + _addingCompany = false; + _savingCompany = false; + _addingCompanyId = null; + } + + async Task ConfirmAddCpu() + { + if(_addingCompanyId is null || + _addingCompanyId <= 0) + { + CancelAddCpu(); + + return; + } + + _savingCompany = true; + + // Yield thread to let UI to update + await Task.Yield(); + + await CompaniesBySoftwareVersionService.CreateAsync(_addingCompanyId.Value, Id, _addingCompanyRoleId, + (await UserManager.GetUserAsync(_authState.User)).Id); + + _softwareVersionCompanies = await CompaniesBySoftwareVersionService.GetBySoftwareVersion(Id); + + _addingCompany = false; + _savingCompany = false; + _addingCompanyId = null; + + // Yield thread to let UI to update + await Task.Yield(); + + // Tell we finished loading + StateHasChanged(); + } + + void ShowCpuDeleteModal(ulong itemId) + { + _currentCompanyBySoftwareVersion = _softwareVersionCompanies.FirstOrDefault(n => n.Id == itemId); + _deletingCompanyBySoftwareVersion = true; + _deleteTitle = L["Delete company from this software version"]; + + _deleteText = + string.Format(L["Are you sure you want to delete the company {0} with role {1} from this software version?"], + _currentCompanyBySoftwareVersion?.Company, _currentCompanyBySoftwareVersion?.Role); + + _frmDelete.Show(); + } + + void ModalClosing(ModalClosingEventArgs obj) + { + _deleteInProgress = false; + _deletingCompanyBySoftwareVersion = false; + _currentCompanyBySoftwareVersion = null; + } + + void HideModal() => _frmDelete.Hide(); + + async void ConfirmDelete() + { + if(_deletingCompanyBySoftwareVersion) + await ConfirmDeleteCpuByMachine(); + } + + async Task ConfirmDeleteCpuByMachine() + { + if(_currentCompanyBySoftwareVersion is null) + return; + + _deleteInProgress = true; + + // Yield thread to let UI to update + await Task.Yield(); + + await CompaniesBySoftwareVersionService.DeleteAsync(_currentCompanyBySoftwareVersion.Id, + (await UserManager.GetUserAsync(_authState.User)).Id); + + _softwareVersionCompanies = await CompaniesBySoftwareVersionService.GetBySoftwareVersion(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/SoftwareVersionsService.en.resx b/Marechai/Resources/Services/SoftwareVersionsService.en.resx index aced7c94..5d800ba9 100644 --- a/Marechai/Resources/Services/SoftwareVersionsService.en.resx +++ b/Marechai/Resources/Services/SoftwareVersionsService.en.resx @@ -101,4 +101,25 @@ Back to list + + Companies involved in this software version + + + Add new + + + Company + + + Role + + + Add + + + Delete company from this software version + + + Are you sure you want to delete the company {0} with role {1} from this software version? + \ No newline at end of file diff --git a/Marechai/Resources/Services/SoftwareVersionsService.es.resx b/Marechai/Resources/Services/SoftwareVersionsService.es.resx index cd5dfc89..d4221ab4 100644 --- a/Marechai/Resources/Services/SoftwareVersionsService.es.resx +++ b/Marechai/Resources/Services/SoftwareVersionsService.es.resx @@ -208,4 +208,25 @@ Volver a la lista + + Compañías involucradas en esta versión de software + + + Añadir nueva + + + Compañía + + + Rol + + + Añadir + + + Eliminar compañía de esta versión de software + + + ¿Estás seguro de eliminar la compañía {0} con rol {1} de esta versión de software? + \ No newline at end of file diff --git a/Marechai/Services/CompaniesBySoftwareVersionService.cs b/Marechai/Services/CompaniesBySoftwareVersionService.cs new file mode 100644 index 00000000..7259e320 --- /dev/null +++ b/Marechai/Services/CompaniesBySoftwareVersionService.cs @@ -0,0 +1,80 @@ +/****************************************************************************** +// 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 CompaniesBySoftwareVersionService + { + readonly MarechaiContext _context; + + public CompaniesBySoftwareVersionService(MarechaiContext context) => _context = context; + + public async Task> GetBySoftwareVersion(ulong softwareVersionId) => + await _context.CompaniesBySoftwareVersions.Where(p => p.SoftwareVersionId == softwareVersionId). + Select(p => new CompanyBySoftwareVersionViewModel + { + Id = p.Id, + Company = p.Company.Name, + CompanyId = p.CompanyId, + RoleId = p.RoleId, + Role = p.Role.Name, + SoftwareVersionId = p.SoftwareVersionId + }).OrderBy(p => p.Company).ThenBy(p => p.Role).ToListAsync(); + + public async Task DeleteAsync(ulong id, string userId) + { + CompaniesBySoftwareVersion item = await _context.CompaniesBySoftwareVersions.FindAsync(id); + + if(item is null) + return; + + _context.CompaniesBySoftwareVersions.Remove(item); + + await _context.SaveChangesWithUserAsync(userId); + } + + public async Task CreateAsync(int companyId, ulong softwareVersionId, string roleId, string userId) + { + var item = new CompaniesBySoftwareVersion + { + CompanyId = companyId, + SoftwareVersionId = softwareVersionId, + RoleId = roleId + }; + + await _context.CompaniesBySoftwareVersions.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 ff78ffc5..3f553794 100644 --- a/Marechai/Services/Register.cs +++ b/Marechai/Services/Register.cs @@ -78,7 +78,13 @@ namespace Marechai.Services services.AddScoped(); services.AddScoped(); services.AddScoped(); - services.AddScoped(); + services.AddScoped(); + services.AddScoped(); + services.AddScoped(); + services.AddScoped(); + services.AddScoped(); + services.AddScoped(); + services.AddScoped(); } } } \ No newline at end of file diff --git a/Marechai/ViewModels/CompanyBySoftwareVersionViewModel.cs b/Marechai/ViewModels/CompanyBySoftwareVersionViewModel.cs new file mode 100644 index 00000000..98ec25f9 --- /dev/null +++ b/Marechai/ViewModels/CompanyBySoftwareVersionViewModel.cs @@ -0,0 +1,36 @@ +/****************************************************************************** +// 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 CompanyBySoftwareVersionViewModel : BaseViewModel + { + public int CompanyId { get; set; } + public ulong SoftwareVersionId { get; set; } + public string RoleId { get; set; } + public string Company { get; set; } + public string Role { get; set; } + } +} \ No newline at end of file