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