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

#774 - account overview: allow accounts to be filtered + save filter configuration in session

parent fec2126d
No related branches found
No related tags found
No related merge requests found
......@@ -11,16 +11,16 @@ import de.deadlocker8.budgetmaster.utils.notification.Notification;
import de.deadlocker8.budgetmaster.utils.notification.NotificationLinkBuilder;
import de.deadlocker8.budgetmaster.utils.notification.NotificationType;
import de.thecodelabs.utils.util.Localization;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.WebRequest;
import jakarta.servlet.http.HttpServletRequest;
import java.text.MessageFormat;
import java.time.LocalDate;
import java.util.List;
......@@ -43,6 +43,7 @@ public class AccountController extends BaseController
public static final String ERROR = "error";
public static final String NOTIFICATIONS = "notifications";
public static final String TODAY = "today";
public static final String FILTER_CONFIGURATION = "accountsFilterConfiguration";
}
private static class ReturnValues
......@@ -115,22 +116,24 @@ public class AccountController extends BaseController
}
@GetMapping
public String accounts(Model model)
public String accounts(Model model, HttpServletRequest request)
{
model.addAttribute(ModelAttributes.ALL_ENTITIES, accountService.getAllEntitiesAsc());
final AccountsFilterConfiguration accountsFilterConfiguration = getAccountsFilterConfiguration(request);
model.addAttribute(ModelAttributes.ALL_ENTITIES, accountService.getFilteredEntitiesAsc(accountsFilterConfiguration));
return ReturnValues.SHOW_ALL;
}
@GetMapping("/{ID}/requestDelete")
public String requestDeleteAccount(Model model, @PathVariable("ID") Integer ID)
public String requestDeleteAccount(Model model, @PathVariable("ID") Integer ID, HttpServletRequest request)
{
model.addAttribute(ModelAttributes.ALL_ENTITIES, accountService.getAllEntitiesAsc());
final AccountsFilterConfiguration accountsFilterConfiguration = getAccountsFilterConfiguration(request);
model.addAttribute(ModelAttributes.ALL_ENTITIES, accountService.getFilteredEntitiesAsc(accountsFilterConfiguration));
model.addAttribute(ModelAttributes.ENTITY_TO_DELETE, accountService.getRepository().getReferenceById(ID));
return ReturnValues.DELETE_ENTITY;
}
@GetMapping("/{ID}/delete")
public String deleteAccountAndReferringTransactions(WebRequest request, Model model, @PathVariable("ID") Integer ID)
public String deleteAccountAndReferringTransactions(HttpServletRequest servletRequest, WebRequest request, Model model, @PathVariable("ID") Integer ID)
{
// at least one account is required (to delete a sole account another one has to be created first)
final Account accountToDelete = accountService.getRepository().getReferenceById(ID);
......@@ -141,7 +144,8 @@ public class AccountController extends BaseController
return ReturnValues.REDIRECT_SHOW_ALL;
}
model.addAttribute(ModelAttributes.ALL_ENTITIES, accountService.getAllEntitiesAsc());
final AccountsFilterConfiguration accountsFilterConfiguration = getAccountsFilterConfiguration(servletRequest);
model.addAttribute(ModelAttributes.ALL_ENTITIES, accountService.getFilteredEntitiesAsc(accountsFilterConfiguration));
model.addAttribute(ModelAttributes.CURRENT_ACCOUNT, accountToDelete);
model.addAttribute(ModelAttributes.ACCOUNT_NOT_DELETABLE, true);
return ReturnValues.SHOW_ALL;
......@@ -272,4 +276,23 @@ public class AccountController extends BaseController
settingsService.updateLastAccountEndDateReminderDate();
return "redirect:" + request.getHeader("Referer");
}
@PostMapping(value = "/applyFilter")
public String applyFilter(WebRequest request,
@ModelAttribute("AccountsFilter") AccountsFilterConfiguration accountsFilterConfiguration)
{
request.setAttribute(ModelAttributes.FILTER_CONFIGURATION, accountsFilterConfiguration, RequestAttributes.SCOPE_SESSION);
return ReturnValues.REDIRECT_SHOW_ALL;
}
private AccountsFilterConfiguration getAccountsFilterConfiguration(HttpServletRequest request)
{
Object sessionAccountsFilterConfiguration = request.getSession().getAttribute(ModelAttributes.FILTER_CONFIGURATION);
if(sessionAccountsFilterConfiguration == null)
{
request.getSession().setAttribute(ModelAttributes.FILTER_CONFIGURATION, AccountsFilterConfiguration.DEFAULT);
return AccountsFilterConfiguration.DEFAULT;
}
return (AccountsFilterConfiguration) sessionAccountsFilterConfiguration;
}
}
\ No newline at end of file
......@@ -24,6 +24,8 @@
<div class="center-align"><@header.buttonLink url='/accounts/newAccount' icon='add' localizationKey='title.account.new' id='button-new-account'/></div>
<br>
<div class="container account-container">
<form name="AccountsFilter" action="<@s.url '/accounts/applyFilter'/>" method="post">
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}" />
<table class="bordered">
<thead class="hide-on-med-and-down">
<tr>
......@@ -32,19 +34,19 @@
<div>${locale.getString("account.new.label.state")}</div>
<div>
<label>
<input type="checkbox" />
<input type="checkbox" name="includeFullAccess" <#if accountsFilterConfiguration?? && accountsFilterConfiguration.includeFullAccess>checked</#if>/>
<span><i class="fas fa-edit placeholder-icon-right"></i>${locale.getString("account.state.full.access")}</span>
</label>
</div>
<div>
<label>
<input type="checkbox" />
<input type="checkbox" name="includeReadOnly" <#if accountsFilterConfiguration?? && accountsFilterConfiguration.includeReadOnly>checked</#if>/>
<span><i class="fas fa-lock placeholder-icon-right"></i>${locale.getString("account.state.read.only")}</span>
</label>
</div>
<div>
<label>
<input type="checkbox" />
<input type="checkbox" name="includeHidden" <#if accountsFilterConfiguration?? && accountsFilterConfiguration.includeHidden>checked</#if>/>
<span><i class="far fa-eye-slash placeholder-icon-right"></i>${locale.getString("account.state.hidden")}</span>
</label>
</div>
......@@ -53,13 +55,13 @@
<div>${locale.getString("account.new.label.endDate")}</div>
<div>
<label>
<input type="checkbox" />
<input type="checkbox" name="includeWithEndDate" <#if accountsFilterConfiguration?? && accountsFilterConfiguration.includeWithEndDate>checked</#if>/>
<span><i class="fas fa-bell placeholder-icon-right"></i>${locale.getString("account.label.endDate.with")}</span>
</label>
</div>
<div>
<label>
<input type="checkbox" />
<input type="checkbox" name="includeWithoutEndDate" <#if accountsFilterConfiguration?? && accountsFilterConfiguration.includeWithoutEndDate>checked</#if>/>
<span><i class="fas fa-bell-slash placeholder-icon-right"></i>${locale.getString("account.label.endDate.without")}</span>
</label>
</div>
......@@ -67,13 +69,13 @@
<th>
<div>${locale.getString("account.new.label.name")}</div>
<div class="input-field">
<input type="text" id="accounts-filter-name">
<input type="text" name="name" value="<#if accountsFilterConfiguration??>${accountsFilterConfiguration.name}</#if>"/>
</div>
</th>
<th>
<div>${locale.getString("transaction.new.label.description")}</div>
<div class="input-field">
<input type="text" id="accounts-filter-description">
<input type="text" name="description" value="<#if accountsFilterConfiguration??>${accountsFilterConfiguration.description}</#if>"/>
</div>
</th>
<th class="vertical-align-middle">
......@@ -121,6 +123,7 @@
</#if>
</#list>
</table>
</form>
<#if accounts?size == 0>
<div class="headline center-align">${locale.getString("placeholder")}</div>
</#if>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment