From 75b2851e62052d24bf21b205e45340c385bb48de Mon Sep 17 00:00:00 2001
From: Robert Goldmann <deadlocker@gmx.de>
Date: Wed, 1 May 2019 16:57:37 +0200
Subject: [PATCH] #274 - list search results

---
 .../budgetmaster/search/SearchController.java | 25 +++++++++--
 src/main/resources/languages/_de.properties   |  2 +
 src/main/resources/languages/_en.properties   |  2 +
 src/main/resources/static/css/dark/search.css |  3 ++
 src/main/resources/static/css/search.css      |  3 ++
 .../resources/templates/search/search.ftl     | 41 ++++++++++++++++++-
 .../templates/transactions/transactions.ftl   |  2 +-
 .../transactions/transactionsMacros.ftl       |  8 ++++
 8 files changed, 80 insertions(+), 6 deletions(-)
 create mode 100644 src/main/resources/static/css/dark/search.css
 create mode 100644 src/main/resources/static/css/search.css

diff --git a/src/main/java/de/deadlocker8/budgetmaster/search/SearchController.java b/src/main/java/de/deadlocker8/budgetmaster/search/SearchController.java
index c94a934e5..63aef3f05 100644
--- a/src/main/java/de/deadlocker8/budgetmaster/search/SearchController.java
+++ b/src/main/java/de/deadlocker8/budgetmaster/search/SearchController.java
@@ -1,7 +1,12 @@
 package de.deadlocker8.budgetmaster.search;
 
+import de.deadlocker8.budgetmaster.accounts.AccountService;
+import de.deadlocker8.budgetmaster.accounts.AccountType;
 import de.deadlocker8.budgetmaster.controller.BaseController;
-import de.deadlocker8.budgetmaster.services.HelpersService;
+import de.deadlocker8.budgetmaster.filter.FilterConfiguration;
+import de.deadlocker8.budgetmaster.transactions.Transaction;
+import de.deadlocker8.budgetmaster.transactions.TransactionService;
+import org.joda.time.DateTime;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
 import org.springframework.ui.Model;
@@ -9,21 +14,33 @@ import org.springframework.web.bind.annotation.ModelAttribute;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
 
+import java.util.List;
+
 
 @Controller
 public class SearchController extends BaseController
 {
-	private final HelpersService helpers;
+	private final TransactionService transactionService;
+	private final AccountService accountService;
 
 	@Autowired
-	public SearchController(HelpersService helpers)
+	public SearchController(TransactionService transactionService, AccountService accountService)
+	{
+		this.transactionService = transactionService;
+		this.accountService = accountService;
+	}
+
+	@RequestMapping(value = "/search", method = RequestMethod.GET)
+	public String get(Model model, @ModelAttribute("NewSearch") Search search)
 	{
-		this.helpers = helpers;
+		return "redirect:/";
 	}
 
 	@RequestMapping(value = "/search", method = RequestMethod.POST)
 	public String post(Model model, @ModelAttribute("NewSearch") Search search)
 	{
+		List<Transaction> transactions = transactionService.getTransactionsForAccountUntilDate(accountService.getRepository().findAllByType(AccountType.ALL).get(0), DateTime.now(), FilterConfiguration.DEFAULT);
+		model.addAttribute("transactions", transactions);
 		model.addAttribute("searchText", search.getSearchText());
 		return "search/search";
 	}
diff --git a/src/main/resources/languages/_de.properties b/src/main/resources/languages/_de.properties
index 92130c709..3662b61d0 100644
--- a/src/main/resources/languages/_de.properties
+++ b/src/main/resources/languages/_de.properties
@@ -208,6 +208,8 @@ datepicker.label.month=Monat:
 datepicker.label.year=Jahr:
 datepicker.button.confirm=�bernehmen
 
+search.for=F�r
+
 # ABOUT
 about=�ber {0}
 about.roadmap.link=Roadmap �ffnen
diff --git a/src/main/resources/languages/_en.properties b/src/main/resources/languages/_en.properties
index 981f41bb5..d90a8f65b 100644
--- a/src/main/resources/languages/_en.properties
+++ b/src/main/resources/languages/_en.properties
@@ -209,6 +209,8 @@ datepicker.label.month=Month:
 datepicker.label.year=Year:
 datepicker.button.confirm=Apply
 
+search.for=For
+
 # ABOUT
 about=About {0}
 about.roadmap.link=Open Roadmap
diff --git a/src/main/resources/static/css/dark/search.css b/src/main/resources/static/css/dark/search.css
new file mode 100644
index 000000000..3e89401fa
--- /dev/null
+++ b/src/main/resources/static/css/dark/search.css
@@ -0,0 +1,3 @@
+.search-result {
+    background-color: #666666;
+}
\ No newline at end of file
diff --git a/src/main/resources/static/css/search.css b/src/main/resources/static/css/search.css
new file mode 100644
index 000000000..0bbc97eba
--- /dev/null
+++ b/src/main/resources/static/css/search.css
@@ -0,0 +1,3 @@
+.search-result {
+    background-color: #fafafa;
+}
\ No newline at end of file
diff --git a/src/main/resources/templates/search/search.ftl b/src/main/resources/templates/search/search.ftl
index 175bf0972..0eb01f818 100644
--- a/src/main/resources/templates/search/search.ftl
+++ b/src/main/resources/templates/search/search.ftl
@@ -2,12 +2,17 @@
     <head>
         <#import "../helpers/header.ftl" as header>
         <@header.header "BudgetMaster"/>
+        <@header.style "transactions"/>
+        <@header.style "categories"/>
+        <@header.style "search"/>
         <#import "/spring.ftl" as s>
     </head>
     <body class="budgetmaster-blue-light">
         <#import "../helpers/navbar.ftl" as navbar>
         <@navbar.navbar "home" settings/>
 
+        <#import "../transactions/transactionsMacros.ftl" as transactionsMacros>
+
         <main>
             <div class="card main-card background-color">
                 <div class="container">
@@ -18,7 +23,41 @@
                 <div class="container">
                     <div class="row">
                         <div class="col s12">
-                            ${searchText}
+                            <div class="headline center-align">${locale.getString("search.for")} "${searchText}"</div>
+                        </div>
+                    </div>
+                    <div class="row transaction-container">
+                        <div class="col s12">
+                            <#list transactions as transaction>
+                                <div class="card-panel search-result">
+                                    <div class="hide-on-large-only">
+                                        <div class="row valign-wrapper">
+                                            <div class="col s3 center-align bold transaction-text">
+                                                ${dateService.getDateStringWithoutYear(transaction.date)}
+                                            </div>
+                                            <@transactionsMacros.transactionType transaction/>
+                                            <@transactionsMacros.transactionLinks transaction/>
+                                        </div>
+                                        <div class="row valign-wrapper no-margin-bottom">
+                                            <@transactionsMacros.transactionCategory transaction "center-align"/>
+                                            <@transactionsMacros.transactionNameAndDescription transaction/>
+                                            <@transactionsMacros.transactionAmount transaction transaction.getAccount()/>
+                                        </div>
+                                    </div>
+                                    <div class="hide-on-med-and-down">
+                                        <div class="row valign-wrapper no-margin-bottom">
+                                            <div class="col l1 xl1 bold transaction-text transaction-line-height">
+                                                ${dateService.getDateStringWithoutYear(transaction.date)}
+                                            </div>
+                                            <@transactionsMacros.transactionCategory transaction "left-align"/>
+                                            <@transactionsMacros.transactionType transaction/>
+                                            <@transactionsMacros.transactionNameAndDescription transaction/>
+                                            <@transactionsMacros.transactionAmount transaction transaction.getAccount()/>
+                                            <@transactionsMacros.transactionLinks transaction/>
+                                        </div>
+                                    </div>
+                                </div>
+                            </#list>
                         </div>
                     </div>
                 </div>
diff --git a/src/main/resources/templates/transactions/transactions.ftl b/src/main/resources/templates/transactions/transactions.ftl
index 8390f9bf8..4ef1f97bf 100644
--- a/src/main/resources/templates/transactions/transactions.ftl
+++ b/src/main/resources/templates/transactions/transactions.ftl
@@ -66,7 +66,7 @@
                         </div>
                         <div class="hide-on-med-and-down">
                             <div class="row valign-wrapper transaction-row">
-                                <div class="col l1 xl1 bold transaction-text">
+                                <div class="col l1 xl1 bold transaction-text transaction-line-height">
                                     ${dateService.getDateStringWithoutYear(transaction.date)}
                                 </div>
                                 <@transactionsMacros.transactionCategory transaction "left-align"/>
diff --git a/src/main/resources/templates/transactions/transactionsMacros.ftl b/src/main/resources/templates/transactions/transactionsMacros.ftl
index a10463f96..3dbc1d068 100644
--- a/src/main/resources/templates/transactions/transactionsMacros.ftl
+++ b/src/main/resources/templates/transactions/transactionsMacros.ftl
@@ -60,6 +60,14 @@
         </div>
 </#macro>
 
+<#macro transactionLinks transaction>
+    <div class="col s8 l2 xl1 right-align transaction-buttons no-wrap">
+        <a href="<@s.url '/transactions/${transaction.ID?c}/edit'/>" class="btn-flat no-padding text-color"><i class="material-icons left">open_in_new</i></a>
+        <a href="<@s.url '/transactions/${transaction.ID?c}/edit'/>" class="btn-flat no-padding text-color"><i class="material-icons left no-margin">edit</i></a>
+    </div>
+</#macro>
+
+
 <#macro placeholder transactions>
     <#assign isOnlyRest = transactions?size == 1 && transactions[0].category.type.name() == "REST"/>
     <#if isOnlyRest>
-- 
GitLab