Templates TreeView PTG
This commit is contained in:
@@ -38,7 +38,7 @@ func InitHttpServer(config *viper.Viper, dbHandler *sql.DB) HttpServer {
|
|||||||
|
|
||||||
// service initialisation:
|
// service initialisation:
|
||||||
importService := services.NewImportService(importRepository)
|
importService := services.NewImportService(importRepository)
|
||||||
propertyTypesService := services.NewPropertyTypeService(propertyTypeRepository, propertyTypeGroupRepository)
|
propertyTypesService := services.NewPropertyTypeService(propertyRepository, propertyTypeRepository, propertyTypeGroupRepository, valueRepository)
|
||||||
|
|
||||||
// handler initialisation:
|
// handler initialisation:
|
||||||
importHandler := handler.NewImportHandler(importService)
|
importHandler := handler.NewImportHandler(importService)
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package handlers
|
package handlers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"SimplyCPQ2/internal/models"
|
||||||
"SimplyCPQ2/internal/services"
|
"SimplyCPQ2/internal/services"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
@@ -11,6 +12,14 @@ type PropertyTypeHandler struct {
|
|||||||
propertyTypeService *services.PropertyTypeService
|
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 {
|
func NewPropertyTypeHandler(propertyTypeService *services.PropertyTypeService) *PropertyTypeHandler {
|
||||||
return &PropertyTypeHandler{
|
return &PropertyTypeHandler{
|
||||||
propertyTypeService: propertyTypeService,
|
propertyTypeService: propertyTypeService,
|
||||||
@@ -31,6 +40,12 @@ func (h *PropertyTypeHandler) GetPropertyTypeGroupContentById(ctx *gin.Context)
|
|||||||
return
|
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
|
// get property type groups by parent ID
|
||||||
ptgs, err := h.propertyTypeService.GetPropertyTypeGroupsByParentId(id)
|
ptgs, err := h.propertyTypeService.GetPropertyTypeGroupsByParentId(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -46,10 +61,15 @@ func (h *PropertyTypeHandler) GetPropertyTypeGroupContentById(ctx *gin.Context)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// template for response
|
// template for response
|
||||||
|
content := PropertyTypeGroupContent{
|
||||||
|
Id: id,
|
||||||
|
Name: ptg.Name,
|
||||||
|
PropertyTypeGroups: ptgs,
|
||||||
|
PropertyTypes: pts,
|
||||||
|
}
|
||||||
|
|
||||||
ctx.JSON(200, gin.H{
|
ctx.HTML(200, "ptg_treenode.html", gin.H{
|
||||||
"propertyTypeGroups": ptgs,
|
"propertyTypeGroupContent": content,
|
||||||
"propertyTypes": pts,
|
|
||||||
})
|
})
|
||||||
|
|
||||||
// Implement the logic to get property type group content by ID here using idParam
|
// 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
|
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) {
|
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)
|
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 {
|
if err != nil {
|
||||||
|
|||||||
@@ -25,7 +25,11 @@ func NewPropertyTypeService(propertyRepo *repositories.PropertyRepository, prope
|
|||||||
// Getter functions
|
// Getter functions
|
||||||
|
|
||||||
func (service *PropertyTypeService) GetPropertyTypeGroupsByParentId(parentId int) ([]models.PropertyTypeGroup, error) {
|
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) {
|
func (service *PropertyTypeService) GetPropertyTypesByGroupId(id int) ([]models.PropertyType, error) {
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
|
||||||
@@ -1,18 +1,26 @@
|
|||||||
{{define "ptg_treeNode"}}
|
{{define "ptg_treeNode"}}
|
||||||
{{- range .}}
|
<!-- der eigentliche Knoten-->
|
||||||
<ul class="node" hx-get="/properties/{{.Id}}/childs" hx-trigger="click" hx-target="#node-{{.Id}}" hx-swap="outerHTML">
|
<ul class="node">
|
||||||
<details closed>
|
<details open>
|
||||||
<summary>
|
<summary>
|
||||||
{{.Name}}
|
{{.Name}}
|
||||||
</summary>
|
</summary>
|
||||||
<div id="node-{{.Id}}">Keine Informationen vorhanden
|
<!-- Die PropertyTypeGroup Subgruppen-->
|
||||||
</div>
|
{{- range .PropertyTypeGroups}}
|
||||||
<ul class="node">
|
<ul class="node" hx-get="/properties/{{.Id}}/childs" hx-trigger="click" hx-swap="outerHTML">
|
||||||
{{range .Property_Types}}
|
<details closed>
|
||||||
<li>{{.Name}}</li>
|
<summary>
|
||||||
{{end}}
|
{{.Name}}
|
||||||
|
</summary>
|
||||||
|
</details>
|
||||||
</ul>
|
</ul>
|
||||||
|
{{- end}}
|
||||||
|
|
||||||
|
<!-- die PropertyTypes der PropertyTypeGroup-->
|
||||||
|
{{- range .PropertyTypes}}
|
||||||
|
<ul class="node">
|
||||||
|
<li>{{.Name}}</li>
|
||||||
|
</ul>
|
||||||
|
{{- end}}
|
||||||
</details>
|
</details>
|
||||||
</ul>
|
</ul>
|
||||||
{{- end}}
|
|
||||||
{{end}}
|
|
||||||
Reference in New Issue
Block a user