Skip to content

Commit c3ef3dc

Browse files
committed
Rename TrendType to TrendPeriod
1 parent 43d9b9c commit c3ef3dc

4 files changed

Lines changed: 32 additions & 28 deletions

File tree

src/main/java/com/hz/mymoney/ui/controllers/TrendsTemplate.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,17 @@ public String accounts(Model model) {
3232
return "Trends";
3333
}
3434

35-
@GetMapping("/trendTypeButtonClick")
35+
@GetMapping("/trendPeriodButtonClick")
3636
@HxRequest
3737
public View distributionButtonsClick(Model model, @RequestParam String button, @RequestParam String accounts) {
38-
model.addAttribute("activeButton", button);
39-
model.addAttribute("trendsData", uiModelBuilderService.createTrendsTemplateData(accounts, button));
38+
try {
39+
model.addAttribute("activeButton", button);
40+
model.addAttribute("trendsData", uiModelBuilderService.createTrendsTemplateData(accounts, button));
41+
} catch (Exception e) {
42+
log.error("Trends Period Button Generation Exception {}", e.getMessage(), e);
43+
}
4044
return FragmentsRendering
41-
.fragment("Trends :: #TrendTypeButtons")
45+
.fragment("Trends :: #trendPeriodButtons")
4246
.fragment("Trends :: #trendsGraph")
4347
.fragment("Trends :: #trendsTotal")
4448
.build();
@@ -50,7 +54,7 @@ public View accountChange(Model model, @RequestParam(name = "accounts") String a
5054
try {
5155
model.addAttribute("trendsData", uiModelBuilderService.createTrendsTemplateData(accountName, trendType));
5256
} catch (Exception e) {
53-
log.error("Trends Page Generation Exception {}", e.getMessage(), e);
57+
log.error("Trends Account Change Generation Exception {}", e.getMessage(), e);
5458
}
5559
return FragmentsRendering
5660
.fragment("Trends :: #trendsGraph")

src/main/java/com/hz/mymoney/ui/models/templates/TrendsTemplateData.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,44 +17,44 @@
1717
public class TrendsTemplateData {
1818
@Getter
1919
private final String account;
20-
private final String trendType;
20+
private final String trendPeriod;
2121
private final List<Movement> movements;
2222

2323
private LocalDate startDate() {
24-
return switch (trendType) {
24+
return switch (trendPeriod) {
2525
case "30d" -> LocalDate.now().minusDays(30);
2626
case "6m" -> LocalDate.now().minusMonths(5);
2727
case "1y" -> LocalDate.now().minusMonths(11);
2828
case "2y" -> LocalDate.now().minusYears(1).minusMonths(11);
2929
case "5y" -> LocalDate.now().minusYears(4).minusMonths(11);
3030
case "10y" -> LocalDate.now().minusYears(9).minusMonths(11);
31-
default -> throw new IllegalStateException("Unexpected value: " + trendType);
31+
default -> throw new IllegalStateException("Unexpected value: " + trendPeriod);
3232
};
3333
}
3434

3535
private String groupBy(LocalDate date) {
36-
return switch (trendType) {
36+
return switch (trendPeriod) {
3737
case "30d" -> date.format(DateTimeFormatter.ISO_LOCAL_DATE);
3838
case "6m", "1y", "2y" -> date.format(DateTimeFormatter.ofPattern("yyyy-MM"));
3939
case "5y", "10y" -> date.format(DateTimeFormatter.ofPattern("yyyy"));
40-
default -> throw new IllegalStateException("Unexpected value: " + trendType);
40+
default -> throw new IllegalStateException("Unexpected value: " + trendPeriod);
4141
};
4242
}
4343

4444
private String toDisplayName(String groupedName) {
45-
LocalDate date = switch (trendType) {
45+
LocalDate date = switch (trendPeriod) {
4646
case "30d" -> LocalDate.parse(groupedName, DateTimeFormatter.ISO_LOCAL_DATE);
4747
case "6m", "1y", "2y" -> LocalDate.parse(groupedName + "-01", DateTimeFormatter.ISO_LOCAL_DATE);
4848
case "5y", "10y" -> LocalDate.parse(groupedName + "-01-01", DateTimeFormatter.ISO_LOCAL_DATE);
49-
default -> throw new IllegalStateException("Unexpected value: " + trendType);
49+
default -> throw new IllegalStateException("Unexpected value: " + trendPeriod);
5050
};
5151

52-
return switch (trendType) {
52+
return switch (trendPeriod) {
5353
case "30d" -> date.format(DateTimeFormatter.ISO_LOCAL_DATE);
5454
case "6m", "1y" -> date.format(DateTimeFormatter.ofPattern("MMM"));
5555
case "2y" -> date.format(DateTimeFormatter.ofPattern("MMM-yy"));
5656
case "5y", "10y" -> date.format(DateTimeFormatter.ofPattern("yyyy"));
57-
default -> throw new IllegalStateException("Unexpected value: " + trendType);
57+
default -> throw new IllegalStateException("Unexpected value: " + trendPeriod);
5858
};
5959
}
6060

src/main/java/com/hz/mymoney/ui/services/UiModelBuilderService.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,17 @@ public boolean isLedgerReadOnly() {
4141
return dataLoaderService.getLedger().isReadOnly();
4242
}
4343

44-
public TrendsTemplateData createTrendsTemplateData(String accountName, String trendType) {
44+
public TrendsTemplateData createTrendsTemplateData(String accountName, String trendPeriod) {
4545
ChartOfAccounts coa = dataLoaderService.getCoa();
4646

4747
var account = coa.findAccount(accountName);
4848

4949
if (account.isPresent()) {
50-
return new TrendsTemplateData(accountName, trendType, account.get().getMovementsAsList());
50+
return new TrendsTemplateData(accountName, trendPeriod, account.get().getMovementsAsList());
5151
}
5252

5353
if (accountName.isEmpty()) {
54-
return new TrendsTemplateData(accountName, trendType, new ArrayList<>());
54+
return new TrendsTemplateData(accountName, trendPeriod, new ArrayList<>());
5555
}
5656

5757
// Merge all the accounts found into single set of movements
@@ -61,7 +61,7 @@ public TrendsTemplateData createTrendsTemplateData(String accountName, String tr
6161
.flatMap(Collection::stream)
6262
.toList();
6363

64-
return new TrendsTemplateData(accountName, trendType, allMovements);
64+
return new TrendsTemplateData(accountName, trendPeriod, allMovements);
6565
}
6666

6767
public List<ScheduledTransaction> getScheduledTransactions() {

src/main/resources/templates/Trends.html

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,42 +5,42 @@
55
<body>
66
<main>
77
<form class="ui form" hx-include="#trend-account-input"
8-
th:attr="hx-get=|@{/accountChanged}?trendType=${activeButton}|"
8+
th:attr="hx-get=|@{/accountChanged}?trendPeriod=${activeButton}|"
99
hx-trigger="focusout[event.target.matches('input')] from:body" hx-select-oob="#trendsGraph,#trendsTotal"
1010
hx-target="none">
1111
<div class="two fields">
1212
<div th:replace="~{fragments/Journal :: AccountInputField ('trend-account', 'Account to Track', '', null, false)}"></div>
13-
<div class="required field" id="TrendTypeButtons">
14-
<label>Trend Type</label>
13+
<div class="required field" id="trendPeriodButtons">
14+
<label>Trend Period</label>
1515
<div class="six ui buttons">
16-
<input type="hidden" th:value="${activeButton}" name="trendType">
16+
<input type="hidden" th:value="${activeButton}" name="trendPeriod">
1717
<div th:class="${activeButton} eq '30d' ? 'ui active button' : 'ui button'"
18-
th:attr="hx-get=|@{/trendTypeButtonClick}?button=30d|" hx-target="#TrendTypeButtons"
18+
th:attr="hx-get=|@{/trendPeriodButtonClick}?button=30d|" hx-target="#trendPeriodButtons"
1919
hx-select-oob="#trendsGraph,#trendsTotal">
2020
30d
2121
</div>
2222
<div th:class="${activeButton} eq '6m' ? 'ui active button' : 'ui button'"
23-
th:attr="hx-get=|@{/trendTypeButtonClick}?button=6m|" hx-target="#TrendTypeButtons"
23+
th:attr="hx-get=|@{/trendPeriodButtonClick}?button=6m|" hx-target="#trendPeriodButtons"
2424
hx-select-oob="#trendsGraph,#trendsTotal">
2525
6m
2626
</div>
2727
<div th:class="${activeButton} eq '1y' ? 'ui active button' : 'ui button'"
28-
th:attr="hx-get=|@{/trendTypeButtonClick}?button=1y|" hx-target="#TrendTypeButtons"
28+
th:attr="hx-get=|@{/trendPeriodButtonClick}?button=1y|" hx-target="#trendPeriodButtons"
2929
hx-select-oob="#trendsGraph,#trendsTotal">
3030
1y
3131
</div>
3232
<div th:class="${activeButton} eq '2y' ? 'ui active button' : 'ui button'"
33-
th:attr="hx-get=|@{/trendTypeButtonClick}?button=2y|" hx-target="#TrendTypeButtons"
33+
th:attr="hx-get=|@{/trendPeriodButtonClick}?button=2y|" hx-target="#trendPeriodButtons"
3434
hx-select-oob="#trendsGraph,#trendsTotal">
3535
2y
3636
</div>
3737
<div th:class="${activeButton} eq '5y' ? 'ui active button' : 'ui button'"
38-
th:attr="hx-get=|@{/trendTypeButtonClick}?button=5y|" hx-target="#TrendTypeButtons"
38+
th:attr="hx-get=|@{/trendPeriodButtonClick}?button=5y|" hx-target="#trendPeriodButtons"
3939
hx-select-oob="#trendsGraph,#trendsTotal">
4040
5y
4141
</div>
4242
<div th:class="${activeButton} eq '10y' ? 'ui active button' : 'ui button'"
43-
th:attr="hx-get=|@{/trendTypeButtonClick}?button=10y|" hx-target="#TrendTypeButtons"
43+
th:attr="hx-get=|@{/trendPeriodButtonClick}?button=10y|" hx-target="#trendPeriodButtons"
4444
hx-select-oob="#trendsGraph,#trendsTotal">
4545
10y
4646
</div>

0 commit comments

Comments
 (0)