From 0e72fb23b736835dc8f7716d8623625a8f650910 Mon Sep 17 00:00:00 2001 From: Thomas Sindt Date: Thu, 30 Jul 2026 23:18:02 +0200 Subject: [PATCH] Property Group Label Translation und erste TreeView fertig --- buildtime/client/logical-editor/src/App.css | 5 +- .../src/components/PropertyTreeView.jsx | 9 ++-- .../logical-editor/src/pages/PropertyPage.jsx | 4 +- .../controller/propertyGroupsController.go | 16 ++++-- .../models/propertygroup.go | 10 ++-- .../repositories/propertygroupsRepository.go | 50 +++++++++++++++---- .../scpq-editor-server/server/httpServer.go | 2 +- .../services/propertygroupsService.go | 4 +- 8 files changed, 71 insertions(+), 29 deletions(-) diff --git a/buildtime/client/logical-editor/src/App.css b/buildtime/client/logical-editor/src/App.css index 84ab6a229..c2ac47afc 100644 --- a/buildtime/client/logical-editor/src/App.css +++ b/buildtime/client/logical-editor/src/App.css @@ -48,12 +48,11 @@ .sidebar { display: flex; flex-flow: column; - height: 70vh; padding: 16px; color: gray; background: var(--code-bg); box-shadow: 0px 4px 4px rgba(0, 0, 0, 0.25); - width: 200px; + width: 300px; } .sidebar h1 { @@ -94,6 +93,8 @@ .side-links { font-size: 12px; background: whitesmoke; + overflow: auto; + height: 70vh; } footer { diff --git a/buildtime/client/logical-editor/src/components/PropertyTreeView.jsx b/buildtime/client/logical-editor/src/components/PropertyTreeView.jsx index 75733205b..30accd20b 100644 --- a/buildtime/client/logical-editor/src/components/PropertyTreeView.jsx +++ b/buildtime/client/logical-editor/src/components/PropertyTreeView.jsx @@ -6,22 +6,21 @@ import { DocumentIcon, FolderIcon } from '@heroicons/react/16/solid'; const PropertyTreeView = ({ node, key }) => { const [expanded, setExpanded] = useState(true); - console.log('node:', key, node.id, node.label, node.subPropertygroups); return (
  • - + {node.subPropertygroups && node.subPropertygroups.length > 0 && ( + )} - {node.label} + {node.labelTranslation} {expanded && ( -
      +
        {node.subPropertygroups?.map((node) => ( ))} diff --git a/buildtime/client/logical-editor/src/pages/PropertyPage.jsx b/buildtime/client/logical-editor/src/pages/PropertyPage.jsx index 7c6a53dff..ad5784a41 100644 --- a/buildtime/client/logical-editor/src/pages/PropertyPage.jsx +++ b/buildtime/client/logical-editor/src/pages/PropertyPage.jsx @@ -4,7 +4,7 @@ import PropertySideBar from '../components/PropertySideBar'; import UseFetch from '../components/tools/UseFetch'; const PropertyPage = () => { - const { data: properties, isLoading, error } = UseFetch(`http://localhost:8088/propertygroup/1`) + const { data: properties, isLoading, error } = UseFetch(`http://localhost:8088/propertygroup/1/lang/1`) if (isLoading) return

        Loading profile...

        if (error) return

        Error: {error}

        @@ -12,7 +12,7 @@ const PropertyPage = () => { return (
        -
        {JSON.stringify(properties)}
        +
        ); }; diff --git a/buildtime/server/src/scpq-editor-server/controller/propertyGroupsController.go b/buildtime/server/src/scpq-editor-server/controller/propertyGroupsController.go index 192cfd29a..aef1194b3 100644 --- a/buildtime/server/src/scpq-editor-server/controller/propertyGroupsController.go +++ b/buildtime/server/src/scpq-editor-server/controller/propertyGroupsController.go @@ -31,7 +31,7 @@ func (lc PropertygroupsController) CreatePropertygroup(ctx *gin.Context) { ctx.AbortWithError(http.StatusInternalServerError, err) return } - parent, responseErr := lc.PropertygroupsService.GetPropertygroup(lId) + parent, responseErr := lc.PropertygroupsService.GetPropertygroup(lId, 1) if responseErr != nil { ctx.JSON(responseErr.Status, responseErr) return @@ -90,7 +90,7 @@ func (lc PropertygroupsController) ChangePropertygroupParent(ctx *gin.Context) { ctx.AbortWithError(http.StatusInternalServerError, err) return } - oldparent, responseErr := lc.PropertygroupsService.GetPropertygroup(lId) + oldparent, responseErr := lc.PropertygroupsService.GetPropertygroup(lId, 1) if responseErr != nil { ctx.JSON(responseErr.Status, responseErr) return @@ -102,7 +102,7 @@ func (lc PropertygroupsController) ChangePropertygroupParent(ctx *gin.Context) { ctx.AbortWithError(http.StatusInternalServerError, err) return } - newparent, responseErr := lc.PropertygroupsService.GetPropertygroup(lId) + newparent, responseErr := lc.PropertygroupsService.GetPropertygroup(lId, 1) if responseErr != nil { ctx.JSON(responseErr.Status, responseErr) return @@ -148,13 +148,21 @@ func (lc PropertygroupsController) DeletePropertygroup(ctx *gin.Context) { func (lc PropertygroupsController) GetPropertygroup(ctx *gin.Context) { PropertygroupId := ctx.Param("id") + LangId := ctx.Param("langid") lId, err := strconv.Atoi(PropertygroupId) if err != nil { log.Println("Error PropertygroupId not int", err) ctx.AbortWithError(http.StatusInternalServerError, err) return } - response, responseErr := lc.PropertygroupsService.GetPropertygroup(lId) + languageId, err := strconv.Atoi(LangId) + if err != nil { + log.Println("Error LangId not int", err) + ctx.AbortWithError(http.StatusInternalServerError, err) + return + } + + response, responseErr := lc.PropertygroupsService.GetPropertygroup(lId, languageId) if responseErr != nil { ctx.JSON(responseErr.Status, responseErr) return diff --git a/buildtime/server/src/scpq-editor-server/models/propertygroup.go b/buildtime/server/src/scpq-editor-server/models/propertygroup.go index 03a873558..2e531945f 100644 --- a/buildtime/server/src/scpq-editor-server/models/propertygroup.go +++ b/buildtime/server/src/scpq-editor-server/models/propertygroup.go @@ -1,8 +1,10 @@ package models type Propertygroup struct { - ID int `json:"id"` - Label string `json:"label"` - Description string `json:"description"` - SubPropertygroups []*Propertygroup `json:"subPropertygroups"` + ID int `json:"id"` + Label string `json:"label"` + LabelTranslation string `json:"labelTranslation"` + Description string `json:"description"` + DescriptionTranslation string `json:"descriptionTranslationKey"` + SubPropertygroups []*Propertygroup `json:"subPropertygroups"` } diff --git a/buildtime/server/src/scpq-editor-server/repositories/propertygroupsRepository.go b/buildtime/server/src/scpq-editor-server/repositories/propertygroupsRepository.go index 9443dd8f8..7e2a0de65 100644 --- a/buildtime/server/src/scpq-editor-server/repositories/propertygroupsRepository.go +++ b/buildtime/server/src/scpq-editor-server/repositories/propertygroupsRepository.go @@ -169,7 +169,7 @@ func (rr PropertygroupsRepository) DeletePropertygroup(PropertygroupId int) *mod return nil } -func (rr PropertygroupsRepository) GetPropertygroup(PropertygroupId int) (*models.Propertygroup, *models.ResponseError) { +func (rr PropertygroupsRepository) GetPropertygroup(PropertygroupId int, langId int) (*models.Propertygroup, *models.ResponseError) { if pg, exists := rr.m[PropertygroupId]; exists { return pg, nil @@ -209,13 +209,45 @@ func (rr PropertygroupsRepository) GetPropertygroup(PropertygroupId int) (*model } } - pg := &models.Propertygroup{ - ID: id, - Label: label, - Description: description, + // translate label and description based on langId + translation_query := `SELECT translation FROM property_group_translations WHERE property_group_id=$1 AND language_id=$2` + translation_rows, err := rr.dbHandler.Query(translation_query, id, langId) + if err != nil { + return nil, &models.ResponseError{ + Message: err.Error(), + Status: http.StatusInternalServerError, + } } - err2 := rr.GetSubPropertygroups(pg) + defer translation_rows.Close() + var translation string + for translation_rows.Next() { + err := translation_rows.Scan(&translation) + if err != nil { + return nil, &models.ResponseError{ + Message: err.Error(), + Status: http.StatusInternalServerError, + } + } + } + if translation_rows.Err() != nil { + return nil, &models.ResponseError{ + Message: err.Error(), + Status: http.StatusInternalServerError, + } + } + + if translation == "" { + translation = label + } + pg := &models.Propertygroup{ + ID: id, + Label: label, + LabelTranslation: translation, + Description: description, + } + + err2 := rr.GetSubPropertygroups(pg, langId) if err2 != nil { return nil, &models.ResponseError{ Message: "Error reading sub propertygroups for propertygroup with id " + strconv.Itoa(pg.ID) + " : " + err2.Message, @@ -227,7 +259,7 @@ func (rr PropertygroupsRepository) GetPropertygroup(PropertygroupId int) (*model return pg, nil } -func (rr PropertygroupsRepository) GetSubPropertygroups(Propertygroup *models.Propertygroup) *models.ResponseError { +func (rr PropertygroupsRepository) GetSubPropertygroups(Propertygroup *models.Propertygroup, langId int) *models.ResponseError { query := `SELECT id FROM property_groups WHERE parent_property_group_id=$1` rows, err := rr.dbHandler.Query(query, Propertygroup.ID) if err != nil { @@ -255,7 +287,7 @@ func (rr PropertygroupsRepository) GetSubPropertygroups(Propertygroup *models.Pr Status: http.StatusInternalServerError, } } - pg, err2 := rr.GetPropertygroup(id) + pg, err2 := rr.GetPropertygroup(id, langId) if err2 != nil { return &models.ResponseError{ Message: "SubPropertygroup not found with the given id " + idstr, @@ -270,7 +302,7 @@ func (rr PropertygroupsRepository) GetSubPropertygroups(Propertygroup *models.Pr } if rows.Err() != nil { return &models.ResponseError{ - Message: err.Error(), + Message: rows.Err().Error(), Status: http.StatusInternalServerError, } } diff --git a/buildtime/server/src/scpq-editor-server/server/httpServer.go b/buildtime/server/src/scpq-editor-server/server/httpServer.go index e2979ad4c..2354c727a 100644 --- a/buildtime/server/src/scpq-editor-server/server/httpServer.go +++ b/buildtime/server/src/scpq-editor-server/server/httpServer.go @@ -52,7 +52,7 @@ func InitHttpServer(config *viper.Viper, dbHandler *sql.DB) HttpServer { router.PUT("/propertygroup", propertygroupsController.UpdatePropertygroup) router.PUT("/propertygroup/:id/change-parent/:newparentid", propertygroupsController.ChangePropertygroupParent) router.DELETE("/propertygroup/:id", propertygroupsController.DeletePropertygroup) - router.GET("/propertygroup/:id", propertygroupsController.GetPropertygroup) + router.GET("/propertygroup/:id/lang/:langid", propertygroupsController.GetPropertygroup) // server return HttpServer{ diff --git a/buildtime/server/src/scpq-editor-server/services/propertygroupsService.go b/buildtime/server/src/scpq-editor-server/services/propertygroupsService.go index a5535f00c..c680215d7 100644 --- a/buildtime/server/src/scpq-editor-server/services/propertygroupsService.go +++ b/buildtime/server/src/scpq-editor-server/services/propertygroupsService.go @@ -44,8 +44,8 @@ func (ls PropertygroupsService) DeletePropertygroup(PropertygroupId int) *models return ls.PropertygroupsRepository.DeletePropertygroup(PropertygroupId) } -func (ls PropertygroupsService) GetPropertygroup(PropertygroupId int) (*models.Propertygroup, *models.ResponseError) { - return ls.PropertygroupsRepository.GetPropertygroup(PropertygroupId) +func (ls PropertygroupsService) GetPropertygroup(PropertygroupId int, langId int) (*models.Propertygroup, *models.ResponseError) { + return ls.PropertygroupsRepository.GetPropertygroup(PropertygroupId, langId) } func validatePropertygroup(Propertygroup *models.Propertygroup) *models.ResponseError {