🎨 Automatically fill in the filter result value when adding rows in the database table view https://github.com/siyuan-note/siyuan/issues/9905

This commit is contained in:
Daniel 2023-12-17 12:00:55 +08:00
parent a379e24b3b
commit 7ff4356316
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
5 changed files with 49 additions and 4 deletions

View file

@ -372,7 +372,7 @@ func renderAttributeView(attrView *av.AttributeView, viewID string, page, pageSi
}
view.Table.Sorts = tmpSorts
viewable, err = renderAttributeViewTable(attrView, view, page, pageSize)
viewable, err = renderAttributeViewTable(attrView, view)
}
viewable.FilterRows()
@ -463,7 +463,7 @@ func renderTemplateCol(ial map[string]string, tplContent string, rowValues []*av
return buf.String()
}
func renderAttributeViewTable(attrView *av.AttributeView, view *av.View, page, pageSize int) (ret *av.Table, err error) {
func renderAttributeViewTable(attrView *av.AttributeView, view *av.View) (ret *av.Table, err error) {
ret = &av.Table{
ID: view.ID,
Icon: view.Icon,
@ -1107,6 +1107,28 @@ func addAttributeViewBlock(blockID string, operation *Operation, tree *parse.Tre
value := &av.Value{ID: ast.NewNodeID(), KeyID: blockValues.Key.ID, BlockID: blockID, Type: av.KeyTypeBlock, IsDetached: operation.IsDetached, IsInitialized: false, Block: &av.ValueBlock{ID: blockID, Content: content, Created: now, Updated: now}}
blockValues.Values = append(blockValues.Values, value)
// 如果存在过滤条件,则将过滤条件应用到新添加的块上
view, _ := attrView.GetCurrentView()
if nil != view && 0 < len(view.Table.Filters) {
viewable, _ := renderAttributeViewTable(attrView, view)
if 0 < len(viewable.Rows) {
row := viewable.Rows[len(viewable.Rows)-1]
for _, filter := range view.Table.Filters {
for _, cell := range row.Cells {
if nil != cell.Value && cell.Value.KeyID == filter.Column {
newValue := cell.Value.Clone()
newValue.ID = ast.NewNodeID()
newValue.BlockID = blockID
newValue.IsDetached = operation.IsDetached
newValue.IsInitialized = false
values, _ := attrView.GetKeyValues(filter.Column)
values.Values = append(values.Values, newValue)
}
}
}
}
}
if !operation.IsDetached {
attrs := parse.IAL2Map(node.KramdownIAL)