mirror of
https://github.com/claunia/marechai.git
synced 2025-12-16 19:14:25 +00:00
Add code to delete processors.
This commit is contained in:
@@ -1,201 +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.Processor
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "Delete";
|
||||
}
|
||||
<h2>Delete</h2>
|
||||
<h3>Are you sure you want to delete this?</h3>
|
||||
<div>
|
||||
<h4>Processor</h4>
|
||||
<hr />
|
||||
<dl class="dl-horizontal">
|
||||
<dt>
|
||||
@Html.DisplayNameFor(model => model.Company)
|
||||
</dt>
|
||||
<dd>
|
||||
@Html.DisplayFor(model => model.Company.Name)
|
||||
</dd>
|
||||
<dt>
|
||||
@Html.DisplayNameFor(model => model.Name)
|
||||
</dt>
|
||||
<dd>
|
||||
@Html.DisplayFor(model => model.Name)
|
||||
</dd>
|
||||
<dt>
|
||||
@Html.DisplayNameFor(model => model.ModelCode)
|
||||
</dt>
|
||||
<dd>
|
||||
@Html.DisplayFor(model => model.ModelCode)
|
||||
</dd>
|
||||
<dt>
|
||||
@Html.DisplayNameFor(model => model.Introduced)
|
||||
</dt>
|
||||
<dd>
|
||||
@Html.DisplayFor(model => model.Introduced)
|
||||
</dd>
|
||||
<dt>
|
||||
@Html.DisplayNameFor(model => model.InstructionSet)
|
||||
</dt>
|
||||
<dd>
|
||||
@Html.DisplayFor(model => model.InstructionSet.Name)
|
||||
</dd>
|
||||
<dt>
|
||||
@Html.DisplayNameFor(model => model.Speed)
|
||||
</dt>
|
||||
<dd>
|
||||
@Html.DisplayFor(model => model.Speed)
|
||||
</dd>
|
||||
<dt>
|
||||
@Html.DisplayNameFor(model => model.Package)
|
||||
</dt>
|
||||
<dd>
|
||||
@Html.DisplayFor(model => model.Package)
|
||||
</dd>
|
||||
<dt>
|
||||
@Html.DisplayNameFor(model => model.Cores)
|
||||
</dt>
|
||||
<dd>
|
||||
@Html.DisplayFor(model => model.Cores)
|
||||
</dd>
|
||||
<dt>
|
||||
@Html.DisplayNameFor(model => model.ThreadsPerCore)
|
||||
</dt>
|
||||
<dd>
|
||||
@Html.DisplayFor(model => model.ThreadsPerCore)
|
||||
</dd>
|
||||
<dt>
|
||||
@Html.DisplayNameFor(model => model.Process)
|
||||
</dt>
|
||||
<dd>
|
||||
@Html.DisplayFor(model => model.Process)
|
||||
</dd>
|
||||
<dt>
|
||||
@Html.DisplayNameFor(model => model.ProcessNm)
|
||||
</dt>
|
||||
<dd>
|
||||
@Html.DisplayFor(model => model.ProcessNm)
|
||||
</dd>
|
||||
<dt>
|
||||
@Html.DisplayNameFor(model => model.DieSize)
|
||||
</dt>
|
||||
<dd>
|
||||
@Html.DisplayFor(model => model.DieSize)
|
||||
</dd>
|
||||
<dt>
|
||||
@Html.DisplayNameFor(model => model.Transistors)
|
||||
</dt>
|
||||
<dd>
|
||||
@Html.DisplayFor(model => model.Transistors)
|
||||
</dd>
|
||||
<dt>
|
||||
@Html.DisplayNameFor(model => model.DataBus)
|
||||
</dt>
|
||||
<dd>
|
||||
@Html.DisplayFor(model => model.DataBus)
|
||||
</dd>
|
||||
<dt>
|
||||
@Html.DisplayNameFor(model => model.AddrBus)
|
||||
</dt>
|
||||
<dd>
|
||||
@Html.DisplayFor(model => model.AddrBus)
|
||||
</dd>
|
||||
<dt>
|
||||
@Html.DisplayNameFor(model => model.Gprs)
|
||||
</dt>
|
||||
<dd>
|
||||
@Html.DisplayFor(model => model.Gprs)
|
||||
</dd>
|
||||
<dt>
|
||||
@Html.DisplayNameFor(model => model.GprSize)
|
||||
</dt>
|
||||
<dd>
|
||||
@Html.DisplayFor(model => model.GprSize)
|
||||
</dd>
|
||||
<dt>
|
||||
@Html.DisplayNameFor(model => model.Fprs)
|
||||
</dt>
|
||||
<dd>
|
||||
@Html.DisplayFor(model => model.Fprs)
|
||||
</dd>
|
||||
<dt>
|
||||
@Html.DisplayNameFor(model => model.FprSize)
|
||||
</dt>
|
||||
<dd>
|
||||
@Html.DisplayFor(model => model.FprSize)
|
||||
</dd>
|
||||
<dt>
|
||||
@Html.DisplayNameFor(model => model.SimdRegisters)
|
||||
</dt>
|
||||
<dd>
|
||||
@Html.DisplayFor(model => model.SimdRegisters)
|
||||
</dd>
|
||||
<dt>
|
||||
@Html.DisplayNameFor(model => model.SimdSize)
|
||||
</dt>
|
||||
<dd>
|
||||
@Html.DisplayFor(model => model.SimdSize)
|
||||
</dd>
|
||||
<dt>
|
||||
@Html.DisplayNameFor(model => model.L1Instruction)
|
||||
</dt>
|
||||
<dd>
|
||||
@Html.DisplayFor(model => model.L1Instruction)
|
||||
</dd>
|
||||
<dt>
|
||||
@Html.DisplayNameFor(model => model.L1Data)
|
||||
</dt>
|
||||
<dd>
|
||||
@Html.DisplayFor(model => model.L1Data)
|
||||
</dd>
|
||||
<dt>
|
||||
@Html.DisplayNameFor(model => model.L2)
|
||||
</dt>
|
||||
<dd>
|
||||
@Html.DisplayFor(model => model.L2)
|
||||
</dd>
|
||||
<dt>
|
||||
@Html.DisplayNameFor(model => model.L3)
|
||||
</dt>
|
||||
<dd>
|
||||
@Html.DisplayFor(model => model.L3)
|
||||
</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>
|
||||
@@ -31,7 +31,6 @@
|
||||
}
|
||||
|
||||
@page "/admin/processors"
|
||||
@using Marechai.Database.Models
|
||||
@inherits OwningComponentBase<ProcessorsService>
|
||||
@inject IStringLocalizer<ProcessorsService> L
|
||||
@attribute [Authorize(Roles = "UberAdmin, Admin")]
|
||||
@@ -94,21 +93,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<ProcessorViewModel> _processors;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
_processors = await Service.GetAsync();
|
||||
}
|
||||
}
|
||||
<Modal @ref="_frmDelete" IsCentered="true" Closing="@ModalClosing">
|
||||
<ModalBackdrop/>
|
||||
<ModalContent Centered="true">
|
||||
<ModalHeader>
|
||||
<ModalTitle>@L["Delete processor"]</ModalTitle>
|
||||
<CloseButton Clicked="@HideModal"/>
|
||||
</ModalHeader>
|
||||
<ModalBody>
|
||||
<Text>@string.Format(@L["Are you sure you want to delete {0}?"], _processor?.Name)</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>
|
||||
|
||||
52
Marechai/Pages/Admin/Processors.razor.cs
Normal file
52
Marechai/Pages/Admin/Processors.razor.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Blazorise;
|
||||
using Marechai.ViewModels;
|
||||
|
||||
namespace Marechai.Pages.Admin
|
||||
{
|
||||
public partial class Processors
|
||||
{
|
||||
bool _deleteInProgress;
|
||||
Modal _frmDelete;
|
||||
ProcessorViewModel _processor;
|
||||
List<ProcessorViewModel> _processors;
|
||||
|
||||
void ShowModal(int itemId)
|
||||
{
|
||||
_processor = _processors.FirstOrDefault(n => n.Id == itemId);
|
||||
_frmDelete.Show();
|
||||
}
|
||||
|
||||
void HideModal() => _frmDelete.Hide();
|
||||
|
||||
async void ConfirmDelete()
|
||||
{
|
||||
if(_processor is null)
|
||||
return;
|
||||
|
||||
_deleteInProgress = true;
|
||||
_processors = null;
|
||||
|
||||
// Yield thread to let UI to update
|
||||
await Task.Yield();
|
||||
|
||||
await Service.DeleteAsync(_processor.Id);
|
||||
_processors = 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) => _processor = null;
|
||||
|
||||
protected override async Task OnInitializedAsync() => _processors = await Service.GetAsync();
|
||||
}
|
||||
}
|
||||
@@ -162,4 +162,16 @@
|
||||
<value>Eliminar</value>
|
||||
<comment>Delete</comment>
|
||||
</data>
|
||||
<data name="Delete processor" xml:space="preserve">
|
||||
<value>Eliminar procesador</value>
|
||||
<comment>Delete processor</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} processor name</comment>
|
||||
</data>
|
||||
<data name="Cancel" xml:space="preserve">
|
||||
<value>Cancelar</value>
|
||||
<comment>Cancel</comment>
|
||||
</data>
|
||||
</root>
|
||||
@@ -41,5 +41,17 @@ namespace Marechai.Services
|
||||
InstructionSetExtensions =
|
||||
p.Processor.InstructionSetExtensions.Select(e => e.Extension.Extension).ToList()
|
||||
}).ToListAsync();
|
||||
|
||||
public async Task DeleteAsync(int id)
|
||||
{
|
||||
Processor item = await _context.Processors.FindAsync(id);
|
||||
|
||||
if(item is null)
|
||||
return;
|
||||
|
||||
_context.Processors.Remove(item);
|
||||
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user