Add code to delete instruction set extensions.

This commit is contained in:
2020-05-24 21:23:01 +01:00
parent 90c7f64296
commit 69451a9eed
5 changed files with 93 additions and 70 deletions

View File

@@ -1,57 +0,0 @@
@{
/******************************************************************************
// MARECHAI: Master repository of computing history artifacts information
// ----------------------------------------------------------------------------
//
// Filename : Delete.cshtml
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// --[ Description ] ----------------------------------------------------------
//
// Admin view delete
//
// --[ 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
*******************************************************************************/
}
@model Marechai.Database.Models.InstructionSetExtension
@{
ViewData["Title"] = "Delete";
}
<h2>Delete</h2>
<h3>Are you sure you want to delete this?</h3>
<div>
<h4>Instruction set extension</h4>
<hr />
<dl class="dl-horizontal">
<dt>
@Html.DisplayNameFor(model => model.Extension)
</dt>
<dd>
@Html.DisplayFor(model => model.Extension)
</dd>
</dl>
<form asp-action="Delete">
<input type="hidden" asp-for="Id" />
<input class="btn btn-danger" type="submit" value="Delete" />
<a asp-action="Index" class="btn btn-secondary">
Back to List
</a>
</form>
</div>

View File

@@ -31,7 +31,6 @@
}
@page "/admin/instruction_set_extensions"
@using Marechai.Database.Models
@inherits OwningComponentBase<InstructionSetExtensionsService>
@inject IStringLocalizer<InstructionSetExtensionsService> L
@attribute [Authorize(Roles = "UberAdmin, Admin")]
@@ -70,21 +69,26 @@
<span class="btn btn-secondary">
@L["Edit"]
</span>
<span class="btn btn-danger">
@L["Delete"]
</span>
<Button Color="Color.Danger" Clicked="() => {ShowModal(item.Id);}">@L["Delete"]</Button>
</td>
</tr>
}
</tbody>
</table>
@code
{
List<InstructionSetExtension> _extensions;
protected override async Task OnInitializedAsync()
{
_extensions = await Service.GetAsync();
}
}
<Modal @ref="_frmDelete" IsCentered="true" Closing="@ModalClosing">
<ModalBackdrop/>
<ModalContent Centered="true">
<ModalHeader>
<ModalTitle>@L["Delete extension"]</ModalTitle>
<CloseButton Clicked="@HideModal"/>
</ModalHeader>
<ModalBody>
<Text>@string.Format(@L["Are you sure you want to delete {0}?"], _extension?.Extension)</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

@@ -0,0 +1,52 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Blazorise;
using Marechai.Database.Models;
namespace Marechai.Pages.Admin
{
public partial class InstructionSetExtensions
{
bool _deleteInProgress;
InstructionSetExtension _extension;
List<InstructionSetExtension> _extensions;
Modal _frmDelete;
void ShowModal(int itemId)
{
_extension = _extensions.FirstOrDefault(n => n.Id == itemId);
_frmDelete.Show();
}
void HideModal() => _frmDelete.Hide();
async void ConfirmDelete()
{
if(_extension is null)
return;
_deleteInProgress = true;
_extensions = null;
// Yield thread to let UI to update
await Task.Yield();
await Service.DeleteAsync(_extension.Id);
_extensions = await Service.GetAsync();
_deleteInProgress = false;
_frmDelete.Hide();
// Yield thread to let UI to update
await Task.Yield();
// Tell we finished loading
StateHasChanged();
}
void ModalClosing(ModalClosingEventArgs obj) => _extension = null;
protected override async Task OnInitializedAsync() => _extensions = await Service.GetAsync();
}
}

View File

@@ -146,4 +146,16 @@
<value>Eliminar</value>
<comment>Delete</comment>
</data>
<data name="Delete extension" xml:space="preserve">
<value>Eliminar extensión</value>
<comment>Delete extension</comment>
</data>
<data name="Are you sure you want to delete {0}?" xml:space="preserve">
<value>¿Está seguro de que desea borrar {0}?</value>
<comment>{0} instruction set extension name</comment>
</data>
<data name="Cancel" xml:space="preserve">
<value>Cancelar</value>
<comment>Cancel</comment>
</data>
</root>

View File

@@ -14,5 +14,17 @@ namespace Marechai.Services
public async Task<List<InstructionSetExtension>> GetAsync() =>
await _context.InstructionSetExtensions.OrderBy(e => e.Extension).ToListAsync();
public async Task DeleteAsync(int id)
{
InstructionSetExtension item = await _context.InstructionSetExtensions.FindAsync(id);
if(item is null)
return;
_context.InstructionSetExtensions.Remove(item);
await _context.SaveChangesAsync();
}
}
}