From 2f84aaa4c712e26f0937f23f3b97d2660dad7595 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Mon, 10 Jul 2023 11:54:27 +0800 Subject: [PATCH 1/3] :art: Add multi-select type column to Attribute View https://github.com/siyuan-note/siyuan/issues/8695 --- kernel/model/attribute_view.go | 39 +++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/kernel/model/attribute_view.go b/kernel/model/attribute_view.go index 4c059fd39..707063a6a 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 } From 7cbd0503fb6128d926c08311a0e75f3235c130f1 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Mon, 10 Jul 2023 11:54:33 +0800 Subject: [PATCH 2/3] :art: Add multi-select type column to Attribute View https://github.com/siyuan-note/siyuan/issues/8695 --- kernel/model/attribute_view.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/kernel/model/attribute_view.go b/kernel/model/attribute_view.go index 707063a6a..eab38bbec 100644 --- a/kernel/model/attribute_view.go +++ b/kernel/model/attribute_view.go @@ -329,8 +329,6 @@ 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 { From 2ae3371674c11ec4a3435cc7a0c4245a7ffdaeb6 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Mon, 10 Jul 2023 11:56:55 +0800 Subject: [PATCH 3/3] :art: Add multi-select type column to Attribute View https://github.com/siyuan-note/siyuan/issues/8695 --- kernel/model/attribute_view.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/kernel/model/attribute_view.go b/kernel/model/attribute_view.go index eab38bbec..01b1e18db 100644 --- a/kernel/model/attribute_view.go +++ b/kernel/model/attribute_view.go @@ -337,9 +337,10 @@ func updateAttributeViewColumnOption(operation *Operation) (err error) { colIndex = i existOpt := false - for _, opt := range col.Options { + for j, opt := range col.Options { if opt.Name == newName { existOpt = true + col.Options = append(col.Options[:j], col.Options[j+1:]...) break } } @@ -358,8 +359,8 @@ func updateAttributeViewColumnOption(operation *Operation) (err error) { } for _, row := range attrView.Rows { - for k, cell := range row.Cells { - if colIndex != k || nil == cell.Value { + for i, cell := range row.Cells { + if colIndex != i || nil == cell.Value { continue } @@ -371,9 +372,10 @@ func updateAttributeViewColumnOption(operation *Operation) (err error) { } } else if nil != cell.Value.MSelect { existInMSelect := false - for _, opt := range cell.Value.MSelect { + for j, opt := range cell.Value.MSelect { if opt.Content == newName { existInMSelect = true + cell.Value.MSelect = append(cell.Value.MSelect[:j], cell.Value.MSelect[j+1:]...) break } }