2020-05-27 18:46:01 +01:00
|
|
|
using System;
|
2020-05-26 01:19:50 +01:00
|
|
|
using System.Threading.Tasks;
|
2020-05-27 18:46:01 +01:00
|
|
|
using Blazorise;
|
|
|
|
|
using Marechai.Shared;
|
2020-05-26 01:19:50 +01:00
|
|
|
using Microsoft.AspNetCore.Components;
|
|
|
|
|
|
|
|
|
|
namespace Marechai.Pages.Admin.Details
|
|
|
|
|
{
|
|
|
|
|
public partial class InstructionSet
|
|
|
|
|
{
|
2020-05-28 01:38:31 +01:00
|
|
|
bool _creating;
|
|
|
|
|
bool _editing;
|
|
|
|
|
bool _loaded;
|
2020-05-26 01:19:50 +01:00
|
|
|
Database.Models.InstructionSet _model;
|
|
|
|
|
[Parameter]
|
|
|
|
|
public int Id { get; set; }
|
|
|
|
|
|
|
|
|
|
protected override async Task OnAfterRenderAsync(bool firstRender)
|
|
|
|
|
{
|
|
|
|
|
if(_loaded)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
_loaded = true;
|
|
|
|
|
|
2020-05-28 01:38:31 +01:00
|
|
|
_creating = NavigationManager.ToBaseRelativePath(NavigationManager.Uri).ToLowerInvariant().
|
|
|
|
|
StartsWith("admin/instruction_sets/create",
|
|
|
|
|
StringComparison.InvariantCulture);
|
|
|
|
|
|
|
|
|
|
if(Id <= 0 &&
|
|
|
|
|
!_creating)
|
2020-05-26 01:19:50 +01:00
|
|
|
return;
|
|
|
|
|
|
2020-05-28 01:38:31 +01:00
|
|
|
_model = _creating ? new Database.Models.InstructionSet() : await Service.GetAsync(Id);
|
2020-05-26 01:19:50 +01:00
|
|
|
|
2020-05-28 01:38:31 +01:00
|
|
|
_editing = _creating || NavigationManager.ToBaseRelativePath(NavigationManager.Uri).ToLowerInvariant().
|
|
|
|
|
StartsWith("admin/instruction_sets/edit/",
|
|
|
|
|
StringComparison.InvariantCulture);
|
2020-05-27 18:46:01 +01:00
|
|
|
|
|
|
|
|
StateHasChanged();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OnEditClicked()
|
|
|
|
|
{
|
|
|
|
|
_editing = true;
|
|
|
|
|
StateHasChanged();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async void OnCancelClicked()
|
|
|
|
|
{
|
|
|
|
|
_editing = false;
|
2020-05-28 01:38:31 +01:00
|
|
|
|
|
|
|
|
if(_creating)
|
|
|
|
|
{
|
|
|
|
|
NavigationManager.ToBaseRelativePath("admin/instruction_sets");
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_model = await Service.GetAsync(Id);
|
2020-05-27 18:46:01 +01:00
|
|
|
StateHasChanged();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async void OnSaveClicked()
|
|
|
|
|
{
|
|
|
|
|
if(string.IsNullOrWhiteSpace(_model.Name) ||
|
|
|
|
|
_model.Name.Length > 45 ||
|
|
|
|
|
!Service.VerifyUnique(_model.Name))
|
|
|
|
|
return;
|
|
|
|
|
|
2020-05-28 01:38:31 +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-26 01:19:50 +01:00
|
|
|
StateHasChanged();
|
|
|
|
|
}
|
2020-05-27 18:46:01 +01:00
|
|
|
|
|
|
|
|
void ValidateName(ValidatorEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Validators.ValidateString(e, L["Instruction set name cannot contain more than 45 characters."], 45);
|
|
|
|
|
|
|
|
|
|
if(e.Status != ValidationStatus.Success)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if(Service.VerifyUnique(_model.Name))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
e.Status = ValidationStatus.Error;
|
|
|
|
|
e.ErrorText = L["Instruction set name must be unique."];
|
|
|
|
|
}
|
2020-05-26 01:19:50 +01:00
|
|
|
}
|
|
|
|
|
}
|