mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-17 15:10:12 +01:00
🎨 Database table view in-table search https://github.com/siyuan-note/siyuan/issues/10419
This commit is contained in:
parent
77ce08d044
commit
1b0ceaaedf
3 changed files with 0 additions and 84 deletions
|
|
@ -39,49 +39,6 @@ func getMirrorDatabaseBlocks(c *gin.Context) {
|
||||||
ret.Data = av.GetMirrorBlockIDs(avID)
|
ret.Data = av.GetMirrorBlockIDs(avID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func searchTableView(c *gin.Context) {
|
|
||||||
ret := gulu.Ret.NewResult()
|
|
||||||
defer c.JSON(http.StatusOK, ret)
|
|
||||||
|
|
||||||
arg, _ := util.JsonArg(c, ret)
|
|
||||||
if nil == arg {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
avID := arg["avID"].(string)
|
|
||||||
viewID := arg["viewID"].(string)
|
|
||||||
query := arg["query"].(string)
|
|
||||||
view, attrView, err := model.SearchTableView(avID, viewID, query)
|
|
||||||
if nil != err {
|
|
||||||
ret.Code = -1
|
|
||||||
ret.Msg = err.Error()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
var views []map[string]interface{}
|
|
||||||
for _, v := range attrView.Views {
|
|
||||||
view := map[string]interface{}{
|
|
||||||
"id": v.ID,
|
|
||||||
"icon": v.Icon,
|
|
||||||
"name": v.Name,
|
|
||||||
"hideAttrViewName": v.HideAttrViewName,
|
|
||||||
"type": v.LayoutType,
|
|
||||||
}
|
|
||||||
|
|
||||||
views = append(views, view)
|
|
||||||
}
|
|
||||||
|
|
||||||
ret.Data = map[string]interface{}{
|
|
||||||
"name": attrView.Name,
|
|
||||||
"id": attrView.ID,
|
|
||||||
"viewType": view.GetType(),
|
|
||||||
"viewID": view.GetID(),
|
|
||||||
"views": views,
|
|
||||||
"view": view,
|
|
||||||
"isMirror": av.IsMirror(attrView.ID),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func setDatabaseBlockView(c *gin.Context) {
|
func setDatabaseBlockView(c *gin.Context) {
|
||||||
ret := gulu.Ret.NewResult()
|
ret := gulu.Ret.NewResult()
|
||||||
defer c.JSON(http.StatusOK, ret)
|
defer c.JSON(http.StatusOK, ret)
|
||||||
|
|
|
||||||
|
|
@ -413,7 +413,6 @@ func ServeAPI(ginServer *gin.Engine) {
|
||||||
ginServer.Handle("POST", "/api/av/removeAttributeViewValues", model.CheckAuth, model.CheckReadonly, removeAttributeViewValues)
|
ginServer.Handle("POST", "/api/av/removeAttributeViewValues", model.CheckAuth, model.CheckReadonly, removeAttributeViewValues)
|
||||||
ginServer.Handle("POST", "/api/av/getAttributeViewPrimaryKeyValues", model.CheckAuth, model.CheckReadonly, getAttributeViewPrimaryKeyValues)
|
ginServer.Handle("POST", "/api/av/getAttributeViewPrimaryKeyValues", model.CheckAuth, model.CheckReadonly, getAttributeViewPrimaryKeyValues)
|
||||||
ginServer.Handle("POST", "/api/av/setDatabaseBlockView", model.CheckAuth, model.CheckReadonly, setDatabaseBlockView)
|
ginServer.Handle("POST", "/api/av/setDatabaseBlockView", model.CheckAuth, model.CheckReadonly, setDatabaseBlockView)
|
||||||
ginServer.Handle("POST", "/api/av/searchTableView", model.CheckAuth, model.CheckReadonly, searchTableView)
|
|
||||||
ginServer.Handle("POST", "/api/av/getMirrorDatabaseBlocks", model.CheckAuth, model.CheckReadonly, getMirrorDatabaseBlocks)
|
ginServer.Handle("POST", "/api/av/getMirrorDatabaseBlocks", model.CheckAuth, model.CheckReadonly, getMirrorDatabaseBlocks)
|
||||||
|
|
||||||
ginServer.Handle("POST", "/api/ai/chatGPT", model.CheckAuth, chatGPT)
|
ginServer.Handle("POST", "/api/ai/chatGPT", model.CheckAuth, chatGPT)
|
||||||
|
|
|
||||||
|
|
@ -39,46 +39,6 @@ import (
|
||||||
"github.com/siyuan-note/siyuan/kernel/util"
|
"github.com/siyuan-note/siyuan/kernel/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
func SearchTableView(avID, viewID, query string) (viewable av.Viewable, attrView *av.AttributeView, err error) {
|
|
||||||
if avJSONPath := av.GetAttributeViewDataPath(avID); !filelock.IsExist(avJSONPath) {
|
|
||||||
attrView = av.NewAttributeView(avID)
|
|
||||||
if err = av.SaveAttributeView(attrView); nil != err {
|
|
||||||
logging.LogErrorf("save attribute view [%s] failed: %s", avID, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
attrView, err = av.ParseAttributeView(avID)
|
|
||||||
if nil != err {
|
|
||||||
logging.LogErrorf("parse attribute view [%s] failed: %s", avID, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
keywords := strings.Split(query, " ")
|
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
func SetDatabaseBlockView(blockID, viewID string) (err error) {
|
func SetDatabaseBlockView(blockID, viewID string) (err error) {
|
||||||
node, tree, err := getNodeByBlockID(nil, blockID)
|
node, tree, err := getNodeByBlockID(nil, blockID)
|
||||||
if nil != err {
|
if nil != err {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue