From 414a56b2f9ac66cdbef6c24939225887b16d8d7f Mon Sep 17 00:00:00 2001 From: Robert Goldmann <deadlocker@gmx.de> Date: Sat, 13 Mar 2021 11:02:05 +0100 Subject: [PATCH] #553 - show statistics (number of accounts, transactions, ...) --- .../controller/IndexController.java | 6 ++- .../statistics/StatisticItem.java | 49 +++++++++++++++++++ .../statistics/StatisticsService.java | 45 +++++++++++++++++ .../resources/languages/base_de.properties | 6 +++ .../resources/languages/base_en.properties | 6 +++ src/main/resources/static/css/style.css | 8 +++ src/main/resources/templates/statistics.ftl | 17 ++++--- 7 files changed, 129 insertions(+), 8 deletions(-) create mode 100644 src/main/java/de/deadlocker8/budgetmaster/statistics/StatisticItem.java create mode 100644 src/main/java/de/deadlocker8/budgetmaster/statistics/StatisticsService.java diff --git a/src/main/java/de/deadlocker8/budgetmaster/controller/IndexController.java b/src/main/java/de/deadlocker8/budgetmaster/controller/IndexController.java index f6e0b4243..e61a63139 100644 --- a/src/main/java/de/deadlocker8/budgetmaster/controller/IndexController.java +++ b/src/main/java/de/deadlocker8/budgetmaster/controller/IndexController.java @@ -1,6 +1,7 @@ package de.deadlocker8.budgetmaster.controller; import de.deadlocker8.budgetmaster.settings.SettingsService; +import de.deadlocker8.budgetmaster.statistics.StatisticsService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; @@ -12,11 +13,13 @@ import org.springframework.web.bind.annotation.RequestMapping; public class IndexController extends BaseController { private final SettingsService settingsService; + private final StatisticsService statisticsService; @Autowired - public IndexController(SettingsService settingsService) + public IndexController(SettingsService settingsService, StatisticsService statisticsService) { this.settingsService = settingsService; + this.statisticsService = statisticsService; } @RequestMapping @@ -37,6 +40,7 @@ public class IndexController extends BaseController public String statistics(Model model) { model.addAttribute("settings", settingsService.getSettings()); + model.addAttribute("statisticItems", statisticsService.getStatisticItems()); return "statistics"; } } \ No newline at end of file diff --git a/src/main/java/de/deadlocker8/budgetmaster/statistics/StatisticItem.java b/src/main/java/de/deadlocker8/budgetmaster/statistics/StatisticItem.java new file mode 100644 index 000000000..cf903a49d --- /dev/null +++ b/src/main/java/de/deadlocker8/budgetmaster/statistics/StatisticItem.java @@ -0,0 +1,49 @@ +package de.deadlocker8.budgetmaster.statistics; + + +public class StatisticItem +{ + private final String icon; + private final String text; + private final String backgroundColor; + private final String textColor; + + public StatisticItem(String icon, String text, String backgroundColor, String textColor) + { + this.icon = icon; + this.text = text; + this.backgroundColor = backgroundColor; + this.textColor = textColor; + } + + public String getIcon() + { + return icon; + } + + public String getText() + { + return text; + } + + public String getBackgroundColor() + { + return backgroundColor; + } + + public String getTextColor() + { + return textColor; + } + + @Override + public String toString() + { + return "StatisticItem{" + + "icon='" + icon + '\'' + + ", text='" + text + '\'' + + ", backgroundColor=" + backgroundColor + + ", textColor=" + textColor + + '}'; + } +} diff --git a/src/main/java/de/deadlocker8/budgetmaster/statistics/StatisticsService.java b/src/main/java/de/deadlocker8/budgetmaster/statistics/StatisticsService.java new file mode 100644 index 000000000..2fe64dae4 --- /dev/null +++ b/src/main/java/de/deadlocker8/budgetmaster/statistics/StatisticsService.java @@ -0,0 +1,45 @@ +package de.deadlocker8.budgetmaster.statistics; + +import de.deadlocker8.budgetmaster.accounts.AccountService; +import de.deadlocker8.budgetmaster.categories.CategoryService; +import de.deadlocker8.budgetmaster.charts.ChartService; +import de.deadlocker8.budgetmaster.charts.ChartType; +import de.deadlocker8.budgetmaster.templates.TemplateService; +import de.deadlocker8.budgetmaster.transactions.TransactionService; +import de.thecodelabs.utils.util.Localization; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.List; + +@Service +public class StatisticsService +{ + private final AccountService accountService; + private final CategoryService categoryService; + private final TransactionService transactionService; + private final TemplateService templateService; + private final ChartService chartService; + + @Autowired + public StatisticsService(AccountService accountService, CategoryService categoryService, TransactionService transactionService, TemplateService templateService, ChartService chartService) + { + this.accountService = accountService; + this.categoryService = categoryService; + this.transactionService = transactionService; + this.templateService = templateService; + this.chartService = chartService; + } + + public List<StatisticItem> getStatisticItems() + { + final List<StatisticItem> statisticItems = new ArrayList<>(); + statisticItems.add(new StatisticItem("account_balance", Localization.getString("statistics.number.of.accounts", accountService.getAllAccountsAsc().size()), "background-red", "text-white")); + statisticItems.add(new StatisticItem("list", Localization.getString("statistics.number.of.transactions", transactionService.getRepository().findAll().size()), "background-blue-baby", "text-white")); + statisticItems.add(new StatisticItem("file_copy", Localization.getString("statistics.number.of.templates", templateService.getRepository().findAll().size()), "background-orange-dark", "text-white")); + statisticItems.add(new StatisticItem("show_chart", Localization.getString("statistics.number.of.custom.charts", chartService.getRepository().findAllByType(ChartType.CUSTOM).size()), "background-purple", "text-white")); + statisticItems.add(new StatisticItem("label", Localization.getString("statistics.number.of.categories", categoryService.getAllCategories().size()), "background-orange", "text-black")); + return statisticItems; + } +} diff --git a/src/main/resources/languages/base_de.properties b/src/main/resources/languages/base_de.properties index 1fe64050c..e5e500889 100644 --- a/src/main/resources/languages/base_de.properties +++ b/src/main/resources/languages/base_de.properties @@ -517,3 +517,9 @@ chart.quick.last.week.days=Letzte 7 Tage chart.quick.last.month.days=Letzte 30 Tage chart.quick.last.year.days=Letzte 365 Tage chart.quick.until.today=Alle bis heute + +statistics.number.of.accounts={0} Konten +statistics.number.of.transactions={0} Buchungen +statistics.number.of.templates={0} Vorlagen +statistics.number.of.custom.charts={0} Eigene Diagramme +statistics.number.of.categories={0} Kategorien diff --git a/src/main/resources/languages/base_en.properties b/src/main/resources/languages/base_en.properties index c441301e3..e8a3203c3 100644 --- a/src/main/resources/languages/base_en.properties +++ b/src/main/resources/languages/base_en.properties @@ -515,3 +515,9 @@ chart.quick.last.week.days=Last 7 days chart.quick.last.month.days=Last 30 days chart.quick.last.year.days=Last 365 days chart.quick.until.today=Until today + +statistics.number.of.accounts={0} Accounts +statistics.number.of.transactions={0} Transactions +statistics.number.of.templates={0} Templates +statistics.number.of.custom.charts={0} Custom Charts +statistics.number.of.categories={0} Categories diff --git a/src/main/resources/static/css/style.css b/src/main/resources/static/css/style.css index eb7c483a7..8edae0b25 100644 --- a/src/main/resources/static/css/style.css +++ b/src/main/resources/static/css/style.css @@ -421,6 +421,14 @@ input[type="radio"]:checked + span::after, [type="radio"].with-gap:checked + spa font-weight: bold; } +.statistics-item o { + font-size: 3rem; +} + +.statistics-item { + font-size: 1.5rem; +} + .tooltipped:hover { cursor: pointer; } diff --git a/src/main/resources/templates/statistics.ftl b/src/main/resources/templates/statistics.ftl index 8fa0b38cb..ab68c8b1c 100644 --- a/src/main/resources/templates/statistics.ftl +++ b/src/main/resources/templates/statistics.ftl @@ -2,7 +2,7 @@ <head> <#import "helpers/header.ftl" as header> <@header.globals/> - <@header.header "BudgetMaster - ${locale.getString('menu.firstUseGuide')}"/> + <@header.header "BudgetMaster - ${locale.getString('menu.statistics')}"/> <#import "/spring.ftl" as s> </head> <@header.body> @@ -22,13 +22,16 @@ <@header.content> <br> - <div class="container"> - <div class="container center-align"> - <div class="row left-align"> - <div class="col s12"> - Lorem Ipsum + <div class="container center-align"> + <div class="row left-align"> + <#list statisticItems as item> + <div class="col s12 m6 xl4 statistics-item"> + <div class="card-panel ${item.getBackgroundColor()} ${item.getTextColor()} center-align"> + <i class="material-icons">${item.getIcon()}</i> + <div>${item.getText()}</div> + </div> </div> - </div> + </#list> </div> </div> </@header.content> -- GitLab