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

This commit is contained in:
Daniel 2023-07-10 11:54:27 +08:00
parent 96e7044baf
commit 2f84aaa4c7
No known key found for this signature in database
GPG Key ID: 86211BA83DF03017

View File

@ -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
}