|
50 | 50 | <div class="mb-3">
|
51 | 51 | @if (_step4Enabled)
|
52 | 52 | {
|
53 |
| - <button class="btn btn-sm btn-primary header-action-button" @onclick=@(() => HandleResult(_dataContext.CreateProfile()))>Create Profile</button> |
| 53 | + <button class="btn btn-sm btn-primary header-action-button" @onclick=@(() => HandleResult(_dataContext.CreateProfile(), "Profile has been created."))>Create Profile</button> |
54 | 54 | }
|
55 |
| - @if (_dataContext.SelectedImportProfile != null && _dataContext.SelectedImportProfile.ImportProfileId != 0) |
| 55 | + @if (_dataContext.SelectedImportProfile is {ImportProfileId: > 0 }) |
56 | 56 | {
|
57 |
| - <button class="btn btn-sm btn-primary header-action-button" @onclick=@(() => HandleResult(_dataContext.SaveProfile()))>Save Profile</button> |
58 |
| - <button class="btn btn-sm btn-danger header-action-button" @onclick=@(() => HandleResult(_dataContext.DeleteProfile()))>Delete Profile</button> |
| 57 | + <button class="btn btn-sm btn-primary header-action-button" @onclick=@(() => HandleResult(_dataContext.SaveProfile(), "Changes for Profile have been saved."))>Save Profile</button> |
| 58 | + <button class="btn btn-sm btn-danger header-action-button" @onclick=@(() => _isDeleteConfirmationDialogVisible = true)>Delete Profile</button> |
59 | 59 | }
|
60 | 60 | </div>
|
61 | 61 | <div class="row mb-3">
|
62 | 62 | <div class="col">
|
63 | 63 | <label class="form-label">Import Profile:</label>
|
64 | 64 | <ObjectSelect
|
65 | 65 | GetSelectedItemIdHandler="@(e => e.ImportProfileId.ToString())"
|
66 |
| - SetSelectedItemHandler="@(e => _dataContext.AvailableImportProfiles.FirstOrDefault(i => i.ImportProfileId == Convert.ToInt32(e), dummyImportProfile))" |
| 66 | + SetSelectedItemHandler="@(e => _dataContext.AvailableImportProfiles.FirstOrDefault(i => i.ImportProfileId == Convert.ToInt32(e), _dummyImportProfile))" |
67 | 67 | @bind-SelectedItem="@_dataContext.SelectedImportProfile"
|
68 | 68 | AvailableItems="@_dataContext.AvailableImportProfiles"
|
69 | 69 | OnSelectedItemChanged="@ImportProfile_SelectionChanged"
|
|
81 | 81 | <label class="form-label">Target Account:</label>
|
82 | 82 | <ObjectSelect
|
83 | 83 | GetSelectedItemIdHandler="@(e => e.AccountId.ToString())"
|
84 |
| - SetSelectedItemHandler="@(e => _dataContext.AvailableAccounts.FirstOrDefault(i => i.AccountId == Convert.ToInt32(e), dummyAccount))" |
| 84 | + SetSelectedItemHandler="@(e => _dataContext.AvailableAccounts.FirstOrDefault(i => i.AccountId == Convert.ToInt32(e), _dummyAccount))" |
85 | 85 | @bind-SelectedItem="@_dataContext.SelectedAccount"
|
86 | 86 | AvailableItems="@_dataContext.AvailableAccounts"
|
87 | 87 | OnSelectedItemChanged="@TargetAccount_SelectionChanged"
|
|
452 | 452 | <div class="modal-backdrop fade show"></div>
|
453 | 453 | }
|
454 | 454 |
|
| 455 | +<InfoDialog |
| 456 | + Title="Import" |
| 457 | + Message="@_infoDialogMessage" |
| 458 | + IsDialogVisible="@_isInfoDialogVisible" |
| 459 | + OnCloseClickCallback="@(() => _isInfoDialogVisible = false)" |
| 460 | + /> |
| 461 | + |
| 462 | +<DeleteConfirmationDialog |
| 463 | + Title="Delete Import Profile" |
| 464 | + Message="Do you really want to delete the selected Import Profile?" |
| 465 | + IsDialogVisible="@_isDeleteConfirmationDialogVisible" |
| 466 | + OnDeleteClickCallback="@DeleteProfile" |
| 467 | + OnCancelClickCallback="@(() => _isDeleteConfirmationDialogVisible = false)" |
| 468 | + /> |
| 469 | + |
455 | 470 | <ErrorMessageDialog
|
456 | 471 | Title="Import"
|
457 | 472 | Message="@_errorModalDialogMessage"
|
|
464 | 479 | ElementReference _inputElement;
|
465 | 480 | ElementReference _step1AccordionButtonElement;
|
466 | 481 |
|
467 |
| - readonly int _placeholderItemId = -1; |
468 |
| - readonly string _placeholderItemValue = "___PlaceholderItem___"; |
| 482 | + const int PlaceholderItemId = -1; |
| 483 | + const string PlaceholderItemValue = "___PlaceholderItem___"; |
| 484 | + const string DummyColumn = "---Select Column---"; |
469 | 485 |
|
470 |
| - ImportProfile dummyImportProfile = new ImportProfile() |
| 486 | + readonly ImportProfile _dummyImportProfile = new() |
471 | 487 | {
|
472 |
| - ImportProfileId = -1, |
473 |
| - ProfileName = "---Select Import Profile---" |
| 488 | + ImportProfileId = PlaceholderItemId, |
| 489 | + ProfileName = "---Select Import Profile---", |
| 490 | + AccountId = PlaceholderItemId |
474 | 491 | };
|
475 |
| - OpenBudgeteer.Core.Models.Account dummyAccount = new OpenBudgeteer.Core.Models.Account() |
| 492 | + |
| 493 | + readonly OpenBudgeteer.Core.Models.Account _dummyAccount = new() |
476 | 494 | {
|
477 |
| - AccountId = -1, |
| 495 | + AccountId = PlaceholderItemId, |
478 | 496 | Name = "---Select Target Account---"
|
479 | 497 | };
|
480 |
| - string dummyColumn = "---Select Column---"; |
481 | 498 |
|
482 | 499 | bool _step2Enabled;
|
483 | 500 | bool _step3Enabled;
|
|
492 | 509 | bool _isConfirmationModalDialogVisible;
|
493 | 510 | string _importConfirmationMessage;
|
494 | 511 |
|
| 512 | + bool _isInfoDialogVisible; |
| 513 | + string _infoDialogMessage; |
| 514 | + |
| 515 | + bool _isDeleteConfirmationDialogVisible; |
| 516 | + |
495 | 517 | bool _isErrorModalDialogVisible;
|
496 | 518 | string _errorModalDialogMessage;
|
497 | 519 |
|
|
514 | 536 | void LoadData()
|
515 | 537 | {
|
516 | 538 | HandleResult(_dataContext.LoadData());
|
517 |
| - _dataContext.AvailableImportProfiles.Insert(0, dummyImportProfile); |
518 |
| - _dataContext.AvailableAccounts.Insert(0, dummyAccount); |
519 |
| - _dataContext.SelectedImportProfile = dummyImportProfile; |
520 |
| - _dataContext.IdentifiedColumns.Insert(0, dummyColumn); |
521 |
| - _dataContext.SelectedAccount = dummyAccount; |
| 539 | + _dataContext.AvailableImportProfiles.Insert(0, _dummyImportProfile); |
| 540 | + _dataContext.AvailableAccounts.Insert(0, _dummyAccount); |
| 541 | + _dataContext.SelectedImportProfile = _dummyImportProfile; |
| 542 | + _dataContext.IdentifiedColumns.Insert(0, DummyColumn); |
| 543 | + _dataContext.SelectedAccount = _dummyAccount; |
522 | 544 | }
|
523 | 545 |
|
524 | 546 | async Task ReadFileAsync()
|
525 | 547 | {
|
526 | 548 | _step2Enabled = false;
|
527 | 549 | _step3Enabled = false;
|
528 | 550 | _step4Enabled = false;
|
529 |
| - _dataContext.SelectedImportProfile = dummyImportProfile; |
530 |
| - _dataContext.IdentifiedColumns.Insert(0, dummyColumn); |
531 |
| - _dataContext.SelectedAccount = dummyAccount; |
| 551 | + _dataContext.SelectedImportProfile = _dummyImportProfile; |
| 552 | + _dataContext.IdentifiedColumns.Insert(0, DummyColumn); |
| 553 | + _dataContext.SelectedAccount = _dummyAccount; |
532 | 554 |
|
533 | 555 | var file = (await FileReaderService.CreateReference(_inputElement).EnumerateFilesAsync()).FirstOrDefault();
|
534 | 556 | if (file == null) return;
|
|
541 | 563 | var result = await _dataContext.LoadProfileAsync();
|
542 | 564 | if (result.IsSuccessful)
|
543 | 565 | {
|
544 |
| - _step3Enabled = _dataContext.SelectedImportProfile.ImportProfileId != 0; |
| 566 | + _step3Enabled = _dataContext.SelectedImportProfile.ImportProfileId > 0; |
545 | 567 | CheckColumnMapping();
|
546 | 568 | StateHasChanged();
|
547 | 569 | }
|
|
551 | 573 | }
|
552 | 574 | }
|
553 | 575 |
|
| 576 | + void DeleteProfile() |
| 577 | + { |
| 578 | + _isDeleteConfirmationDialogVisible = false; |
| 579 | + HandleResult(_dataContext.DeleteProfile()); |
| 580 | + if (_dataContext.SelectedImportProfile.ImportProfileId < 1) |
| 581 | + { |
| 582 | + _dataContext.SelectedImportProfile = _dummyImportProfile; |
| 583 | + _dataContext.AvailableImportProfiles.Insert(0, _dummyImportProfile); |
| 584 | + _dataContext.SelectedAccount = _dummyAccount; |
| 585 | + } |
| 586 | + } |
| 587 | + |
554 | 588 | void LoadHeaders()
|
555 | 589 | {
|
556 | 590 | var result = _dataContext.LoadHeaders();
|
|
568 | 602 | {
|
569 | 603 | _step4Enabled = false;
|
570 | 604 | if (string.IsNullOrEmpty(_dataContext.SelectedImportProfile.TransactionDateColumnName) ||
|
571 |
| - _dataContext.SelectedImportProfile.TransactionDateColumnName == _placeholderItemValue) return; |
| 605 | + _dataContext.SelectedImportProfile.TransactionDateColumnName == PlaceholderItemValue) return; |
572 | 606 | // Make Payee optional
|
573 | 607 | //if (string.IsNullOrEmpty(_dataContext.PayeeColumn) || _dataContext.PayeeColumn == _placeholderItemValue) return;
|
574 | 608 | if (string.IsNullOrEmpty(_dataContext.SelectedImportProfile.MemoColumnName) ||
|
575 |
| - _dataContext.SelectedImportProfile.MemoColumnName == _placeholderItemValue) return; |
| 609 | + _dataContext.SelectedImportProfile.MemoColumnName == PlaceholderItemValue) return; |
576 | 610 | if (string.IsNullOrEmpty(_dataContext.SelectedImportProfile.AmountColumnName) ||
|
577 |
| - _dataContext.SelectedImportProfile.AmountColumnName == _placeholderItemValue) return; |
| 611 | + _dataContext.SelectedImportProfile.AmountColumnName == PlaceholderItemValue) return; |
578 | 612 | _step4Enabled = true;
|
579 | 613 | }
|
580 | 614 |
|
|
646 | 680 | _dataContext.SelectedImportProfile.AdditionalSettingCreditValue = value;
|
647 | 681 | }
|
648 | 682 |
|
649 |
| - void HandleResult(ViewModelOperationResult result) |
| 683 | + void HandleResult(ViewModelOperationResult result, string successMessage = "") |
650 | 684 | {
|
651 | 685 | if (!result.IsSuccessful)
|
652 | 686 | {
|
653 | 687 | _errorModalDialogMessage = result.Message;
|
654 | 688 | _isErrorModalDialogVisible = true;
|
| 689 | + return; |
655 | 690 | }
|
| 691 | + if (string.IsNullOrEmpty(successMessage)) return; |
| 692 | + |
| 693 | + _infoDialogMessage = successMessage; |
| 694 | + _isInfoDialogVisible = true; |
656 | 695 | }
|
657 | 696 | }
|
0 commit comments