Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: Add multi-select type column to Attribute View https://github.com/siyuan-note/siyuan/issues/8695

Daniel2f84aaa4c712
diff --git a/kernel/model/attribute_view.go b/kernel/model/attribute_view.go
index 4c059fd398..707063a6a7 100644
--- a/kernel/model/attribute_view.go
+++ b/kernel/model/attribute_view.go
@@ -329,6 +329,8 @@ func updateAttributeViewColumnOption(operation *Operation) (err error) {
newName := data["newName"].(string)
newColor := data["newColor"].(string)
+ // TODO 如果 newName 已经存在
+
var colIndex int
for i, col := range attrView.Columns {
if col.ID != colID {
@@ -336,15 +338,23 @@ func updateAttributeViewColumnOption(operation *Operation) (err error) {
}
colIndex = i
-
+ existOpt := false
for _, opt := range col.Options {
- if opt.Name != oldName {
- continue
+ if opt.Name == newName {
+ existOpt = true
+ break
}
+ }
+ if !existOpt {
+ for _, opt := range col.Options {
+ if opt.Name != oldName {
+ continue
+ }
- opt.Name = newName
- opt.Color = newColor
- break
+ opt.Name = newName
+ opt.Color = newColor
+ break
+ }
}
break
}
@@ -362,13 +372,22 @@ func updateAttributeViewColumnOption(operation *Operation) (err error) {
break
}
} else if nil != cell.Value.MSelect {
- for j, opt := range cell.Value.MSelect {
- if oldName == opt.Content {
- cell.Value.MSelect[j].Content = newName
- cell.Value.MSelect[j].Color = newColor
+ existInMSelect := false
+ for _, opt := range cell.Value.MSelect {
+ if opt.Content == newName {
+ existInMSelect = true
break
}
}
+ if !existInMSelect {
+ for j, opt := range cell.Value.MSelect {
+ if oldName == opt.Content {
+ cell.Value.MSelect[j].Content = newName
+ cell.Value.MSelect[j].Color = newColor
+ break
+ }
+ }
+ }
}
break
}