Skip to content

Commit

Permalink
Merge pull request #123 from TheAxelander/121_122_fix_import
Browse files Browse the repository at this point in the history
Merge changes for version 1.6.2
  • Loading branch information
TheAxelander authored Jan 11, 2023
2 parents 183d863 + 177e4b5 commit 16e8bb6
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 19 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### 1.6.2 (2023-01-11)

* [Fixed] Due to implemented fix for [#114](https://github.com/TheAxelander/OpenBudgeteer/issues/114) Column mapping on Import Page was not working properly [#121](https://github.com/TheAxelander/OpenBudgeteer/issues/121) [#122](https://github.com/TheAxelander/OpenBudgeteer/issues/122)

### 1.6.1 (2022-12-31)

* [Changed] Slight visual changes for Mapping Rule modification
Expand Down
12 changes: 4 additions & 8 deletions OpenBudgeteer.Blazor/Pages/Import.razor
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
<label class="form-label">Import Profile:</label>
<ObjectSelect
GetSelectedItemIdHandler="@(e => e.ImportProfileId.ToString())"
SetSelectedItemHandler="@(e => _dataContext.AvailableImportProfiles.First(i => i.ImportProfileId == Convert.ToInt32(e)))"
SetSelectedItemHandler="@(e => _dataContext.AvailableImportProfiles.FirstOrDefault(i => i.ImportProfileId == Convert.ToInt32(e), dummyImportProfile))"
@bind-SelectedItem="@_dataContext.SelectedImportProfile"
AvailableItems="@_dataContext.AvailableImportProfiles"
OnSelectedItemChanged="@ImportProfile_SelectionChanged"
Expand All @@ -81,7 +81,7 @@
<label class="form-label">Target Account:</label>
<ObjectSelect
GetSelectedItemIdHandler="@(e => e.AccountId.ToString())"
SetSelectedItemHandler="@(e => _dataContext.AvailableAccounts.First(i => i.AccountId == Convert.ToInt32(e)))"
SetSelectedItemHandler="@(e => _dataContext.AvailableAccounts.FirstOrDefault(i => i.AccountId == Convert.ToInt32(e), dummyAccount))"
@bind-SelectedItem="@_dataContext.SelectedAccount"
AvailableItems="@_dataContext.AvailableAccounts"
OnSelectedItemChanged="@TargetAccount_SelectionChanged"
Expand Down Expand Up @@ -516,8 +516,8 @@
HandleResult(_dataContext.LoadData());
_dataContext.AvailableImportProfiles.Insert(0, dummyImportProfile);
_dataContext.AvailableAccounts.Insert(0, dummyAccount);
_dataContext.IdentifiedColumns.Insert(0, dummyColumn);
_dataContext.SelectedImportProfile = dummyImportProfile;
_dataContext.IdentifiedColumns.Insert(0, dummyColumn);
_dataContext.SelectedAccount = dummyAccount;
}

Expand All @@ -527,6 +527,7 @@
_step3Enabled = false;
_step4Enabled = false;
_dataContext.SelectedImportProfile = dummyImportProfile;
_dataContext.IdentifiedColumns.Insert(0, dummyColumn);
_dataContext.SelectedAccount = dummyAccount;

var file = (await FileReaderService.CreateReference(_inputElement).EnumerateFilesAsync()).FirstOrDefault();
Expand All @@ -537,11 +538,6 @@

async Task LoadProfile()
{
//// Workaround for setting the SelectedImportProfile as the first item is always selected but doesn't trigger OnChange
//if (_dataContext.SelectedImportProfile == null && _dataContext.AvailableImportProfiles.Count > 0)
//{
// _dataContext.SelectedImportProfile = _dataContext.AvailableImportProfiles.First();
//}
var result = await _dataContext.LoadProfileAsync();
if (result.IsSuccessful)
{
Expand Down
2 changes: 1 addition & 1 deletion OpenBudgeteer.Blazor/Shared/NavMenu.razor
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
<div class="col-md-auto">
<div class="navbar-text">
<span>
Version: 1.6.1 (<a href="https://github.com/TheAxelander/OpenBudgeteer/blob/master/CHANGELOG.md" target="_blank">Change Log</a>)
Version: 1.6.2 (<a href="https://github.com/TheAxelander/OpenBudgeteer/blob/master/CHANGELOG.md" target="_blank">Change Log</a>)
</span>
</div>
</div>
Expand Down
1 change: 0 additions & 1 deletion OpenBudgeteer.Blazor/Shared/Selector/BucketSelect.razor
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
SelectedItemId = value.BucketId;
return;
}
var oldValue = _selectedItem;
_selectedItem = value;
SelectedItemChanged.InvokeAsync(value);
OnSelectedItemChanged.InvokeAsync(new ChangeEventArgs() { Value = value });
Expand Down
1 change: 0 additions & 1 deletion OpenBudgeteer.Blazor/Shared/Selector/IntegerSelect.razor
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
// Check if there is no real change
if (_selectedItem == value) return;

var oldValue = _selectedItem;
_selectedItem = value;
SelectedItemChanged.InvokeAsync(value);
OnSelectedItemChanged.InvokeAsync(new ChangeEventArgs() { Value = value });
Expand Down
1 change: 0 additions & 1 deletion OpenBudgeteer.Blazor/Shared/Selector/ObjectSelect.razor
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
SelectedItemId = GetSelectedItemIdHandler(value);
return;
}
var oldValue = _selectedItem;
_selectedItem = value;
SelectedItemChanged.InvokeAsync(value);
OnSelectedItemChanged.InvokeAsync(new ChangeEventArgs() { Value = value });
Expand Down
1 change: 0 additions & 1 deletion OpenBudgeteer.Blazor/Shared/Selector/StringSelect.razor
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
// Check if there is no real change
if (_selectedItem == value) return;

var oldValue = _selectedItem;
_selectedItem = value;
SelectedItemChanged.InvokeAsync(value);
OnSelectedItemChanged.InvokeAsync(new ChangeEventArgs() { Value = value });
Expand Down
49 changes: 43 additions & 6 deletions OpenBudgeteer.Core/ViewModels/ImportDataViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,13 @@ public Account SelectedAccount
public ImportProfile SelectedImportProfile
{
get => _selectedImportProfile;
set => Set(ref _selectedImportProfile, value);
set
{
// Load Headers already to prevent hiccups with other SelectedItem properties from Column Mappings
// as they depend on SelectedImportProfile
if (value != null) LoadHeaders(value);
Set(ref _selectedImportProfile, value);
}
}

private int _totalRecords;
Expand Down Expand Up @@ -398,8 +404,8 @@ public async Task<ViewModelOperationResult> LoadProfileAsync()
SelectedAccount = AvailableAccounts.First(i => i.AccountId == SelectedImportProfile.AccountId);
}

var result = LoadHeaders();
if (!result.IsSuccessful) throw new Exception(result.Message);
// var result = LoadHeaders();
// if (!result.IsSuccessful) throw new Exception(result.Message);

//await ValidateDataAsync();
_isProfileValid = true;
Expand All @@ -416,19 +422,50 @@ public async Task<ViewModelOperationResult> LoadProfileAsync()
/// <summary>
/// Reads column headers from the loaded file
/// </summary>
/// <remarks>
/// Uses settings from current <see cref="SelectedImportProfile"/>
/// </remarks>
/// <returns>Object which contains information and results of this method</returns>
public ViewModelOperationResult LoadHeaders()
{
var result = LoadHeaders(SelectedImportProfile);

// If possible and necessary make initial selections after loading headers
if (IdentifiedColumns.Count == 0) return result;
var firstSelection = IdentifiedColumns.First();
if (string.IsNullOrEmpty(SelectedImportProfile.TransactionDateColumnName))
SelectedImportProfile.TransactionDateColumnName = firstSelection;
if (string.IsNullOrEmpty(SelectedImportProfile.PayeeColumnName))
SelectedImportProfile.PayeeColumnName = firstSelection;
if (string.IsNullOrEmpty(SelectedImportProfile.MemoColumnName))
SelectedImportProfile.MemoColumnName = firstSelection;
if (string.IsNullOrEmpty(SelectedImportProfile.AmountColumnName))
SelectedImportProfile.AmountColumnName = firstSelection;
if (string.IsNullOrEmpty(SelectedImportProfile.CreditColumnName))
SelectedImportProfile.CreditColumnName = firstSelection;
if (string.IsNullOrEmpty(SelectedImportProfile.CreditColumnIdentifierColumnName))
SelectedImportProfile.CreditColumnIdentifierColumnName = firstSelection;

return result;
}

/// <summary>
/// Reads column headers from the loaded file
/// </summary>
/// <param name="importProfile"><see cref="ImportProfile"/> containing the settings how to parse the headers</param>
/// <returns>Object which contains information and results of this method</returns>
public ViewModelOperationResult LoadHeaders(ImportProfile importProfile)
{
try
{
// Set ComboBox selection for Column Mapping
IdentifiedColumns.Clear();
var headerLine = _fileLines[SelectedImportProfile.HeaderRow - 1];
var columns = headerLine.Split(SelectedImportProfile.Delimiter);
var headerLine = _fileLines[importProfile.HeaderRow - 1];
var columns = headerLine.Split(importProfile.Delimiter);
foreach (var column in columns)
{
if (column != string.Empty)
IdentifiedColumns.Add(column.Trim(SelectedImportProfile.TextQualifier)); // Exclude TextQualifier
IdentifiedColumns.Add(column.Trim(importProfile.TextQualifier)); // Exclude TextQualifier
}

return new ViewModelOperationResult(true);
Expand Down

0 comments on commit 16e8bb6

Please sign in to comment.