Use same template for account and all-accounts

This commit is contained in:
Jan Bader 2021-12-10 16:38:10 +00:00
parent 4cd81592e4
commit e0eeaadc60
3 changed files with 9 additions and 36 deletions

View File

@ -9,12 +9,13 @@ import (
"github.com/google/uuid" "github.com/google/uuid"
) )
type BudgetData struct { type AllAccountsData struct {
AlwaysNeededData AlwaysNeededData
Account *postgres.Account
Transactions []postgres.GetTransactionsForBudgetRow Transactions []postgres.GetTransactionsForBudgetRow
} }
func (h *Handler) budget(c *gin.Context) { func (h *Handler) allAccounts(c *gin.Context) {
budgetID := c.Param("budgetid") budgetID := c.Param("budgetid")
budgetUUID, err := uuid.Parse(budgetID) budgetUUID, err := uuid.Parse(budgetID)
if err != nil { if err != nil {
@ -28,12 +29,15 @@ func (h *Handler) budget(c *gin.Context) {
return return
} }
d := BudgetData{ d := AllAccountsData{
c.MustGet("data").(AlwaysNeededData), c.MustGet("data").(AlwaysNeededData),
&postgres.Account{
Name: "All accounts",
},
transactions, transactions,
} }
c.HTML(http.StatusOK, "budget.html", d) c.HTML(http.StatusOK, "account.html", d)
} }
func (h *Handler) newBudget(c *gin.Context) { func (h *Handler) newBudget(c *gin.Context) {

View File

@ -58,7 +58,7 @@ func (h *Handler) Serve() {
withBudget.Use(h.getImportantData) withBudget.Use(h.getImportantData)
withBudget.GET("/budget/:budgetid", h.budgeting) withBudget.GET("/budget/:budgetid", h.budgeting)
withBudget.GET("/budget/:budgetid/:year/:month", h.budgeting) withBudget.GET("/budget/:budgetid/:year/:month", h.budgeting)
withBudget.GET("/budget/:budgetid/all-accounts", h.budget) withBudget.GET("/budget/:budgetid/all-accounts", h.allAccounts)
withBudget.GET("/budget/:budgetid/accounts", h.accounts) withBudget.GET("/budget/:budgetid/accounts", h.accounts)
withBudget.GET("/budget/:budgetid/account/:accountid", h.account) withBudget.GET("/budget/:budgetid/account/:accountid", h.account)
withBudget.GET("/budget/:budgetid/clear", h.clearBudget) withBudget.GET("/budget/:budgetid/clear", h.clearBudget)

View File

@ -1,31 +0,0 @@
{{template "base" .}}
{{define "title"}}Budget{{end}}
{{define "new"}}
{{template "transaction-new"}}
{{end}}
{{define "main"}}
<div class="budget-item">
<a href="#newtransactionmodal" data-toggle="modal" data-target="#newtransactionmodal">New Transaction</a>
<span class="time"></span>
</div>
<table class="container col-lg-12" id="content">
{{range .Transactions}}
<tr>
<td>{{.Date.Format "02.01.2006"}}</td>
<td>
{{.Account}}
</td>
<td>
{{.Payee}}
</td>
<td>
<a href="transaction/{{.ID}}">{{.Memo}}</a>
</td>
{{template "amount-cell" .Amount}}
</tr>
{{end}}
</table>
{{end}}