mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-18 07:30:12 +01:00
🎨 Candidate values of the database relation fields are no longer subject to view filtering https://github.com/siyuan-note/siyuan/issues/10411
This commit is contained in:
parent
412c7a8d6b
commit
bc6d6b17f7
2 changed files with 25 additions and 6 deletions
|
|
@ -48,7 +48,7 @@ func getAttributeViewPrimaryKeyValues(c *gin.Context) {
|
||||||
pageSize = int(pageSizeArg.(float64))
|
pageSize = int(pageSizeArg.(float64))
|
||||||
}
|
}
|
||||||
|
|
||||||
rows, err := model.GetAttributeViewPrimaryKeyValues(id, page, pageSize)
|
attributeViewName, rows, err := model.GetAttributeViewPrimaryKeyValues(id, page, pageSize)
|
||||||
if nil != err {
|
if nil != err {
|
||||||
ret.Code = -1
|
ret.Code = -1
|
||||||
ret.Msg = err.Error()
|
ret.Msg = err.Error()
|
||||||
|
|
@ -56,6 +56,7 @@ func getAttributeViewPrimaryKeyValues(c *gin.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ret.Data = map[string]interface{}{
|
ret.Data = map[string]interface{}{
|
||||||
|
"name": attributeViewName,
|
||||||
"rows": rows,
|
"rows": rows,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ import (
|
||||||
"github.com/siyuan-note/siyuan/kernel/util"
|
"github.com/siyuan-note/siyuan/kernel/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetAttributeViewPrimaryKeyValues(avID string, page, pageSize int) (ret *av.KeyValues, err error) {
|
func GetAttributeViewPrimaryKeyValues(avID string, page, pageSize int) (attributeViewName string, keyValues *av.KeyValues, err error) {
|
||||||
waitForSyncingStorages()
|
waitForSyncingStorages()
|
||||||
|
|
||||||
attrView, err := av.ParseAttributeView(avID)
|
attrView, err := av.ParseAttributeView(avID)
|
||||||
|
|
@ -46,17 +46,35 @@ func GetAttributeViewPrimaryKeyValues(avID string, page, pageSize int) (ret *av.
|
||||||
logging.LogErrorf("parse attribute view [%s] failed: %s", avID, err)
|
logging.LogErrorf("parse attribute view [%s] failed: %s", avID, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
attributeViewName = attrView.Name
|
||||||
|
|
||||||
|
keyValues = attrView.GetBlockKeyValues()
|
||||||
|
// 不在视图中的值要过滤掉
|
||||||
|
tmp := map[string]*av.Value{}
|
||||||
|
for _, kv := range keyValues.Values {
|
||||||
|
for _, view := range attrView.Views {
|
||||||
|
switch view.LayoutType {
|
||||||
|
case av.LayoutTypeTable:
|
||||||
|
if gulu.Str.Contains(kv.Block.ID, view.Table.RowIDs) {
|
||||||
|
tmp[kv.Block.ID] = kv
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
keyValues.Values = []*av.Value{}
|
||||||
|
for _, v := range tmp {
|
||||||
|
keyValues.Values = append(keyValues.Values, v)
|
||||||
|
}
|
||||||
|
|
||||||
ret = attrView.GetBlockKeyValues()
|
|
||||||
if 1 > pageSize {
|
if 1 > pageSize {
|
||||||
pageSize = 50
|
pageSize = 50
|
||||||
}
|
}
|
||||||
start := (page - 1) * pageSize
|
start := (page - 1) * pageSize
|
||||||
end := start + pageSize
|
end := start + pageSize
|
||||||
if len(ret.Values) < end {
|
if len(keyValues.Values) < end {
|
||||||
end = len(ret.Values)
|
end = len(keyValues.Values)
|
||||||
}
|
}
|
||||||
ret.Values = ret.Values[start:end]
|
keyValues.Values = keyValues.Values[start:end]
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue