Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
Vanessa 2024-03-08 11:15:34 +08:00
commit 0c4f54cf22
7 changed files with 81 additions and 32 deletions

View File

@ -26,6 +26,19 @@ import (
"github.com/siyuan-note/siyuan/kernel/util" "github.com/siyuan-note/siyuan/kernel/util"
) )
func getMirrorDatabaseBlocks(c *gin.Context) {
ret := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, ret)
arg, ok := util.JsonArg(c, ret)
if !ok {
return
}
avID := arg["avID"].(string)
ret.Data = av.GetMirrorBlockIDs(avID)
}
func searchTableView(c *gin.Context) { func searchTableView(c *gin.Context) {
ret := gulu.Ret.NewResult() ret := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, ret) defer c.JSON(http.StatusOK, ret)

View File

@ -414,6 +414,7 @@ func ServeAPI(ginServer *gin.Engine) {
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/searchTableView", model.CheckAuth, model.CheckReadonly, searchTableView)
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)
ginServer.Handle("POST", "/api/ai/chatGPTWithAction", model.CheckAuth, chatGPTWithAction) ginServer.Handle("POST", "/api/ai/chatGPTWithAction", model.CheckAuth, chatGPTWithAction)

View File

@ -77,12 +77,8 @@ const (
func (filter *ViewFilter) GetAffectValue(key *Key, defaultVal *Value) (ret *Value) { func (filter *ViewFilter) GetAffectValue(key *Key, defaultVal *Value) (ret *Value) {
if nil != filter.Value { if nil != filter.Value {
if filter.Value.IsGenerated() { if KeyTypeRelation == filter.Value.Type || KeyTypeTemplate == filter.Value.Type || KeyTypeRollup == filter.Value.Type || KeyTypeUpdated == filter.Value.Type || KeyTypeCreated == filter.Value.Type {
// 自动生成类型的过滤条件不设置默认值 // 所有生成的数据都不设置默认值
return nil
}
if KeyTypeRelation == filter.Value.Type {
// 关联类型的过滤条件不设置默认值 https://ld246.com/article/1709608533749
return nil return nil
} }
} }

View File

@ -86,11 +86,19 @@ func (value *Value) Compare(other *Value) int {
switch value.Type { switch value.Type {
case KeyTypeBlock: case KeyTypeBlock:
if nil != value.Block && nil != other.Block { if nil != value.Block && nil != other.Block {
return strings.Compare(value.Block.Content, other.Block.Content) ret := strings.Compare(value.Block.Content, other.Block.Content)
if 0 == ret {
ret = int(value.CreatedAt - other.CreatedAt)
}
return ret
} }
case KeyTypeText: case KeyTypeText:
if nil != value.Text && nil != other.Text { if nil != value.Text && nil != other.Text {
return strings.Compare(value.Text.Content, other.Text.Content) ret := strings.Compare(value.Text.Content, other.Text.Content)
if 0 == ret {
ret = int(value.CreatedAt - other.CreatedAt)
}
return ret
} }
case KeyTypeNumber: case KeyTypeNumber:
if nil != value.Number && nil != other.Number { if nil != value.Number && nil != other.Number {
@ -104,7 +112,7 @@ func (value *Value) Compare(other *Value) int {
} else if value.Number.Content < other.Number.Content { } else if value.Number.Content < other.Number.Content {
return -1 return -1
} else { } else {
return 0 return int(value.CreatedAt - other.CreatedAt)
} }
} else { } else {
if other.Number.IsNotEmpty { if other.Number.IsNotEmpty {
@ -124,7 +132,7 @@ func (value *Value) Compare(other *Value) int {
} else if value.Date.Content < other.Date.Content { } else if value.Date.Content < other.Date.Content {
return -1 return -1
} else { } else {
return 0 return int(value.CreatedAt - other.CreatedAt)
} }
} else { } else {
if other.Date.IsNotEmpty { if other.Date.IsNotEmpty {
@ -140,7 +148,7 @@ func (value *Value) Compare(other *Value) int {
} else if value.Created.Content < other.Created.Content { } else if value.Created.Content < other.Created.Content {
return -1 return -1
} else { } else {
return 0 return int(value.CreatedAt - other.CreatedAt)
} }
} }
case KeyTypeUpdated: case KeyTypeUpdated:
@ -150,7 +158,7 @@ func (value *Value) Compare(other *Value) int {
} else if value.Updated.Content < other.Updated.Content { } else if value.Updated.Content < other.Updated.Content {
return -1 return -1
} else { } else {
return 0 return int(value.CreatedAt - other.CreatedAt)
} }
} }
case KeyTypeSelect, KeyTypeMSelect: case KeyTypeSelect, KeyTypeMSelect:
@ -163,19 +171,35 @@ func (value *Value) Compare(other *Value) int {
for _, v := range other.MSelect { for _, v := range other.MSelect {
v2 += v.Content v2 += v.Content
} }
return strings.Compare(v1, v2) ret := strings.Compare(v1, v2)
if 0 == ret {
ret = int(value.CreatedAt - other.CreatedAt)
}
return ret
} }
case KeyTypeURL: case KeyTypeURL:
if nil != value.URL && nil != other.URL { if nil != value.URL && nil != other.URL {
return strings.Compare(value.URL.Content, other.URL.Content) ret := strings.Compare(value.URL.Content, other.URL.Content)
if 0 == ret {
ret = int(value.CreatedAt - other.CreatedAt)
}
return ret
} }
case KeyTypeEmail: case KeyTypeEmail:
if nil != value.Email && nil != other.Email { if nil != value.Email && nil != other.Email {
return strings.Compare(value.Email.Content, other.Email.Content) ret := strings.Compare(value.Email.Content, other.Email.Content)
if 0 == ret {
ret = int(value.CreatedAt - other.CreatedAt)
}
return ret
} }
case KeyTypePhone: case KeyTypePhone:
if nil != value.Phone && nil != other.Phone { if nil != value.Phone && nil != other.Phone {
return strings.Compare(value.Phone.Content, other.Phone.Content) ret := strings.Compare(value.Phone.Content, other.Phone.Content)
if 0 == ret {
ret = int(value.CreatedAt - other.CreatedAt)
}
return ret
} }
case KeyTypeMAsset: case KeyTypeMAsset:
if nil != value.MAsset && nil != other.MAsset { if nil != value.MAsset && nil != other.MAsset {
@ -187,7 +211,11 @@ func (value *Value) Compare(other *Value) int {
for _, v := range other.MAsset { for _, v := range other.MAsset {
v2 += v.Content v2 += v.Content
} }
return strings.Compare(v1, v2) ret := strings.Compare(v1, v2)
if 0 == ret {
ret = int(value.CreatedAt - other.CreatedAt)
}
return ret
} }
case KeyTypeTemplate: case KeyTypeTemplate:
if nil != value.Template && nil != other.Template { if nil != value.Template && nil != other.Template {
@ -199,13 +227,16 @@ func (value *Value) Compare(other *Value) int {
if v1 > v2 { if v1 > v2 {
return 1 return 1
} }
if v1 < v2 { if v1 < v2 {
return -1 return -1
} }
return 0 return int(value.CreatedAt - other.CreatedAt)
} }
return strings.Compare(value.Template.Content, other.Template.Content) ret := strings.Compare(value.Template.Content, other.Template.Content)
if 0 == ret {
ret = int(value.CreatedAt - other.CreatedAt)
}
return ret
} }
case KeyTypeCheckbox: case KeyTypeCheckbox:
if nil != value.Checkbox && nil != other.Checkbox { if nil != value.Checkbox && nil != other.Checkbox {
@ -215,7 +246,7 @@ func (value *Value) Compare(other *Value) int {
if !value.Checkbox.Checked && other.Checkbox.Checked { if !value.Checkbox.Checked && other.Checkbox.Checked {
return -1 return -1
} }
return 0 return int(value.CreatedAt - other.CreatedAt)
} }
case KeyTypeRelation: case KeyTypeRelation:
if nil != value.Relation && nil != other.Relation { if nil != value.Relation && nil != other.Relation {
@ -242,9 +273,13 @@ func (value *Value) Compare(other *Value) int {
if v1 < v2 { if v1 < v2 {
return -1 return -1
} }
return 0 return int(value.CreatedAt - other.CreatedAt)
} }
return strings.Compare(vContent, oContent) ret := strings.Compare(vContent, oContent)
if 0 == ret {
ret = int(value.CreatedAt - other.CreatedAt)
}
return ret
} }
case KeyTypeRollup: case KeyTypeRollup:
if nil != value.Rollup && nil != other.Rollup { if nil != value.Rollup && nil != other.Rollup {
@ -267,13 +302,16 @@ func (value *Value) Compare(other *Value) int {
if v1 > v2 { if v1 > v2 {
return 1 return 1
} }
if v1 < v2 { if v1 < v2 {
return -1 return -1
} }
return 0 return int(value.CreatedAt - other.CreatedAt)
} }
return strings.Compare(vContent, oContent) ret := strings.Compare(vContent, oContent)
if 0 == ret {
ret = int(value.CreatedAt - other.CreatedAt)
}
return ret
} }
} }
return int(value.CreatedAt - other.CreatedAt) return int(value.CreatedAt - other.CreatedAt)

View File

@ -193,8 +193,7 @@ func (value *Value) IsEdited() bool {
return true return true
} }
if value.IsGenerated() { if KeyTypeUpdated == value.Type || KeyTypeCreated == value.Type {
// 所有生成的数据都认为是编辑过的
return true return true
} }
@ -206,7 +205,7 @@ func (value *Value) IsEdited() bool {
} }
func (value *Value) IsGenerated() bool { func (value *Value) IsGenerated() bool {
return KeyTypeTemplate == value.Type || KeyTypeRollup == value.Type || KeyTypeUpdated == value.Type || KeyTypeCreated == value.Type return KeyTypeUpdated == value.Type || KeyTypeCreated == value.Type
} }
func (value *Value) IsEmpty() bool { func (value *Value) IsEmpty() bool {

View File

@ -1007,7 +1007,7 @@ func renderAttributeViewTable(attrView *av.AttributeView, view *av.View) (ret *a
for _, blockID := range relVal.Relation.BlockIDs { for _, blockID := range relVal.Relation.BlockIDs {
destVal := destAv.GetValue(rollupKey.Rollup.KeyID, blockID) destVal := destAv.GetValue(rollupKey.Rollup.KeyID, blockID)
if nil == destVal { if nil == destVal {
destVal = treenode.GetAttributeViewDefaultValue(ast.NewNodeID(), rollupKey.Rollup.KeyID, blockID, destKey.Type) continue
} }
if av.KeyTypeNumber == destKey.Type { if av.KeyTypeNumber == destKey.Type {
destVal.Number.Format = destKey.NumberFormat destVal.Number.Format = destKey.NumberFormat
@ -1034,7 +1034,9 @@ func renderAttributeViewTable(attrView *av.AttributeView, view *av.View) (ret *a
blocks[blockValue.BlockID] = blockValue blocks[blockValue.BlockID] = blockValue
} }
for _, blockID := range cell.Value.Relation.BlockIDs { for _, blockID := range cell.Value.Relation.BlockIDs {
cell.Value.Relation.Contents = append(cell.Value.Relation.Contents, blocks[blockID]) if val := blocks[blockID]; nil != val {
cell.Value.Relation.Contents = append(cell.Value.Relation.Contents, val)
}
} }
} }
} }

View File

@ -805,7 +805,7 @@ func renderAttributeViewTable(attrView *av.AttributeView, view *av.View) (ret *a
for _, blockID := range relVal.Relation.BlockIDs { for _, blockID := range relVal.Relation.BlockIDs {
destVal := destAv.GetValue(rollupKey.Rollup.KeyID, blockID) destVal := destAv.GetValue(rollupKey.Rollup.KeyID, blockID)
if nil == destVal { if nil == destVal {
destVal = GetAttributeViewDefaultValue(ast.NewNodeID(), rollupKey.Rollup.KeyID, blockID, destKey.Type) continue
} }
if av.KeyTypeNumber == destKey.Type { if av.KeyTypeNumber == destKey.Type {
destVal.Number.Format = destKey.NumberFormat destVal.Number.Format = destKey.NumberFormat