Skip to content

Commit

Permalink
#764 - global account select: show warning icons if the end date of a…
Browse files Browse the repository at this point in the history
…n account will soon be reached or is already reached
  • Loading branch information
deadlocker8 committed Jun 23, 2024
1 parent 667c7d9 commit ae6d062
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.springframework.format.annotation.DateTimeFormat;

import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
import java.util.List;
import java.util.Objects;

Expand Down Expand Up @@ -206,6 +207,16 @@ public String getDefaultFontColor(boolean isDarkTheme)
return FONT_COLOR_LIGHT_THEME;
}

public Long getRemainingDays()
{
if(this.endDate == null)
{
return null;
}

return LocalDate.now().until(this.endDate, ChronoUnit.DAYS);
}

@Override
public String toString()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,8 @@ account.new.label.endDate=Enddatum
account.default.name=Standardkonto
account.all=Alle Konten
account.tooltip.default=Als Standardkonto festlegen
account.tooltip.endDate.soon=Das Enddatum für dieses Konto wird in {0} Tagen erreicht!
account.tooltip.endDate.done=Das Enddatum für dieses Konto wurde vor {0} Tagen erreicht!

account.state.full.access=Vollzugriff
account.state.read.only=Lesezugriff
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,8 @@ account.new.label.endDate=End Date
account.default.name=Default Account
account.all=All Accounts
account.tooltip.default=Set as default account
account.tooltip.endDate.soon=The end date for this account will be reached in {0} days!
account.tooltip.endDate.done=The end date for this account was reached {0} days ago!

account.state.full.access=Full access
account.state.read.only=Read-only
Expand Down
13 changes: 12 additions & 1 deletion BudgetMasterServer/src/main/resources/static/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,6 @@ input[type="radio"]:checked + span::after, [type="radio"].with-gap:checked + spa
.global-account-select-option {
display: flex;
flex-direction: row;
align-items: flex-start;
background-color: var(--color-background);
border: 3px solid transparent;
padding: 0;
Expand All @@ -375,6 +374,18 @@ input[type="radio"]:checked + span::after, [type="radio"].with-gap:checked + spa
border: 3px solid var(--color-grey);
}

.global-account-select-option-header {
display: flex;
flex-direction: column;
justify-content: space-between;
align-items: center;
padding-bottom: 5px;
}

.global-account-select-option-header i {
font-size: 1.3rem;
}

.global-account-select-option-column-2 {
display: flex;
flex-direction: column;
Expand Down
1 change: 1 addition & 0 deletions BudgetMasterServer/src/main/resources/static/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ function fetchAndShowModal(item, containerID, modalID)
$('#' + containerID).html(data);
$(modalID).modal();
$(modalID).modal('open');
$('.global-account-select-option').find('.tooltipped').tooltip();
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,23 @@
<div class="col s12 m6 xl6">
<a href="<@s.url '/accounts/${account.getID()?c}/select'/>" class="text-default">
<div class="card-panel global-account-select-option" data-account-index="${account?index}">
<#if account?index < 10>
<div class="keyboard-key bold global-account-select-option-key">${account?index}</div>
<#else>
<div class="keyboard-key bold global-account-select-option-key-hidden">&nbsp;</div>
</#if>
<div class="global-account-select-option-header">
<#if account?index < 10>
<div class="keyboard-key bold global-account-select-option-key">${account?index}</div>
<#else>
<div class="keyboard-key bold global-account-select-option-key-hidden">&nbsp;</div>
</#if>

<#if account.getEndDate()??>
<#assign remainingDays=account.getRemainingDays()/>
<#if remainingDays <= 0>
<i class="fas fa-bell text-red tooltipped" data-position="right" data-tooltip="${locale.getString("account.tooltip.endDate.done", remainingDays?abs)}"></i>
<#elseif remainingDays <= 30>
<i class="fas fa-bell text-yellow tooltipped" data-position="right" data-tooltip="${locale.getString("account.tooltip.endDate.soon", remainingDays)}"></i>
</#if>
</#if>

</div>
<div class="global-account-select-option-content">
<@customSelectMacros.accountIcon account accountName "category-circle-preview account-icon-big"/>
<div class="global-account-select-option-column-2">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package de.deadlocker8.budgetmaster.unit;

import de.deadlocker8.budgetmaster.accounts.Account;
import de.deadlocker8.budgetmaster.accounts.AccountType;
import org.junit.jupiter.api.Test;

import java.time.LocalDate;

import static org.assertj.core.api.Assertions.assertThat;

class AccountTest
{

@Test
void test_getRemainingDays_NoEndDate()
{
final Account account = new Account("account", "", AccountType.CUSTOM, null);
assertThat(account.getRemainingDays())
.isNull();
}

@Test
void test_getRemainingDays_EndDateNotReached()
{
final LocalDate today = LocalDate.now();
final Account account = new Account("account", "", AccountType.CUSTOM, today.plusDays(30));
assertThat(account.getRemainingDays())
.isEqualTo(30);
}

@Test
void test_getRemainingDays_EndDateExactlyReached()
{
final LocalDate today = LocalDate.now();
final Account account = new Account("account", "", AccountType.CUSTOM, today);
assertThat(account.getRemainingDays())
.isZero();
}

@Test
void test_getRemainingDays_EndDateReached()
{
final LocalDate today = LocalDate.now();
final Account account = new Account("account", "", AccountType.CUSTOM, today.minusDays(5));
assertThat(account.getRemainingDays())
.isEqualTo(-5);
}
}

0 comments on commit ae6d062

Please sign in to comment.