mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-22 17:40:13 +01:00
🎨 Database table view in-table search https://github.com/siyuan-note/siyuan/issues/10419
This commit is contained in:
parent
f0efd8ac67
commit
b6c2c829b1
2 changed files with 24 additions and 3 deletions
|
|
@ -37,8 +37,8 @@ func searchTableView(c *gin.Context) {
|
||||||
|
|
||||||
avID := arg["avID"].(string)
|
avID := arg["avID"].(string)
|
||||||
viewID := arg["viewID"].(string)
|
viewID := arg["viewID"].(string)
|
||||||
keyword := arg["keyword"].(string)
|
query := arg["query"].(string)
|
||||||
view, attrView, err := model.SearchTableView(avID, viewID, keyword)
|
view, attrView, err := model.SearchTableView(avID, viewID, query)
|
||||||
if nil != err {
|
if nil != err {
|
||||||
ret.Code = -1
|
ret.Code = -1
|
||||||
ret.Msg = err.Error()
|
ret.Msg = err.Error()
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ import (
|
||||||
"github.com/siyuan-note/siyuan/kernel/util"
|
"github.com/siyuan-note/siyuan/kernel/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
func SearchTableView(avID, viewID, keyword string) (viewable av.Viewable, attrView *av.AttributeView, err error) {
|
func SearchTableView(avID, viewID, query string) (viewable av.Viewable, attrView *av.AttributeView, err error) {
|
||||||
if avJSONPath := av.GetAttributeViewDataPath(avID); !filelock.IsExist(avJSONPath) {
|
if avJSONPath := av.GetAttributeViewDataPath(avID); !filelock.IsExist(avJSONPath) {
|
||||||
attrView = av.NewAttributeView(avID)
|
attrView = av.NewAttributeView(avID)
|
||||||
if err = av.SaveAttributeView(attrView); nil != err {
|
if err = av.SaveAttributeView(attrView); nil != err {
|
||||||
|
|
@ -54,7 +54,28 @@ func SearchTableView(avID, viewID, keyword string) (viewable av.Viewable, attrVi
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
keywords := strings.Split(query, " ")
|
||||||
viewable, err = renderAttributeView(attrView, viewID, 1, -1)
|
viewable, err = renderAttributeView(attrView, viewID, 1, -1)
|
||||||
|
var rows []*av.TableRow
|
||||||
|
switch viewable.GetType() {
|
||||||
|
case av.LayoutTypeTable:
|
||||||
|
table := viewable.(*av.Table)
|
||||||
|
for _, row := range table.Rows {
|
||||||
|
hit := false
|
||||||
|
for _, cell := range row.Cells {
|
||||||
|
for _, keyword := range keywords {
|
||||||
|
if strings.Contains(strings.ToLower(cell.Value.String()), strings.ToLower(keyword)) {
|
||||||
|
hit = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if hit {
|
||||||
|
rows = append(rows, row)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
table.Rows = rows
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue