🎨 Improve database table view

This commit is contained in:
Daniel 2024-02-16 16:02:22 +08:00
parent 491f1f58dc
commit ec2843ae8c
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
2 changed files with 55 additions and 26 deletions

View file

@ -210,6 +210,11 @@ func NewAttributeView(id string) (ret *AttributeView) {
return
}
func IsAttributeViewExist(avID string) bool {
avJSONPath := GetAttributeViewDataPath(avID)
return filelock.IsExist(avJSONPath)
}
func ParseAttributeView(avID string) (ret *AttributeView, err error) {
avJSONPath := GetAttributeViewDataPath(avID)
if !filelock.IsExist(avJSONPath) {

View file

@ -370,6 +370,15 @@ func GetBlockAttributeViewKeys(blockID string) (ret []*BlockAttributeViewKeys) {
}
}
if 1 > len(blockIDs) {
tree, _ := loadTreeByBlockID(blockID)
if nil != tree {
node := treenode.GetNodeInTree(tree, blockID)
if nil != node {
if removeErr := removeNodeAvID(node, avID, nil, tree); nil != removeErr {
logging.LogErrorf("remove node avID [%s] failed: %s", avID, removeErr)
}
}
}
continue
}
blockIDs = gulu.Str.RemoveDuplicatedElem(blockIDs)
@ -1755,6 +1764,28 @@ func removeAttributeViewBlock(srcIDs []string, avID string, tx *Transaction) (er
if nil != tree {
trees[bt.RootID] = tree
if node := treenode.GetNodeInTree(tree, values.BlockID); nil != node {
if err = removeNodeAvID(node, avID, tx, tree); nil != err {
return
}
}
}
}
}
}
keyValues.Values = tmp
}
for _, view := range attrView.Views {
for _, blockID := range srcIDs {
view.Table.RowIDs = gulu.Str.RemoveElem(view.Table.RowIDs, blockID)
}
}
err = av.SaveAttributeView(attrView)
return
}
func removeNodeAvID(node *ast.Node, avID string, tx *Transaction, tree *parse.Tree) (err error) {
attrs := parse.IAL2Map(node.KramdownIAL)
if ast.NodeDocument == node.Type {
delete(attrs, "custom-hidden")
@ -1764,6 +1795,14 @@ func removeAttributeViewBlock(srcIDs []string, avID string, tx *Transaction) (er
if avs := attrs[av.NodeAttrNameAvs]; "" != avs {
avIDs := strings.Split(avs, ",")
avIDs = gulu.Str.RemoveElem(avIDs, avID)
var existAvIDs []string
for _, attributeViewID := range avIDs {
if av.IsAttributeViewExist(attributeViewID) {
existAvIDs = append(existAvIDs, attributeViewID)
}
}
avIDs = existAvIDs
if 0 == len(avIDs) {
delete(attrs, av.NodeAttrNameAvs)
node.RemoveIALAttr(av.NodeAttrNameAvs)
@ -1782,21 +1821,6 @@ func removeAttributeViewBlock(srcIDs []string, avID string, tx *Transaction) (er
return
}
}
}
}
}
}
}
keyValues.Values = tmp
}
for _, view := range attrView.Views {
for _, blockID := range srcIDs {
view.Table.RowIDs = gulu.Str.RemoveElem(view.Table.RowIDs, blockID)
}
}
err = av.SaveAttributeView(attrView)
return
}