🎨 Keep the width when duplicating database table view field https://github.com/siyuan-note/siyuan/issues/11552
This commit is contained in:
parent
f1993e13e3
commit
68585e21e3
5 changed files with 69 additions and 19 deletions
2
app/stage/protyle/js/lute/lute.min.js
vendored
2
app/stage/protyle/js/lute/lute.min.js
vendored
File diff suppressed because one or more lines are too long
|
@ -19,11 +19,8 @@ package av
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
|
@ -644,20 +641,6 @@ func (av *AttributeView) GetBlockKey() (ret *Key) {
|
|||
return
|
||||
}
|
||||
|
||||
func (av *AttributeView) GetDuplicateViewName(masterViewName string) (ret string) {
|
||||
ret = masterViewName + " (1)"
|
||||
r := regexp.MustCompile("^(.*) \\((\\d+)\\)$")
|
||||
m := r.FindStringSubmatch(masterViewName)
|
||||
if nil == m || 3 > len(m) {
|
||||
return
|
||||
}
|
||||
|
||||
num, _ := strconv.Atoi(m[2])
|
||||
num++
|
||||
ret = fmt.Sprintf("%s (%d)", m[1], num)
|
||||
return
|
||||
}
|
||||
|
||||
func (av *AttributeView) ShallowClone() (ret *AttributeView) {
|
||||
ret = &AttributeView{}
|
||||
data, err := gulu.JSON.MarshalJSON(av)
|
||||
|
|
|
@ -30,6 +30,7 @@ import (
|
|||
"github.com/88250/gulu"
|
||||
"github.com/88250/lute/ast"
|
||||
"github.com/88250/lute/parse"
|
||||
"github.com/jinzhu/copier"
|
||||
"github.com/siyuan-note/dejavu/entity"
|
||||
"github.com/siyuan-note/filelock"
|
||||
"github.com/siyuan-note/logging"
|
||||
|
@ -1500,7 +1501,7 @@ func (tx *Transaction) doDuplicateAttrViewView(operation *Operation) (ret *TxErr
|
|||
attrView.ViewID = view.ID
|
||||
|
||||
view.Icon = masterView.Icon
|
||||
view.Name = attrView.GetDuplicateViewName(masterView.Name)
|
||||
view.Name = util.GetDuplicateName(masterView.Name)
|
||||
view.LayoutType = masterView.LayoutType
|
||||
view.HideAttrViewName = masterView.HideAttrViewName
|
||||
|
||||
|
@ -2179,6 +2180,54 @@ func removeNodeAvID(node *ast.Node, avID string, tx *Transaction, tree *parse.Tr
|
|||
return
|
||||
}
|
||||
|
||||
func (tx *Transaction) doDuplicateAttrViewKey(operation *Operation) (ret *TxErr) {
|
||||
err := duplicateAttributeViewKey(operation)
|
||||
if nil != err {
|
||||
return &TxErr{code: TxErrWriteAttributeView, id: operation.AvID, msg: err.Error()}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func duplicateAttributeViewKey(operation *Operation) (err error) {
|
||||
attrView, err := av.ParseAttributeView(operation.AvID)
|
||||
if nil != err {
|
||||
return
|
||||
}
|
||||
|
||||
key, _ := attrView.GetKey(operation.KeyID)
|
||||
if nil == key {
|
||||
return
|
||||
}
|
||||
|
||||
if av.KeyTypeBlock == key.Type || av.KeyTypeRelation == key.Type || av.KeyTypeRollup == key.Type {
|
||||
return
|
||||
}
|
||||
|
||||
copyKey := &av.Key{}
|
||||
if err = copier.Copy(copyKey, key); nil != err {
|
||||
logging.LogErrorf("clone key failed: %s", err)
|
||||
}
|
||||
copyKey.ID = operation.NextID
|
||||
copyKey.Name = util.GetDuplicateName(key.Name)
|
||||
|
||||
attrView.KeyValues = append(attrView.KeyValues, &av.KeyValues{Key: copyKey})
|
||||
|
||||
for _, view := range attrView.Views {
|
||||
switch view.LayoutType {
|
||||
case av.LayoutTypeTable:
|
||||
for i, column := range view.Table.Columns {
|
||||
if column.ID == key.ID {
|
||||
view.Table.Columns = append(view.Table.Columns[:i+1], append([]*av.ViewTableColumn{{ID: key.ID}}, view.Table.Columns[i+1:]...)...)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
err = av.SaveAttributeView(attrView)
|
||||
return
|
||||
}
|
||||
|
||||
func (tx *Transaction) doSetAttrViewColumnWidth(operation *Operation) (ret *TxErr) {
|
||||
err := setAttributeViewColWidth(operation)
|
||||
if nil != err {
|
||||
|
|
|
@ -298,6 +298,8 @@ func performTx(tx *Transaction) (ret *TxErr) {
|
|||
ret = tx.doSetAttrViewColDate(op)
|
||||
case "unbindAttrViewBlock":
|
||||
ret = tx.doUnbindAttrViewBlock(op)
|
||||
case "duplicateAttrViewKey":
|
||||
ret = tx.doDuplicateAttrViewKey(op)
|
||||
}
|
||||
|
||||
if nil != ret {
|
||||
|
|
|
@ -18,7 +18,9 @@ package util
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
@ -32,6 +34,20 @@ func init() {
|
|||
rand.Seed(time.Now().UTC().UnixNano())
|
||||
}
|
||||
|
||||
func GetDuplicateName(master string) (ret string) {
|
||||
ret = master + " (1)"
|
||||
r := regexp.MustCompile("^(.*) \\((\\d+)\\)$")
|
||||
m := r.FindStringSubmatch(master)
|
||||
if nil == m || 3 > len(m) {
|
||||
return
|
||||
}
|
||||
|
||||
num, _ := strconv.Atoi(m[2])
|
||||
num++
|
||||
ret = fmt.Sprintf("%s (%d)", m[1], num)
|
||||
return
|
||||
}
|
||||
|
||||
var (
|
||||
letter = []rune("abcdefghijklmnopqrstuvwxyz0123456789")
|
||||
)
|
||||
|
|
Loading…
Add table
Reference in a new issue