html tables work
This commit is contained in:
parent
4bb69e98fa
commit
6945e0822e
3 changed files with 89 additions and 24 deletions
12
cmd/main.go
12
cmd/main.go
|
|
@ -1,6 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"html/template"
|
||||
"log"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
|
@ -21,13 +22,20 @@ func main() {
|
|||
// Initialize Gin router
|
||||
router := gin.Default()
|
||||
|
||||
// Register the safeHTML function
|
||||
router.SetFuncMap(template.FuncMap{
|
||||
"safeHTML": func(s string) template.HTML {
|
||||
return template.HTML(s)
|
||||
},
|
||||
})
|
||||
|
||||
// Load HTML templates
|
||||
router.LoadHTMLGlob("templates/*")
|
||||
|
||||
// Serve static files (CSS)
|
||||
router.Static("/static", "./static")
|
||||
|
||||
// Initialize API handlers (MOVE THIS UP!)
|
||||
// Initialize API handlers
|
||||
apiHandler := api.NewAPIHandler(database)
|
||||
|
||||
// Define API routes
|
||||
|
|
@ -41,7 +49,7 @@ func main() {
|
|||
apiGroup.DELETE("/:id", apiHandler.DeleteNombre)
|
||||
}
|
||||
|
||||
// HTML Routes (MOVE THIS DOWN!)
|
||||
// HTML Routes
|
||||
apiGroup.GET("/html", apiHandler.GetNombresHTML)
|
||||
apiGroup.GET("/html/:id", apiHandler.GetNombreByIDHTML)
|
||||
|
||||
|
|
|
|||
|
|
@ -2,20 +2,51 @@
|
|||
<html>
|
||||
|
||||
<head>
|
||||
<title>Nombre</title>
|
||||
<title>Nombre Details</title>
|
||||
<link rel="stylesheet" href="/static/style.css">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Nombre Details</h1>
|
||||
<p><strong>NombreID:</strong> {{ .NombreID }}</p>
|
||||
<p><strong>FamiliaID:</strong> {{ .FamiliaID }}</p>
|
||||
<p><strong>Nombre:</strong> {{ .Nombre }}</p>
|
||||
<p><strong>Fecha:</strong> {{ .Fecha }}</p>
|
||||
<p><strong>ProveedorID:</strong> {{ .ProveedorID }}</p>
|
||||
<p><strong>Precio:</strong> {{ .Precio }}</p>
|
||||
<p><strong>Inactivo:</strong> {{ .Inactivo }}</p>
|
||||
<a href="/nombres">Back to List</a>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Field</th>
|
||||
<th>Value</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>NombreID</td>
|
||||
<td>{{ .NombreID }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>FamiliaID</td>
|
||||
<td>{{ .FamiliaID }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Nombre</td>
|
||||
<td>{{ .Nombre | safeHTML }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Fecha</td>
|
||||
<td>{{ .Fecha }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>ProveedorID</td>
|
||||
<td>{{ .ProveedorID }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Precio</td>
|
||||
<td>{{ .Precio }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Inactivo</td>
|
||||
<td>{{ .Inactivo }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<a href="/nombres/html">Back to List</a>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
|
@ -1,13 +1,39 @@
|
|||
<tbody>
|
||||
{{ range . }}
|
||||
<tr>
|
||||
<td>{{ .NombreID }}</td>
|
||||
<td>{{ .FamiliaID }}</td>
|
||||
<td>{{ .Nombre }}</td>
|
||||
<td>{{ .Fecha }}</td>
|
||||
<td>{{ .ProveedorID }}</td>
|
||||
<td>{{ .Precio }}</td>
|
||||
<td>{{ .Inactivo }}</td>
|
||||
</tr>
|
||||
{{ end }}
|
||||
</tbody>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<title>Nombres</title>
|
||||
<link rel="stylesheet" href="/static/style.css">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Nombres</h1>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>NombreID</th>
|
||||
<th>FamiliaID</th>
|
||||
<th>Nombre</th>
|
||||
<th>Fecha</th>
|
||||
<th>ProveedorID</th>
|
||||
<th>Precio</th>
|
||||
<th>Inactivo</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{{ range . }}
|
||||
<tr>
|
||||
<td>{{ .NombreID }}</td>
|
||||
<td>{{ .FamiliaID }}</td>
|
||||
<td>{{ .Nombre | safeHTML }}</td>
|
||||
<td>{{ .Fecha }}</td>
|
||||
<td>{{ .ProveedorID }}</td>
|
||||
<td>{{ .Precio }}</td>
|
||||
<td>{{ .Inactivo }}</td>
|
||||
</tr>
|
||||
{{ end }}
|
||||
</tbody>
|
||||
</table>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Loading…
Reference in a new issue