From b7773981ed147b40790fd4e1ac1c6945595badf3 Mon Sep 17 00:00:00 2001 From: Nickiel12 Date: Sat, 10 Feb 2024 08:51:27 -0800 Subject: [PATCH] rearranged files --- .gitignore | 2 +- main.go => recount-server.go | 0 web/{data_endpoints.go => rendering.go} | 29 ++++++--------- web/router.go | 45 ++++++++++++++++-------- web/sass/site.scss | 11 ++---- web/{ => templates}/dashboard.templ | 9 ++--- web/{ => templates}/dataendpoints.templ | 12 +++---- web/templates/index.html | 20 +++-------- web/templates/new_transaction_pane.templ | 9 +++++ web/{ => templates}/transactions.templ | 4 +-- 10 files changed, 67 insertions(+), 74 deletions(-) rename main.go => recount-server.go (100%) rename web/{data_endpoints.go => rendering.go} (77%) rename web/{ => templates}/dashboard.templ (95%) rename web/{ => templates}/dataendpoints.templ (90%) create mode 100644 web/templates/new_transaction_pane.templ rename web/{ => templates}/transactions.templ (98%) 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() { Dashboard
@@ -75,8 +75,3 @@ templ dashboard() {
} -templ new_transaction_pane() { -
- -
-} diff --git a/web/dataendpoints.templ b/web/templates/dataendpoints.templ similarity index 90% rename from web/dataendpoints.templ rename to web/templates/dataendpoints.templ index 6da9475..7a6eff3 100644 --- a/web/dataendpoints.templ +++ b/web/templates/dataendpoints.templ @@ -1,4 +1,4 @@ -package web +package templates import ( "nickiel.net/recount_server/types" @@ -6,7 +6,7 @@ import ( "strconv" ) -templ transaction_rows(transactions *[]types.HumanLegibleTransaction) { +templ TransactionRows(transactions *[]types.HumanLegibleTransaction) { for i, value := range *transactions { @@ -27,7 +27,7 @@ templ transaction_rows(transactions *[]types.HumanLegibleTransaction) { } } -templ account_summary_rows(accounts *[]types.TwoIntsItem){ +templ AccountSummaryRows(accounts *[]types.TwoIntsItem){ for _, value := range *accounts {
@@ -57,7 +57,7 @@ templ account_summary_rows(accounts *[]types.TwoIntsItem){ } } -templ transaction_quick_access_entries(transactions *[]types.HumanLegibleTransaction) { +templ TransactionQuickAccessEntries(transactions *[]types.HumanLegibleTransaction) { for _, value := range *transactions {
@@ -84,7 +84,7 @@ templ transaction_quick_access_entries(transactions *[]types.HumanLegibleTransac } } -templ right_panel_quick_access() { -
+templ QuickAccessPane() { +
} diff --git a/web/templates/index.html b/web/templates/index.html index afb9277..a79b686 100644 --- a/web/templates/index.html +++ b/web/templates/index.html @@ -14,7 +14,7 @@
-
+