mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-23 01:50:12 +01:00
🎨 Supports multiple views for the database https://github.com/siyuan-note/siyuan/issues/9751
This commit is contained in:
parent
0cf13cca8f
commit
1f130d4b1c
2 changed files with 24 additions and 3 deletions
|
|
@ -747,6 +747,29 @@ func (av *AttributeView) GetBlockKey() (ret *Key) {
|
|||
return
|
||||
}
|
||||
|
||||
func (av *AttributeView) GetDuplicateViewName(masterViewName string) string {
|
||||
count := 1
|
||||
ret := masterViewName + " (" + strconv.Itoa(count) + ")"
|
||||
|
||||
existViewByName := func(name string) bool {
|
||||
for _, v := range av.Views {
|
||||
if v.Name == name {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
for i := 0; i < 32; i++ {
|
||||
if !existViewByName(ret) {
|
||||
return ret
|
||||
}
|
||||
count++
|
||||
ret = masterViewName + " (" + strconv.Itoa(count) + ")"
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func GetAttributeViewDataPath(avID string) (ret string) {
|
||||
av := filepath.Join(util.DataDir, "storage", "av")
|
||||
ret = filepath.Join(av, avID+".json")
|
||||
|
|
|
|||
|
|
@ -687,7 +687,7 @@ func (tx *Transaction) doDuplicateAttrViewView(operation *Operation) (ret *TxErr
|
|||
attrView.ViewID = view.ID
|
||||
|
||||
view.Icon = masterView.Icon
|
||||
view.Name = masterView.Name
|
||||
view.Name = attrView.GetDuplicateViewName(masterView.Name)
|
||||
view.LayoutType = masterView.LayoutType
|
||||
|
||||
for _, col := range masterView.Table.Columns {
|
||||
|
|
@ -716,7 +716,6 @@ func (tx *Transaction) doDuplicateAttrViewView(operation *Operation) (ret *TxErr
|
|||
})
|
||||
}
|
||||
|
||||
attrView.ViewID = view.ID
|
||||
if err = av.SaveAttributeView(attrView); nil != err {
|
||||
logging.LogErrorf("save attribute view [%s] failed: %s", avID, err)
|
||||
return &TxErr{code: TxErrWriteAttributeView, msg: err.Error(), id: avID}
|
||||
|
|
@ -748,7 +747,6 @@ func (tx *Transaction) doAddAttrViewView(operation *Operation) (ret *TxErr) {
|
|||
view.Table.Columns = append(view.Table.Columns, &av.ViewTableColumn{ID: col.ID})
|
||||
}
|
||||
|
||||
attrView.ViewID = view.ID
|
||||
if err = av.SaveAttributeView(attrView); nil != err {
|
||||
logging.LogErrorf("save attribute view [%s] failed: %s", avID, err)
|
||||
return &TxErr{code: TxErrWriteAttributeView, msg: err.Error(), id: avID}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue