mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-17 07:00:12 +01:00
🎨 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:
parent
a379e24b3b
commit
7ff4356316
5 changed files with 49 additions and 4 deletions
|
|
@ -313,6 +313,17 @@ func (av *AttributeView) GetBlockKeyValues() (ret *KeyValues) {
|
|||
return
|
||||
}
|
||||
|
||||
func (av *AttributeView) GetKeyValues(keyID string) (ret *KeyValues, err error) {
|
||||
for _, kv := range av.KeyValues {
|
||||
if kv.Key.ID == keyID {
|
||||
ret = kv
|
||||
return
|
||||
}
|
||||
}
|
||||
err = ErrKeyNotFound
|
||||
return
|
||||
}
|
||||
|
||||
func (av *AttributeView) GetBlockKey() (ret *Key) {
|
||||
for _, kv := range av.KeyValues {
|
||||
if KeyTypeBlock == kv.Key.Type {
|
||||
|
|
|
|||
|
|
@ -160,6 +160,18 @@ func (value *Value) ToJSONString() string {
|
|||
return string(data)
|
||||
}
|
||||
|
||||
func (value *Value) Clone() (ret *Value) {
|
||||
data, err := gulu.JSON.MarshalJSON(value)
|
||||
if nil != err {
|
||||
return
|
||||
}
|
||||
err = gulu.JSON.UnmarshalJSON(data, &ret)
|
||||
if nil != err {
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
type ValueBlock struct {
|
||||
ID string `json:"id"`
|
||||
Content string `json:"content"`
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
|
|
@ -1916,7 +1916,7 @@ func exportTree(tree *parse.Tree, wysiwyg, expandKaTexMacros, keepFold bool,
|
|||
return ast.WalkContinue
|
||||
}
|
||||
|
||||
table, err := renderAttributeViewTable(attrView, view, 1, -1)
|
||||
table, err := renderAttributeViewTable(attrView, view)
|
||||
if nil != err {
|
||||
logging.LogErrorf("render attribute view [%s] table failed: %s", avID, err)
|
||||
return ast.WalkContinue
|
||||
|
|
|
|||
|
|
@ -333,7 +333,7 @@ func renderTemplate(p, id string, preview bool) (string, error) {
|
|||
return ast.WalkContinue
|
||||
}
|
||||
|
||||
table, renderErr := renderAttributeViewTable(attrView, view, 1, -1)
|
||||
table, renderErr := renderAttributeViewTable(attrView, view)
|
||||
if nil != renderErr {
|
||||
logging.LogErrorf("render attribute view [%s] table failed: %s", n.AttributeViewID, renderErr)
|
||||
return ast.WalkContinue
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue