diff --git a/.gitignore b/.gitignore index 36484f4..33769d1 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,7 @@ test.db # --> generated files -web/*_templ.go +*_templ.go web/static/*.css web/static/*.css.map .sass-cache/* diff --git a/main.go b/recount-server.go similarity index 100% rename from main.go rename to recount-server.go diff --git a/web/data_endpoints.go b/web/rendering.go similarity index 77% rename from web/data_endpoints.go rename to web/rendering.go index 72d5c7a..c9ae6dd 100644 --- a/web/data_endpoints.go +++ b/web/rendering.go @@ -1,6 +1,8 @@ package web import ( + "nickiel.net/recount_server/web/templates" + "context" "database/sql" "encoding/json" @@ -16,7 +18,7 @@ import ( const DEFAULT_RESULT_COUNT = 20; -func getTransactionsRows(w http.ResponseWriter, req *http.Request) { +func GetTransactionsRows(w http.ResponseWriter, req *http.Request) { transactions := make([]types.HumanLegibleTransaction, 10) // Populate the slice with dummy data (you can replace this with your actual data) @@ -35,11 +37,11 @@ func getTransactionsRows(w http.ResponseWriter, req *http.Request) { transactions[10 - i] = transaction } - component := transaction_rows(&transactions); + component := templates.TransactionRows(&transactions); component.Render(context.Background(), w); } -func getTransactionQuickAccessEntries(w http.ResponseWriter, req *http.Request) { +func GetTransactionQuickAccessEntries(w http.ResponseWriter, req *http.Request) { transactions := make([]types.HumanLegibleTransaction, 20) // Populate the slice with dummy data (you can replace this with your actual data) @@ -57,22 +59,11 @@ func getTransactionQuickAccessEntries(w http.ResponseWriter, req *http.Request) transactions[i] = transaction } - component := transaction_quick_access_entries(&transactions); + component := templates.TransactionQuickAccessEntries(&transactions); component.Render(context.Background(), w); } -func getNewTransactionPane(w http.ResponseWriter, req *http.Request) { - component := new_transaction_pane(); - component.Render(context.Background(), w); -} - -func getRightPanelQuickAccess(w http.ResponseWriter, req *http.Request) { - component := right_panel_quick_access(); - component.Render(context.Background(), w); - -} - -func getExpenditureChart(w http.ResponseWriter, req *http.Request) { +func GetExpenditureChart(w http.ResponseWriter, req *http.Request) { data_package := struct{ Labels []string `json:"labels"` IncomeDataset []int `json:"income_data"` @@ -91,16 +82,16 @@ func getExpenditureChart(w http.ResponseWriter, req *http.Request) { w.Write(json_data); } -func getAccountSummaries(w http.ResponseWriter, req *http.Request) { +func GetAccountSummaries(w http.ResponseWriter, req *http.Request) { accounts := make([]types.TwoIntsItem, 20) for i := 0; i < 20; i++ { accounts[i] = types.TwoIntsItem {Item1: i*100, Item2: i+5} } - component := account_summary_rows(&accounts) + component := templates.AccountSummaryRows(&accounts) component.Render(context.Background(), w) } -func getAccountSummaryChart(w http.ResponseWriter, req *http.Request) { +func GetAccountSummaryChart(w http.ResponseWriter, req *http.Request) { accountID := chi.URLParam(req, "accountID") data_package := types.ChartjsData { diff --git a/web/router.go b/web/router.go index ebc083f..cdaa31b 100644 --- a/web/router.go +++ b/web/router.go @@ -1,6 +1,8 @@ package web import ( + "nickiel.net/recount_server/web/templates" + "html/template" "net/http" "strconv" @@ -14,9 +16,11 @@ import ( "github.com/rs/zerolog/log" ) -type TemplateState struct { +type IndexTemplateModel struct { InnerHtml template.HTML ActivePage string + NewTransactionPane template.HTML + QuickAccessPane template.HTML } const TemplateDir = "./web/templates/" @@ -30,14 +34,12 @@ func WebRouter() http.Handler { r.Get("/", getDashboard) r.Get("/transactions", getTransactionsPage) - r.Get("/components/account_summaries", getAccountSummaries) - r.Get("/components/new_transaction_pane", getNewTransactionPane) - r.Get("/components/right_panel_quick_access", getRightPanelQuickAccess) + r.Get("/components/account_summaries", GetAccountSummaries) - r.Get("/components/data/transaction_table_rows", getTransactionsRows) - r.Get("/components/data/expenditure_chart", getExpenditureChart) - r.Get("/components/data/account_summary/{accountID}", getAccountSummaryChart) - r.Get("/components/data/transaction_quick_access", getTransactionQuickAccessEntries) + r.Get("/components/data/transaction_table_rows", GetTransactionsRows) + r.Get("/components/data/expenditure_chart", GetExpenditureChart) + r.Get("/components/data/account_summary/{accountID}", GetAccountSummaryChart) + r.Get("/components/data/transaction_quick_access", GetTransactionQuickAccessEntries) r.Handle("/static/*", http.StripPrefix("/static/", http.FileServer(http.Dir("web/static/")))) return r @@ -51,10 +53,10 @@ func WebRouter() http.Handler { // } func renderFullPage(w http.ResponseWriter, c templ.Component, pageName string) { - var buf bytes.Buffer + var main_component bytes.Buffer // Render the provided templ component - err := c.Render(context.Background(), &buf) + err := c.Render(context.Background(), &main_component) if err != nil { log.Fatal().Err(err).Msg("Fatal error reading hello template"); } @@ -66,12 +68,27 @@ func renderFullPage(w http.ResponseWriter, c templ.Component, pageName string) { Err(err). Msg("Fatal error reading index template") } + + + var new_tp bytes.Buffer; + err = templates.NewTransactionPane().Render(context.Background(), &new_tp); + if err != nil { + log.Fatal().Err(err).Msg("Could not render new transaction pane for index"); + } + + var quick_ap bytes.Buffer; + err = templates.QuickAccessPane().Render(context.Background(), &quick_ap); + if err != nil { + log.Fatal().Err(err).Msg("Could not render quick access pane for index"); + } // Inject the templ component html into the index template err = index.Execute(w, - TemplateState{ - InnerHtml: template.HTML(buf.String()), + IndexTemplateModel{ + InnerHtml: template.HTML(main_component.String()), ActivePage: pageName, + NewTransactionPane: template.HTML(new_tp.String()), + QuickAccessPane: template.HTML(quick_ap.String()), }); if err != nil { log.Fatal().Err(err).Msg("Fatal error reading hello template"); @@ -79,7 +96,7 @@ func renderFullPage(w http.ResponseWriter, c templ.Component, pageName string) { } func getDashboard(w http.ResponseWriter, req *http.Request) { - component := dashboard(); + component := templates.Dashboard(); _, ok := req.Header["Hx-Request"] if ok { @@ -98,7 +115,7 @@ func getTransactionsPage(w http.ResponseWriter, req *http.Request) { accounts[i] = strconv.Itoa(i) + " Account"; } - component := transactions_page(1, &accounts); + component := templates.TransactionsPage(1, &accounts); _, ok := req.Header["Hx-Request"] if ok { err := component.Render(context.Background(), w); diff --git a/web/sass/site.scss b/web/sass/site.scss index 349c295..851c4ce 100644 --- a/web/sass/site.scss +++ b/web/sass/site.scss @@ -14,6 +14,7 @@ $border-radius: 8px; body { background-color: var(--#{$prefix}-base); height: 97vh; + overflow-x: hidden; } .row { @@ -54,7 +55,6 @@ div#left-col { width: 15vw; padding: 10px; background-color: var(--#{$prefix}-nav-bg); - border-radius: $border-radius; } div#main-body-content { @@ -76,18 +76,11 @@ div#right-col { width: 15vw; padding: 10px; background-color: var(--#{$prefix}-nav-bg); - border-radius: $border-radius; display: flex; flex-direction: column; } -#transactions-quick-access { - border-radius: $border-radius; - height: 500px; -} - -#right-panel-quick-access { - border-radius: $border-radius; +#quick-access-pane { margin-top: auto; margin-bottom: 10px; height: 300px; diff --git a/web/dashboard.templ b/web/templates/dashboard.templ similarity index 95% rename from web/dashboard.templ rename to web/templates/dashboard.templ index 6757873..5138a88 100644 --- a/web/dashboard.templ +++ b/web/templates/dashboard.templ @@ -1,6 +1,6 @@ -package web +package templates -templ dashboard() { +templ Dashboard() {