mirror of
https://github.com/claunia/marechai.git
synced 2025-12-16 19:14:25 +00:00
Add machines to book admin page.
This commit is contained in:
@@ -41,28 +41,35 @@ namespace Marechai.Pages.Admin.Details
|
||||
bool _addingCompany;
|
||||
int? _addingCompanyId;
|
||||
string _addingCompanyRoleId;
|
||||
bool _addingMachine;
|
||||
bool _addingMachineFamily;
|
||||
int? _addingMachineFamilyId;
|
||||
int? _addingMachineId;
|
||||
AuthenticationState _authState;
|
||||
List<CompanyByBookViewModel> _bookCompanies;
|
||||
List<BookByMachineFamilyViewModel> _bookMachineFamilies;
|
||||
List<BookByMachineViewModel> _bookMachines;
|
||||
List<DocumentCompanyViewModel> _companies;
|
||||
List<Iso31661Numeric> _countries;
|
||||
bool _creating;
|
||||
BookByMachineViewModel _currentBookByMachine;
|
||||
BookByMachineFamilyViewModel _currentBookByMachineFamily;
|
||||
CompanyByBookViewModel _currentCompanyByBook;
|
||||
bool _deleteInProgress;
|
||||
string _deleteText;
|
||||
string _deleteTitle;
|
||||
bool _deletingBookByMachine;
|
||||
bool _deletingBookByMachineFamily;
|
||||
bool _deletingCompanyByBook;
|
||||
bool _editing;
|
||||
Modal _frmDelete;
|
||||
bool _loaded;
|
||||
List<MachineFamilyViewModel> _machineFamilies;
|
||||
List<MachineViewModel> _machines;
|
||||
BookViewModel _model;
|
||||
List<DocumentRoleViewModel> _roles;
|
||||
bool _savingCompany;
|
||||
bool _savingMachine;
|
||||
bool _savingMachineFamily;
|
||||
bool _unknownCountry;
|
||||
bool _unknownEdition;
|
||||
@@ -92,12 +99,15 @@ namespace Marechai.Pages.Admin.Details
|
||||
_companies = await CompaniesService.GetAsync();
|
||||
_roles = await DocumentRolesService.GetEnabledAsync();
|
||||
_machineFamilies = await MachineFamiliesService.GetAsync();
|
||||
_machines = await MachinesService.GetAsync();
|
||||
_model = _creating ? new BookViewModel() : await Service.GetAsync(Id);
|
||||
_authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
|
||||
_addingCompanyRoleId = _roles.First().Id;
|
||||
_bookCompanies = await CompaniesByBookService.GetByBook(Id);
|
||||
_addingMachineFamilyId = _machineFamilies.First().Id;
|
||||
_bookMachineFamilies = await BooksByMachineFamilyService.GetByBook(Id);
|
||||
_addingMachineId = _machines.First().Id;
|
||||
_bookMachines = await BooksByMachineService.GetByBook(Id);
|
||||
|
||||
_editing = _creating || NavigationManager.ToBaseRelativePath(NavigationManager.Uri).ToLowerInvariant().
|
||||
StartsWith("admin/books/edit/",
|
||||
@@ -291,7 +301,9 @@ namespace Marechai.Pages.Admin.Details
|
||||
_deletingCompanyByBook = false;
|
||||
_currentCompanyByBook = null;
|
||||
_deletingBookByMachineFamily = false;
|
||||
_currentCompanyByBook = null;
|
||||
_currentBookByMachineFamily = null;
|
||||
_deletingBookByMachine = false;
|
||||
_currentBookByMachine = null;
|
||||
}
|
||||
|
||||
void HideModal() => _frmDelete.Hide();
|
||||
@@ -302,6 +314,8 @@ namespace Marechai.Pages.Admin.Details
|
||||
await ConfirmDeleteCompanyByBook();
|
||||
else if(_deletingBookByMachineFamily)
|
||||
await ConfirmDeleteBookByMachineFamily();
|
||||
else if(_deletingBookByMachine)
|
||||
await ConfirmDeleteBookByMachine();
|
||||
}
|
||||
|
||||
async Task ConfirmDeleteCompanyByBook()
|
||||
@@ -410,5 +424,87 @@ namespace Marechai.Pages.Admin.Details
|
||||
// Tell we finished loading
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
void OnAddMachineClick()
|
||||
{
|
||||
_addingMachine = true;
|
||||
_savingMachine = false;
|
||||
_addingMachineId = _machines.First().Id;
|
||||
}
|
||||
|
||||
void CancelAddMachine()
|
||||
{
|
||||
_addingMachine = false;
|
||||
_savingMachine = false;
|
||||
_addingMachineId = null;
|
||||
}
|
||||
|
||||
async Task ConfirmAddMachine()
|
||||
{
|
||||
if(_addingMachineId is null ||
|
||||
_addingMachineId <= 0)
|
||||
{
|
||||
CancelAddMachine();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
_savingMachine = true;
|
||||
|
||||
// Yield thread to let UI to update
|
||||
await Task.Yield();
|
||||
|
||||
await BooksByMachineService.CreateAsync(_addingMachineId.Value, Id,
|
||||
(await UserManager.GetUserAsync(_authState.User)).Id);
|
||||
|
||||
_bookMachines = await BooksByMachineService.GetByBook(Id);
|
||||
|
||||
_addingMachine = false;
|
||||
_savingMachine = false;
|
||||
_addingMachineId = null;
|
||||
|
||||
// Yield thread to let UI to update
|
||||
await Task.Yield();
|
||||
|
||||
// Tell we finished loading
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
void ShowMachineDeleteModal(long itemId)
|
||||
{
|
||||
_currentBookByMachine = _bookMachines.FirstOrDefault(n => n.Id == itemId);
|
||||
_deletingBookByMachine = true;
|
||||
_deleteTitle = L["Delete machine from this book"];
|
||||
|
||||
_deleteText = string.Format(L["Are you sure you want to delete the machine {0} from this book?"],
|
||||
_currentBookByMachine?.Machine);
|
||||
|
||||
_frmDelete.Show();
|
||||
}
|
||||
|
||||
async Task ConfirmDeleteBookByMachine()
|
||||
{
|
||||
if(_currentBookByMachine is null)
|
||||
return;
|
||||
|
||||
_deleteInProgress = true;
|
||||
|
||||
// Yield thread to let UI to update
|
||||
await Task.Yield();
|
||||
|
||||
await BooksByMachineService.DeleteAsync(_currentBookByMachine.Id,
|
||||
(await UserManager.GetUserAsync(_authState.User)).Id);
|
||||
|
||||
_bookMachines = await BooksByMachineService.GetByBook(Id);
|
||||
|
||||
_deleteInProgress = false;
|
||||
_frmDelete.Hide();
|
||||
|
||||
// Yield thread to let UI to update
|
||||
await Task.Yield();
|
||||
|
||||
// Tell we finished loading
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user