Getting rid of the templating subpackage, complete unecessary
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
{{ define "expense" }}
|
||||||
<div>
|
<div>
|
||||||
<form id="expense-form" action="submit">
|
<form id="expense-form" action="submit">
|
||||||
<div id="form-state" class="warning"></div>
|
<div id="form-state" class="warning"></div>
|
||||||
@@ -58,144 +59,12 @@
|
|||||||
|
|
||||||
<fieldset id="shares-table-fields">
|
<fieldset id="shares-table-fields">
|
||||||
<legend>SHARES</legend>
|
<legend>SHARES</legend>
|
||||||
<button
|
{{ template "expenseShares" . }}
|
||||||
type="button"
|
|
||||||
onclick="addShareRow()"
|
|
||||||
>+ Share</button>
|
|
||||||
<table id="shares-table">
|
|
||||||
<tr>
|
|
||||||
<th>ID</th>
|
|
||||||
<th>USER</th>
|
|
||||||
<th>SHARE</th>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
<!-- Data row to be copied -->
|
|
||||||
<tr id="template-share-row" style="display: none;">
|
|
||||||
<td>
|
|
||||||
<input name="shares-ids[]" disabled readonly
|
|
||||||
value="" class="tui-dropdown">
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
<select name="shares-user-ids[]" disabled class="tui-dropdown">
|
|
||||||
{{ range .users }}
|
|
||||||
<option
|
|
||||||
{{ if eq .UserID $.expense.OwnerUser.UserID }}selected{{ end }}
|
|
||||||
value="{{ .UserID }}">{{ .UserName }}</option>
|
|
||||||
{{ end }}
|
|
||||||
</select>
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
<input type="number" name="shares-percent[]"
|
|
||||||
value="1" disabled class="tui-dropdown">
|
|
||||||
</td>
|
|
||||||
<td class="row-delete-button">
|
|
||||||
<button type="button" onclick="deleteShareRow(this)">X</button>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
{{ range .expense.Shares }}
|
|
||||||
{{ $share := . }}
|
|
||||||
<tr>
|
|
||||||
<td>
|
|
||||||
<input
|
|
||||||
name="shares-ids[]" readonly
|
|
||||||
value="{{ $share.ExpShareID }}" class="tui-dropdown">
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
<select name="shares-user-ids[]" class="tui-dropdown">
|
|
||||||
{{ range $.users }}
|
|
||||||
<option
|
|
||||||
value="{{ .UserID }}"
|
|
||||||
{{ if eq .UserID $share.User.UserID }}selected{{ end }}>
|
|
||||||
{{ .UserName }}
|
|
||||||
</option>
|
|
||||||
{{ end }}
|
|
||||||
</select>
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
<input type="number" name="shares-percent[]"
|
|
||||||
value="{{ $share.Share }}" class="tui-dropdown">
|
|
||||||
</td>
|
|
||||||
<td class="row-delete-button">
|
|
||||||
<button type="button" onclick="deleteShareRow(this)">X</button>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
{{ end }}
|
|
||||||
</table>
|
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<legend>PAYMENTS</legend>
|
<legend>PAYMENTS</legend>
|
||||||
<button
|
{{ template "expensePayments" . }}
|
||||||
type="button"
|
|
||||||
onclick="addPaymentRow()"
|
|
||||||
>+ Payment</button>
|
|
||||||
<div id="operation-state" class="warning"> </div><br>
|
|
||||||
<table id="payments-table">
|
|
||||||
<tr>
|
|
||||||
<th>ID</th>
|
|
||||||
<th>USER</th>
|
|
||||||
<th>PAYED</th>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
<!-- Data row to be copied -->
|
|
||||||
<tr id="template-payment-row" style="display: none;">
|
|
||||||
<td >
|
|
||||||
<input name="payments-ids[]" disabled readonly
|
|
||||||
value="" class="tui-dropdown">
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
<select name="payments-user-ids[]" disabled class="tui-dropdown">
|
|
||||||
{{ range .users }}
|
|
||||||
<option
|
|
||||||
{{ if eq .UserID $.expense.OwnerUser.UserID }}selected{{ end }}
|
|
||||||
value="{{ .UserID }}">{{ .UserName }}</option>
|
|
||||||
{{ end }}
|
|
||||||
</select>
|
|
||||||
</td>
|
|
||||||
|
|
||||||
<td>
|
|
||||||
<input type="number" name="payments-payment[]" value="0" disabled class="tui-dropdown">
|
|
||||||
</td>
|
|
||||||
|
|
||||||
<td class="row-delete-button">
|
|
||||||
<button type="button" onclick="deleteShareRow(this)">X</button>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
{{ range .expense.Payments }}
|
|
||||||
{{ $payment := . }}
|
|
||||||
<tr data-id="{{ $payment.ExpPaymID }}">
|
|
||||||
<td>
|
|
||||||
<input name="payments-ids[]" readonly
|
|
||||||
value="{{ $payment.ExpPaymID }}" class="tui-dropdown">
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
<select name="payments-user-ids[]" class="tui-dropdown">
|
|
||||||
{{ range $.users }}
|
|
||||||
<option
|
|
||||||
value="{{ .UserID }}"
|
|
||||||
{{ if eq .UserID $payment.User.UserID }}selected{{ end }}>
|
|
||||||
{{ .UserName }}
|
|
||||||
</option>
|
|
||||||
{{ end }}
|
|
||||||
</select>
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
<input type="number" name="payments-payment[]"
|
|
||||||
value="{{ $payment.PayedAmount }}" class="tui-dropdown">
|
|
||||||
</td>
|
|
||||||
<td class="row-delete-button">
|
|
||||||
<!-- <button type="button" onclick="deleteShareRow(this)">X</button> -->
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
class="delete-button"
|
|
||||||
hx-delete="/payments/{{ $payment.ExpPaymID }}"
|
|
||||||
hx-target="closest tr">X</button>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
{{ end }}
|
|
||||||
</table>
|
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
|
||||||
<br>
|
<br>
|
||||||
@@ -213,11 +82,6 @@
|
|||||||
{{- if eq .method "put" }}UPDATE{{- end }}
|
{{- if eq .method "put" }}UPDATE{{- end }}
|
||||||
{{- if eq .method "post" }}CREATE{{- end }}</button>
|
{{- if eq .method "post" }}CREATE{{- end }}</button>
|
||||||
{{ if eq .method "put" }}
|
{{ if eq .method "put" }}
|
||||||
<!-- <button -->
|
|
||||||
<!-- hx-delete="/expenses/{{ .expense.ExpID }}" -->
|
|
||||||
<!-- hx-swap="none" -->
|
|
||||||
<!-- type="button" -->
|
|
||||||
<!-- id="expense-delete-button">DELETE</button> -->
|
|
||||||
<button
|
<button
|
||||||
onclick="confirmDelete(this)"
|
onclick="confirmDelete(this)"
|
||||||
type="button"
|
type="button"
|
||||||
@@ -276,3 +140,4 @@
|
|||||||
deleteTarget = null;
|
deleteTarget = null;
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
{{ end }}
|
||||||
|
|||||||
@@ -0,0 +1,72 @@
|
|||||||
|
{{ define "expensePayments" }}
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onclick="addPaymentRow()"
|
||||||
|
>+ Payment</button>
|
||||||
|
<div id="operation-state" class="warning"> </div><br>
|
||||||
|
<table id="payments-table">
|
||||||
|
<tr>
|
||||||
|
<th>ID</th>
|
||||||
|
<th>USER</th>
|
||||||
|
<th>PAYED</th>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<!-- Data row to be copied -->
|
||||||
|
<tr id="template-payment-row" style="display: none;">
|
||||||
|
<td >
|
||||||
|
<input name="payments-ids[]" disabled readonly
|
||||||
|
value="" class="tui-dropdown">
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<select name="payments-user-ids[]" disabled class="tui-dropdown">
|
||||||
|
{{ range .users }}
|
||||||
|
<option
|
||||||
|
{{ if eq .UserID $.expense.OwnerUser.UserID }}selected{{ end }}
|
||||||
|
value="{{ .UserID }}">{{ .UserName }}</option>
|
||||||
|
{{ end }}
|
||||||
|
</select>
|
||||||
|
</td>
|
||||||
|
|
||||||
|
<td>
|
||||||
|
<input type="number" name="payments-payment[]" value="0" disabled class="tui-dropdown">
|
||||||
|
</td>
|
||||||
|
|
||||||
|
<td class="row-delete-button">
|
||||||
|
<button type="button" onclick="deleteShareRow(this)">X</button>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
{{ range .expense.Payments }}
|
||||||
|
{{ $payment := . }}
|
||||||
|
<tr data-id="{{ $payment.ExpPaymID }}">
|
||||||
|
<td>
|
||||||
|
<input name="payments-ids[]" readonly
|
||||||
|
value="{{ $payment.ExpPaymID }}" class="tui-dropdown">
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<select name="payments-user-ids[]" class="tui-dropdown">
|
||||||
|
{{ range $.users }}
|
||||||
|
<option
|
||||||
|
value="{{ .UserID }}"
|
||||||
|
{{ if eq .UserID $payment.User.UserID }}selected{{ end }}>
|
||||||
|
{{ .UserName }}
|
||||||
|
</option>
|
||||||
|
{{ end }}
|
||||||
|
</select>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<input type="number" name="payments-payment[]"
|
||||||
|
value="{{ $payment.PayedAmount }}" class="tui-dropdown">
|
||||||
|
</td>
|
||||||
|
<td class="row-delete-button">
|
||||||
|
<!-- <button type="button" onclick="deleteShareRow(this)">X</button> -->
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="delete-button"
|
||||||
|
hx-delete="/payments/{{ $payment.ExpPaymID }}"
|
||||||
|
hx-target="closest tr">X</button>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{{ end }}
|
||||||
|
</table>
|
||||||
|
{{ end }}
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
{{ define "expenseShares" }}
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onclick="addShareRow()"
|
||||||
|
>+ Share</button>
|
||||||
|
<table id="shares-table">
|
||||||
|
<tr>
|
||||||
|
<th>ID</th>
|
||||||
|
<th>USER</th>
|
||||||
|
<th>SHARE</th>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<!-- Data row to be copied -->
|
||||||
|
<tr id="template-share-row" style="display: none;">
|
||||||
|
<td>
|
||||||
|
<input name="shares-ids[]" disabled readonly
|
||||||
|
value="" class="tui-dropdown">
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<select name="shares-user-ids[]" disabled class="tui-dropdown">
|
||||||
|
{{ range .users }}
|
||||||
|
<option
|
||||||
|
{{ if eq .UserID $.expense.OwnerUser.UserID }}selected{{ end }}
|
||||||
|
value="{{ .UserID }}">{{ .UserName }}</option>
|
||||||
|
{{ end }}
|
||||||
|
</select>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<input type="number" name="shares-percent[]"
|
||||||
|
value="1" disabled class="tui-dropdown">
|
||||||
|
</td>
|
||||||
|
<td class="row-delete-button">
|
||||||
|
<button type="button" onclick="deleteShareRow(this)">X</button>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
{{ range .expense.Shares }}
|
||||||
|
{{ $share := . }}
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<input
|
||||||
|
name="shares-ids[]" readonly
|
||||||
|
value="{{ $share.ExpShareID }}" class="tui-dropdown">
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<select name="shares-user-ids[]" class="tui-dropdown">
|
||||||
|
{{ range $.users }}
|
||||||
|
<option
|
||||||
|
value="{{ .UserID }}"
|
||||||
|
{{ if eq .UserID $share.User.UserID }}selected{{ end }}>
|
||||||
|
{{ .UserName }}
|
||||||
|
</option>
|
||||||
|
{{ end }}
|
||||||
|
</select>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<input type="number" name="shares-percent[]"
|
||||||
|
value="{{ $share.Share }}" class="tui-dropdown">
|
||||||
|
</td>
|
||||||
|
<td class="row-delete-button">
|
||||||
|
<button type="button" onclick="deleteShareRow(this)">X</button>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{{ end }}
|
||||||
|
</table>
|
||||||
|
{{ end }}
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
{{ define "expenses" }}
|
||||||
<table>
|
<table>
|
||||||
<tr>
|
<tr>
|
||||||
<th>ID</th>
|
<th>ID</th>
|
||||||
@@ -20,3 +21,4 @@
|
|||||||
</tr>
|
</tr>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
</table>
|
</table>
|
||||||
|
{{ end }}
|
||||||
|
|||||||
@@ -47,7 +47,15 @@
|
|||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
<main id="content">
|
<main id="content">
|
||||||
{{ .content }}
|
{{ if eq .content "expense" }}
|
||||||
|
{{ template "expense" . }}
|
||||||
|
{{ else if eq .content "expenses" }}
|
||||||
|
{{ template "expenses" . }}
|
||||||
|
{{ else if eq .content "newExpense" }}
|
||||||
|
{{ template "expense" . }}
|
||||||
|
{{ else }}
|
||||||
|
<div>Unknown page</div>
|
||||||
|
{{ end }}
|
||||||
</main>
|
</main>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
+13
-6
@@ -3,10 +3,12 @@ package main
|
|||||||
import (
|
import (
|
||||||
"expenses/config"
|
"expenses/config"
|
||||||
"expenses/pages"
|
"expenses/pages"
|
||||||
|
"expenses/templating"
|
||||||
|
|
||||||
|
"html/template"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"path/filepath"
|
fp "path/filepath"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
@@ -15,16 +17,21 @@ import (
|
|||||||
var ginMode = "debug"
|
var ginMode = "debug"
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
gin.SetMode(ginMode)
|
|
||||||
|
|
||||||
config.SetConfig("./config.yaml")
|
config.SetConfig("./config.yaml")
|
||||||
|
|
||||||
cfg := config.GetInstance()
|
cfg := config.GetInstance()
|
||||||
|
|
||||||
|
gin.SetMode(ginMode)
|
||||||
|
templates := template.Must(
|
||||||
|
template.New("").
|
||||||
|
Funcs(templating.TmplFuncMap).
|
||||||
|
ParseGlob(fp.Join(cfg.AssetsDir, "htmx/*.html")),
|
||||||
|
)
|
||||||
|
|
||||||
router := gin.Default()
|
router := gin.Default()
|
||||||
|
router.SetHTMLTemplate(templates)
|
||||||
|
|
||||||
router.StaticFS("/assets", http.Dir(cfg.AssetsDir))
|
router.StaticFS("/assets", http.Dir(cfg.AssetsDir))
|
||||||
router.StaticFile("/favicon.ico", filepath.Join(cfg.AssetsDir, "img/favicon.webp"))
|
router.StaticFile("/favicon.ico", fp.Join(cfg.AssetsDir, "img/favicon.webp"))
|
||||||
router.LoadHTMLGlob(filepath.Join(cfg.AssetsDir, "htmx/*.gotempl"))
|
|
||||||
|
|
||||||
pages.RouteHome(router)
|
pages.RouteHome(router)
|
||||||
pages.RouteExpenses(router)
|
pages.RouteExpenses(router)
|
||||||
|
|||||||
+2
-2
@@ -13,12 +13,12 @@ func NotFoundView(c *gin.Context, msg string) {
|
|||||||
cfg := config.GetInstance()
|
cfg := config.GetInstance()
|
||||||
|
|
||||||
errHtml := templating.HtmlTemplate(
|
errHtml := templating.HtmlTemplate(
|
||||||
cfg.AssetsDir+"htmx/panic.tpl", map[string]any{
|
cfg.AssetsDir+"htmx/panic.html", map[string]any{
|
||||||
"msg": msg,
|
"msg": msg,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
c.HTML(404, "terminal.gotempl", gin.H{
|
c.HTML(404, "terminal.html", gin.H{
|
||||||
"warning": true,
|
"warning": true,
|
||||||
"renderNavBar": false,
|
"renderNavBar": false,
|
||||||
"content": errHtml,
|
"content": errHtml,
|
||||||
|
|||||||
+2
-2
@@ -11,12 +11,12 @@ func ServerErrorView(c *gin.Context, msg string) {
|
|||||||
cfg := config.GetInstance()
|
cfg := config.GetInstance()
|
||||||
|
|
||||||
errHtml := templating.HtmlTemplate(
|
errHtml := templating.HtmlTemplate(
|
||||||
cfg.AssetsDir+"htmx/panic.tpl", map[string]any{
|
cfg.AssetsDir+"htmx/panic.html", map[string]any{
|
||||||
"msg": msg,
|
"msg": msg,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
c.HTML(500, "terminal.gotempl", gin.H{
|
c.HTML(500, "terminal.html", gin.H{
|
||||||
"warning": true,
|
"warning": true,
|
||||||
"renderNavBar": false,
|
"renderNavBar": false,
|
||||||
"content": errHtml,
|
"content": errHtml,
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ func categoriesGlobalPage(c *gin.Context) {
|
|||||||
categories,
|
categories,
|
||||||
)
|
)
|
||||||
|
|
||||||
c.HTML(http.StatusOK, "terminal.gotempl", gin.H{
|
c.HTML(http.StatusOK, "terminal.html", gin.H{
|
||||||
"page": "categories",
|
"page": "categories",
|
||||||
"renderNavBar": true,
|
"renderNavBar": true,
|
||||||
"content": content,
|
"content": content,
|
||||||
@@ -68,7 +68,7 @@ func categoryPage(c *gin.Context) {
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
c.HTML(http.StatusOK, "terminal.gotempl", gin.H{
|
c.HTML(http.StatusOK, "terminal.html", gin.H{
|
||||||
"page": "category",
|
"page": "category",
|
||||||
"renderNavBar": false,
|
"renderNavBar": false,
|
||||||
"content": content,
|
"content": content,
|
||||||
@@ -82,7 +82,7 @@ func newCategoryPage(c *gin.Context) {
|
|||||||
fp.Join(cfg.AssetsDir, "/htmx/categoryNew.html"), map[string]any{},
|
fp.Join(cfg.AssetsDir, "/htmx/categoryNew.html"), map[string]any{},
|
||||||
)
|
)
|
||||||
|
|
||||||
c.HTML(http.StatusOK, "terminal.gotempl", gin.H{
|
c.HTML(http.StatusOK, "terminal.html", gin.H{
|
||||||
"page": "expenseNew",
|
"page": "expenseNew",
|
||||||
"renderNavBar": false,
|
"renderNavBar": false,
|
||||||
"content": content,
|
"content": content,
|
||||||
|
|||||||
+26
-68
@@ -2,14 +2,11 @@ package pages
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"expenses/config"
|
|
||||||
"expenses/expenses"
|
"expenses/expenses"
|
||||||
"expenses/templating"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"net/http"
|
"net/http"
|
||||||
fp "path/filepath"
|
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
@@ -18,60 +15,34 @@ const (
|
|||||||
ExpensesPath = "/expenses"
|
ExpensesPath = "/expenses"
|
||||||
)
|
)
|
||||||
|
|
||||||
func expensesContent() (map[string]any, error) {
|
|
||||||
expenses, err := expenses.GetAllExpenses()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
data := map[string]any{
|
|
||||||
"size": len(expenses) - 1,
|
|
||||||
"expenses": expenses,
|
|
||||||
"resource": "expenses",
|
|
||||||
}
|
|
||||||
|
|
||||||
return data, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func expensesPartial(c *gin.Context) {
|
func expensesPartial(c *gin.Context) {
|
||||||
cfg := config.GetInstance()
|
expenses, err := expenses.GetAllExpenses()
|
||||||
|
|
||||||
expenses, err := expensesContent()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Header("HX-Redirect", "/500")
|
c.Header("HX-Redirect", "/500")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
content := templating.HtmlTemplate(
|
|
||||||
fp.Join(cfg.AssetsDir, "htmx/expenses.html"),
|
|
||||||
expenses,
|
|
||||||
)
|
|
||||||
|
|
||||||
c.String(http.StatusOK, string(content))
|
c.HTML(http.StatusOK, "expenses", gin.H{
|
||||||
|
"expenses": expenses,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func ExpensesGlobalPage(c *gin.Context) {
|
func ExpensesGlobalPage(c *gin.Context) {
|
||||||
cfg := config.GetInstance()
|
expenses, err := expenses.GetAllExpenses()
|
||||||
|
|
||||||
expenses, err := expensesContent()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Header("HX-Redirect", "/500")
|
c.Header("HX-Redirect", "/500")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
content := templating.HtmlTemplate(
|
|
||||||
fp.Join(cfg.AssetsDir, "htmx/expenses.html"),
|
|
||||||
expenses,
|
|
||||||
)
|
|
||||||
|
|
||||||
c.HTML(http.StatusOK, "terminal.gotempl", gin.H{
|
c.HTML(http.StatusOK, "terminal.html", gin.H{
|
||||||
"page": "expenses",
|
"page": "expenses",
|
||||||
"renderNavBar": true,
|
"renderNavBar": true,
|
||||||
"content": content,
|
"content": "expenses",
|
||||||
|
"expenses": expenses,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func expensePage(c *gin.Context) {
|
func expensePage(c *gin.Context) {
|
||||||
cfg := config.GetInstance()
|
|
||||||
|
|
||||||
expenseID, err := strconv.Atoi(c.Param("id"))
|
expenseID, err := strconv.Atoi(c.Param("id"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Redirect(404, "/404")
|
c.Redirect(404, "/404")
|
||||||
@@ -120,34 +91,26 @@ func expensePage(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
content := templating.HtmlTemplate(
|
|
||||||
fp.Join(cfg.AssetsDir, "/htmx/expense.html"),
|
|
||||||
map[string]any{
|
|
||||||
"method": "put",
|
|
||||||
"expense": expense,
|
|
||||||
"categories": categories,
|
|
||||||
"stores": stores,
|
|
||||||
"types": types,
|
|
||||||
"summary": summary,
|
|
||||||
"users": users,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
if expense.ExpID == -1 {
|
if expense.ExpID == -1 {
|
||||||
NotFoundView(c, fmt.Sprintf("ID `%d` doesn't exist", expenseID))
|
NotFoundView(c, fmt.Sprintf("ID `%d` doesn't exist", expenseID))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.HTML(http.StatusOK, "terminal.gotempl", gin.H{
|
c.HTML(http.StatusOK, "terminal.html", gin.H{
|
||||||
"page": "expense",
|
"page": "expense",
|
||||||
"renderNavBar": false,
|
"renderNavBar": false,
|
||||||
"content": content,
|
"content": "expense",
|
||||||
|
"method": "put",
|
||||||
|
"expense": expense,
|
||||||
|
"categories": categories,
|
||||||
|
"stores": stores,
|
||||||
|
"types": types,
|
||||||
|
"summary": summary,
|
||||||
|
"users": users,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func newExpensePage(c *gin.Context) {
|
func newExpensePage(c *gin.Context) {
|
||||||
cfg := config.GetInstance()
|
|
||||||
|
|
||||||
categories, err := expenses.GetAllCategories()
|
categories, err := expenses.GetAllCategories()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ServerErrorView(c, "failed to fetch categories")
|
ServerErrorView(c, "failed to fetch categories")
|
||||||
@@ -172,21 +135,16 @@ func newExpensePage(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
content := templating.HtmlTemplate(
|
c.HTML(http.StatusOK, "terminal.html", gin.H{
|
||||||
fp.Join(cfg.AssetsDir, "/htmx/expense.html"), map[string]any{
|
|
||||||
"method": "post",
|
|
||||||
"expense": expenses.NewExpense(),
|
|
||||||
"categories": categories,
|
|
||||||
"stores": stores,
|
|
||||||
"types": types,
|
|
||||||
"users": users,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
c.HTML(http.StatusOK, "terminal.gotempl", gin.H{
|
|
||||||
"page": "expenseNew",
|
"page": "expenseNew",
|
||||||
"renderNavBar": false,
|
"renderNavBar": false,
|
||||||
"content": content,
|
"content": "newExpense",
|
||||||
|
"method": "post",
|
||||||
|
"expense": expenses.NewExpense(),
|
||||||
|
"categories": categories,
|
||||||
|
"stores": stores,
|
||||||
|
"types": types,
|
||||||
|
"users": users,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -242,7 +200,7 @@ func deleteExpense(c *gin.Context) {
|
|||||||
|
|
||||||
payment := expenses.Expense{
|
payment := expenses.Expense{
|
||||||
ExpID: expenseID,
|
ExpID: expenseID,
|
||||||
}
|
}
|
||||||
|
|
||||||
err = payment.Delete()
|
err = payment.Delete()
|
||||||
if err == expenses.ErrNotFound {
|
if err == expenses.ErrNotFound {
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ func overviewPartialPage(c *gin.Context) {
|
|||||||
func overviewPage(c *gin.Context) {
|
func overviewPage(c *gin.Context) {
|
||||||
content := overviewContent()
|
content := overviewContent()
|
||||||
|
|
||||||
c.HTML(http.StatusOK, "terminal.gotempl", gin.H{
|
c.HTML(http.StatusOK, "terminal.html", gin.H{
|
||||||
"page": "overview",
|
"page": "overview",
|
||||||
"renderNavBar": true,
|
"renderNavBar": true,
|
||||||
"content": content,
|
"content": content,
|
||||||
|
|||||||
+3
-3
@@ -45,7 +45,7 @@ func storesGlobalPage(c *gin.Context) {
|
|||||||
stores,
|
stores,
|
||||||
)
|
)
|
||||||
|
|
||||||
c.HTML(http.StatusOK, "terminal.gotempl", gin.H{
|
c.HTML(http.StatusOK, "terminal.html", gin.H{
|
||||||
"page": "stores",
|
"page": "stores",
|
||||||
"renderNavBar": true,
|
"renderNavBar": true,
|
||||||
"content": content,
|
"content": content,
|
||||||
@@ -68,7 +68,7 @@ func storePage(c *gin.Context) {
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
c.HTML(http.StatusOK, "terminal.gotempl", gin.H{
|
c.HTML(http.StatusOK, "terminal.html", gin.H{
|
||||||
"page": "store",
|
"page": "store",
|
||||||
"renderNavBar": false,
|
"renderNavBar": false,
|
||||||
"content": content,
|
"content": content,
|
||||||
@@ -82,7 +82,7 @@ func newStorePage(c *gin.Context) {
|
|||||||
fp.Join(cfg.AssetsDir, "/htmx/storeNew.html"), map[string]any{},
|
fp.Join(cfg.AssetsDir, "/htmx/storeNew.html"), map[string]any{},
|
||||||
)
|
)
|
||||||
|
|
||||||
c.HTML(http.StatusOK, "terminal.gotempl", gin.H{
|
c.HTML(http.StatusOK, "terminal.html", gin.H{
|
||||||
"page": "storeNew",
|
"page": "storeNew",
|
||||||
"renderNavBar": false,
|
"renderNavBar": false,
|
||||||
"content": content,
|
"content": content,
|
||||||
|
|||||||
+3
-3
@@ -45,7 +45,7 @@ func typesGlobalPage(c *gin.Context) {
|
|||||||
types,
|
types,
|
||||||
)
|
)
|
||||||
|
|
||||||
c.HTML(http.StatusOK, "terminal.gotempl", gin.H{
|
c.HTML(http.StatusOK, "terminal.html", gin.H{
|
||||||
"page": "types",
|
"page": "types",
|
||||||
"renderNavBar": true,
|
"renderNavBar": true,
|
||||||
"content": content,
|
"content": content,
|
||||||
@@ -68,7 +68,7 @@ func typePage(c *gin.Context) {
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
c.HTML(http.StatusOK, "terminal.gotempl", gin.H{
|
c.HTML(http.StatusOK, "terminal.html", gin.H{
|
||||||
"page": "type",
|
"page": "type",
|
||||||
"renderNavBar": false,
|
"renderNavBar": false,
|
||||||
"content": content,
|
"content": content,
|
||||||
@@ -82,7 +82,7 @@ func newTypePage(c *gin.Context) {
|
|||||||
fp.Join(cfg.AssetsDir, "/htmx/typeNew.html"), map[string]any{},
|
fp.Join(cfg.AssetsDir, "/htmx/typeNew.html"), map[string]any{},
|
||||||
)
|
)
|
||||||
|
|
||||||
c.HTML(http.StatusOK, "terminal.gotempl", gin.H{
|
c.HTML(http.StatusOK, "terminal.html", gin.H{
|
||||||
"page": "typeNew",
|
"page": "typeNew",
|
||||||
"renderNavBar": false,
|
"renderNavBar": false,
|
||||||
"content": content,
|
"content": content,
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package templating
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"expenses/config"
|
||||||
"fmt"
|
"fmt"
|
||||||
"html/template"
|
"html/template"
|
||||||
"log"
|
"log"
|
||||||
@@ -9,8 +10,8 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func createTemplateEngine(name string) *template.Template {
|
var (
|
||||||
funcMap := template.FuncMap{
|
TmplFuncMap = template.FuncMap{
|
||||||
"formatDate": func(ts int64) string {
|
"formatDate": func(ts int64) string {
|
||||||
return time.Unix(ts, 0).Format("02-Jan-2006")
|
return time.Unix(ts, 0).Format("02-Jan-2006")
|
||||||
},
|
},
|
||||||
@@ -18,8 +19,17 @@ func createTemplateEngine(name string) *template.Template {
|
|||||||
return fmt.Sprintf("%.2f", v)
|
return fmt.Sprintf("%.2f", v)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
)
|
||||||
|
|
||||||
tmpl := template.New(name).Funcs(funcMap)
|
func createTemplateEngine(name string) *template.Template {
|
||||||
|
cfg := config.GetInstance()
|
||||||
|
|
||||||
|
|
||||||
|
tmpl := template.New(name).Funcs(TmplFuncMap)
|
||||||
|
tmpl, err := tmpl.ParseGlob(fp.Join(cfg.AssetsDir, "htmx/*.html"))
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
return tmpl
|
return tmpl
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user