diff --git a/Marechai/Areas/Admin/Controllers/InstructionSetExtensionsByProcessorController.cs b/Marechai/Areas/Admin/Controllers/InstructionSetExtensionsByProcessorController.cs deleted file mode 100644 index cac4b708..00000000 --- a/Marechai/Areas/Admin/Controllers/InstructionSetExtensionsByProcessorController.cs +++ /dev/null @@ -1,182 +0,0 @@ -using System.Linq; -using System.Threading.Tasks; -using Marechai.Areas.Admin.Models; -using Marechai.Database.Models; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Mvc.Rendering; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Query; - -namespace Marechai.Areas.Admin.Controllers -{ - [Area("Admin"), Authorize] - public class InstructionSetExtensionsByProcessorController : Controller - { - readonly MarechaiContext _context; - - public InstructionSetExtensionsByProcessorController(MarechaiContext context) => _context = context; - - // GET: InstructionSetExtensionsByProcessor - public async Task Index() - { - IIncludableQueryable marechaiContext = - _context.InstructionSetExtensionsByProcessor.Include(i => i.Extension).Include(i => i.Processor); - - return View(await marechaiContext.OrderBy(e => e.Processor.Name).ThenBy(e => e.Extension.Extension). - Select(e => new InstructionSetExtensionsByProcessorViewModel - { - Id = e.Id, Extension = e.Extension.Extension, - Processor = e.Processor.Name - }).ToListAsync()); - } - - // GET: InstructionSetExtensionsByProcessor/Details/5 - public async Task Details(int? id) - { - if(id == null) - return NotFound(); - - InstructionSetExtensionsByProcessor instructionSetExtensionsByProcessor = - await _context.InstructionSetExtensionsByProcessor.Include(i => i.Extension).Include(i => i.Processor). - FirstOrDefaultAsync(m => m.Id == id); - - if(instructionSetExtensionsByProcessor == null) - return NotFound(); - - return View(instructionSetExtensionsByProcessor); - } - - // GET: InstructionSetExtensionsByProcessor/Create - public IActionResult Create() - { - ViewData["ExtensionId"] = new SelectList(_context.InstructionSetExtensions, "Id", "Extension"); - ViewData["ProcessorId"] = new SelectList(_context.Processors, "Id", "Name"); - - return View(); - } - - // POST: InstructionSetExtensionsByProcessor/Create - // To protect from overposting attacks, please enable the specific properties you want to bind to, for - // more details see http://go.microsoft.com/fwlink/?LinkId=317598. - [HttpPost, ValidateAntiForgeryToken] - public async Task Create( - [Bind("Id,ProcessorId,ExtensionId")] - InstructionSetExtensionsByProcessor instructionSetExtensionsByProcessor) - { - if(ModelState.IsValid) - { - _context.Add(instructionSetExtensionsByProcessor); - await _context.SaveChangesAsync(); - - return RedirectToAction(nameof(Index)); - } - - ViewData["ExtensionId"] = new SelectList(_context.InstructionSetExtensions, "Id", "Extension", - instructionSetExtensionsByProcessor.ExtensionId); - - ViewData["ProcessorId"] = new SelectList(_context.Processors, "Id", "Name", - instructionSetExtensionsByProcessor.ProcessorId); - - return View(instructionSetExtensionsByProcessor); - } - - // GET: InstructionSetExtensionsByProcessor/Edit/5 - public async Task Edit(int? id) - { - if(id == null) - return NotFound(); - - InstructionSetExtensionsByProcessor instructionSetExtensionsByProcessor = - await _context.InstructionSetExtensionsByProcessor.FirstOrDefaultAsync(e => e.Id == id); - - if(instructionSetExtensionsByProcessor == null) - return NotFound(); - - ViewData["ExtensionId"] = new SelectList(_context.InstructionSetExtensions, "Id", "Extension", - instructionSetExtensionsByProcessor.ExtensionId); - - ViewData["ProcessorId"] = new SelectList(_context.Processors, "Id", "Name", - instructionSetExtensionsByProcessor.ProcessorId); - - return View(instructionSetExtensionsByProcessor); - } - - // POST: InstructionSetExtensionsByProcessor/Edit/5 - // To protect from overposting attacks, please enable the specific properties you want to bind to, for - // more details see http://go.microsoft.com/fwlink/?LinkId=317598. - [HttpPost, ValidateAntiForgeryToken] - public async Task Edit( - int id, - [Bind("Id,ProcessorId,ExtensionId")] - InstructionSetExtensionsByProcessor instructionSetExtensionsByProcessor) - { - if(id != instructionSetExtensionsByProcessor.Id) - return NotFound(); - - if(ModelState.IsValid) - { - try - { - _context.Update(instructionSetExtensionsByProcessor); - await _context.SaveChangesAsync(); - } - catch(DbUpdateConcurrencyException) - { - if(!InstructionSetExtensionsByProcessorExists(instructionSetExtensionsByProcessor.Id)) - return NotFound(); - - throw; - } - - return RedirectToAction(nameof(Index)); - } - - ViewData["ExtensionId"] = new SelectList(_context.InstructionSetExtensions, "Id", "Extension", - instructionSetExtensionsByProcessor.ExtensionId); - - ViewData["ProcessorId"] = new SelectList(_context.Processors, "Id", "Name", - instructionSetExtensionsByProcessor.ProcessorId); - - return View(instructionSetExtensionsByProcessor); - } - - // GET: InstructionSetExtensionsByProcessor/Delete/5 - public async Task Delete(int? id) - { - if(id == null) - return NotFound(); - - InstructionSetExtensionsByProcessor instructionSetExtensionsByProcessor = - await _context.InstructionSetExtensionsByProcessor.Include(i => i.Extension).Include(i => i.Processor). - FirstOrDefaultAsync(m => m.Id == id); - - if(instructionSetExtensionsByProcessor == null) - return NotFound(); - - return View(instructionSetExtensionsByProcessor); - } - - // POST: InstructionSetExtensionsByProcessor/Delete/5 - [HttpPost, ActionName("Delete"), ValidateAntiForgeryToken] - public async Task DeleteConfirmed(int id) - { - InstructionSetExtensionsByProcessor instructionSetExtensionsByProcessor = - await _context.InstructionSetExtensionsByProcessor.FirstOrDefaultAsync(e => e.Id == id); - - _context.InstructionSetExtensionsByProcessor.Remove(instructionSetExtensionsByProcessor); - await _context.SaveChangesAsync(); - - return RedirectToAction(nameof(Index)); - } - - bool InstructionSetExtensionsByProcessorExists(int id) => - _context.InstructionSetExtensionsByProcessor.Any(e => e.Id == id); - - [AcceptVerbs("Get", "Post")] - public async Task VerifyUnique(int processorId, int extensionId) => - await _context.InstructionSetExtensionsByProcessor.FirstOrDefaultAsync(i => i.ProcessorId == processorId && - i.ExtensionId == extensionId) is - null ? Json(true) : Json("The selected processor already has the selected extension."); - } -} \ No newline at end of file diff --git a/Marechai/Areas/Admin/Views/InstructionSetExtensionsByProcessor/Create.cshtml b/Marechai/Areas/Admin/Views/InstructionSetExtensionsByProcessor/Create.cshtml deleted file mode 100644 index 8126a589..00000000 --- a/Marechai/Areas/Admin/Views/InstructionSetExtensionsByProcessor/Create.cshtml +++ /dev/null @@ -1,42 +0,0 @@ -@model Marechai.Database.Models.InstructionSetExtensionsByProcessor - -@{ - ViewData["Title"] = "Create"; -} -

Create

-

Instruction set extensions by processor

-
-
-
-
-
-
-
- - - - -
-
- - - - -
- -
-
-
- -@section Scripts { - @{ await Html.RenderPartialAsync("_ValidationScriptsPartial"); } -} \ No newline at end of file diff --git a/Marechai/Areas/Admin/Views/InstructionSetExtensionsByProcessor/Delete.cshtml b/Marechai/Areas/Admin/Views/InstructionSetExtensionsByProcessor/Delete.cshtml deleted file mode 100644 index 89556ba2..00000000 --- a/Marechai/Areas/Admin/Views/InstructionSetExtensionsByProcessor/Delete.cshtml +++ /dev/null @@ -1,34 +0,0 @@ -@model Marechai.Database.Models.InstructionSetExtensionsByProcessor - -@{ - ViewData["Title"] = "Delete"; -} -

Delete

-

Are you sure you want to delete this?

-
-

Instruction set extensions by processor

-
-
-
- @Html.DisplayNameFor(model => model.Extension) -
-
- @Html.DisplayFor(model => model.Extension.Extension) -
-
- @Html.DisplayNameFor(model => model.Processor) -
-
- @Html.DisplayFor(model => model.Processor.Name) -
-
-
- - - - - - Back to List - -
-
\ No newline at end of file diff --git a/Marechai/Areas/Admin/Views/InstructionSetExtensionsByProcessor/Details.cshtml b/Marechai/Areas/Admin/Views/InstructionSetExtensionsByProcessor/Details.cshtml deleted file mode 100644 index c9cc49ed..00000000 --- a/Marechai/Areas/Admin/Views/InstructionSetExtensionsByProcessor/Details.cshtml +++ /dev/null @@ -1,32 +0,0 @@ -@model Marechai.Database.Models.InstructionSetExtensionsByProcessor - -@{ - ViewData["Title"] = "Details"; -} -

Details

-
-

Instruction set extensions by processor

-
-
-
- @Html.DisplayNameFor(model => model.Extension) -
-
- @Html.DisplayFor(model => model.Extension.Extension) -
-
- @Html.DisplayNameFor(model => model.Processor) -
-
- @Html.DisplayFor(model => model.Processor.Name) -
-
-
- \ No newline at end of file diff --git a/Marechai/Areas/Admin/Views/InstructionSetExtensionsByProcessor/Edit.cshtml b/Marechai/Areas/Admin/Views/InstructionSetExtensionsByProcessor/Edit.cshtml deleted file mode 100644 index a8c84eb9..00000000 --- a/Marechai/Areas/Admin/Views/InstructionSetExtensionsByProcessor/Edit.cshtml +++ /dev/null @@ -1,43 +0,0 @@ -@model Marechai.Database.Models.InstructionSetExtensionsByProcessor - -@{ - ViewData["Title"] = "Edit"; -} -

Edit

-

Instruction set extensions by processor

-
-
-
-
-
-
- -
- - - - -
-
- - - - -
- -
-
-
- -@section Scripts { - @{ await Html.RenderPartialAsync("_ValidationScriptsPartial"); } -} \ No newline at end of file diff --git a/Marechai/Areas/Admin/Views/InstructionSetExtensionsByProcessor/Index.cshtml b/Marechai/Areas/Admin/Views/InstructionSetExtensionsByProcessor/Index.cshtml deleted file mode 100644 index 43c621c3..00000000 --- a/Marechai/Areas/Admin/Views/InstructionSetExtensionsByProcessor/Index.cshtml +++ /dev/null @@ -1,48 +0,0 @@ -@model IEnumerable - -@{ - ViewData["Title"] = "Index"; -} -

Instruction set extensions by processor

-

- - Create new - -

- - - - - - - - - - @foreach (var item in Model) - { - - - - - - } - -
- @Html.DisplayNameFor(model => model.Processor) - - @Html.DisplayNameFor(model => model.Extension) -
- @Html.DisplayFor(modelItem => item.Processor) - - @Html.DisplayFor(modelItem => item.Extension) - - - Details - - - Edit - - - Delete - -
\ No newline at end of file diff --git a/Marechai/Marechai.csproj b/Marechai/Marechai.csproj index 289ba025..40d3450f 100644 --- a/Marechai/Marechai.csproj +++ b/Marechai/Marechai.csproj @@ -2,7 +2,7 @@ netcoreapp3.1 - 3.0.99.1396 + 3.0.99.1399 Canary Islands Computer Museum Copyright © 2003-2020 Natalia Portillo Canary Islands Computer Museum Website @@ -174,5 +174,10 @@ <_ContentIncludedByDefault Remove="Areas\Admin\Views\ScreensByMachine\Details.cshtml" /> <_ContentIncludedByDefault Remove="Areas\Admin\Views\ScreensByMachine\Edit.cshtml" /> <_ContentIncludedByDefault Remove="Areas\Admin\Views\ScreensByMachine\Index.cshtml" /> + <_ContentIncludedByDefault Remove="Areas\Admin\Views\InstructionSetExtensionsByProcessor\Create.cshtml" /> + <_ContentIncludedByDefault Remove="Areas\Admin\Views\InstructionSetExtensionsByProcessor\Delete.cshtml" /> + <_ContentIncludedByDefault Remove="Areas\Admin\Views\InstructionSetExtensionsByProcessor\Details.cshtml" /> + <_ContentIncludedByDefault Remove="Areas\Admin\Views\InstructionSetExtensionsByProcessor\Edit.cshtml" /> + <_ContentIncludedByDefault Remove="Areas\Admin\Views\InstructionSetExtensionsByProcessor\Index.cshtml" /> \ No newline at end of file diff --git a/Marechai/Pages/Admin/Details/Machine.razor b/Marechai/Pages/Admin/Details/Machine.razor index 9d01e720..dcdfd254 100644 --- a/Marechai/Pages/Admin/Details/Machine.razor +++ b/Marechai/Pages/Admin/Details/Machine.razor @@ -567,9 +567,9 @@ diff --git a/Marechai/Pages/Admin/Details/Processor.razor b/Marechai/Pages/Admin/Details/Processor.razor index 79b50410..8c8b39e0 100644 --- a/Marechai/Pages/Admin/Details/Processor.razor +++ b/Marechai/Pages/Admin/Details/Processor.razor @@ -38,6 +38,8 @@ @inject CompaniesService CompaniesService @inject InstructionSetsService InstructionSetsService @inject NavigationManager NavigationManager +@inject InstructionSetExtensionsByProcessorService InstructionSetExtensionsByProcessorService +@inject InstructionSetExtensionsService InstructionSetExtensionsService @attribute [Authorize(Roles = "UberAdmin, Admin")]

@L["Processor details"]


@@ -583,4 +585,74 @@ } @L["Back to list"] - \ No newline at end of file + +@if (!_editing) +{ +
+

@L["Instruction set extensions implemented by this processor"]

+ + @if (_addingExtension) + { +
+ + @L["Instruction set extensions"] + + + + +
+ } + @if (_processorExtensions?.Count > 0) + { +
+ + + + + + + + + @foreach (var item in _processorExtensions) + { + + + + + } + +
+ @L["Name"] +
+ @item.Extension + + +
+
+ } + + + + + + @_deleteTitle + + + + @_deleteText + + + + + + + +} \ No newline at end of file diff --git a/Marechai/Pages/Admin/Details/Processor.razor.cs b/Marechai/Pages/Admin/Details/Processor.razor.cs index fede4d83..1ec0e999 100644 --- a/Marechai/Pages/Admin/Details/Processor.razor.cs +++ b/Marechai/Pages/Admin/Details/Processor.razor.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Threading.Tasks; using Blazorise; using Marechai.Shared; @@ -10,37 +11,49 @@ namespace Marechai.Pages.Admin.Details { public partial class Processor { - List _companies; - bool _creating; - bool _editing; - List _instructionSets; - bool _loaded; - ProcessorViewModel _model; - bool _prototype; - bool _unknownAddressBus; - bool _unknownCompany; - bool _unknownCores; - bool _unknownDataBus; - bool _unknownDieSize; - bool _unknownFprs; - bool _unknownFprSize; - bool _unknownGprs; - bool _unknownGprSize; - bool _unknownInstructionSet; - bool _unknownIntroduced; - bool _unknownL1Data; - bool _unknownL1Instruction; - bool _unknownL2; - bool _unknownL3; - bool _unknownModelCode; - bool _unknownPackage; - bool _unknownProcess; - bool _unknownProcessNm; - bool _unknownSimdRegisters; - bool _unknownSimdSize; - bool _unknownSpeed; - bool _unknownThreadsPerCore; - bool _unknownTransistors; + bool _addingExtension; + int? _addingExtensionId; + List _companies; + bool _creating; + + InstructionSetExtensionByProcessorViewModel _currentInstructionByMachine; + bool _deleteInProgress; + string _deleteText; + string _deleteTitle; + bool _editing; + Modal _frmDelete; + List _instructionSetExtensions; + List _instructionSets; + bool _loaded; + ProcessorViewModel _model; + + List _processorExtensions; + bool _prototype; + bool _savingExtension; + bool _unknownAddressBus; + bool _unknownCompany; + bool _unknownCores; + bool _unknownDataBus; + bool _unknownDieSize; + bool _unknownFprs; + bool _unknownFprSize; + bool _unknownGprs; + bool _unknownGprSize; + bool _unknownInstructionSet; + bool _unknownIntroduced; + bool _unknownL1Data; + bool _unknownL1Instruction; + bool _unknownL2; + bool _unknownL3; + bool _unknownModelCode; + bool _unknownPackage; + bool _unknownProcess; + bool _unknownProcessNm; + bool _unknownSimdRegisters; + bool _unknownSimdSize; + bool _unknownSpeed; + bool _unknownThreadsPerCore; + bool _unknownTransistors; [Parameter] public int Id { get; set; } @@ -58,9 +71,11 @@ namespace Marechai.Pages.Admin.Details !_creating) return; - _companies = await CompaniesService.GetAsync(); - _instructionSets = await InstructionSetsService.GetAsync(); - _model = _creating ? new ProcessorViewModel() : await Service.GetAsync(Id); + _companies = await CompaniesService.GetAsync(); + _instructionSets = await InstructionSetsService.GetAsync(); + _model = _creating ? new ProcessorViewModel() : await Service.GetAsync(Id); + _instructionSetExtensions = await InstructionSetExtensionsService.GetAsync(); + _processorExtensions = await InstructionSetExtensionsByProcessorService.GetByProcessor(Id); _editing = _creating || NavigationManager.ToBaseRelativePath(NavigationManager.Uri).ToLowerInvariant(). StartsWith("admin/processors/edit/", @@ -285,5 +300,91 @@ namespace Marechai.Pages.Admin.Details void ValidateProcess(ValidatorEventArgs e) => Validators.ValidateString(e, L["Process must be 45 characters or less."], 45); + + void ShowExtensionDeleteModal(long itemId) + { + _currentInstructionByMachine = _processorExtensions.FirstOrDefault(n => n.Id == itemId); + _deleteTitle = L["Delete instruction set extension from this processor"]; + + _deleteText = + string.Format(L["Are you sure you want to delete the instruction set extension {0} from this processor?"], + _currentInstructionByMachine?.Extension); + + _frmDelete.Show(); + } + + void HideModal() => _frmDelete.Hide(); + + async void ConfirmDelete() + { + if(_currentInstructionByMachine is null) + return; + + _deleteInProgress = true; + + // Yield thread to let UI to update + await Task.Yield(); + + await InstructionSetExtensionsByProcessorService.DeleteAsync(_currentInstructionByMachine.Id); + _processorExtensions = await InstructionSetExtensionsByProcessorService.GetByProcessor(Id); + + _deleteInProgress = false; + _frmDelete.Hide(); + + // Yield thread to let UI to update + await Task.Yield(); + + // Tell we finished loading + StateHasChanged(); + } + + void ModalClosing(ModalClosingEventArgs obj) + { + _deleteInProgress = false; + _currentInstructionByMachine = null; + } + + void OnAddExtensionClick() + { + _addingExtension = true; + _savingExtension = false; + _addingExtensionId = _instructionSetExtensions.First().Id; + } + + void CancelAddExtension() + { + _addingExtension = false; + _savingExtension = false; + _addingExtensionId = null; + } + + async Task ConfirmAddExtension() + { + if(_addingExtensionId is null || + _addingExtensionId <= 0) + { + CancelAddExtension(); + + return; + } + + _savingExtension = true; + + // Yield thread to let UI to update + await Task.Yield(); + + await InstructionSetExtensionsByProcessorService.CreateAsync(Id, _addingExtensionId.Value); + _processorExtensions = await InstructionSetExtensionsByProcessorService.GetByProcessor(Id); + + _addingExtension = false; + _savingExtension = false; + _addingExtensionId = null; + + // 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/ProcessorsService.en.resx b/Marechai/Resources/Services/ProcessorsService.en.resx index 308cf69d..6203905c 100644 --- a/Marechai/Resources/Services/ProcessorsService.en.resx +++ b/Marechai/Resources/Services/ProcessorsService.en.resx @@ -214,4 +214,8 @@ Unknown Unknown, referring to the size of the L3 data cache + + Add new + Add new, referring to an instruction set extension for a processor + \ No newline at end of file diff --git a/Marechai/Resources/Services/ProcessorsService.es.resx b/Marechai/Resources/Services/ProcessorsService.es.resx index ea27ad57..ed728414 100644 --- a/Marechai/Resources/Services/ProcessorsService.es.resx +++ b/Marechai/Resources/Services/ProcessorsService.es.resx @@ -374,10 +374,6 @@ Por favor introduce un modelo válido. Please enter a valid model code. - - Prototipo - Prototype - Por favor elige una fecha válida. Please enter an introduction date. @@ -470,4 +466,24 @@ Por favor introduce un tamaño válido de la caché L3 en kibibytes. Please enter a valid L3 cache size in kibibytes. + + Añadir nueva + Add new, referring to an instruction set extension for a processor + + + Eliminar extensión de arquitectura de este procesador + Delete instruction set extension from this processor + + + ¿Estás seguro de eliminar la extensión de arquitecture {0} de este procesador? + Are you sure you want to delete the instruction set extension {0} from this processor? + + + Extensiones de arquitectura implementadas por este procesador + Instruction set extensions implemented by this processor + + + Añadir + Add + \ No newline at end of file diff --git a/Marechai/Services/InstructionSetExtensionsByProcessorService.cs b/Marechai/Services/InstructionSetExtensionsByProcessorService.cs new file mode 100644 index 00000000..0ebadc49 --- /dev/null +++ b/Marechai/Services/InstructionSetExtensionsByProcessorService.cs @@ -0,0 +1,49 @@ +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 InstructionSetExtensionsByProcessorService + { + readonly MarechaiContext _context; + + public InstructionSetExtensionsByProcessorService(MarechaiContext context) => _context = context; + + public async Task> GetByProcessor(int processorId) => + await _context.InstructionSetExtensionsByProcessor.Where(e => e.ProcessorId == processorId). + Select(e => new InstructionSetExtensionByProcessorViewModel + { + Id = e.Id, Extension = e.Extension.Extension, Processor = e.Processor.Name, + ProcessorId = e.ProcessorId, ExtensionId = e.ExtensionId + }).OrderBy(e => e.Extension).ToListAsync(); + + public async Task DeleteAsync(int id) + { + InstructionSetExtensionsByProcessor item = await _context.InstructionSetExtensionsByProcessor.FindAsync(id); + + if(item is null) + return; + + _context.InstructionSetExtensionsByProcessor.Remove(item); + + await _context.SaveChangesAsync(); + } + + public async Task CreateAsync(int processorId, int extensionId) + { + var item = new InstructionSetExtensionsByProcessor + { + ProcessorId = processorId, ExtensionId = extensionId + }; + + await _context.InstructionSetExtensionsByProcessor.AddAsync(item); + await _context.SaveChangesAsync(); + + return item.Id; + } + } +} \ No newline at end of file diff --git a/Marechai/ViewModels/InstructionSetExtensionByProcessorViewModel.cs b/Marechai/ViewModels/InstructionSetExtensionByProcessorViewModel.cs new file mode 100644 index 00000000..54ab57df --- /dev/null +++ b/Marechai/ViewModels/InstructionSetExtensionByProcessorViewModel.cs @@ -0,0 +1,10 @@ +namespace Marechai.ViewModels +{ + public class InstructionSetExtensionByProcessorViewModel : BaseViewModel + { + public string Extension { get; set; } + public string Processor { get; set; } + public int ProcessorId { get; set; } + public int ExtensionId { get; set; } + } +} \ No newline at end of file