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