Allow to add and remove storage from machine details in admin view.

This commit is contained in:
2020-05-29 05:02:31 +01:00
parent d0db223521
commit 092121c6c2
12 changed files with 272 additions and 618 deletions

View File

@@ -1,186 +0,0 @@
/******************************************************************************
// MARECHAI: Master repository of computing history artifacts information
// ----------------------------------------------------------------------------
//
// Filename : StorageByMachinesController.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// --[ Description ] ----------------------------------------------------------
//
// Storage by machines 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 StorageByMachinesController : Controller
{
readonly MarechaiContext _context;
public StorageByMachinesController(MarechaiContext context) => _context = context;
// GET: Admin/StorageByMachines
public async Task<IActionResult> Index()
{
IIncludableQueryable<StorageByMachine, Machine> marechaiContext =
_context.StorageByMachine.Include(s => s.Machine);
return View(await marechaiContext.OrderBy(s => s.Machine.Company.Name).ThenBy(s => s.Machine.Name).
Select(s => new StorageByMachineViewModel
{
Id = s.Id, Company = s.Machine.Company.Name,
Machine = s.Machine.Name,
Type = s.Type, Interface = s.Interface,
Capacity = s.Capacity
}).ToListAsync());
}
// GET: Admin/StorageByMachines/Details/5
public async Task<IActionResult> Details(long? id)
{
if(id == null)
return NotFound();
StorageByMachine storageByMachine =
await _context.StorageByMachine.Include(s => s.Machine).FirstOrDefaultAsync(m => m.Id == id);
if(storageByMachine == null)
return NotFound();
return View(storageByMachine);
}
// GET: Admin/StorageByMachines/Create
public IActionResult Create()
{
ViewData["MachineId"] = new SelectList(_context.Machines, "Id", "Name");
return View();
}
// POST: Admin/StorageByMachines/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("MachineId,Type,Interface,Capacity,Id")]
StorageByMachine storageByMachine)
{
if(ModelState.IsValid)
{
_context.Add(storageByMachine);
await _context.SaveChangesAsync();
return RedirectToAction(nameof(Index));
}
ViewData["MachineId"] = new SelectList(_context.Machines, "Id", "Name", storageByMachine.MachineId);
return View(storageByMachine);
}
// GET: Admin/StorageByMachines/Edit/5
public async Task<IActionResult> Edit(long? id)
{
if(id == null)
return NotFound();
StorageByMachine storageByMachine = await _context.StorageByMachine.FindAsync(id);
if(storageByMachine == null)
return NotFound();
ViewData["MachineId"] = new SelectList(_context.Machines, "Id", "Name", storageByMachine.MachineId);
return View(storageByMachine);
}
// POST: Admin/StorageByMachines/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("MachineId,Type,Interface,Capacity,Id")]
StorageByMachine storageByMachine)
{
if(id != storageByMachine.Id)
return NotFound();
if(ModelState.IsValid)
{
try
{
_context.Update(storageByMachine);
await _context.SaveChangesAsync();
}
catch(DbUpdateConcurrencyException)
{
if(!StorageByMachineExists(storageByMachine.Id))
return NotFound();
throw;
}
return RedirectToAction(nameof(Index));
}
ViewData["MachineId"] = new SelectList(_context.Machines, "Id", "Name", storageByMachine.MachineId);
return View(storageByMachine);
}
// GET: Admin/StorageByMachines/Delete/5
public async Task<IActionResult> Delete(long? id)
{
if(id == null)
return NotFound();
StorageByMachine storageByMachine =
await _context.StorageByMachine.Include(s => s.Machine).FirstOrDefaultAsync(m => m.Id == id);
if(storageByMachine == null)
return NotFound();
return View(storageByMachine);
}
// POST: Admin/StorageByMachines/Delete/5
[HttpPost, ActionName("Delete"), ValidateAntiForgeryToken]
public async Task<IActionResult> DeleteConfirmed(long id)
{
StorageByMachine storageByMachine = await _context.StorageByMachine.FindAsync(id);
_context.StorageByMachine.Remove(storageByMachine);
await _context.SaveChangesAsync();
return RedirectToAction(nameof(Index));
}
bool StorageByMachineExists(long id) => _context.StorageByMachine.Any(e => e.Id == id);
}
}

View File

@@ -1,87 +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
*******************************************************************************/
}
@using Marechai.Database
@model Marechai.Database.Models.StorageByMachine
@{
ViewData["Title"] = "Create";
}
<h2>Create</h2>
<h4>Storage 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="MachineId" class="form-control" asp-items="ViewBag.MachineId">
</select>
</div>
<div class="form-group">
<label asp-for="Type" class="control-label">
</label>
<select asp-for="Type" class="form-control" asp-items="Html.GetEnumSelectList<StorageType>().OrderBy(s => s.Text)">
</select>
<span asp-validation-for="Type" class="text-danger">
</span>
</div>
<div class="form-group">
<label asp-for="Interface" class="control-label">
</label>
<select asp-for="Interface" class="form-control" asp-items="Html.GetEnumSelectList<StorageInterface>().OrderBy(s => s.Text)">
</select>
<span asp-validation-for="Interface" class="text-danger">
</span>
</div>
<div class="form-group">
<label asp-for="Capacity" class="control-label">
</label>
<input asp-for="Capacity" class="form-control" />
<span asp-validation-for="Capacity" 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"); }
}

View File

@@ -1,75 +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.StorageByMachine
@{
ViewData["Title"] = "Delete";
}
<h2>Delete</h2>
<h3>Are you sure you want to delete this?</h3>
<div>
<h4>Storage by machine</h4>
<hr />
<dl class="dl-horizontal">
<dt>
@Html.DisplayNameFor(model => model.Type)
</dt>
<dd>
@Html.DisplayFor(model => model.Type)
</dd>
<dt>
@Html.DisplayNameFor(model => model.Interface)
</dt>
<dd>
@Html.DisplayFor(model => model.Interface)
</dd>
<dt>
@Html.DisplayNameFor(model => model.Capacity)
</dt>
<dd>
@Html.DisplayFor(model => model.Capacity)
</dd>
<dt>
@Html.DisplayNameFor(model => model.Machine)
</dt>
<dd>
@Html.DisplayFor(model => model.Machine.Name)
</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

@@ -1,71 +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.StorageByMachine
@{
ViewData["Title"] = "Details";
}
<h2>Details</h2>
<div>
<h4>Storage by machine</h4>
<hr />
<dl class="dl-horizontal">
<dt>
@Html.DisplayNameFor(model => model.Type)
</dt>
<dd>
@Html.DisplayFor(model => model.Type)
</dd>
<dt>
@Html.DisplayNameFor(model => model.Interface)
</dt>
<dd>
@Html.DisplayFor(model => model.Interface)
</dd>
<dt>
@Html.DisplayNameFor(model => model.Capacity)
</dt>
<dd>
@Html.DisplayFor(model => model.Capacity)
</dd>
<dt>
@Html.DisplayNameFor(model => model.Machine)
</dt>
<dd>
@Html.DisplayFor(model => model.Machine.Name)
</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>

View File

@@ -1,90 +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
*******************************************************************************/
}
@using Marechai.Database
@model Marechai.Database.Models.StorageByMachine
@{
ViewData["Title"] = "Edit";
}
<h2>Edit</h2>
<h4>Storage 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="MachineId" 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="Type" class="control-label">
</label>
<select asp-for="Type" class="form-control" asp-items="Html.GetEnumSelectList<StorageType>().OrderBy(s => s.Text)">
</select>
<span asp-validation-for="Type" class="text-danger">
</span>
</div>
<div class="form-group">
<label asp-for="Interface" class="control-label">
</label>
<select asp-for="Interface" class="form-control" asp-items="Html.GetEnumSelectList<StorageInterface>().OrderBy(s => s.Text)">
</select>
<span asp-validation-for="Interface" class="text-danger">
</span>
</div>
<div class="form-group">
<label asp-for="Capacity" class="control-label">
</label>
<input asp-for="Capacity" class="form-control" />
<span asp-validation-for="Capacity" 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"); }
}

View File

@@ -1,97 +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.StorageByMachineViewModel>
@{
ViewData["Title"] = "Storage by machines (Admin)";
}
<h2>Storage by machines</h2>
<p>
<a asp-action="Create" class="btn btn-primary">
Create new
</a>
</p>
<table class="table">
<thead>
<tr>
<th>
@Html.DisplayNameFor(model => model.Company)
</th>
<th>
@Html.DisplayNameFor(model => model.Machine)
</th>
<th>
@Html.DisplayNameFor(model => model.Type)
</th>
<th>
@Html.DisplayNameFor(model => model.Interface)
</th>
<th>
@Html.DisplayNameFor(model => model.Capacity)
</th>
<th></th>
</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Company)
</td>
<td>
@Html.DisplayFor(modelItem => item.Machine)
</td>
<td>
@Html.DisplayFor(modelItem => item.Type)
</td>
<td>
@Html.DisplayFor(modelItem => item.Interface)
</td>
<td>
@Html.DisplayFor(modelItem => item.Capacity)
</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>

View File

@@ -2,7 +2,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<Version>3.0.99.1387</Version>
<Version>3.0.99.1390</Version>
<Company>Canary Islands Computer Museum</Company>
<Copyright>Copyright © 2003-2020 Natalia Portillo</Copyright>
<Product>Canary Islands Computer Museum Website</Product>
@@ -164,5 +164,10 @@
<_ContentIncludedByDefault Remove="Areas\Admin\Views\MemoryByMachines\Details.cshtml" />
<_ContentIncludedByDefault Remove="Areas\Admin\Views\MemoryByMachines\Edit.cshtml" />
<_ContentIncludedByDefault Remove="Areas\Admin\Views\MemoryByMachines\Index.cshtml" />
<_ContentIncludedByDefault Remove="Areas\Admin\Views\StorageByMachines\Create.cshtml" />
<_ContentIncludedByDefault Remove="Areas\Admin\Views\StorageByMachines\Delete.cshtml" />
<_ContentIncludedByDefault Remove="Areas\Admin\Views\StorageByMachines\Details.cshtml" />
<_ContentIncludedByDefault Remove="Areas\Admin\Views\StorageByMachines\Edit.cshtml" />
<_ContentIncludedByDefault Remove="Areas\Admin\Views\StorageByMachines\Index.cshtml" />
</ItemGroup>
</Project>

View File

@@ -46,6 +46,7 @@
@inject ProcessorsByMachineService ProcessorsByMachineService
@inject ProcessorsService ProcessorsService
@inject MemoriesByMachineService MemoriesByMachineService
@inject StorageByMachineService StorageByMachineService
@attribute [Authorize(Roles = "UberAdmin, Admin")]
<h3>@L["Machine details"]</h3>
<hr />
@@ -463,6 +464,96 @@
</div>
}
<hr />
<h3>@L["Storage belonging to this machine"]</h3>
<Button Color="Color.Success" Clicked="OnAddStorageClick" Disabled="_addingStorage">@L["Add new (storage by machine)"]</Button>
@if (_addingStorage)
{
<div>
<Field>
<FieldLabel>@L["Storage type"]</FieldLabel>
<Select TValue="int" @bind-SelectedValue="@_addingStorageType">
@foreach (int type in Enum.GetValues(typeof(StorageType)))
{
<SelectItem TValue="int" Value="@type">@(((StorageType)type).ToString())</SelectItem>
}
</Select>
</Field>
<Field>
<FieldLabel>@L["Storage interface"]</FieldLabel>
<Select TValue="int" @bind-SelectedValue="@_addingStorageInterface">
@foreach (int usage in Enum.GetValues(typeof(StorageInterface)))
{
<SelectItem TValue="int" Value="@usage">@(((StorageInterface)usage).ToString())</SelectItem>
}
</Select>
</Field>
<Field>
<FieldLabel>@L["Nominal capacity (bytes)"]</FieldLabel>
<Check TValue="bool" @bind-Checked="@_unknownStorageSize">@L["Unknown (storage by machine nominal capacity)"]</Check>
@if (!_unknownStorageSize)
{
<Validation Validator="@ValidateStorageSize">
<NumericEdit TValue="long?" Decimals="0" @bind-Value="@_addingStorageSize" >
<Feedback>
<ValidationError>@L["Please enter a valid size for this storage."]</ValidationError>
</Feedback>
</NumericEdit>
</Validation>
}
</Field>
<Button Color="Color.Primary" Clicked="@CancelAddStorage" Disabled="@_savingStorage">@L["Cancel"]</Button>
<Button Color="Color.Success" Clicked="@ConfirmAddStorage" Disabled="@_savingStorage">@L["Add"]</Button>
</div>
}
@if (_machineStorage?.Count > 0)
{
<div>
<table class="table table-striped">
<thead>
<tr>
<th>
@L["Type"]
</th>
<th>
@L["Interface"]
</th>
<th>
@L["Nominal capacity"]
</th>
<th></th>
</tr>
</thead>
<tbody>
@foreach (var item in _machineStorage)
{
<tr>
<td>
@item.Type
</td>
<td>
@item.Interface
</td>
<td>
@if (item.Capacity.HasValue)
{
@string.Format(L["{0} bytes"], item.Capacity)
}
else
{
@L["Unknown (storage by machine nominal capacity)"]
}
</td>
<td>
<Button Color="Color.Danger" Clicked="() => {ShowStorageDeleteModal(item.Id);}" Disabled="@_addingStorage">@L["Delete"]</Button>
</td>
</tr>
}
</tbody>
</table>
</div>
}
<Modal @ref="_frmDelete" IsCentered="true" Closing="@ModalClosing">
<ModalBackdrop />
<ModalContent Centered="true">

View File

@@ -12,16 +12,19 @@ namespace Marechai.Pages.Admin.Details
{
public partial class Machine
{
bool _addingCpu;
int? _addingCpuId;
bool _addingGpu;
int? _addingGpuId;
bool _addingMemory;
long? _addingMemorySize;
double? _addingMemorySpeed;
bool _addingCpu;
int? _addingCpuId;
bool _addingGpu;
int? _addingGpuId;
bool _addingMemory;
long? _addingMemorySize;
double? _addingMemorySpeed;
int _addingMemoryType;
int _addingMemoryUsage;
bool _addingStorage;
long? _addingStorageSize;
int _addingStorageType;
int _addingStorageInterface;
float? _addingProcessorSpeed;
bool _addingSound;
int? _addingSoundId;
@@ -31,13 +34,15 @@ namespace Marechai.Pages.Admin.Details
ProcessorByMachineViewModel _currentCpuByMachine;
GpuByMachineViewModel _currentGpuByMachine;
MemoryByMachineViewModel _currentMemoryByMachine;
SoundSynthByMachineViewModel _currentSoundByMachine;
SoundSynthByMachineViewModel _currentSoundByMachine;
StorageByMachineViewModel _currentStorageByMachine;
bool _deleteInProgress;
string _deleteText;
string _deleteTitle;
bool _deletingCpuByMachine;
bool _deletingGpuByMachine;
bool _deletingMemoryByMachine;
bool _deletingMemoryByMachine;
bool _deletingStorageByMachine;
bool _deletingSoundByMachine;
bool _editing;
List<MachineFamilyViewModel> _families;
@@ -48,19 +53,22 @@ namespace Marechai.Pages.Admin.Details
List<GpuByMachineViewModel> _machineGpus;
List<MemoryByMachineViewModel> _machineMemories;
List<SoundSynthByMachineViewModel> _machineSound;
List<StorageByMachineViewModel> _machineStorage;
MachineViewModel _model;
bool _noFamily;
bool _prototype;
bool _savingCpu;
bool _savingGpu;
bool _savingMemory;
bool _savingSound;
bool _savingSound;
bool _savingStorage;
List<SoundSynthViewModel> _soundSynths;
bool _unknownIntroduced;
bool _unknownMemorySize;
bool _unknownMemorySpeed;
bool _unknownModel;
bool _unknownProcessorSpeed;
bool _unknownStorageSize;
[Parameter]
public int Id { get; set; }
@@ -93,6 +101,7 @@ namespace Marechai.Pages.Admin.Details
_cpus = await ProcessorsService.GetAsync();
_soundSynths = await SoundSynthsService.GetAsync();
_machineMemories = await MemoriesByMachineService.GetByMachine(Id);
_machineStorage = await StorageByMachineService.GetByMachine(Id);
_editing = _creating || NavigationManager.ToBaseRelativePath(NavigationManager.Uri).ToLowerInvariant().
StartsWith("admin/machines/edit/",
@@ -197,6 +206,10 @@ namespace Marechai.Pages.Admin.Details
await ConfirmDeleteSoundByMachine();
else if(_deletingCpuByMachine)
await ConfirmDeleteCpuByMachine();
else if(_deletingMemoryByMachine)
await ConfirmDeleteMemoryByMachine();
else if(_deletingStorageByMachine)
await ConfirmDeleteStorageByMachine();
}
async Task ConfirmDeleteGpuByMachine()
@@ -556,5 +569,92 @@ namespace Marechai.Pages.Admin.Details
e.Status = item > 0 ? ValidationStatus.Success : ValidationStatus.Error;
}
void ShowStorageDeleteModal(long itemId)
{
_currentStorageByMachine = _machineStorage.FirstOrDefault(n => n.Id == itemId);
_deletingStorageByMachine = true;
_deleteTitle = L["Delete storage from this machine"];
_deleteText =
string.Format(L["Are you sure you want to delete the storage type {0} with interface {1} from this machine?"],
_currentStorageByMachine?.Type, _currentStorageByMachine?.Interface);
_frmDelete.Show();
}
async Task ConfirmDeleteStorageByMachine()
{
if(_currentStorageByMachine is null)
return;
_deleteInProgress = true;
// Yield thread to let UI to update
await Task.Yield();
await StorageByMachineService.DeleteAsync(_currentStorageByMachine.Id);
_machineStorage = await StorageByMachineService.GetByMachine(Id);
_deleteInProgress = false;
_frmDelete.Hide();
// Yield thread to let UI to update
await Task.Yield();
// Tell we finished loading
StateHasChanged();
}
void OnAddStorageClick()
{
_addingStorage = true;
_savingStorage = false;
_addingStorageSize = 0;
_unknownStorageSize = true;
}
void CancelAddStorage()
{
_addingStorage = false;
_savingStorage = false;
}
async Task ConfirmAddStorage()
{
// TODO: Validation
_savingStorage = true;
// Yield thread to let UI to update
await Task.Yield();
await StorageByMachineService.CreateAsync(Id, (StorageType)_addingStorageType,
(StorageInterface)_addingStorageInterface,
_unknownStorageSize ? null : _addingStorageSize);
_machineStorage = await StorageByMachineService.GetByMachine(Id);
_addingStorage = false;
_savingStorage = false;
// Yield thread to let UI to update
await Task.Yield();
// Tell we finished loading
StateHasChanged();
}
void ValidateStorageSize(ValidatorEventArgs e)
{
if(!(e.Value is long item))
{
e.Status = ValidationStatus.Error;
return;
}
e.Status = item > 0 ? ValidationStatus.Success : ValidationStatus.Error;
}
}
}

View File

@@ -66,6 +66,7 @@ namespace Marechai.Services
services.AddScoped<SoundSynthsByMachineService>();
services.AddScoped<ProcessorsByMachineService>();
services.AddScoped<MemoriesByMachineService>();
services.AddScoped<StorageByMachineService>();
}
}
}

View File

@@ -0,0 +1,51 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Marechai.Database;
using Marechai.Database.Models;
using Marechai.ViewModels;
using Microsoft.EntityFrameworkCore;
namespace Marechai.Services
{
public class StorageByMachineService
{
readonly MarechaiContext _context;
public StorageByMachineService(MarechaiContext context) => _context = context;
public async Task<List<StorageByMachineViewModel>> GetByMachine(int machineId) =>
await _context.StorageByMachine.Where(s => s.MachineId == machineId).
Select(s => new StorageByMachineViewModel
{
Id = s.Id, Type = s.Type, Interface = s.Interface, Capacity = s.Capacity,
MachineId = s.MachineId
}).OrderBy(s => s.Type).ThenBy(s => s.Interface).ThenBy(s => s.Capacity).ToListAsync();
public async Task DeleteAsync(long id)
{
StorageByMachine item = await _context.StorageByMachine.FindAsync(id);
if(item is null)
return;
_context.StorageByMachine.Remove(item);
await _context.SaveChangesAsync();
}
public async Task<long> CreateAsync(int machineId, StorageType type, StorageInterface @interface,
long? capacity)
{
var item = new StorageByMachine
{
MachineId = machineId, Type = type, Interface = @interface, Capacity = capacity
};
await _context.StorageByMachine.AddAsync(item);
await _context.SaveChangesAsync();
return item.Id;
}
}
}

View File

@@ -0,0 +1,12 @@
using Marechai.Database;
namespace Marechai.ViewModels
{
public class StorageByMachineViewModel : BaseViewModel<long>
{
public int MachineId { get; set; }
public StorageType Type { get; set; }
public StorageInterface Interface { get; set; }
public long? Capacity { get; set; }
}
}