Browse Source

creating invoice template

cli-archive
nic 2 years ago
parent
commit
45799b7d60
  1. 23
      internal/handlers/dashboard.go
  2. 14
      internal/handlers/jobs.go
  3. 8
      templates/dashboard.html
  4. 12
      templates/partials/invoice_search.html
  5. 8
      templates/partials/invoice_search_results.html
  6. 2
      templates/partials/jobs.html

23
internal/handlers/dashboard.go

@ -2,10 +2,29 @@ package handlers
import ( import (
"html/template" "html/template"
"log"
"net/http" "net/http"
) )
func DashboardHandler(w http.ResponseWriter, r *http.Request) { func DashboardHandler(w http.ResponseWriter, r *http.Request) {
tmpl := template.Must(template.ParseFiles("templates/layout.html", "templates/dashboard.html")) tmpl, err := template.ParseFiles(
tmpl.Execute(w, nil) "templates/layout.html",
"templates/dashboard.html",
"templates/partials/invoice_search.html",
"templates/partials/invoice_search_results.html",
)
if err != nil {
log.Printf("Template parsing error: %v", err)
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
return
}
data := struct{}{} // Empty struct as data
err = tmpl.ExecuteTemplate(w, "layout.html", data)
if err != nil {
log.Printf("Template execution error: %v", err)
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
return
}
} }

14
internal/handlers/jobs.go

@ -6,16 +6,18 @@ import (
) )
func JobsHandler(w http.ResponseWriter, r *http.Request) { func JobsHandler(w http.ResponseWriter, r *http.Request) {
jobs := []string{"Job 1", "Job 2", "Job 3"} // Replace with actual data fetching
if r.Header.Get("HX-Request") == "true" { if r.Header.Get("HX-Request") == "true" {
// This is an HTMX request, return only the jobs partial // This is an HTMX request, return the jobs content wrapped in the content template
tmpl := template.Must(template.ParseFiles("templates/partials/jobs.html")) tmpl := template.Must(template.ParseFiles("templates/layout.html", "templates/partials/jobs.html"))
jobs := []string{"Job 1", "Job 2", "Job 3"} // Replace with actual data fetching tmpl.ExecuteTemplate(w, "content", map[string]interface{}{
tmpl.Execute(w, jobs) "Title": "Jobs",
"Jobs": jobs,
})
} else { } else {
// This is a full page request // This is a full page request
tmpl := template.Must(template.ParseFiles("templates/layout.html", "templates/partials/jobs.html")) tmpl := template.Must(template.ParseFiles("templates/layout.html", "templates/partials/jobs.html"))
jobs := []string{"Job 1", "Job 2", "Job 3"} // Replace with actual data fetching
tmpl.Execute(w, map[string]interface{}{ tmpl.Execute(w, map[string]interface{}{
"Title": "Jobs", "Title": "Jobs",
"Jobs": jobs, "Jobs": jobs,

8
templates/dashboard.html

@ -4,12 +4,12 @@
<div class="dashboard-grid"> <div class="dashboard-grid">
<div class="dashboard-item"> <div class="dashboard-item">
<h3>Manage Jobs</h3> <h3>Invoices</h3>
<a href="/jobs" hx-get="/jobs" hx-target="#content">View Jobs</a> {{template "invoice_search" .}}
</div> </div>
<div class="dashboard-item"> <div class="dashboard-item">
<h3>Manage Assets</h3> <h3>Manage Jobs</h3>
<a href="/assets" hx-get="/assets" hx-target="#content">View Assets</a> <a href="/jobs" hx-get="/jobs" hx-target="#content">View Jobs</a>
</div> </div>
<div class="dashboard-item"> <div class="dashboard-item">
<h3>Manage Companies</h3> <h3>Manage Companies</h3>

12
templates/partials/invoice_search.html

@ -0,0 +1,12 @@
{{define "invoice_search"}}
<div id="invoice-search"></div>
<input
type="text"
name="search"
id="invoice-search-input"
hx-trigger="keyup changed delay:300ms"
hx-target="#invoice-search-results"
hx-indicator="#invoice-search-spinner" />
<div id="invoice-search-spinner" class="htmx-indicator">Searching...</div>
<div id="invoice-search-results"></div>
{{end}}

8
templates/partials/invoice_search_results.html

@ -0,0 +1,8 @@
<ul>
{{range .}}
<li>
<!-- Customize this based on your invoice data structure -->
Invoice: {{.Number}} - Amount: {{.Amount}}
</li>
{{end}}
</ul>

2
templates/partials/jobs.html

@ -1,4 +1,3 @@
{{define "content"}}
<div class="submenu-container"> <div class="submenu-container">
<h2 class="submenu-header">Jobs</h2> <h2 class="submenu-header">Jobs</h2>
<div class="submenu-grid"> <div class="submenu-grid">
@ -25,4 +24,3 @@
</div> </div>
</div> </div>
</div> </div>
{{end}}

Loading…
Cancel
Save