Property Group Label Translation und erste TreeView fertig
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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 (
|
||||
<li key={node.id}>
|
||||
<span className="flex items-center gap-1.5 py-1">
|
||||
<span className="flex items-center gap-1 py-1">
|
||||
{node.subPropertygroups && node.subPropertygroups.length > 0 && (
|
||||
<button onClick={() => setExpanded(!expanded)} className="p-1 -m-1">
|
||||
<ChevronRightIcon
|
||||
className={`size-4 text-gray-500 ${expanded ? 'rotate-90' : ''}`}
|
||||
/>
|
||||
</button>
|
||||
</button>
|
||||
)}
|
||||
<FolderIcon className={`size-3 text-gray-500`} />{node.label}
|
||||
<FolderIcon className={`size-3 text-gray-500`} />{node.labelTranslation}
|
||||
</span>
|
||||
|
||||
{expanded && (
|
||||
<ul>
|
||||
<ul className="ml-1 border-l border-gray-300 pl-8">
|
||||
{node.subPropertygroups?.map((node) => (
|
||||
<PropertyTreeView node={node} key={node.id} />
|
||||
))}
|
||||
|
||||
@@ -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 <p>Loading profile...</p>
|
||||
if (error) return <p>Error: {error}</p>
|
||||
@@ -12,7 +12,7 @@ const PropertyPage = () => {
|
||||
return (
|
||||
<div className="content">
|
||||
<div><PropertySideBar properties={[properties]} /></div>
|
||||
<div className="main">{JSON.stringify(properties)}</div>
|
||||
<div className="main"></div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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"`
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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{
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user