mirror of
https://github.com/claunia/marechai.git
synced 2025-12-16 19:14:25 +00:00
Add processor creation in admin view.
This commit is contained in:
@@ -1,198 +0,0 @@
|
||||
/******************************************************************************
|
||||
// MARECHAI: Master repository of computing history artifacts information
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : ProcessorsController.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// Processors admin controller
|
||||
//
|
||||
// --[ 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.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 ProcessorsController : Controller
|
||||
{
|
||||
readonly MarechaiContext _context;
|
||||
|
||||
public ProcessorsController(MarechaiContext context) => _context = context;
|
||||
|
||||
// GET: Admin/Processors
|
||||
public async Task<IActionResult> Index()
|
||||
{
|
||||
IIncludableQueryable<Processor, InstructionSet> marechaiContext =
|
||||
_context.Processors.Include(p => p.Company).Include(p => p.InstructionSet);
|
||||
|
||||
return View(await marechaiContext.OrderBy(p => p.Company.Name).ThenBy(p => p.Name).
|
||||
Select(p => new ProcessorViewModel
|
||||
{
|
||||
Company = p.Company.Name, Id = p.Id,
|
||||
InstructionSet = p.InstructionSet.Name, Introduced = p.Introduced,
|
||||
ModelCode = p.ModelCode, Name = p.Name
|
||||
}).ToListAsync());
|
||||
}
|
||||
|
||||
// GET: Admin/Processors/Details/5
|
||||
public async Task<IActionResult> Details(int? id)
|
||||
{
|
||||
if(id == null)
|
||||
return NotFound();
|
||||
|
||||
Processor processor = await _context.Processors.Include(p => p.Company).Include(p => p.InstructionSet).
|
||||
FirstOrDefaultAsync(m => m.Id == id);
|
||||
|
||||
if(processor == null)
|
||||
return NotFound();
|
||||
|
||||
return View(processor);
|
||||
}
|
||||
|
||||
// GET: Admin/Processors/Create
|
||||
public IActionResult Create()
|
||||
{
|
||||
ViewData["CompanyId"] = new SelectList(_context.Companies, "Id", "Name");
|
||||
ViewData["InstructionSetId"] = new SelectList(_context.InstructionSets, "Id", "Name");
|
||||
|
||||
return View();
|
||||
}
|
||||
|
||||
// POST: Admin/Processors/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<IActionResult> Create(
|
||||
[Bind("Id,Name,CompanyId,ModelCode,Introduced,InstructionSetId,Speed,Package,Gprs,GprSize,Fprs,FprSize,Cores,ThreadsPerCore,Process,ProcessNm,DieSize,Transistors,DataBus,AddrBus,SimdRegisters,SimdSize,L1Instruction,L1Data,L2,L3")]
|
||||
Processor processor)
|
||||
{
|
||||
if(ModelState.IsValid)
|
||||
{
|
||||
_context.Add(processor);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return RedirectToAction(nameof(Index));
|
||||
}
|
||||
|
||||
ViewData["CompanyId"] = new SelectList(_context.Companies, "Id", "Name", processor.CompanyId);
|
||||
|
||||
ViewData["InstructionSetId"] =
|
||||
new SelectList(_context.InstructionSets, "Id", "Name", processor.InstructionSetId);
|
||||
|
||||
return View(processor);
|
||||
}
|
||||
|
||||
// GET: Admin/Processors/Edit/5
|
||||
public async Task<IActionResult> Edit(int? id)
|
||||
{
|
||||
if(id == null)
|
||||
return NotFound();
|
||||
|
||||
Processor processor = await _context.Processors.FindAsync(id);
|
||||
|
||||
if(processor == null)
|
||||
return NotFound();
|
||||
|
||||
ViewData["CompanyId"] = new SelectList(_context.Companies, "Id", "Name", processor.CompanyId);
|
||||
|
||||
ViewData["InstructionSetId"] =
|
||||
new SelectList(_context.InstructionSets, "Id", "Name", processor.InstructionSetId);
|
||||
|
||||
return View(processor);
|
||||
}
|
||||
|
||||
// POST: Admin/Processors/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<IActionResult> Edit(
|
||||
int id,
|
||||
[Bind("Id,Name,CompanyId,ModelCode,Introduced,InstructionSetId,Speed,Package,Gprs,GprSize,Fprs,FprSize,Cores,ThreadsPerCore,Process,ProcessNm,DieSize,Transistors,DataBus,AddrBus,SimdRegisters,SimdSize,L1Instruction,L1Data,L2,L3")]
|
||||
Processor processor)
|
||||
{
|
||||
if(id != processor.Id)
|
||||
return NotFound();
|
||||
|
||||
if(ModelState.IsValid)
|
||||
{
|
||||
try
|
||||
{
|
||||
_context.Update(processor);
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
catch(DbUpdateConcurrencyException)
|
||||
{
|
||||
if(!ProcessorExists(processor.Id))
|
||||
return NotFound();
|
||||
|
||||
throw;
|
||||
}
|
||||
|
||||
return RedirectToAction(nameof(Index));
|
||||
}
|
||||
|
||||
ViewData["CompanyId"] = new SelectList(_context.Companies, "Id", "Name", processor.CompanyId);
|
||||
|
||||
ViewData["InstructionSetId"] =
|
||||
new SelectList(_context.InstructionSets, "Id", "Name", processor.InstructionSetId);
|
||||
|
||||
return View(processor);
|
||||
}
|
||||
|
||||
// GET: Admin/Processors/Delete/5
|
||||
public async Task<IActionResult> Delete(int? id)
|
||||
{
|
||||
if(id == null)
|
||||
return NotFound();
|
||||
|
||||
Processor processor = await _context.Processors.Include(p => p.Company).Include(p => p.InstructionSet).
|
||||
FirstOrDefaultAsync(m => m.Id == id);
|
||||
|
||||
if(processor == null)
|
||||
return NotFound();
|
||||
|
||||
return View(processor);
|
||||
}
|
||||
|
||||
// POST: Admin/Processors/Delete/5
|
||||
[HttpPost, ActionName("Delete"), ValidateAntiForgeryToken]
|
||||
public async Task<IActionResult> DeleteConfirmed(int id)
|
||||
{
|
||||
Processor processor = await _context.Processors.FindAsync(id);
|
||||
_context.Processors.Remove(processor);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return RedirectToAction(nameof(Index));
|
||||
}
|
||||
|
||||
bool ProcessorExists(int id) => _context.Processors.Any(e => e.Id == id);
|
||||
}
|
||||
}
|
||||
@@ -1,230 +0,0 @@
|
||||
@{
|
||||
/******************************************************************************
|
||||
// MARECHAI: Master repository of computing history artifacts information
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : Create.cshtml
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// Admin view create
|
||||
//
|
||||
// --[ 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"] = "Create";
|
||||
}
|
||||
<h2>Create</h2>
|
||||
<h4>Processor</h4>
|
||||
<hr />
|
||||
<div class="row">
|
||||
<div class="col-md-4">
|
||||
<form asp-action="Create">
|
||||
<div asp-validation-summary="ModelOnly" class="text-danger">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label asp-for="Company" class="control-label">
|
||||
</label>
|
||||
<select asp-for="CompanyId" class="form-control" asp-items="ViewBag.CompanyId">
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label asp-for="Name" class="control-label">
|
||||
</label>
|
||||
<input asp-for="Name" class="form-control" />
|
||||
<span asp-validation-for="Name" class="text-danger">
|
||||
</span>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label asp-for="ModelCode" class="control-label">
|
||||
</label>
|
||||
<input asp-for="ModelCode" class="form-control" />
|
||||
<span asp-validation-for="ModelCode" class="text-danger">
|
||||
</span>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label asp-for="Introduced" class="control-label">
|
||||
</label>
|
||||
<input asp-for="Introduced" class="form-control" />
|
||||
<span asp-validation-for="Introduced" class="text-danger">
|
||||
</span>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label asp-for="InstructionSetId" class="control-label">
|
||||
</label>
|
||||
<select asp-for="InstructionSetId" class="form-control" asp-items="ViewBag.InstructionSetId">
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label asp-for="Speed" class="control-label">
|
||||
</label>
|
||||
<input asp-for="Speed" class="form-control" />
|
||||
<span asp-validation-for="Speed" class="text-danger">
|
||||
</span>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label asp-for="Package" class="control-label">
|
||||
</label>
|
||||
<input asp-for="Package" class="form-control" />
|
||||
<span asp-validation-for="Package" class="text-danger">
|
||||
</span>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label asp-for="Cores" class="control-label">
|
||||
</label>
|
||||
<input asp-for="Cores" class="form-control" />
|
||||
<span asp-validation-for="Cores" class="text-danger">
|
||||
</span>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label asp-for="ThreadsPerCore" class="control-label">
|
||||
</label>
|
||||
<input asp-for="ThreadsPerCore" class="form-control" />
|
||||
<span asp-validation-for="ThreadsPerCore" class="text-danger">
|
||||
</span>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label asp-for="Process" class="control-label">
|
||||
</label>
|
||||
<input asp-for="Process" class="form-control" />
|
||||
<span asp-validation-for="Process" class="text-danger">
|
||||
</span>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label asp-for="ProcessNm" class="control-label">
|
||||
</label>
|
||||
<input asp-for="ProcessNm" class="form-control" />
|
||||
<span asp-validation-for="ProcessNm" class="text-danger">
|
||||
</span>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label asp-for="DieSize" class="control-label">
|
||||
</label>
|
||||
<input asp-for="DieSize" class="form-control" />
|
||||
<span asp-validation-for="DieSize" class="text-danger">
|
||||
</span>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label asp-for="Transistors" class="control-label">
|
||||
</label>
|
||||
<input asp-for="Transistors" class="form-control" />
|
||||
<span asp-validation-for="Transistors" class="text-danger">
|
||||
</span>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label asp-for="DataBus" class="control-label">
|
||||
</label>
|
||||
<input asp-for="DataBus" class="form-control" />
|
||||
<span asp-validation-for="DataBus" class="text-danger">
|
||||
</span>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label asp-for="AddrBus" class="control-label">
|
||||
</label>
|
||||
<input asp-for="AddrBus" class="form-control" />
|
||||
<span asp-validation-for="AddrBus" class="text-danger">
|
||||
</span>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label asp-for="Gprs" class="control-label">
|
||||
</label>
|
||||
<input asp-for="Gprs" class="form-control" />
|
||||
<span asp-validation-for="Gprs" class="text-danger">
|
||||
</span>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label asp-for="GprSize" class="control-label">
|
||||
</label>
|
||||
<input asp-for="GprSize" class="form-control" />
|
||||
<span asp-validation-for="GprSize" class="text-danger">
|
||||
</span>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label asp-for="Fprs" class="control-label">
|
||||
</label>
|
||||
<input asp-for="Fprs" class="form-control" />
|
||||
<span asp-validation-for="Fprs" class="text-danger">
|
||||
</span>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label asp-for="FprSize" class="control-label">
|
||||
</label>
|
||||
<input asp-for="FprSize" class="form-control" />
|
||||
<span asp-validation-for="FprSize" class="text-danger">
|
||||
</span>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label asp-for="SimdRegisters" class="control-label">
|
||||
</label>
|
||||
<input asp-for="SimdRegisters" class="form-control" />
|
||||
<span asp-validation-for="SimdRegisters" class="text-danger">
|
||||
</span>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label asp-for="SimdSize" class="control-label">
|
||||
</label>
|
||||
<input asp-for="SimdSize" class="form-control" />
|
||||
<span asp-validation-for="SimdSize" class="text-danger">
|
||||
</span>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label asp-for="L1Instruction" class="control-label">
|
||||
</label>
|
||||
<input asp-for="L1Instruction" class="form-control" />
|
||||
<span asp-validation-for="L1Instruction" class="text-danger">
|
||||
</span>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label asp-for="L1Data" class="control-label">
|
||||
</label>
|
||||
<input asp-for="L1Data" class="form-control" />
|
||||
<span asp-validation-for="L1Data" class="text-danger">
|
||||
</span>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label asp-for="L2" class="control-label">
|
||||
</label>
|
||||
<input asp-for="L2" class="form-control" />
|
||||
<span asp-validation-for="L2" class="text-danger">
|
||||
</span>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label asp-for="L3" class="control-label">
|
||||
</label>
|
||||
<input asp-for="L3" class="form-control" />
|
||||
<span asp-validation-for="L3" class="text-danger">
|
||||
</span>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<input class="btn btn-primary" type="submit" value="Create" />
|
||||
<a asp-action="Index" class="btn btn-secondary">
|
||||
Back to List
|
||||
</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@section Scripts {
|
||||
@{ await Html.RenderPartialAsync("_ValidationScriptsPartial"); }
|
||||
}
|
||||
@@ -139,5 +139,6 @@
|
||||
<_ContentIncludedByDefault Remove="Areas\Admin\Views\MachineFamilies\Create.cshtml" />
|
||||
<_ContentIncludedByDefault Remove="Areas\Admin\Views\Machines\Create.cshtml" />
|
||||
<_ContentIncludedByDefault Remove="Areas\Admin\Views\People\Create.cshtml" />
|
||||
<_ContentIncludedByDefault Remove="Areas\Admin\Views\Processors\Create.cshtml" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -32,6 +32,7 @@
|
||||
|
||||
@page "/admin/processors/details/{Id:int}"
|
||||
@page "/admin/processors/edit/{Id:int}"
|
||||
@page "/admin/processors/create"
|
||||
@inherits OwningComponentBase<ProcessorsService>
|
||||
@inject IStringLocalizer<ProcessorsService> L
|
||||
@inject CompaniesService CompaniesService
|
||||
|
||||
@@ -11,6 +11,7 @@ namespace Marechai.Pages.Admin.Details
|
||||
public partial class Processor
|
||||
{
|
||||
List<CompanyViewModel> _companies;
|
||||
bool _creating;
|
||||
bool _editing;
|
||||
List<Database.Models.InstructionSet> _instructionSets;
|
||||
bool _loaded;
|
||||
@@ -50,15 +51,20 @@ namespace Marechai.Pages.Admin.Details
|
||||
|
||||
_loaded = true;
|
||||
|
||||
if(Id <= 0)
|
||||
_creating = NavigationManager.ToBaseRelativePath(NavigationManager.Uri).ToLowerInvariant().
|
||||
StartsWith("admin/processors/create", StringComparison.InvariantCulture);
|
||||
|
||||
if(Id <= 0 &&
|
||||
!_creating)
|
||||
return;
|
||||
|
||||
_companies = await CompaniesService.GetAsync();
|
||||
_instructionSets = await InstructionSetsService.GetAsync();
|
||||
_model = await Service.GetAsync(Id);
|
||||
_model = _creating ? new ProcessorViewModel() : await Service.GetAsync(Id);
|
||||
|
||||
_editing = NavigationManager.ToBaseRelativePath(NavigationManager.Uri).ToLowerInvariant().
|
||||
StartsWith("admin/processors/edit/", StringComparison.InvariantCulture);
|
||||
_editing = _creating || NavigationManager.ToBaseRelativePath(NavigationManager.Uri).ToLowerInvariant().
|
||||
StartsWith("admin/processors/edit/",
|
||||
StringComparison.InvariantCulture);
|
||||
|
||||
if(_editing)
|
||||
SetCheckboxes();
|
||||
@@ -105,7 +111,15 @@ namespace Marechai.Pages.Admin.Details
|
||||
async void OnCancelClicked()
|
||||
{
|
||||
_editing = false;
|
||||
_model = await Service.GetAsync(Id);
|
||||
|
||||
if(_creating)
|
||||
{
|
||||
NavigationManager.ToBaseRelativePath("admin/processors");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
_model = await Service.GetAsync(Id);
|
||||
SetCheckboxes();
|
||||
StateHasChanged();
|
||||
}
|
||||
@@ -234,9 +248,14 @@ namespace Marechai.Pages.Admin.Details
|
||||
else if(_model.L3 < 0)
|
||||
return;
|
||||
|
||||
_editing = false;
|
||||
await Service.UpdateAsync(_model);
|
||||
_model = await Service.GetAsync(Id);
|
||||
if(_creating)
|
||||
Id = await Service.CreateAsync(_model);
|
||||
else
|
||||
await Service.UpdateAsync(_model);
|
||||
|
||||
_editing = false;
|
||||
_creating = false;
|
||||
_model = await Service.GetAsync(Id);
|
||||
SetCheckboxes();
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
@@ -42,9 +42,7 @@
|
||||
return;
|
||||
}
|
||||
<p>
|
||||
<span class="btn btn-primary">
|
||||
@L["Create new"]
|
||||
</span>
|
||||
<a class="btn btn-primary" href="/admin/processors/create">@L["Create new"]</a>
|
||||
</p>
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
|
||||
@@ -90,6 +90,27 @@ namespace Marechai.Services
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
|
||||
public async Task<int> CreateAsync(ProcessorViewModel viewModel)
|
||||
{
|
||||
var model = new Processor
|
||||
{
|
||||
AddrBus = viewModel.AddrBus, CompanyId = viewModel.CompanyId, Cores = viewModel.Cores,
|
||||
DataBus = viewModel.DataBus, DieSize = viewModel.DieSize, Fprs = viewModel.Fprs,
|
||||
FprSize = viewModel.FprSize, Gprs = viewModel.Gprs, GprSize = viewModel.GprSize,
|
||||
InstructionSetId = viewModel.InstructionSetId, Introduced = viewModel.Introduced,
|
||||
L1Data = viewModel.L1Data, L1Instruction = viewModel.L1Instruction, L2 = viewModel.L2,
|
||||
L3 = viewModel.L3, ModelCode = viewModel.ModelCode, Name = viewModel.Name, Package = viewModel.Package,
|
||||
Process = viewModel.Process, ProcessNm = viewModel.ProcessNm, SimdRegisters = viewModel.SimdRegisters,
|
||||
SimdSize = viewModel.SimdSize, Speed = viewModel.Speed, ThreadsPerCore = viewModel.ThreadsPerCore,
|
||||
Transistors = viewModel.Transistors
|
||||
};
|
||||
|
||||
await _context.Processors.AddAsync(model);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return model.Id;
|
||||
}
|
||||
|
||||
public async Task DeleteAsync(int id)
|
||||
{
|
||||
Processor item = await _context.Processors.FindAsync(id);
|
||||
|
||||
Reference in New Issue
Block a user