Skip to content
Snippets Groups Projects
Commit 4d30a5d7 authored by Robert Goldmann's avatar Robert Goldmann
Browse files

#259 - pass acountmatches to controller

parent b640de4e
No related branches found
No related tags found
No related merge requests found
Pipeline #179 passed
...@@ -2,10 +2,9 @@ package de.deadlocker8.budgetmaster.controller; ...@@ -2,10 +2,9 @@ package de.deadlocker8.budgetmaster.controller;
import de.deadlocker8.budgetmaster.authentication.User; import de.deadlocker8.budgetmaster.authentication.User;
import de.deadlocker8.budgetmaster.authentication.UserRepository; import de.deadlocker8.budgetmaster.authentication.UserRepository;
import de.deadlocker8.budgetmaster.database.AccountMatch; import de.deadlocker8.budgetmaster.database.accountmatches.AccountMatchList;
import de.deadlocker8.budgetmaster.database.Database; import de.deadlocker8.budgetmaster.database.Database;
import de.deadlocker8.budgetmaster.database.DatabaseParser; import de.deadlocker8.budgetmaster.database.DatabaseParser;
import de.deadlocker8.budgetmaster.entities.Account;
import de.deadlocker8.budgetmaster.entities.Settings; import de.deadlocker8.budgetmaster.entities.Settings;
import de.deadlocker8.budgetmaster.repositories.AccountRepository; import de.deadlocker8.budgetmaster.repositories.AccountRepository;
import de.deadlocker8.budgetmaster.repositories.SettingsRepository; import de.deadlocker8.budgetmaster.repositories.SettingsRepository;
...@@ -33,8 +32,6 @@ import javax.servlet.http.HttpServletRequest; ...@@ -33,8 +32,6 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.IOException; import java.io.IOException;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;
@Controller @Controller
...@@ -226,4 +223,12 @@ public class SettingsController extends BaseController ...@@ -226,4 +223,12 @@ public class SettingsController extends BaseController
model.addAttribute("availableAccounts", accountRepository.findAllByOrderByNameAsc()); model.addAttribute("availableAccounts", accountRepository.findAllByOrderByNameAsc());
return "import"; return "import";
} }
@RequestMapping("/settings/database/import")
public String importDatabase(Model model, @ModelAttribute("Import") AccountMatchList accountMatchList, BindingResult bindingResult)
{
System.out.println(accountMatchList);
System.out.println(bindingResult);
return "settings";
}
} }
\ No newline at end of file
package de.deadlocker8.budgetmaster.database; package de.deadlocker8.budgetmaster.database.accountmatches;
import de.deadlocker8.budgetmaster.entities.Account; import de.deadlocker8.budgetmaster.entities.Account;
...@@ -7,6 +7,10 @@ public class AccountMatch ...@@ -7,6 +7,10 @@ public class AccountMatch
private Account accountSource; private Account accountSource;
private Account accountDestination; private Account accountDestination;
public AccountMatch()
{
}
public AccountMatch(Account accountSource) public AccountMatch(Account accountSource)
{ {
this.accountSource = accountSource; this.accountSource = accountSource;
......
package de.deadlocker8.budgetmaster.database.accountmatches;
import java.util.List;
public class AccountMatchList
{
private List<AccountMatch> accountMatches;
public AccountMatchList()
{
}
public AccountMatchList(List<AccountMatch> accountMatches)
{
this.accountMatches = accountMatches;
}
public List<AccountMatch> getAccountMatches()
{
return accountMatches;
}
public void setAccountMatches(List<AccountMatch> accountMatches)
{
this.accountMatches = accountMatches;
}
@Override
public String toString()
{
return "AccountMatchList{" +
"accountMatches=" + accountMatches +
'}';
}
}
\ No newline at end of file
package de.deadlocker8.budgetmaster.services; package de.deadlocker8.budgetmaster.services;
import de.deadlocker8.budgetmaster.database.AccountMatch; import de.deadlocker8.budgetmaster.database.accountmatches.AccountMatch;
import de.deadlocker8.budgetmaster.entities.Account; import de.deadlocker8.budgetmaster.entities.Account;
import de.deadlocker8.budgetmaster.entities.Payment; import de.deadlocker8.budgetmaster.entities.Payment;
import de.deadlocker8.budgetmaster.entities.Settings; import de.deadlocker8.budgetmaster.entities.Settings;
......
$( document ).ready(function() {
// prevent form submit on enter
$(document).on("keypress", 'form', function (e) {
var code = e.keyCode || e.which;
if (code === 13) {
e.preventDefault();
return false;
}
});
});
function validateForm()
{
// handle account matches
var accountSources = $('.account-source');
var accountDestinations = $('select.account-destination');
var parent = document.getElementById("hidden-account-matches");
for(var i = 0; i < accountSources.length; i++)
{
var input = document.createElement("input");
input.setAttribute("type", "hidden");
input.setAttribute("name", "accountMatches[" + i + "].accountSource.name");
input.setAttribute("value", accountSources[i].innerText);
parent.appendChild(input);
var inputDestination = document.createElement("input");
inputDestination.setAttribute("type", "hidden");
inputDestination.setAttribute("name", "accountMatches[" + i + "].accountDestination.name");
inputDestination.setAttribute("value", accountDestinations[i].value);
parent.appendChild(inputDestination);
}
return true;
}
\ No newline at end of file
...@@ -17,17 +17,17 @@ ...@@ -17,17 +17,17 @@
</div> </div>
<div class="container"> <div class="container">
<#import "validation.ftl" as validation> <#import "validation.ftl" as validation>
<form name="Import" action="/settings/database/import" method="post"> <form name="Import" action="/settings/database/import" method="post" onsubmit="return validateForm()">
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/> <input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/>
<table class="bordered"> <table class="bordered">
<#list helpers.getAccountMatches(database.getAccounts()) as accountMatch> <#list helpers.getAccountMatches(database.getAccounts()) as accountMatch>
<tr> <tr>
<td class="import-text">${locale.getString("info.database.import.source")}</td> <td class="import-text">${locale.getString("info.database.import.source")}</td>
<td>${accountMatch.getAccountSource().getName()}</td> <td class="account-source">${accountMatch.getAccountSource().getName()}</td>
<td class="import-text">${locale.getString("info.database.import.destination")}</td> <td class="import-text">${locale.getString("info.database.import.destination")}</td>
<td> <td>
<select> <select class="account-destination">
<#list availableAccounts as account> <#list availableAccounts as account>
<option value="${account.getName()}">${account.getName()}</option> <option value="${account.getName()}">${account.getName()}</option>
</#list> </#list>
...@@ -44,6 +44,8 @@ ...@@ -44,6 +44,8 @@
<div class="headline center-align">${locale.getString("placeholder")}</div> <div class="headline center-align">${locale.getString("placeholder")}</div>
</#if> </#if>
<div id="hidden-account-matches"></div>
<br> <br>
<#-- buttons --> <#-- buttons -->
...@@ -62,5 +64,6 @@ ...@@ -62,5 +64,6 @@
<!-- Scripts--> <!-- Scripts-->
<#import "scripts.ftl" as scripts> <#import "scripts.ftl" as scripts>
<@scripts.scripts/> <@scripts.scripts/>
<script src="/js/import.js"></script>
</body> </body>
</html> </html>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment