mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-01-01 14:28:49 +01:00
🎨 Improve adding row prompt when database filter exists https://github.com/siyuan-note/siyuan/issues/10517
Improve adding row prompt when database sort exists https://github.com/siyuan-note/siyuan/issues/10525
This commit is contained in:
parent
1848f5aae0
commit
b134313b16
4 changed files with 169 additions and 53 deletions
|
|
@ -17,8 +17,6 @@
|
|||
package av
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/siyuan-note/siyuan/kernel/util"
|
||||
)
|
||||
|
||||
|
|
@ -77,7 +75,7 @@ const (
|
|||
FilterOperatorIsFalse FilterOperator = "Is false"
|
||||
)
|
||||
|
||||
func (filter *ViewFilter) GetAffectValue(key *Key) (ret *Value) {
|
||||
func (filter *ViewFilter) GetAffectValue(key *Key, defaultVal *Value) (ret *Value) {
|
||||
if nil != filter.Value {
|
||||
if filter.Value.IsGenerated() {
|
||||
// 自动生成类型的过滤条件不设置默认值
|
||||
|
|
@ -99,17 +97,29 @@ func (filter *ViewFilter) GetAffectValue(key *Key) (ret *Value) {
|
|||
}
|
||||
|
||||
ret = filter.Value.Clone()
|
||||
|
||||
if nil != defaultVal {
|
||||
// 如果有默认值则优先使用默认值
|
||||
clonedDefaultVal := defaultVal.Clone()
|
||||
defaultRawVal := clonedDefaultVal.GetValByType(filter.Value.Type)
|
||||
if nil != defaultRawVal {
|
||||
ret.SetValByType(filter.Value.Type, defaultRawVal)
|
||||
return
|
||||
}
|
||||
}
|
||||
// 没有默认值则使用过滤条件的值
|
||||
|
||||
switch filter.Value.Type {
|
||||
case KeyTypeBlock:
|
||||
switch filter.Operator {
|
||||
case FilterOperatorIsEqual:
|
||||
ret.Block = &ValueBlock{ID: filter.Value.Block.ID, Content: filter.Value.Block.Content}
|
||||
case FilterOperatorIsNotEqual:
|
||||
ret.Block = &ValueBlock{ID: filter.Value.Block.ID, Content: strings.TrimSpace(filter.Value.Block.Content + " Untitled")}
|
||||
ret.Block = &ValueBlock{ID: filter.Value.Block.ID, Content: ""}
|
||||
case FilterOperatorContains:
|
||||
ret.Block = &ValueBlock{ID: filter.Value.Block.ID, Content: filter.Value.Block.Content}
|
||||
case FilterOperatorDoesNotContain:
|
||||
ret.Block = &ValueBlock{ID: filter.Value.Block.ID, Content: strings.ReplaceAll("Untitled", filter.Value.Block.Content, "")}
|
||||
ret.Block = &ValueBlock{ID: filter.Value.Block.ID, Content: ""}
|
||||
case FilterOperatorStartsWith:
|
||||
ret.Block = &ValueBlock{ID: filter.Value.Block.ID, Content: filter.Value.Block.Content}
|
||||
case FilterOperatorEndsWith:
|
||||
|
|
@ -117,18 +127,18 @@ func (filter *ViewFilter) GetAffectValue(key *Key) (ret *Value) {
|
|||
case FilterOperatorIsEmpty:
|
||||
ret.Block = &ValueBlock{ID: filter.Value.Block.ID, Content: ""}
|
||||
case FilterOperatorIsNotEmpty:
|
||||
ret.Block = &ValueBlock{ID: filter.Value.Block.ID, Content: "Untitled"}
|
||||
ret.Block = &ValueBlock{ID: filter.Value.Block.ID, Content: ""}
|
||||
}
|
||||
case KeyTypeText:
|
||||
switch filter.Operator {
|
||||
case FilterOperatorIsEqual:
|
||||
ret.Text = &ValueText{Content: filter.Value.Text.Content}
|
||||
case FilterOperatorIsNotEqual:
|
||||
ret.Text = &ValueText{Content: strings.TrimSpace(filter.Value.Text.Content + " Untitled")}
|
||||
ret.Text = &ValueText{Content: ""}
|
||||
case FilterOperatorContains:
|
||||
ret.Text = &ValueText{Content: filter.Value.Text.Content}
|
||||
case FilterOperatorDoesNotContain:
|
||||
ret.Text = &ValueText{Content: strings.ReplaceAll("Untitled", filter.Value.Text.Content, "")}
|
||||
ret.Text = &ValueText{Content: ""}
|
||||
case FilterOperatorStartsWith:
|
||||
ret.Text = &ValueText{Content: filter.Value.Text.Content}
|
||||
case FilterOperatorEndsWith:
|
||||
|
|
@ -136,7 +146,7 @@ func (filter *ViewFilter) GetAffectValue(key *Key) (ret *Value) {
|
|||
case FilterOperatorIsEmpty:
|
||||
ret.Text = &ValueText{Content: ""}
|
||||
case FilterOperatorIsNotEmpty:
|
||||
ret.Text = &ValueText{Content: "Untitled"}
|
||||
ret.Text = &ValueText{Content: ""}
|
||||
}
|
||||
case KeyTypeNumber:
|
||||
switch filter.Operator {
|
||||
|
|
@ -182,32 +192,21 @@ func (filter *ViewFilter) GetAffectValue(key *Key) (ret *Value) {
|
|||
case FilterOperatorIsNotEmpty:
|
||||
ret.Date = &ValueDate{Content: util.CurrentTimeMillis(), IsNotEmpty: true}
|
||||
}
|
||||
case KeyTypeSelect:
|
||||
case KeyTypeSelect, KeyTypeMSelect:
|
||||
switch filter.Operator {
|
||||
case FilterOperatorIsEqual:
|
||||
if 0 < len(filter.Value.MSelect) {
|
||||
ret.MSelect = []*ValueSelect{{Content: filter.Value.MSelect[0].Content, Color: filter.Value.MSelect[0].Color}}
|
||||
valueSelect := &ValueSelect{Content: "", Color: "1"}
|
||||
if 0 < len(key.Options) {
|
||||
valueSelect.Color = key.Options[0].Color
|
||||
}
|
||||
if 0 < len(filter.Value.MSelect) {
|
||||
valueSelect.Content = filter.Value.MSelect[0].Content
|
||||
valueSelect.Color = filter.Value.MSelect[0].Color
|
||||
}
|
||||
ret.MSelect = []*ValueSelect{valueSelect}
|
||||
case FilterOperatorIsNotEqual:
|
||||
if 0 < len(filter.Value.MSelect) {
|
||||
ret.MSelect = []*ValueSelect{{Content: filter.Value.MSelect[0].Content + " Untitled", Color: "1"}}
|
||||
}
|
||||
case FilterOperatorIsEmpty:
|
||||
ret.MSelect = []*ValueSelect{}
|
||||
case FilterOperatorIsNotEmpty:
|
||||
if 0 < len(key.Options) {
|
||||
ret.MSelect = []*ValueSelect{{Content: key.Options[0].Name, Color: key.Options[0].Color}}
|
||||
}
|
||||
}
|
||||
case KeyTypeMSelect:
|
||||
switch filter.Operator {
|
||||
case FilterOperatorIsEqual, FilterOperatorContains:
|
||||
if 0 < len(filter.Value.MSelect) {
|
||||
ret.MSelect = []*ValueSelect{{Content: filter.Value.MSelect[0].Content, Color: filter.Value.MSelect[0].Color}}
|
||||
}
|
||||
case FilterOperatorIsNotEqual, FilterOperatorDoesNotContain:
|
||||
if 0 < len(filter.Value.MSelect) {
|
||||
ret.MSelect = []*ValueSelect{{Content: filter.Value.MSelect[0].Content + " Untitled", Color: "1"}}
|
||||
ret.MSelect = []*ValueSelect{}
|
||||
}
|
||||
case FilterOperatorIsEmpty:
|
||||
ret.MSelect = []*ValueSelect{}
|
||||
|
|
@ -221,30 +220,30 @@ func (filter *ViewFilter) GetAffectValue(key *Key) (ret *Value) {
|
|||
case FilterOperatorIsEqual:
|
||||
ret.URL = &ValueURL{Content: filter.Value.URL.Content}
|
||||
case FilterOperatorIsNotEqual:
|
||||
ret.URL = &ValueURL{Content: filter.Value.URL.Content + " Untitled"}
|
||||
ret.URL = &ValueURL{Content: filter.Value.URL.Content}
|
||||
case FilterOperatorContains:
|
||||
ret.URL = &ValueURL{Content: filter.Value.URL.Content}
|
||||
case FilterOperatorDoesNotContain:
|
||||
ret.URL = &ValueURL{Content: strings.ReplaceAll("Untitled", filter.Value.URL.Content, "")}
|
||||
ret.URL = &ValueURL{Content: ""}
|
||||
case FilterOperatorStartsWith:
|
||||
ret.URL = &ValueURL{Content: filter.Value.URL.Content}
|
||||
case FilterOperatorEndsWith:
|
||||
ret.URL = &ValueURL{Content: filter.Value.URL.Content}
|
||||
case FilterOperatorIsEmpty:
|
||||
ret.URL = &ValueURL{Content: ""}
|
||||
ret.URL = &ValueURL{}
|
||||
case FilterOperatorIsNotEmpty:
|
||||
ret.URL = &ValueURL{Content: "Untitled"}
|
||||
ret.URL = &ValueURL{}
|
||||
}
|
||||
case KeyTypeEmail:
|
||||
switch filter.Operator {
|
||||
case FilterOperatorIsEqual:
|
||||
ret.Email = &ValueEmail{Content: filter.Value.Email.Content}
|
||||
case FilterOperatorIsNotEqual:
|
||||
ret.Email = &ValueEmail{Content: filter.Value.Email.Content + " Untitled"}
|
||||
ret.Email = &ValueEmail{Content: filter.Value.Email.Content}
|
||||
case FilterOperatorContains:
|
||||
ret.Email = &ValueEmail{Content: filter.Value.Email.Content}
|
||||
case FilterOperatorDoesNotContain:
|
||||
ret.Email = &ValueEmail{Content: strings.ReplaceAll("Untitled", filter.Value.Email.Content, "")}
|
||||
ret.Email = &ValueEmail{Content: ""}
|
||||
case FilterOperatorStartsWith:
|
||||
ret.Email = &ValueEmail{Content: filter.Value.Email.Content}
|
||||
case FilterOperatorEndsWith:
|
||||
|
|
@ -252,18 +251,18 @@ func (filter *ViewFilter) GetAffectValue(key *Key) (ret *Value) {
|
|||
case FilterOperatorIsEmpty:
|
||||
ret.Email = &ValueEmail{Content: ""}
|
||||
case FilterOperatorIsNotEmpty:
|
||||
ret.Email = &ValueEmail{Content: "Untitled"}
|
||||
ret.Email = &ValueEmail{Content: ""}
|
||||
}
|
||||
case KeyTypePhone:
|
||||
switch filter.Operator {
|
||||
case FilterOperatorIsEqual:
|
||||
ret.Phone = &ValuePhone{Content: filter.Value.Phone.Content}
|
||||
case FilterOperatorIsNotEqual:
|
||||
ret.Phone = &ValuePhone{Content: filter.Value.Phone.Content + " Untitled"}
|
||||
ret.Phone = &ValuePhone{Content: filter.Value.Phone.Content + ""}
|
||||
case FilterOperatorContains:
|
||||
ret.Phone = &ValuePhone{Content: filter.Value.Phone.Content}
|
||||
case FilterOperatorDoesNotContain:
|
||||
ret.Phone = &ValuePhone{Content: strings.ReplaceAll("Untitled", filter.Value.Phone.Content, "")}
|
||||
ret.Phone = &ValuePhone{Content: ""}
|
||||
case FilterOperatorStartsWith:
|
||||
ret.Phone = &ValuePhone{Content: filter.Value.Phone.Content}
|
||||
case FilterOperatorEndsWith:
|
||||
|
|
@ -271,7 +270,7 @@ func (filter *ViewFilter) GetAffectValue(key *Key) (ret *Value) {
|
|||
case FilterOperatorIsEmpty:
|
||||
ret.Phone = &ValuePhone{Content: ""}
|
||||
case FilterOperatorIsNotEmpty:
|
||||
ret.Phone = &ValuePhone{Content: "Untitled"}
|
||||
ret.Phone = &ValuePhone{Content: ""}
|
||||
}
|
||||
case KeyTypeMAsset:
|
||||
switch filter.Operator {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue