feat(dashboard): #163 first summary
Some checks failed
Build Docker Image / Build-Docker-Image (push) Has been cancelled
Some checks failed
Build Docker Image / Build-Docker-Image (push) Has been cancelled
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
package account
|
||||
|
||||
import "fmt"
|
||||
import "spend-sparrow/internal/template/svg"
|
||||
import "spend-sparrow/internal/types"
|
||||
|
||||
@@ -81,9 +80,9 @@ templ AccountItem(account *types.Account) {
|
||||
<div class="text-xl flex justify-end gap-4">
|
||||
<p class="mr-auto">{ account.Name }</p>
|
||||
if account.CurrentBalance < 0 {
|
||||
<p class="mr-20 text-red-700">{ displayBalance(account.CurrentBalance) }</p>
|
||||
<p class="mr-20 text-red-700">{ types.FormatEuros(account.CurrentBalance) }</p>
|
||||
} else {
|
||||
<p class="mr-20 text-green-700">{ displayBalance(account.CurrentBalance) }</p>
|
||||
<p class="mr-20 text-green-700">{ types.FormatEuros(account.CurrentBalance) }</p>
|
||||
}
|
||||
<a
|
||||
href={ templ.URL("/transaction?account-id=" + account.Id.String()) }
|
||||
@@ -121,9 +120,3 @@ templ AccountItem(account *types.Account) {
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
func displayBalance(balance int64) string {
|
||||
|
||||
euros := float64(balance) / 100
|
||||
return fmt.Sprintf("%.2f €", euros)
|
||||
}
|
||||
|
||||
@@ -4,18 +4,41 @@ import "spend-sparrow/internal/types"
|
||||
|
||||
templ Dashboard(summary *types.DashboardMonthlySummary) {
|
||||
<div class="mt-10">
|
||||
<label for="month">Select Month:</label>
|
||||
<input name="month" type="date" class="input"/>
|
||||
<form hx-get="/" hx-target="#dashboard" hx-trigger="change" hx-push-url="true">
|
||||
<label for="month">Select Month:</label>
|
||||
<input
|
||||
name="month"
|
||||
type="date"
|
||||
class="input"
|
||||
value={ summary.Month.String() }
|
||||
/>
|
||||
</form>
|
||||
<div id="dashboard">
|
||||
@DashboardData(summary)
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
templ DashboardData(summary *types.DashboardMonthlySummary) {
|
||||
<div class="mt-10">
|
||||
<section class="grid grid-cols-[auto_auto_auto_auto_1fr] gap-4">
|
||||
<span>Savings</span>
|
||||
<span>Income</span>
|
||||
<span>Expenses</span>
|
||||
<span>Total</span>
|
||||
<span></span>
|
||||
<span>{ summary.Savings }</span>
|
||||
<span>{ summary.Income }</span>
|
||||
<span>{ summary.Expenses }</span>
|
||||
<span>{ summary.Total }</span>
|
||||
<span>{ types.FormatEuros(summary.Savings) }</span>
|
||||
@balance(summary.Income)
|
||||
@balance(summary.Expenses)
|
||||
@balance(summary.Total)
|
||||
</section>
|
||||
</div>
|
||||
}
|
||||
|
||||
templ balance(balance int64) {
|
||||
if balance < 0 {
|
||||
<span class="text-red-700">{ types.FormatEuros(balance) }</span>
|
||||
} else {
|
||||
<span class="text-green-700">{ types.FormatEuros(balance) }</span>
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,7 +103,7 @@ templ EditTransaction(transaction *types.Transaction, accounts []*types.Account,
|
||||
if transaction.TreasureChestId != nil {
|
||||
treasureChestId = transaction.TreasureChestId.String()
|
||||
}
|
||||
value = displayBalance(transaction.Value)
|
||||
value = formatFloat(transaction.Value)
|
||||
|
||||
id = transaction.Id.String()
|
||||
cancelUrl = "/transaction/" + id
|
||||
@@ -250,9 +250,9 @@ templ TransactionItem(transaction *types.Transaction, accounts, treasureChests m
|
||||
</p>
|
||||
</div>
|
||||
if transaction.Value < 0 {
|
||||
<p class="mr-8 min-w-22 text-right text-red-700">{ displayBalance(transaction.Value)+" €" }</p>
|
||||
<p class="mr-8 min-w-22 text-right text-red-700">{ types.FormatEuros(transaction.Value) }</p>
|
||||
} else {
|
||||
<p class="mr-8 w-22 text-right text-green-700">{ displayBalance(transaction.Value)+" €" }</p>
|
||||
<p class="mr-8 w-22 text-right text-green-700">{ types.FormatEuros(transaction.Value) }</p>
|
||||
}
|
||||
<button
|
||||
hx-get={ "/transaction/" + transaction.Id.String() + "?edit=true" }
|
||||
@@ -280,11 +280,8 @@ templ TransactionItem(transaction *types.Transaction, accounts, treasureChests m
|
||||
</div>
|
||||
}
|
||||
|
||||
func displayBalance(balance int64) string {
|
||||
func formatFloat(balance int64) string {
|
||||
|
||||
euros := float64(balance) / 100
|
||||
return fmt.Sprintf("%.2f", euros)
|
||||
}
|
||||
|
||||
func calculateReferences() {
|
||||
}
|
||||
|
||||
@@ -53,9 +53,9 @@ templ TransactionRecurringItem(transactionRecurring *types.TransactionRecurring,
|
||||
Every <span class="text-xl">{ transactionRecurring.IntervalMonths }</span> month(s)
|
||||
</p>
|
||||
if transactionRecurring.Value < 0 {
|
||||
<p class="text-right text-red-700">{ displayBalance(transactionRecurring.Value)+" €" }</p>
|
||||
<p class="text-right text-red-700">{ types.FormatEuros(transactionRecurring.Value) }</p>
|
||||
} else {
|
||||
<p class="text-right text-green-700">{ displayBalance(transactionRecurring.Value)+" €" }</p>
|
||||
<p class="text-right text-green-700">{ types.FormatEuros(transactionRecurring.Value) }</p>
|
||||
}
|
||||
<div class="flex gap-2">
|
||||
<button
|
||||
@@ -104,7 +104,7 @@ templ EditTransactionRecurring(transactionRecurring *types.TransactionRecurring,
|
||||
}
|
||||
party = transactionRecurring.Party
|
||||
description = transactionRecurring.Description
|
||||
value = displayBalance(transactionRecurring.Value)
|
||||
value = formatFloat(transactionRecurring.Value)
|
||||
|
||||
id = transactionRecurring.Id.String()
|
||||
}
|
||||
@@ -201,11 +201,8 @@ templ EditTransactionRecurring(transactionRecurring *types.TransactionRecurring,
|
||||
</div>
|
||||
}
|
||||
|
||||
func displayBalance(balance int64) string {
|
||||
func formatFloat(balance int64) string {
|
||||
|
||||
euros := float64(balance) / 100
|
||||
return fmt.Sprintf("%.2f", euros)
|
||||
}
|
||||
|
||||
func calculateReferences() {
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package treasurechest
|
||||
|
||||
import "fmt"
|
||||
import "spend-sparrow/internal/template/svg"
|
||||
import "spend-sparrow/internal/types"
|
||||
import "github.com/google/uuid"
|
||||
@@ -130,14 +129,14 @@ templ TreasureChestItem(treasureChest *types.TreasureChest, monthlySums map[uuid
|
||||
<p class="mr-auto">{ treasureChest.Name }</p>
|
||||
<p class="mr-20 text-gray-600">
|
||||
if treasureChest.ParentId != nil {
|
||||
+ { displayBalance(monthlySums[treasureChest.Id]) } <span class="text-gray-500 text-sm"> per month</span>
|
||||
+ { types.FormatEuros(monthlySums[treasureChest.Id]) } <span class="text-gray-500 text-sm"> per month</span>
|
||||
}
|
||||
</p>
|
||||
if treasureChest.ParentId != nil {
|
||||
if treasureChest.CurrentBalance < 0 {
|
||||
<p class="mr-20 min-w-20 text-right text-red-700">{ displayBalance(treasureChest.CurrentBalance) }</p>
|
||||
<p class="mr-20 min-w-20 text-right text-red-700">{ types.FormatEuros(treasureChest.CurrentBalance) }</p>
|
||||
} else {
|
||||
<p class="mr-20 min-w-20 text-right text-green-700">{ displayBalance(treasureChest.CurrentBalance) }</p>
|
||||
<p class="mr-20 min-w-20 text-right text-green-700">{ types.FormatEuros(treasureChest.CurrentBalance) }</p>
|
||||
}
|
||||
}
|
||||
<a
|
||||
@@ -187,9 +186,3 @@ func filterNoChildNoSelf(nodes []*types.TreasureChest, selfId string) []*types.T
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
func displayBalance(balance int64) string {
|
||||
|
||||
euros := float64(balance) / 100
|
||||
return fmt.Sprintf("%.2f €", euros)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user