2020-05-27 14:24:47 +01:00
|
|
|
using System;
|
2020-05-26 02:41:55 +01:00
|
|
|
using System.Collections.Generic;
|
2020-05-29 02:13:46 +01:00
|
|
|
using System.Linq;
|
2020-05-26 02:41:55 +01:00
|
|
|
using System.Threading.Tasks;
|
2020-05-27 14:24:47 +01:00
|
|
|
using Blazorise;
|
2020-05-26 02:41:55 +01:00
|
|
|
using Marechai.Database;
|
2020-05-27 14:24:47 +01:00
|
|
|
using Marechai.Shared;
|
2020-05-26 02:41:55 +01:00
|
|
|
using Marechai.ViewModels;
|
|
|
|
|
using Microsoft.AspNetCore.Components;
|
|
|
|
|
|
|
|
|
|
namespace Marechai.Pages.Admin.Details
|
|
|
|
|
{
|
|
|
|
|
public partial class Machine
|
|
|
|
|
{
|
2020-05-29 05:02:31 +01:00
|
|
|
bool _addingCpu;
|
|
|
|
|
int? _addingCpuId;
|
|
|
|
|
bool _addingGpu;
|
|
|
|
|
int? _addingGpuId;
|
|
|
|
|
bool _addingMemory;
|
|
|
|
|
long? _addingMemorySize;
|
|
|
|
|
double? _addingMemorySpeed;
|
2020-05-29 04:41:24 +01:00
|
|
|
int _addingMemoryType;
|
|
|
|
|
int _addingMemoryUsage;
|
2020-05-29 05:02:31 +01:00
|
|
|
bool _addingStorage;
|
|
|
|
|
long? _addingStorageSize;
|
|
|
|
|
int _addingStorageType;
|
|
|
|
|
int _addingStorageInterface;
|
2020-05-29 03:56:48 +01:00
|
|
|
float? _addingProcessorSpeed;
|
2020-05-29 02:35:09 +01:00
|
|
|
bool _addingSound;
|
|
|
|
|
int? _addingSoundId;
|
|
|
|
|
List<CompanyViewModel> _companies;
|
2020-05-29 03:56:48 +01:00
|
|
|
List<ProcessorViewModel> _cpus;
|
2020-05-29 02:35:09 +01:00
|
|
|
bool _creating;
|
2020-05-29 03:56:48 +01:00
|
|
|
ProcessorByMachineViewModel _currentCpuByMachine;
|
2020-05-29 02:35:09 +01:00
|
|
|
GpuByMachineViewModel _currentGpuByMachine;
|
2020-05-29 04:41:24 +01:00
|
|
|
MemoryByMachineViewModel _currentMemoryByMachine;
|
2020-05-29 05:02:31 +01:00
|
|
|
SoundSynthByMachineViewModel _currentSoundByMachine;
|
|
|
|
|
StorageByMachineViewModel _currentStorageByMachine;
|
2020-05-29 02:35:09 +01:00
|
|
|
bool _deleteInProgress;
|
|
|
|
|
string _deleteText;
|
|
|
|
|
string _deleteTitle;
|
2020-05-29 03:56:48 +01:00
|
|
|
bool _deletingCpuByMachine;
|
2020-05-29 02:35:09 +01:00
|
|
|
bool _deletingGpuByMachine;
|
2020-05-29 05:02:31 +01:00
|
|
|
bool _deletingMemoryByMachine;
|
|
|
|
|
bool _deletingStorageByMachine;
|
2020-05-29 02:35:09 +01:00
|
|
|
bool _deletingSoundByMachine;
|
|
|
|
|
bool _editing;
|
|
|
|
|
List<MachineFamilyViewModel> _families;
|
|
|
|
|
Modal _frmDelete;
|
|
|
|
|
List<GpuViewModel> _gpus;
|
|
|
|
|
bool _loaded;
|
2020-05-29 03:56:48 +01:00
|
|
|
List<ProcessorByMachineViewModel> _machineCpus;
|
2020-05-29 02:35:09 +01:00
|
|
|
List<GpuByMachineViewModel> _machineGpus;
|
2020-05-29 04:41:24 +01:00
|
|
|
List<MemoryByMachineViewModel> _machineMemories;
|
2020-05-29 02:35:09 +01:00
|
|
|
List<SoundSynthByMachineViewModel> _machineSound;
|
2020-05-29 05:02:31 +01:00
|
|
|
List<StorageByMachineViewModel> _machineStorage;
|
2020-05-29 02:35:09 +01:00
|
|
|
MachineViewModel _model;
|
|
|
|
|
bool _noFamily;
|
|
|
|
|
bool _prototype;
|
2020-05-29 03:56:48 +01:00
|
|
|
bool _savingCpu;
|
2020-05-29 02:35:09 +01:00
|
|
|
bool _savingGpu;
|
2020-05-29 04:41:24 +01:00
|
|
|
bool _savingMemory;
|
2020-05-29 05:02:31 +01:00
|
|
|
bool _savingSound;
|
|
|
|
|
bool _savingStorage;
|
2020-05-29 02:35:09 +01:00
|
|
|
List<SoundSynthViewModel> _soundSynths;
|
|
|
|
|
bool _unknownIntroduced;
|
2020-05-29 04:41:24 +01:00
|
|
|
bool _unknownMemorySize;
|
|
|
|
|
bool _unknownMemorySpeed;
|
2020-05-29 02:35:09 +01:00
|
|
|
bool _unknownModel;
|
2020-05-29 03:56:48 +01:00
|
|
|
bool _unknownProcessorSpeed;
|
2020-05-29 05:02:31 +01:00
|
|
|
bool _unknownStorageSize;
|
2020-05-26 02:41:55 +01:00
|
|
|
[Parameter]
|
|
|
|
|
public int Id { get; set; }
|
|
|
|
|
|
|
|
|
|
int Type
|
|
|
|
|
{
|
|
|
|
|
get => (int)_model.Type;
|
|
|
|
|
set => _model.Type = (MachineType)value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override async Task OnAfterRenderAsync(bool firstRender)
|
|
|
|
|
{
|
|
|
|
|
if(_loaded)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
_loaded = true;
|
|
|
|
|
|
2020-05-28 02:57:49 +01:00
|
|
|
_creating = NavigationManager.ToBaseRelativePath(NavigationManager.Uri).ToLowerInvariant().
|
|
|
|
|
StartsWith("admin/machines/create", StringComparison.InvariantCulture);
|
|
|
|
|
|
|
|
|
|
if(Id <= 0 &&
|
|
|
|
|
!_creating)
|
2020-05-26 02:41:55 +01:00
|
|
|
return;
|
|
|
|
|
|
2020-05-29 04:41:24 +01:00
|
|
|
_companies = await CompaniesService.GetAsync();
|
|
|
|
|
_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();
|
|
|
|
|
_machineMemories = await MemoriesByMachineService.GetByMachine(Id);
|
2020-05-29 05:02:31 +01:00
|
|
|
_machineStorage = await StorageByMachineService.GetByMachine(Id);
|
2020-05-26 02:41:55 +01:00
|
|
|
|
2020-05-28 02:57:49 +01:00
|
|
|
_editing = _creating || NavigationManager.ToBaseRelativePath(NavigationManager.Uri).ToLowerInvariant().
|
|
|
|
|
StartsWith("admin/machines/edit/",
|
|
|
|
|
StringComparison.InvariantCulture);
|
2020-05-27 14:24:47 +01:00
|
|
|
|
|
|
|
|
if(_editing)
|
|
|
|
|
SetCheckboxes();
|
|
|
|
|
|
|
|
|
|
StateHasChanged();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SetCheckboxes()
|
|
|
|
|
{
|
|
|
|
|
_noFamily = !_model.FamilyId.HasValue;
|
|
|
|
|
_prototype = _model.Introduced?.Year == 1000;
|
|
|
|
|
_unknownIntroduced = !_model.Introduced.HasValue;
|
|
|
|
|
_unknownModel = string.IsNullOrWhiteSpace(_model.Model);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OnEditClicked()
|
|
|
|
|
{
|
|
|
|
|
_editing = true;
|
|
|
|
|
SetCheckboxes();
|
|
|
|
|
StateHasChanged();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async void OnCancelClicked()
|
|
|
|
|
{
|
|
|
|
|
_editing = false;
|
2020-05-28 02:57:49 +01:00
|
|
|
|
|
|
|
|
if(_creating)
|
|
|
|
|
{
|
|
|
|
|
NavigationManager.ToBaseRelativePath("admin/machines");
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_model = await Service.GetAsync(Id);
|
2020-05-27 14:24:47 +01:00
|
|
|
SetCheckboxes();
|
2020-05-26 02:41:55 +01:00
|
|
|
StateHasChanged();
|
|
|
|
|
}
|
2020-05-27 14:24:47 +01:00
|
|
|
|
|
|
|
|
async void OnSaveClicked()
|
|
|
|
|
{
|
|
|
|
|
if(_noFamily)
|
|
|
|
|
_model.FamilyId = null;
|
|
|
|
|
else if(_model.FamilyId < 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if(_unknownIntroduced)
|
|
|
|
|
_model.Introduced = null;
|
|
|
|
|
else if(_prototype)
|
|
|
|
|
_model.Introduced = new DateTime(1000, 1, 1);
|
|
|
|
|
else if(_model.Introduced?.Date >= DateTime.UtcNow.Date)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if(_unknownModel)
|
|
|
|
|
_model.Model = null;
|
|
|
|
|
else if(string.IsNullOrWhiteSpace(_model.Model))
|
|
|
|
|
return;
|
|
|
|
|
|
2020-05-28 02:57:49 +01:00
|
|
|
if(_creating)
|
|
|
|
|
Id = await Service.CreateAsync(_model);
|
|
|
|
|
else
|
|
|
|
|
await Service.UpdateAsync(_model);
|
|
|
|
|
|
|
|
|
|
_editing = false;
|
|
|
|
|
_creating = false;
|
|
|
|
|
_model = await Service.GetAsync(Id);
|
2020-05-27 14:24:47 +01:00
|
|
|
SetCheckboxes();
|
|
|
|
|
StateHasChanged();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ValidateName(ValidatorEventArgs e) =>
|
|
|
|
|
Validators.ValidateString(e, L["Name must contain less than 255 characters."], 255);
|
|
|
|
|
|
|
|
|
|
void ValidateModel(ValidatorEventArgs e) =>
|
|
|
|
|
Validators.ValidateString(e, L["Model must contain less than 50 characters."], 50);
|
|
|
|
|
|
|
|
|
|
void ValidateIntroduced(ValidatorEventArgs e) => Validators.ValidateIntroducedDate(e);
|
2020-05-29 02:13:46 +01:00
|
|
|
|
|
|
|
|
void ShowGpuDeleteModal(long itemId)
|
|
|
|
|
{
|
|
|
|
|
_currentGpuByMachine = _machineGpus.FirstOrDefault(n => n.Id == itemId);
|
|
|
|
|
_deletingGpuByMachine = true;
|
|
|
|
|
_deleteTitle = L["Delete graphical processing unit from this machine"];
|
|
|
|
|
|
|
|
|
|
_deleteText =
|
|
|
|
|
string.Format(L["Are you sure you want to delete the graphical processing unit {0} manufactured by {1} from this machine?"],
|
|
|
|
|
_currentGpuByMachine?.Name, _currentGpuByMachine?.CompanyName);
|
|
|
|
|
|
|
|
|
|
_frmDelete.Show();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void HideModal() => _frmDelete.Hide();
|
|
|
|
|
|
|
|
|
|
async void ConfirmDelete()
|
|
|
|
|
{
|
|
|
|
|
if(_deletingGpuByMachine)
|
|
|
|
|
await ConfirmDeleteGpuByMachine();
|
2020-05-29 02:35:09 +01:00
|
|
|
else if(_deletingSoundByMachine)
|
|
|
|
|
await ConfirmDeleteSoundByMachine();
|
2020-05-29 03:56:48 +01:00
|
|
|
else if(_deletingCpuByMachine)
|
|
|
|
|
await ConfirmDeleteCpuByMachine();
|
2020-05-29 05:02:31 +01:00
|
|
|
else if(_deletingMemoryByMachine)
|
|
|
|
|
await ConfirmDeleteMemoryByMachine();
|
|
|
|
|
else if(_deletingStorageByMachine)
|
|
|
|
|
await ConfirmDeleteStorageByMachine();
|
2020-05-29 02:13:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async Task ConfirmDeleteGpuByMachine()
|
|
|
|
|
{
|
|
|
|
|
if(_currentGpuByMachine is null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
_deleteInProgress = true;
|
|
|
|
|
|
|
|
|
|
// Yield thread to let UI to update
|
|
|
|
|
await Task.Yield();
|
|
|
|
|
|
2020-05-29 02:45:06 +01:00
|
|
|
await GpusByMachineService.DeleteAsync(_currentGpuByMachine.Id);
|
|
|
|
|
_machineGpus = await GpusByMachineService.GetByMachine(Id);
|
2020-05-29 02:13:46 +01:00
|
|
|
|
|
|
|
|
_deleteInProgress = false;
|
|
|
|
|
_frmDelete.Hide();
|
|
|
|
|
|
|
|
|
|
// Yield thread to let UI to update
|
|
|
|
|
await Task.Yield();
|
|
|
|
|
|
|
|
|
|
// Tell we finished loading
|
|
|
|
|
StateHasChanged();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ModalClosing(ModalClosingEventArgs obj)
|
|
|
|
|
{
|
2020-05-29 02:35:09 +01:00
|
|
|
_deleteInProgress = false;
|
|
|
|
|
_deletingGpuByMachine = false;
|
|
|
|
|
_currentGpuByMachine = null;
|
|
|
|
|
_deletingSoundByMachine = false;
|
2020-05-29 03:56:48 +01:00
|
|
|
_currentSoundByMachine = null;
|
|
|
|
|
_deletingCpuByMachine = false;
|
|
|
|
|
_currentCpuByMachine = null;
|
2020-05-29 02:13:46 +01:00
|
|
|
}
|
|
|
|
|
|
2020-05-29 04:41:24 +01:00
|
|
|
void OnAddGpuClick()
|
2020-05-29 02:13:46 +01:00
|
|
|
{
|
|
|
|
|
_addingGpu = true;
|
|
|
|
|
_savingGpu = false;
|
2020-05-29 03:56:48 +01:00
|
|
|
_addingGpuId = _gpus.First().Id;
|
2020-05-29 02:13:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CancelAddGpu()
|
|
|
|
|
{
|
|
|
|
|
_addingGpu = false;
|
|
|
|
|
_savingGpu = false;
|
|
|
|
|
_addingGpuId = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async Task ConfirmAddGpu()
|
|
|
|
|
{
|
2020-05-29 03:56:48 +01:00
|
|
|
if(_addingGpuId is null ||
|
|
|
|
|
_addingGpuId <= 0)
|
2020-05-29 02:13:46 +01:00
|
|
|
{
|
|
|
|
|
CancelAddGpu();
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_savingGpu = true;
|
|
|
|
|
|
|
|
|
|
// Yield thread to let UI to update
|
|
|
|
|
await Task.Yield();
|
|
|
|
|
|
2020-05-29 02:45:06 +01:00
|
|
|
await GpusByMachineService.CreateAsync(_addingGpuId.Value, Id);
|
|
|
|
|
_machineGpus = await GpusByMachineService.GetByMachine(Id);
|
2020-05-29 02:13:46 +01:00
|
|
|
|
|
|
|
|
_addingGpu = false;
|
|
|
|
|
_savingGpu = false;
|
|
|
|
|
_addingGpuId = null;
|
|
|
|
|
|
|
|
|
|
// Yield thread to let UI to update
|
|
|
|
|
await Task.Yield();
|
|
|
|
|
|
|
|
|
|
// Tell we finished loading
|
|
|
|
|
StateHasChanged();
|
|
|
|
|
}
|
2020-05-29 02:35:09 +01:00
|
|
|
|
|
|
|
|
void ShowSoundDeleteModal(long itemId)
|
|
|
|
|
{
|
|
|
|
|
_currentSoundByMachine = _machineSound.FirstOrDefault(n => n.Id == itemId);
|
|
|
|
|
_deletingSoundByMachine = true;
|
|
|
|
|
_deleteTitle = L["Delete sound synthesizer from this machine"];
|
|
|
|
|
|
|
|
|
|
_deleteText =
|
|
|
|
|
string.Format(L["Are you sure you want to delete the sound synthesizer {0} manufactured by {1} from this machine?"],
|
|
|
|
|
_currentSoundByMachine?.Name, _currentSoundByMachine?.CompanyName);
|
|
|
|
|
|
|
|
|
|
_frmDelete.Show();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async Task ConfirmDeleteSoundByMachine()
|
|
|
|
|
{
|
|
|
|
|
if(_currentSoundByMachine is null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
_deleteInProgress = true;
|
|
|
|
|
|
|
|
|
|
// Yield thread to let UI to update
|
|
|
|
|
await Task.Yield();
|
|
|
|
|
|
|
|
|
|
await SoundSynthsByMachineService.DeleteAsync(_currentSoundByMachine.Id);
|
|
|
|
|
_machineSound = await SoundSynthsByMachineService.GetByMachine(Id);
|
|
|
|
|
|
|
|
|
|
_deleteInProgress = false;
|
|
|
|
|
_frmDelete.Hide();
|
|
|
|
|
|
|
|
|
|
// Yield thread to let UI to update
|
|
|
|
|
await Task.Yield();
|
|
|
|
|
|
|
|
|
|
// Tell we finished loading
|
|
|
|
|
StateHasChanged();
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-29 04:41:24 +01:00
|
|
|
void OnAddSoundClick()
|
2020-05-29 02:35:09 +01:00
|
|
|
{
|
|
|
|
|
_addingSound = true;
|
|
|
|
|
_savingSound = false;
|
2020-05-29 03:56:48 +01:00
|
|
|
_addingSoundId = _soundSynths.First().Id;
|
2020-05-29 02:35:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CancelAddSound()
|
|
|
|
|
{
|
|
|
|
|
_addingSound = false;
|
|
|
|
|
_savingSound = false;
|
|
|
|
|
_addingSoundId = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async Task ConfirmAddSound()
|
|
|
|
|
{
|
2020-05-29 03:56:48 +01:00
|
|
|
if(_addingSoundId is null ||
|
|
|
|
|
_addingSoundId <= 0)
|
2020-05-29 02:35:09 +01:00
|
|
|
{
|
|
|
|
|
CancelAddSound();
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_savingSound = true;
|
|
|
|
|
|
|
|
|
|
// Yield thread to let UI to update
|
|
|
|
|
await Task.Yield();
|
|
|
|
|
|
|
|
|
|
await SoundSynthsByMachineService.CreateAsync(_addingSoundId.Value, Id);
|
|
|
|
|
_machineSound = await SoundSynthsByMachineService.GetByMachine(Id);
|
|
|
|
|
|
|
|
|
|
_addingSound = false;
|
|
|
|
|
_savingSound = false;
|
|
|
|
|
_addingSoundId = null;
|
|
|
|
|
|
|
|
|
|
// Yield thread to let UI to update
|
|
|
|
|
await Task.Yield();
|
|
|
|
|
|
|
|
|
|
// Tell we finished loading
|
|
|
|
|
StateHasChanged();
|
|
|
|
|
}
|
2020-05-29 03:56:48 +01:00
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-29 04:41:24 +01:00
|
|
|
void OnAddCpuClick()
|
2020-05-29 03:56:48 +01:00
|
|
|
{
|
|
|
|
|
_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;
|
|
|
|
|
}
|
2020-05-29 04:41:24 +01:00
|
|
|
|
|
|
|
|
void ShowMemoryDeleteModal(long itemId)
|
|
|
|
|
{
|
|
|
|
|
_currentMemoryByMachine = _machineMemories.FirstOrDefault(n => n.Id == itemId);
|
|
|
|
|
_deletingMemoryByMachine = true;
|
|
|
|
|
_deleteTitle = L["Delete memory from this machine"];
|
|
|
|
|
|
|
|
|
|
_deleteText =
|
|
|
|
|
string.Format(L["Are you sure you want to delete the memory type {0} with usage {1} from this machine?"],
|
|
|
|
|
_currentMemoryByMachine?.Type, _currentMemoryByMachine?.Usage);
|
|
|
|
|
|
|
|
|
|
_frmDelete.Show();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async Task ConfirmDeleteMemoryByMachine()
|
|
|
|
|
{
|
|
|
|
|
if(_currentMemoryByMachine is null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
_deleteInProgress = true;
|
|
|
|
|
|
|
|
|
|
// Yield thread to let UI to update
|
|
|
|
|
await Task.Yield();
|
|
|
|
|
|
|
|
|
|
await MemoriesByMachineService.DeleteAsync(_currentMemoryByMachine.Id);
|
|
|
|
|
_machineMemories = await MemoriesByMachineService.GetByMachine(Id);
|
|
|
|
|
|
|
|
|
|
_deleteInProgress = false;
|
|
|
|
|
_frmDelete.Hide();
|
|
|
|
|
|
|
|
|
|
// Yield thread to let UI to update
|
|
|
|
|
await Task.Yield();
|
|
|
|
|
|
|
|
|
|
// Tell we finished loading
|
|
|
|
|
StateHasChanged();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OnAddMemoryClick()
|
|
|
|
|
{
|
|
|
|
|
_addingMemory = true;
|
|
|
|
|
_savingMemory = false;
|
|
|
|
|
_addingMemorySpeed = 0;
|
|
|
|
|
_unknownMemorySpeed = true;
|
|
|
|
|
_addingMemorySize = 0;
|
|
|
|
|
_unknownMemorySize = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CancelAddMemory()
|
|
|
|
|
{
|
|
|
|
|
_addingMemory = false;
|
|
|
|
|
_savingMemory = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async Task ConfirmAddMemory()
|
|
|
|
|
{
|
|
|
|
|
// TODO: Validation
|
|
|
|
|
|
|
|
|
|
_savingMemory = true;
|
|
|
|
|
|
|
|
|
|
// Yield thread to let UI to update
|
|
|
|
|
await Task.Yield();
|
|
|
|
|
|
|
|
|
|
await MemoriesByMachineService.CreateAsync(Id, (MemoryType)_addingMemoryType,
|
|
|
|
|
(MemoryUsage)_addingMemoryUsage,
|
|
|
|
|
_unknownMemorySize ? null : _addingMemorySize,
|
|
|
|
|
_unknownMemorySpeed ? null : _addingMemorySpeed);
|
|
|
|
|
|
|
|
|
|
_machineMemories = await MemoriesByMachineService.GetByMachine(Id);
|
|
|
|
|
|
|
|
|
|
_addingMemory = false;
|
|
|
|
|
_savingMemory = false;
|
|
|
|
|
|
|
|
|
|
// Yield thread to let UI to update
|
|
|
|
|
await Task.Yield();
|
|
|
|
|
|
|
|
|
|
// Tell we finished loading
|
|
|
|
|
StateHasChanged();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ValidateMemorySpeed(ValidatorEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if(!(e.Value is double item))
|
|
|
|
|
{
|
|
|
|
|
e.Status = ValidationStatus.Error;
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
e.Status = item > 0 ? ValidationStatus.Success : ValidationStatus.Error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ValidateMemorySize(ValidatorEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if(!(e.Value is long item))
|
|
|
|
|
{
|
|
|
|
|
e.Status = ValidationStatus.Error;
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
e.Status = item > 0 ? ValidationStatus.Success : ValidationStatus.Error;
|
|
|
|
|
}
|
2020-05-29 05:02:31 +01:00
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
2020-05-26 02:41:55 +01:00
|
|
|
}
|
|
|
|
|
}
|