mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-27 20:08:49 +01:00
🎨 Database table view in-table search https://github.com/siyuan-note/siyuan/issues/10419
This commit is contained in:
parent
4a00e5a124
commit
cbcc8141a8
2 changed files with 33 additions and 2 deletions
|
|
@ -485,7 +485,13 @@ func renderAttributeView(c *gin.Context) {
|
|||
pageSize = int(pageSizeArg.(float64))
|
||||
}
|
||||
|
||||
view, attrView, err := model.RenderAttributeView(id, viewID, page, pageSize)
|
||||
query := ""
|
||||
queryArg := arg["query"]
|
||||
if nil != queryArg {
|
||||
query = queryArg.(string)
|
||||
}
|
||||
|
||||
view, attrView, err := model.RenderAttributeView(id, viewID, query, page, pageSize)
|
||||
if nil != err {
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
|
|
|
|||
|
|
@ -596,7 +596,7 @@ func RenderHistoryAttributeView(avID, created string) (viewable av.Viewable, att
|
|||
return
|
||||
}
|
||||
|
||||
func RenderAttributeView(avID, viewID string, page, pageSize int) (viewable av.Viewable, attrView *av.AttributeView, err error) {
|
||||
func RenderAttributeView(avID, viewID, query string, page, pageSize int) (viewable av.Viewable, attrView *av.AttributeView, err error) {
|
||||
waitForSyncingStorages()
|
||||
|
||||
if avJSONPath := av.GetAttributeViewDataPath(avID); !filelock.IsExist(avJSONPath) {
|
||||
|
|
@ -614,6 +614,31 @@ func RenderAttributeView(avID, viewID string, page, pageSize int) (viewable av.V
|
|||
}
|
||||
|
||||
viewable, err = renderAttributeView(attrView, viewID, page, pageSize)
|
||||
|
||||
query = strings.TrimSpace(query)
|
||||
if "" != query {
|
||||
keywords := strings.Split(query, " ")
|
||||
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
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue