mirror of
https://github.com/claunia/marechai.git
synced 2025-12-16 19:14:25 +00:00
Allow to add and remove processors from machine details in admin view.
This commit is contained in:
@@ -1,196 +0,0 @@
|
||||
/******************************************************************************
|
||||
// MARECHAI: Master repository of computing history artifacts information
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : ProcessorsByMachinesController.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// Processors by machine 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 ProcessorsByMachinesController : Controller
|
||||
{
|
||||
readonly MarechaiContext _context;
|
||||
|
||||
public ProcessorsByMachinesController(MarechaiContext context) => _context = context;
|
||||
|
||||
// GET: Admin/ProcessorsByMachines
|
||||
public async Task<IActionResult> Index()
|
||||
{
|
||||
IIncludableQueryable<ProcessorsByMachine, Processor> marechaiContext =
|
||||
_context.ProcessorsByMachine.Include(p => p.Machine).Include(p => p.Processor);
|
||||
|
||||
return View(await marechaiContext.OrderBy(p => p.Machine.Name).ThenBy(p => p.Processor.Name).
|
||||
Select(p => new ProcessorsByMachineViewModel
|
||||
{
|
||||
Id = p.Id, Machine = p.Machine.Name, Processor = p.Processor.Name,
|
||||
Speed = p.Speed
|
||||
}).ToListAsync());
|
||||
}
|
||||
|
||||
// GET: Admin/ProcessorsByMachines/Details/5
|
||||
public async Task<IActionResult> Details(long? id)
|
||||
{
|
||||
if(id == null)
|
||||
return NotFound();
|
||||
|
||||
ProcessorsByMachine processorsByMachine =
|
||||
await _context.ProcessorsByMachine.Include(p => p.Machine).Include(p => p.Processor).
|
||||
FirstOrDefaultAsync(m => m.Id == id);
|
||||
|
||||
if(processorsByMachine == null)
|
||||
return NotFound();
|
||||
|
||||
return View(processorsByMachine);
|
||||
}
|
||||
|
||||
// GET: Admin/ProcessorsByMachines/Create
|
||||
public IActionResult Create()
|
||||
{
|
||||
ViewData["MachineId"] = new SelectList(_context.Machines, "Id", "Name");
|
||||
ViewData["ProcessorId"] = new SelectList(_context.Processors, "Id", "Name");
|
||||
|
||||
return View();
|
||||
}
|
||||
|
||||
// POST: Admin/ProcessorsByMachines/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("ProcessorId,MachineId,Speed,Id")]
|
||||
ProcessorsByMachine processorsByMachine)
|
||||
{
|
||||
if(ModelState.IsValid)
|
||||
{
|
||||
_context.Add(processorsByMachine);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return RedirectToAction(nameof(Index));
|
||||
}
|
||||
|
||||
ViewData["MachineId"] = new SelectList(_context.Machines, "Id", "Name", processorsByMachine.MachineId);
|
||||
|
||||
ViewData["ProcessorId"] =
|
||||
new SelectList(_context.Processors, "Id", "Name", processorsByMachine.ProcessorId);
|
||||
|
||||
return View(processorsByMachine);
|
||||
}
|
||||
|
||||
// GET: Admin/ProcessorsByMachines/Edit/5
|
||||
public async Task<IActionResult> Edit(long? id)
|
||||
{
|
||||
if(id == null)
|
||||
return NotFound();
|
||||
|
||||
ProcessorsByMachine processorsByMachine = await _context.ProcessorsByMachine.FindAsync(id);
|
||||
|
||||
if(processorsByMachine == null)
|
||||
return NotFound();
|
||||
|
||||
ViewData["MachineId"] = new SelectList(_context.Machines, "Id", "Name", processorsByMachine.MachineId);
|
||||
|
||||
ViewData["ProcessorId"] =
|
||||
new SelectList(_context.Processors, "Id", "Name", processorsByMachine.ProcessorId);
|
||||
|
||||
return View(processorsByMachine);
|
||||
}
|
||||
|
||||
// POST: Admin/ProcessorsByMachines/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(long id, [Bind("ProcessorId,MachineId,Speed,Id")]
|
||||
ProcessorsByMachine processorsByMachine)
|
||||
{
|
||||
if(id != processorsByMachine.Id)
|
||||
return NotFound();
|
||||
|
||||
if(ModelState.IsValid)
|
||||
{
|
||||
try
|
||||
{
|
||||
_context.Update(processorsByMachine);
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
catch(DbUpdateConcurrencyException)
|
||||
{
|
||||
if(!ProcessorsByMachineExists(processorsByMachine.Id))
|
||||
return NotFound();
|
||||
|
||||
throw;
|
||||
}
|
||||
|
||||
return RedirectToAction(nameof(Index));
|
||||
}
|
||||
|
||||
ViewData["MachineId"] = new SelectList(_context.Machines, "Id", "Name", processorsByMachine.MachineId);
|
||||
|
||||
ViewData["ProcessorId"] =
|
||||
new SelectList(_context.Processors, "Id", "Name", processorsByMachine.ProcessorId);
|
||||
|
||||
return View(processorsByMachine);
|
||||
}
|
||||
|
||||
// GET: Admin/ProcessorsByMachines/Delete/5
|
||||
public async Task<IActionResult> Delete(long? id)
|
||||
{
|
||||
if(id == null)
|
||||
return NotFound();
|
||||
|
||||
ProcessorsByMachine processorsByMachine =
|
||||
await _context.ProcessorsByMachine.Include(p => p.Machine).Include(p => p.Processor).
|
||||
FirstOrDefaultAsync(m => m.Id == id);
|
||||
|
||||
if(processorsByMachine == null)
|
||||
return NotFound();
|
||||
|
||||
return View(processorsByMachine);
|
||||
}
|
||||
|
||||
// POST: Admin/ProcessorsByMachines/Delete/5
|
||||
[HttpPost, ActionName("Delete"), ValidateAntiForgeryToken]
|
||||
public async Task<IActionResult> DeleteConfirmed(long id)
|
||||
{
|
||||
ProcessorsByMachine processorsByMachine = await _context.ProcessorsByMachine.FindAsync(id);
|
||||
_context.ProcessorsByMachine.Remove(processorsByMachine);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return RedirectToAction(nameof(Index));
|
||||
}
|
||||
|
||||
bool ProcessorsByMachineExists(long id) => _context.ProcessorsByMachine.Any(e => e.Id == id);
|
||||
}
|
||||
}
|
||||
@@ -1,76 +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.ProcessorsByMachine
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "Create";
|
||||
}
|
||||
<h2>Create</h2>
|
||||
<h4>Processor by machine</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="Machine" class="control-label">
|
||||
</label>
|
||||
<select asp-for="Machine" class="form-control" asp-items="ViewBag.MachineId">
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label asp-for="ProcessorId" class="control-label">
|
||||
</label>
|
||||
<select asp-for="ProcessorId" class="form-control" asp-items="ViewBag.ProcessorId">
|
||||
</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">
|
||||
<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"); }
|
||||
}
|
||||
@@ -1,69 +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.ProcessorsByMachine
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "Delete";
|
||||
}
|
||||
<h2>Delete</h2>
|
||||
<h3>Are you sure you want to delete this?</h3>
|
||||
<div>
|
||||
<h4>Processors by machine</h4>
|
||||
<hr />
|
||||
<dl class="dl-horizontal">
|
||||
<dt>
|
||||
@Html.DisplayNameFor(model => model.Machine)
|
||||
</dt>
|
||||
<dd>
|
||||
@Html.DisplayFor(model => model.Machine.Name)
|
||||
</dd>
|
||||
<dt>
|
||||
@Html.DisplayNameFor(model => model.Processor)
|
||||
</dt>
|
||||
<dd>
|
||||
@Html.DisplayFor(model => model.Processor.Name)
|
||||
</dd>
|
||||
<dt>
|
||||
@Html.DisplayNameFor(model => model.Speed)
|
||||
</dt>
|
||||
<dd>
|
||||
@Html.DisplayFor(model => model.Speed)
|
||||
</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>
|
||||
@@ -1,69 +0,0 @@
|
||||
@{
|
||||
/******************************************************************************
|
||||
// MARECHAI: Master repository of computing history artifacts information
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : Details.cshtml
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// Admin view details
|
||||
//
|
||||
// --[ 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.ProcessorsByMachine
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "Details";
|
||||
}
|
||||
<h2>Details</h2>
|
||||
<div>
|
||||
<h4>Processors by machine</h4>
|
||||
<hr />
|
||||
<dl class="dl-horizontal">
|
||||
<dt>
|
||||
@Html.DisplayNameFor(model => model.Machine)
|
||||
</dt>
|
||||
<dd>
|
||||
@Html.DisplayFor(model => model.Machine.Name)
|
||||
</dd>
|
||||
<dt>
|
||||
@Html.DisplayNameFor(model => model.Processor)
|
||||
</dt>
|
||||
<dd>
|
||||
@Html.DisplayFor(model => model.Processor.Name)
|
||||
</dd>
|
||||
<dt>
|
||||
@Html.DisplayNameFor(model => model.Speed)
|
||||
</dt>
|
||||
<dd>
|
||||
@Html.DisplayFor(model => model.Speed)
|
||||
</dd>
|
||||
</dl>
|
||||
</div>
|
||||
<div>
|
||||
<a asp-action="Edit" asp-route-id="@Model.Id" class="btn btn-primary">
|
||||
Edit
|
||||
</a>
|
||||
<a asp-action="Index" class="btn btn-secondary">
|
||||
Back to List
|
||||
</a>
|
||||
</div>
|
||||
@@ -1,81 +0,0 @@
|
||||
@{
|
||||
/******************************************************************************
|
||||
// MARECHAI: Master repository of computing history artifacts information
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : Edit.cshtml
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// Admin view edit
|
||||
//
|
||||
// --[ 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.ProcessorsByMachine
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "Edit";
|
||||
}
|
||||
<h2>Edit</h2>
|
||||
<h4>Processors by machine</h4>
|
||||
<hr />
|
||||
<div class="row">
|
||||
<div class="col-md-4">
|
||||
<form asp-action="Edit">
|
||||
<div asp-validation-summary="ModelOnly" class="text-danger">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label asp-for="Machine" class="control-label">
|
||||
</label>
|
||||
<select asp-for="MachineId" class="form-control" asp-items="ViewBag.MachineId">
|
||||
</select>
|
||||
<span asp-validation-for="MachineId" class="text-danger">
|
||||
</span>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label asp-for="Processor" class="control-label">
|
||||
</label>
|
||||
<select asp-for="ProcessorId" class="form-control" asp-items="ViewBag.ProcessorId">
|
||||
</select>
|
||||
<span asp-validation-for="ProcessorId" class="text-danger">
|
||||
</span>
|
||||
</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>
|
||||
<input type="hidden" asp-for="Id" />
|
||||
<div class="form-group">
|
||||
<input class="btn btn-primary" type="submit" value="Save" />
|
||||
<a asp-action="Index" class="btn btn-secondary">
|
||||
Back to List
|
||||
</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@section Scripts {
|
||||
@{ await Html.RenderPartialAsync("_ValidationScriptsPartial"); }
|
||||
}
|
||||
@@ -1,85 +0,0 @@
|
||||
@{
|
||||
/******************************************************************************
|
||||
// MARECHAI: Master repository of computing history artifacts information
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : Index.cshtml
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// --[ Description ] ----------------------------------------------------------
|
||||
//
|
||||
// Admin view index
|
||||
//
|
||||
// --[ 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 IEnumerable<Marechai.Areas.Admin.Models.ProcessorsByMachineViewModel>
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "Processors by machine (Admin)";
|
||||
}
|
||||
<h2>Processors by machine</h2>
|
||||
<p>
|
||||
<a asp-action="Create" class="btn btn-primary">
|
||||
Create new
|
||||
</a>
|
||||
</p>
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>
|
||||
@Html.DisplayNameFor(model => model.Machine)
|
||||
</th>
|
||||
<th>
|
||||
@Html.DisplayNameFor(model => model.Processor)
|
||||
</th>
|
||||
<th>
|
||||
@Html.DisplayNameFor(model => model.Speed)
|
||||
</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var item in Model)
|
||||
{
|
||||
<tr>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.Machine)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.Processor)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.Speed)
|
||||
</td>
|
||||
<td>
|
||||
<a asp-action="Details" asp-route-id="@item.Id" class="btn btn-primary">
|
||||
Details
|
||||
</a>
|
||||
<a asp-action="Edit" asp-route-id="@item.Id" class="btn btn-secondary">
|
||||
Edit
|
||||
</a>
|
||||
<a asp-action="Delete" asp-route-id="@item.Id" class="btn btn-danger">
|
||||
Delete
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
@@ -2,7 +2,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<Version>3.0.99.1377</Version>
|
||||
<Version>3.0.99.1385</Version>
|
||||
<Company>Canary Islands Computer Museum</Company>
|
||||
<Copyright>Copyright © 2003-2020 Natalia Portillo</Copyright>
|
||||
<Product>Canary Islands Computer Museum Website</Product>
|
||||
@@ -154,5 +154,10 @@
|
||||
<_ContentIncludedByDefault Remove="Areas\Admin\Views\SoundByMachine\Details.cshtml" />
|
||||
<_ContentIncludedByDefault Remove="Areas\Admin\Views\SoundByMachine\Edit.cshtml" />
|
||||
<_ContentIncludedByDefault Remove="Areas\Admin\Views\SoundByMachine\Index.cshtml" />
|
||||
<_ContentIncludedByDefault Remove="Areas\Admin\Views\ProcessorsByMachines\Create.cshtml" />
|
||||
<_ContentIncludedByDefault Remove="Areas\Admin\Views\ProcessorsByMachines\Delete.cshtml" />
|
||||
<_ContentIncludedByDefault Remove="Areas\Admin\Views\ProcessorsByMachines\Details.cshtml" />
|
||||
<_ContentIncludedByDefault Remove="Areas\Admin\Views\ProcessorsByMachines\Edit.cshtml" />
|
||||
<_ContentIncludedByDefault Remove="Areas\Admin\Views\ProcessorsByMachines\Index.cshtml" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -43,6 +43,8 @@
|
||||
@inject GpusService GpusService
|
||||
@inject SoundSynthsByMachineService SoundSynthsByMachineService
|
||||
@inject SoundSynthsService SoundSynthsService
|
||||
@inject ProcessorsByMachineService ProcessorsByMachineService
|
||||
@inject ProcessorsService ProcessorsService
|
||||
@attribute [Authorize(Roles = "UberAdmin, Admin")]
|
||||
<h3>@L["Machine details"]</h3>
|
||||
<hr />
|
||||
@@ -206,7 +208,7 @@
|
||||
@item.Name
|
||||
</td>
|
||||
<td>
|
||||
<Button Color="Color.Danger" Clicked="() => {ShowSoundDeleteModal(item.Id);}" Disabled="@_addingGpu">@L["Delete"]</Button>
|
||||
<Button Color="Color.Danger" Clicked="() => {ShowGpuDeleteModal(item.Id);}" Disabled="@_addingGpu">@L["Delete"]</Button>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
@@ -260,7 +262,81 @@
|
||||
@item.Name
|
||||
</td>
|
||||
<td>
|
||||
<Button Color="Color.Danger" Clicked="() => {ShowGpuDeleteModal(item.Id);}" Disabled="@_addingSound">@L["Delete"]</Button>
|
||||
<Button Color="Color.Danger" Clicked="() => {ShowSoundDeleteModal(item.Id);}" Disabled="@_addingSound">@L["Delete"]</Button>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
}
|
||||
|
||||
<hr />
|
||||
<h3>@L["Processors belonging to this machine"]</h3>
|
||||
<Button Color="Color.Success" Clicked="OnAddCpuClick" Disabled="_addingCpu">@L["Add new (processor by machine)"]</Button>
|
||||
@if (_addingCpu)
|
||||
{
|
||||
<div>
|
||||
<Field>
|
||||
<FieldLabel>@L["Processors"]</FieldLabel>
|
||||
<Select Disabled="_savingCpu" TValue="int?" @bind-SelectedValue="@_addingCpuId">
|
||||
@foreach (var cpu in _cpus)
|
||||
{
|
||||
<SelectItem TValue="int?" Value="@cpu.Id">@cpu.CompanyName - @cpu.Name</SelectItem>
|
||||
}
|
||||
</Select>
|
||||
</Field>
|
||||
<Field>
|
||||
<FieldLabel>@L["Nominal speed (MHz)"]</FieldLabel>
|
||||
<Check TValue="bool" @bind-Checked="@_unknownProcessorSpeed">@L["Unknown (processor by machine speed)"]</Check>
|
||||
@if (!_unknownProcessorSpeed)
|
||||
{
|
||||
<Validation Validator="@ValidateProcessorSpeed">
|
||||
<NumericEdit TValue="float?" Decimals="3" @bind-Value="@_addingProcessorSpeed" >
|
||||
<Feedback>
|
||||
<ValidationError>@L["Please enter a valid speed for this processor."]</ValidationError>
|
||||
</Feedback>
|
||||
</NumericEdit>
|
||||
</Validation>
|
||||
}
|
||||
</Field>
|
||||
<Button Color="Color.Primary" Clicked="@CancelAddCpu" Disabled="@_savingCpu">@L["Cancel"]</Button>
|
||||
<Button Color="Color.Success" Clicked="@ConfirmAddCpu" Disabled="@_savingCpu">@L["Add"]</Button>
|
||||
</div>
|
||||
}
|
||||
@if (_machineCpus?.Count > 0)
|
||||
{
|
||||
<div>
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>
|
||||
@L["Company"]
|
||||
</th>
|
||||
<th>
|
||||
@L["Name"]
|
||||
</th>
|
||||
<th>
|
||||
@L["Speed"]
|
||||
</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var item in _machineCpus)
|
||||
{
|
||||
<tr>
|
||||
<td>
|
||||
@item.CompanyName
|
||||
</td>
|
||||
<td>
|
||||
@item.Name
|
||||
</td>
|
||||
<td>
|
||||
@string.Format(L["{0:F3} MHz"], item.Speed)
|
||||
</td>
|
||||
<td>
|
||||
<Button Color="Color.Danger" Clicked="() => {ShowCpuDeleteModal(item.Id);}" Disabled="@_addingCpu">@L["Delete"]</Button>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
|
||||
@@ -12,17 +12,23 @@ namespace Marechai.Pages.Admin.Details
|
||||
{
|
||||
public partial class Machine
|
||||
{
|
||||
bool _addingCpu;
|
||||
int? _addingCpuId;
|
||||
bool _addingGpu;
|
||||
int? _addingGpuId;
|
||||
float? _addingProcessorSpeed;
|
||||
bool _addingSound;
|
||||
int? _addingSoundId;
|
||||
List<CompanyViewModel> _companies;
|
||||
List<ProcessorViewModel> _cpus;
|
||||
bool _creating;
|
||||
ProcessorByMachineViewModel _currentCpuByMachine;
|
||||
GpuByMachineViewModel _currentGpuByMachine;
|
||||
SoundSynthByMachineViewModel _currentSoundByMachine;
|
||||
bool _deleteInProgress;
|
||||
string _deleteText;
|
||||
string _deleteTitle;
|
||||
bool _deletingCpuByMachine;
|
||||
bool _deletingGpuByMachine;
|
||||
bool _deletingSoundByMachine;
|
||||
bool _editing;
|
||||
@@ -30,16 +36,19 @@ namespace Marechai.Pages.Admin.Details
|
||||
Modal _frmDelete;
|
||||
List<GpuViewModel> _gpus;
|
||||
bool _loaded;
|
||||
List<ProcessorByMachineViewModel> _machineCpus;
|
||||
List<GpuByMachineViewModel> _machineGpus;
|
||||
List<SoundSynthByMachineViewModel> _machineSound;
|
||||
MachineViewModel _model;
|
||||
bool _noFamily;
|
||||
bool _prototype;
|
||||
bool _savingCpu;
|
||||
bool _savingGpu;
|
||||
bool _savingSound;
|
||||
List<SoundSynthViewModel> _soundSynths;
|
||||
bool _unknownIntroduced;
|
||||
bool _unknownModel;
|
||||
bool _unknownProcessorSpeed;
|
||||
[Parameter]
|
||||
public int Id { get; set; }
|
||||
|
||||
@@ -67,7 +76,9 @@ namespace Marechai.Pages.Admin.Details
|
||||
_families = await MachineFamiliesService.GetAsync();
|
||||
_model = _creating ? new MachineViewModel() : await Service.GetAsync(Id);
|
||||
_machineGpus = await GpusByMachineService.GetByMachine(Id);
|
||||
_machineCpus = await ProcessorsByMachineService.GetByMachine(Id);
|
||||
_gpus = await GpusService.GetAsync();
|
||||
_cpus = await ProcessorsService.GetAsync();
|
||||
_soundSynths = await SoundSynthsService.GetAsync();
|
||||
|
||||
_editing = _creating || NavigationManager.ToBaseRelativePath(NavigationManager.Uri).ToLowerInvariant().
|
||||
@@ -171,6 +182,8 @@ namespace Marechai.Pages.Admin.Details
|
||||
await ConfirmDeleteGpuByMachine();
|
||||
else if(_deletingSoundByMachine)
|
||||
await ConfirmDeleteSoundByMachine();
|
||||
else if(_deletingCpuByMachine)
|
||||
await ConfirmDeleteCpuByMachine();
|
||||
}
|
||||
|
||||
async Task ConfirmDeleteGpuByMachine()
|
||||
@@ -202,13 +215,16 @@ namespace Marechai.Pages.Admin.Details
|
||||
_deletingGpuByMachine = false;
|
||||
_currentGpuByMachine = null;
|
||||
_deletingSoundByMachine = false;
|
||||
_currentSoundByMachine = null;
|
||||
_deletingCpuByMachine = false;
|
||||
_currentCpuByMachine = null;
|
||||
}
|
||||
|
||||
async Task OnAddGpuClick()
|
||||
{
|
||||
_addingGpu = true;
|
||||
_savingGpu = false;
|
||||
_addingGpuId = null;
|
||||
_addingGpuId = _gpus.First().Id;
|
||||
}
|
||||
|
||||
void CancelAddGpu()
|
||||
@@ -220,7 +236,8 @@ namespace Marechai.Pages.Admin.Details
|
||||
|
||||
async Task ConfirmAddGpu()
|
||||
{
|
||||
if(_addingGpuId is null)
|
||||
if(_addingGpuId is null ||
|
||||
_addingGpuId <= 0)
|
||||
{
|
||||
CancelAddGpu();
|
||||
|
||||
@@ -286,7 +303,7 @@ namespace Marechai.Pages.Admin.Details
|
||||
{
|
||||
_addingSound = true;
|
||||
_savingSound = false;
|
||||
_addingSoundId = null;
|
||||
_addingSoundId = _soundSynths.First().Id;
|
||||
}
|
||||
|
||||
void CancelAddSound()
|
||||
@@ -298,7 +315,8 @@ namespace Marechai.Pages.Admin.Details
|
||||
|
||||
async Task ConfirmAddSound()
|
||||
{
|
||||
if(_addingSoundId is null)
|
||||
if(_addingSoundId is null ||
|
||||
_addingSoundId <= 0)
|
||||
{
|
||||
CancelAddSound();
|
||||
|
||||
@@ -323,5 +341,105 @@ namespace Marechai.Pages.Admin.Details
|
||||
// Tell we finished loading
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
void ShowCpuDeleteModal(long itemId)
|
||||
{
|
||||
_currentCpuByMachine = _machineCpus.FirstOrDefault(n => n.Id == itemId);
|
||||
_deletingCpuByMachine = true;
|
||||
_deleteTitle = L["Delete processor from this machine"];
|
||||
|
||||
string speed;
|
||||
|
||||
speed = _currentCpuByMachine?.Speed == null ? L["Unknown (processor by machine speed)"]
|
||||
: string.Format(L["{0:F3} MHz"], _currentCpuByMachine?.Speed);
|
||||
|
||||
_deleteText =
|
||||
string.Format(L["Are you sure you want to delete the graphical processing unit {0} with speed {2} manufactured by {1} from this machine?"],
|
||||
_currentCpuByMachine?.Name, _currentCpuByMachine?.CompanyName, speed);
|
||||
|
||||
_frmDelete.Show();
|
||||
}
|
||||
|
||||
async Task ConfirmDeleteCpuByMachine()
|
||||
{
|
||||
if(_currentCpuByMachine is null)
|
||||
return;
|
||||
|
||||
_deleteInProgress = true;
|
||||
|
||||
// Yield thread to let UI to update
|
||||
await Task.Yield();
|
||||
|
||||
await ProcessorsByMachineService.DeleteAsync(_currentCpuByMachine.Id);
|
||||
_machineCpus = await ProcessorsByMachineService.GetByMachine(Id);
|
||||
|
||||
_deleteInProgress = false;
|
||||
_frmDelete.Hide();
|
||||
|
||||
// Yield thread to let UI to update
|
||||
await Task.Yield();
|
||||
|
||||
// Tell we finished loading
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
async Task OnAddCpuClick()
|
||||
{
|
||||
_addingCpu = true;
|
||||
_savingCpu = false;
|
||||
_addingCpuId = _cpus.First().Id;
|
||||
_addingProcessorSpeed = 0;
|
||||
_unknownProcessorSpeed = true;
|
||||
}
|
||||
|
||||
void CancelAddCpu()
|
||||
{
|
||||
_addingCpu = false;
|
||||
_savingCpu = false;
|
||||
_addingCpuId = null;
|
||||
}
|
||||
|
||||
async Task ConfirmAddCpu()
|
||||
{
|
||||
if(_addingCpuId is null ||
|
||||
_addingCpuId <= 0)
|
||||
{
|
||||
CancelAddCpu();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
_savingGpu = true;
|
||||
|
||||
// Yield thread to let UI to update
|
||||
await Task.Yield();
|
||||
|
||||
await ProcessorsByMachineService.CreateAsync(_addingCpuId.Value, Id,
|
||||
_unknownProcessorSpeed ? null : _addingProcessorSpeed);
|
||||
|
||||
_machineCpus = await ProcessorsByMachineService.GetByMachine(Id);
|
||||
|
||||
_addingCpu = false;
|
||||
_savingCpu = false;
|
||||
_addingCpuId = null;
|
||||
|
||||
// Yield thread to let UI to update
|
||||
await Task.Yield();
|
||||
|
||||
// Tell we finished loading
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
void ValidateProcessorSpeed(ValidatorEventArgs e)
|
||||
{
|
||||
if(!(e.Value is float item))
|
||||
{
|
||||
e.Status = ValidationStatus.Error;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
e.Status = item > 0 ? ValidationStatus.Success : ValidationStatus.Error;
|
||||
}
|
||||
}
|
||||
}
|
||||
49
Marechai/Services/ProcessorsByMachineService.cs
Normal file
49
Marechai/Services/ProcessorsByMachineService.cs
Normal file
@@ -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 ProcessorsByMachineService
|
||||
{
|
||||
readonly MarechaiContext _context;
|
||||
|
||||
public ProcessorsByMachineService(MarechaiContext context) => _context = context;
|
||||
|
||||
public async Task<List<ProcessorByMachineViewModel>> GetByMachine(int machineId) =>
|
||||
await _context.ProcessorsByMachine.Where(p => p.MachineId == machineId).
|
||||
Select(p => new ProcessorByMachineViewModel
|
||||
{
|
||||
Id = p.Id, Name = p.Processor.Name, CompanyName = p.Processor.Company.Name,
|
||||
ProcessorId = p.ProcessorId, MachineId = p.MachineId, Speed = p.Speed
|
||||
}).OrderBy(p => p.CompanyName).ThenBy(p => p.Name).ToListAsync();
|
||||
|
||||
public async Task DeleteAsync(long id)
|
||||
{
|
||||
ProcessorsByMachine item = await _context.ProcessorsByMachine.FindAsync(id);
|
||||
|
||||
if(item is null)
|
||||
return;
|
||||
|
||||
_context.ProcessorsByMachine.Remove(item);
|
||||
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
|
||||
public async Task<long> CreateAsync(int processorId, int machineId, float? speed)
|
||||
{
|
||||
var item = new ProcessorsByMachine
|
||||
{
|
||||
ProcessorId = processorId, MachineId = machineId, Speed = speed
|
||||
};
|
||||
|
||||
await _context.ProcessorsByMachine.AddAsync(item);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return item.Id;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -22,7 +22,7 @@ namespace Marechai.Services
|
||||
ThreadsPerCore = p.ThreadsPerCore, Process = p.Process, ProcessNm = p.ProcessNm, DieSize = p.DieSize,
|
||||
Transistors = p.Transistors, DataBus = p.DataBus, AddrBus = p.AddrBus, SimdRegisters = p.SimdRegisters,
|
||||
SimdSize = p.SimdSize, L1Instruction = p.L1Instruction, L1Data = p.L1Data, L2 = p.L2,
|
||||
L3 = p.L3, InstructionSet = p.InstructionSet.Name,
|
||||
L3 = p.L3, InstructionSet = p.InstructionSet.Name, Id = p.Id,
|
||||
InstructionSetExtensions = p.InstructionSetExtensions.Select(e => e.Extension.Extension).ToList()
|
||||
}).ToListAsync();
|
||||
|
||||
@@ -38,6 +38,7 @@ namespace Marechai.Services
|
||||
DataBus = p.Processor.DataBus, AddrBus = p.Processor.AddrBus, SimdRegisters = p.Processor.SimdRegisters,
|
||||
SimdSize = p.Processor.SimdSize, L1Instruction = p.Processor.L1Instruction, L1Data = p.Processor.L1Data,
|
||||
L2 = p.Processor.L2, L3 = p.Processor.L3, InstructionSet = p.Processor.InstructionSet.Name,
|
||||
Id = p.Processor.Id,
|
||||
InstructionSetExtensions =
|
||||
p.Processor.InstructionSetExtensions.Select(e => e.Extension.Extension).ToList()
|
||||
}).ToListAsync();
|
||||
|
||||
@@ -64,6 +64,7 @@ namespace Marechai.Services
|
||||
services.AddScoped<CompanyLogosService>();
|
||||
services.AddScoped<GpusByMachineService>();
|
||||
services.AddScoped<SoundSynthsByMachineService>();
|
||||
services.AddScoped<ProcessorsByMachineService>();
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Marechai/ViewModels/ProcessorByMachineViewModel.cs
Normal file
11
Marechai/ViewModels/ProcessorByMachineViewModel.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
namespace Marechai.ViewModels
|
||||
{
|
||||
public class ProcessorByMachineViewModel : BaseViewModel<long>
|
||||
{
|
||||
public int ProcessorId { get; set; }
|
||||
public int MachineId { get; set; }
|
||||
public string CompanyName { get; set; }
|
||||
public string Name { get; set; }
|
||||
public float? Speed { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user