Add companies to software version admin page.

This commit is contained in:
2020-08-09 17:05:57 +01:00
parent 5d8e345447
commit 8beec5b6c7
10 changed files with 397 additions and 21 deletions

View File

@@ -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; }
}
}

View File

@@ -126,6 +126,9 @@ namespace Marechai.Database.Models
public virtual DbSet<MasteringText> MasteringTexts { get; set; }
public virtual DbSet<MediaTagDump> MediaTagDumps { get; set; }
public virtual DbSet<SoftwareVariantByCompilationMedia> SoftwareVariantByCompilationMedia { get; set; }
public virtual DbSet<CompaniesBySoftwareFamily> CompaniesBySoftwareFamilies { get; set; }
public virtual DbSet<CompaniesBySoftwareVariant> CompaniesBySoftwareVariants { get; set; }
public virtual DbSet<CompaniesBySoftwareVersion> CompaniesBySoftwareVersions { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
@@ -1839,6 +1842,8 @@ namespace Marechai.Database.Models
modelBuilder.Entity<CompaniesBySoftwareFamily>(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<CompaniesBySoftwareVersion>(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<CompaniesBySoftwareVariant>(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);
});

View File

@@ -2,7 +2,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<Version>4.0.0.1817</Version>
<Version>4.0.0.1820</Version>
<Company>Canary Islands Computer Museum</Company>
<Copyright>Copyright © 2003-2020 Natalia Portillo</Copyright>
<Product>Canary Islands Computer Museum Website</Product>

View File

@@ -34,6 +34,9 @@
@inject IStringLocalizer<SoftwareVersionsService> 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 @@
}
<a href="/admin/software_versions" class="btn btn-secondary">@L["Back to list"]</a>
</div>
@if (!_editing)
{
<hr />
<h3>@L["Companies involved in this software version"]</h3>
<Button Color="Color.Success" Clicked="OnAddCompanyClick" Disabled="_addingCompany">@L["Add new (company)"]</Button>
@if (_addingCompany)
{
<div>
<Field>
<FieldLabel>@L["Company"]</FieldLabel>
<Select Disabled="_savingCompany" TValue="int?" @bind-SelectedValue="@_addingCompanyId">
@foreach (var company in _companies)
{
<SelectItem TValue="int?" Value="@company.Id">@company.Name</SelectItem>
}
</Select>
</Field>
<Field>
<FieldLabel>@L["Role"]</FieldLabel>
<Select Disabled="!_editing" TValue="string" @bind-SelectedValue="@_addingCompanyRoleId">
@foreach (var role in _roles)
{
<SelectItem TValue="string" Value="@role.Id">@role.Name</SelectItem>
}
</Select>
</Field>
<Button Color="Color.Primary" Clicked="@CancelAddCpu" Disabled="@_savingCompany">@L["Cancel"]</Button>
<Button Color="Color.Success" Clicked="@ConfirmAddCpu" Disabled="@_savingCompany">@L["Add"]</Button>
</div>
}
@if (_softwareVersionCompanies?.Count > 0)
{
<div>
<table class="table table-striped">
<thead>
<tr>
<th>
@L["Company"]
</th>
<th>
@L["Role"]
</th>
<th></th>
</tr>
</thead>
<tbody>
@foreach (var item in _softwareVersionCompanies)
{
<tr>
<td>
@item.Company
</td>
<td>
@item.Role
</td>
<td>
<Button Color="Color.Danger" Clicked="() => {ShowCpuDeleteModal(item.Id);}" Disabled="@_addingCompany">@L["Delete"]</Button>
</td>
</tr>
}
</tbody>
</table>
</div>
}
<Modal @ref="_frmDelete" IsCentered="true" Closing="@ModalClosing">
<ModalBackdrop />
<ModalContent Centered="true">
<ModalHeader>
<ModalTitle>@_deleteTitle</ModalTitle>
<CloseButton Clicked="@HideModal" />
</ModalHeader>
<ModalBody>
<Text>@_deleteText</Text>
</ModalBody>
<ModalFooter>
<Button Color="Color.Primary" Clicked="@HideModal" Disabled="@_deleteInProgress">@L["Cancel"]</Button>
<Button Color="Color.Danger" Clicked="@ConfirmDelete" Disabled="@_deleteInProgress">@L["Delete"]</Button>
</ModalFooter>
</ModalContent>
</Modal>
}

View File

@@ -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<Database.Models.License> _licenses;
bool _loaded;
SoftwareVersionViewModel _model;
List<SoftwareFamilyViewModel> _softwareFamilies;
List<SoftwareVersionViewModel> _softwareVersions;
bool _unknownCodename;
bool _unknownIntroduced;
bool _unknownLicense;
bool _unknownName;
bool _unknownPrevious;
bool _addingCompany;
int? _addingCompanyId;
string _addingCompanyRoleId;
AuthenticationState _authState;
List<CompanyViewModel> _companies;
bool _creating;
CompanyBySoftwareVersionViewModel _currentCompanyBySoftwareVersion;
bool _deleteInProgress;
string _deleteText;
string _deleteTitle;
bool _deletingCompanyBySoftwareVersion;
bool _editing;
Modal _frmDelete;
List<Database.Models.License> _licenses;
bool _loaded;
SoftwareVersionViewModel _model;
List<DocumentRoleViewModel> _roles;
bool _savingCompany;
List<SoftwareFamilyViewModel> _softwareFamilies;
List<CompanyBySoftwareVersionViewModel> _softwareVersionCompanies;
List<SoftwareVersionViewModel> _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();
}
}
}

View File

@@ -101,4 +101,25 @@
<data name="Back to list" xml:space="preserve">
<value>Back to list</value>
</data>
<data name="Companies involved in this software version" xml:space="preserve">
<value>Companies involved in this software version</value>
</data>
<data name="Add new (company)" xml:space="preserve">
<value>Add new</value>
</data>
<data name="Company" xml:space="preserve">
<value>Company</value>
</data>
<data name="Role" xml:space="preserve">
<value>Role</value>
</data>
<data name="Add" xml:space="preserve">
<value>Add</value>
</data>
<data name="Delete company from this software version" xml:space="preserve">
<value>Delete company from this software version</value>
</data>
<data name="Are you sure you want to delete the company {0} with role {1} from this software version?" xml:space="preserve">
<value>Are you sure you want to delete the company {0} with role {1} from this software version?</value>
</data>
</root>

View File

@@ -208,4 +208,25 @@
<data name="Back to list" xml:space="preserve">
<value>Volver a la lista</value>
</data>
<data name="Companies involved in this software version" xml:space="preserve">
<value>Compañías involucradas en esta versión de software</value>
</data>
<data name="Add new (company)" xml:space="preserve">
<value>Añadir nueva</value>
</data>
<data name="Company" xml:space="preserve">
<value>Compañía</value>
</data>
<data name="Role" xml:space="preserve">
<value>Rol</value>
</data>
<data name="Add" xml:space="preserve">
<value>Añadir</value>
</data>
<data name="Delete company from this software version" xml:space="preserve">
<value>Eliminar compañía de esta versión de software</value>
</data>
<data name="Are you sure you want to delete the company {0} with role {1} from this software version?" xml:space="preserve">
<value>¿Estás seguro de eliminar la compañía {0} con rol {1} de esta versión de software?</value>
</data>
</root>

View File

@@ -0,0 +1,80 @@
/******************************************************************************
// 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 CompaniesBySoftwareVersionService
{
readonly MarechaiContext _context;
public CompaniesBySoftwareVersionService(MarechaiContext context) => _context = context;
public async Task<List<CompanyBySoftwareVersionViewModel>> 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<ulong> 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;
}
}
}

View File

@@ -78,7 +78,13 @@ namespace Marechai.Services
services.AddScoped<MagazineIssuesService>();
services.AddScoped<SoftwareFamiliesService>();
services.AddScoped<SoftwareVersionsService>();
services.AddScoped<SoftwareVariantsService>();
services.AddScoped<CompaniesByBookService>();
services.AddScoped<CompaniesByDocumentService>();
services.AddScoped<CompaniesByMagazineService>();
services.AddScoped<CompaniesBySoftwareFamilyService>();
services.AddScoped<CompaniesBySoftwareVariantService>();
services.AddScoped<CompaniesBySoftwareVersionService>();
services.AddScoped<DocumentRolesService>();
}
}
}

View File

@@ -0,0 +1,36 @@
/******************************************************************************
// 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 CompanyBySoftwareVersionViewModel : BaseViewModel<ulong>
{
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; }
}
}