mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-17 15:10:12 +01:00
🎨 Improve database table view
This commit is contained in:
parent
491f1f58dc
commit
ec2843ae8c
2 changed files with 55 additions and 26 deletions
|
|
@ -210,6 +210,11 @@ func NewAttributeView(id string) (ret *AttributeView) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func IsAttributeViewExist(avID string) bool {
|
||||||
|
avJSONPath := GetAttributeViewDataPath(avID)
|
||||||
|
return filelock.IsExist(avJSONPath)
|
||||||
|
}
|
||||||
|
|
||||||
func ParseAttributeView(avID string) (ret *AttributeView, err error) {
|
func ParseAttributeView(avID string) (ret *AttributeView, err error) {
|
||||||
avJSONPath := GetAttributeViewDataPath(avID)
|
avJSONPath := GetAttributeViewDataPath(avID)
|
||||||
if !filelock.IsExist(avJSONPath) {
|
if !filelock.IsExist(avJSONPath) {
|
||||||
|
|
|
||||||
|
|
@ -370,6 +370,15 @@ func GetBlockAttributeViewKeys(blockID string) (ret []*BlockAttributeViewKeys) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if 1 > len(blockIDs) {
|
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
|
continue
|
||||||
}
|
}
|
||||||
blockIDs = gulu.Str.RemoveDuplicatedElem(blockIDs)
|
blockIDs = gulu.Str.RemoveDuplicatedElem(blockIDs)
|
||||||
|
|
@ -1755,6 +1764,28 @@ func removeAttributeViewBlock(srcIDs []string, avID string, tx *Transaction) (er
|
||||||
if nil != tree {
|
if nil != tree {
|
||||||
trees[bt.RootID] = tree
|
trees[bt.RootID] = tree
|
||||||
if node := treenode.GetNodeInTree(tree, values.BlockID); nil != node {
|
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)
|
attrs := parse.IAL2Map(node.KramdownIAL)
|
||||||
if ast.NodeDocument == node.Type {
|
if ast.NodeDocument == node.Type {
|
||||||
delete(attrs, "custom-hidden")
|
delete(attrs, "custom-hidden")
|
||||||
|
|
@ -1764,6 +1795,14 @@ func removeAttributeViewBlock(srcIDs []string, avID string, tx *Transaction) (er
|
||||||
if avs := attrs[av.NodeAttrNameAvs]; "" != avs {
|
if avs := attrs[av.NodeAttrNameAvs]; "" != avs {
|
||||||
avIDs := strings.Split(avs, ",")
|
avIDs := strings.Split(avs, ",")
|
||||||
avIDs = gulu.Str.RemoveElem(avIDs, avID)
|
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) {
|
if 0 == len(avIDs) {
|
||||||
delete(attrs, av.NodeAttrNameAvs)
|
delete(attrs, av.NodeAttrNameAvs)
|
||||||
node.RemoveIALAttr(av.NodeAttrNameAvs)
|
node.RemoveIALAttr(av.NodeAttrNameAvs)
|
||||||
|
|
@ -1782,21 +1821,6 @@ func removeAttributeViewBlock(srcIDs []string, avID string, tx *Transaction) (er
|
||||||
return
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue