Templates TreeView PTG
This commit is contained in:
@@ -38,7 +38,7 @@ func InitHttpServer(config *viper.Viper, dbHandler *sql.DB) HttpServer {
|
||||
|
||||
// service initialisation:
|
||||
importService := services.NewImportService(importRepository)
|
||||
propertyTypesService := services.NewPropertyTypeService(propertyTypeRepository, propertyTypeGroupRepository)
|
||||
propertyTypesService := services.NewPropertyTypeService(propertyRepository, propertyTypeRepository, propertyTypeGroupRepository, valueRepository)
|
||||
|
||||
// handler initialisation:
|
||||
importHandler := handler.NewImportHandler(importService)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"SimplyCPQ2/internal/models"
|
||||
"SimplyCPQ2/internal/services"
|
||||
"strconv"
|
||||
|
||||
@@ -11,6 +12,14 @@ type PropertyTypeHandler struct {
|
||||
propertyTypeService *services.PropertyTypeService
|
||||
}
|
||||
|
||||
// Datentypen zum rendern
|
||||
type PropertyTypeGroupContent struct {
|
||||
Id int `json:"id"`
|
||||
Name string `json:"name"`
|
||||
PropertyTypeGroups []models.PropertyTypeGroup `json:"propertyTypeGroups"`
|
||||
PropertyTypes []models.PropertyType `json:"propertyTypes"`
|
||||
}
|
||||
|
||||
func NewPropertyTypeHandler(propertyTypeService *services.PropertyTypeService) *PropertyTypeHandler {
|
||||
return &PropertyTypeHandler{
|
||||
propertyTypeService: propertyTypeService,
|
||||
@@ -31,6 +40,12 @@ func (h *PropertyTypeHandler) GetPropertyTypeGroupContentById(ctx *gin.Context)
|
||||
return
|
||||
}
|
||||
|
||||
ptg, err := h.propertyTypeService.GetPropertyTypeGroupByID(id)
|
||||
if err != nil {
|
||||
ctx.JSON(500, gin.H{"error": "Failed to get property type group"})
|
||||
return
|
||||
}
|
||||
|
||||
// get property type groups by parent ID
|
||||
ptgs, err := h.propertyTypeService.GetPropertyTypeGroupsByParentId(id)
|
||||
if err != nil {
|
||||
@@ -46,10 +61,15 @@ func (h *PropertyTypeHandler) GetPropertyTypeGroupContentById(ctx *gin.Context)
|
||||
}
|
||||
|
||||
// template for response
|
||||
content := PropertyTypeGroupContent{
|
||||
Id: id,
|
||||
Name: ptg.Name,
|
||||
PropertyTypeGroups: ptgs,
|
||||
PropertyTypes: pts,
|
||||
}
|
||||
|
||||
ctx.JSON(200, gin.H{
|
||||
"propertyTypeGroups": ptgs,
|
||||
"propertyTypes": pts,
|
||||
ctx.HTML(200, "ptg_treenode.html", gin.H{
|
||||
"propertyTypeGroupContent": content,
|
||||
})
|
||||
|
||||
// Implement the logic to get property type group content by ID here using idParam
|
||||
|
||||
@@ -33,6 +33,32 @@ func (r *PropertyTypeGroupRepository) GetPropertyTypeGroupByID(id int) (models.P
|
||||
return value, nil
|
||||
}
|
||||
|
||||
func (r *PropertyTypeGroupRepository) GetPropertyTypeGroupsByParentId(parentId int) ([]models.PropertyTypeGroup, error) {
|
||||
rows, err := r.db.Query("SELECT id, name, description, parenz_property_typw_goup_id, image_url FROM property_type_groups WHERE parenz_property_typw_goup_id = ?", parentId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
var groups []models.PropertyTypeGroup
|
||||
for rows.Next() {
|
||||
var value models.PropertyTypeGroup
|
||||
err := rows.Scan(&value.Id, &value.Name, &value.Description, &value.ParentPropertyTypeGroupId, &value.ImageURL)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if _, ok := r.cache[value.Id]; !ok {
|
||||
r.cache[value.Id] = value
|
||||
}
|
||||
|
||||
groups = append(groups, value)
|
||||
}
|
||||
if err = rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return groups, nil
|
||||
}
|
||||
|
||||
func (r *PropertyTypeGroupRepository) GetPropertyTypesByGroupId(gid int) ([]models.PropertyTypeGroup, error) {
|
||||
rows, err := r.db.Query("SELECT id, name, description, parenz_property_typw_goup_id, image_url FROM property_type_groups WHERE parenz_property_typw_goup_id = ?", gid)
|
||||
if err != nil {
|
||||
|
||||
@@ -25,7 +25,11 @@ func NewPropertyTypeService(propertyRepo *repositories.PropertyRepository, prope
|
||||
// Getter functions
|
||||
|
||||
func (service *PropertyTypeService) GetPropertyTypeGroupsByParentId(parentId int) ([]models.PropertyTypeGroup, error) {
|
||||
return service.PropertyTypeGroups_Repository.GetPropertyTypesByGroupId(parentId)
|
||||
return service.PropertyTypeGroups_Repository.GetPropertyTypeGroupsByParentId(parentId)
|
||||
}
|
||||
|
||||
func (service *PropertyTypeService) GetPropertyTypeGroupByID(id int) (models.PropertyTypeGroup, error) {
|
||||
return service.PropertyTypeGroups_Repository.GetPropertyTypeGroupByID(id)
|
||||
}
|
||||
|
||||
func (service *PropertyTypeService) GetPropertyTypesByGroupId(id int) ([]models.PropertyType, error) {
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
@@ -1,18 +1,26 @@
|
||||
{{define "ptg_treeNode"}}
|
||||
{{- range .}}
|
||||
<ul class="node" hx-get="/properties/{{.Id}}/childs" hx-trigger="click" hx-target="#node-{{.Id}}" hx-swap="outerHTML">
|
||||
<details closed>
|
||||
<!-- der eigentliche Knoten-->
|
||||
<ul class="node">
|
||||
<details open>
|
||||
<summary>
|
||||
{{.Name}}
|
||||
</summary>
|
||||
<div id="node-{{.Id}}">Keine Informationen vorhanden
|
||||
</div>
|
||||
<ul class="node">
|
||||
{{range .Property_Types}}
|
||||
<li>{{.Name}}</li>
|
||||
{{end}}
|
||||
<!-- Die PropertyTypeGroup Subgruppen-->
|
||||
{{- range .PropertyTypeGroups}}
|
||||
<ul class="node" hx-get="/properties/{{.Id}}/childs" hx-trigger="click" hx-swap="outerHTML">
|
||||
<details closed>
|
||||
<summary>
|
||||
{{.Name}}
|
||||
</summary>
|
||||
</details>
|
||||
</ul>
|
||||
{{- end}}
|
||||
|
||||
<!-- die PropertyTypes der PropertyTypeGroup-->
|
||||
{{- range .PropertyTypes}}
|
||||
<ul class="node">
|
||||
<li>{{.Name}}</li>
|
||||
</ul>
|
||||
{{- end}}
|
||||
</details>
|
||||
</ul>
|
||||
{{- end}}
|
||||
{{end}}
|
||||
</ul>
|
||||
Reference in New Issue
Block a user