Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Vanessa219 committed Nov 30, 2023
2 parents 44d3db3 + fa5ee62 commit e29e7f3
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 33 deletions.
2 changes: 1 addition & 1 deletion app/stage/protyle/js/lute/lute.min.js

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion kernel/api/av.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,12 @@ func renderAttributeView(c *gin.Context) {
}

id := arg["id"].(string)
view, attrView, err := model.RenderAttributeView(id)
viewIDArg := arg["viewID"]
var viewID string
if nil != viewIDArg {
viewID = viewIDArg.(string)
}
view, attrView, err := model.RenderAttributeView(id, viewID)
if nil != err {
ret.Code = -1
ret.Msg = err.Error()
Expand Down
14 changes: 12 additions & 2 deletions kernel/av/av.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func ShallowCloneAttributeView(av *AttributeView) (ret *AttributeView) {
}

ret.ID = ast.NewNodeID()
view, err := ret.GetView()
view, err := ret.GetCurrentView()
if nil == err {
view.ID = ast.NewNodeID()
ret.ViewID = view.ID
Expand Down Expand Up @@ -678,7 +678,17 @@ func SaveAttributeView(av *AttributeView) (err error) {
return
}

func (av *AttributeView) GetView() (ret *View, err error) {
func (av *AttributeView) GetView(viewID string) (ret *View) {
for _, v := range av.Views {
if v.ID == viewID {
ret = v
return
}
}
return
}

func (av *AttributeView) GetCurrentView() (ret *View, err error) {
for _, v := range av.Views {
if v.ID == av.ViewID {
ret = v
Expand Down
2 changes: 1 addition & 1 deletion kernel/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/88250/clipboard v0.1.5
github.com/88250/epub v0.0.0-20230830085737-c19055cd1f48
github.com/88250/gulu v1.2.3-0.20231023172823-f152fc5d93ef
github.com/88250/lute v1.7.6-0.20231127150400-9af4adcb4786
github.com/88250/lute v1.7.6-0.20231130131003-24f7d3743f7b
github.com/88250/pdfcpu v0.3.14-0.20230401044135-c7369a99720c
github.com/88250/vitess-sqlparser v0.0.0-20210205111146-56a2ded2aba1
github.com/ClarkThan/ahocorasick v0.0.0-20231011042242-30d1ef1347f4
Expand Down
4 changes: 2 additions & 2 deletions kernel/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ github.com/88250/go-sqlite3 v1.14.13-0.20220714142610-fbbda1ee84f5 h1:8HdZozCsXS
github.com/88250/go-sqlite3 v1.14.13-0.20220714142610-fbbda1ee84f5/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
github.com/88250/gulu v1.2.3-0.20231023172823-f152fc5d93ef h1:LVJO3aj18v63T2whGGt3gL5imkJk+7ujPfFv38X7Oi8=
github.com/88250/gulu v1.2.3-0.20231023172823-f152fc5d93ef/go.mod h1:pTWnjt+6qUqNnP9xltswsJxgCBVu3C7eW09u48LWX0k=
github.com/88250/lute v1.7.6-0.20231127150400-9af4adcb4786 h1:ZDEa5WSNyAt3KGAxsMO8HyGo36ndhO1TyLYJmBvQzoQ=
github.com/88250/lute v1.7.6-0.20231127150400-9af4adcb4786/go.mod h1:+wUqx/1kdFDbWtxn9LYJlaCOAeol2pjSO6w+WJTVQsg=
github.com/88250/lute v1.7.6-0.20231130131003-24f7d3743f7b h1:JhiOgdKE2XP13rI47jNa5EMxUFgfDTjbnI9QiwrsZOc=
github.com/88250/lute v1.7.6-0.20231130131003-24f7d3743f7b/go.mod h1:+wUqx/1kdFDbWtxn9LYJlaCOAeol2pjSO6w+WJTVQsg=
github.com/88250/pdfcpu v0.3.14-0.20230401044135-c7369a99720c h1:Dl/8S9iLyPMTElnWIBxmjaLiWrkI5P4a21ivwAn5pU0=
github.com/88250/pdfcpu v0.3.14-0.20230401044135-c7369a99720c/go.mod h1:S5YT38L/GCjVjmB4PB84PymA1qfopjEhfhTNQilLpv4=
github.com/88250/vitess-sqlparser v0.0.0-20210205111146-56a2ded2aba1 h1:48T899JQDwyyRu9yXHePYlPdHtpJfrJEUGBMH3SMBWY=
Expand Down
56 changes: 32 additions & 24 deletions kernel/model/attribute_view.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func GetBlockAttributeViewKeys(blockID string) (ret []*BlockAttributeViewKeys) {
}

// Attribute Panel - Database sort attributes by view column order https://github.com/siyuan-note/siyuan/issues/9319
view, _ := attrView.GetView()
view, _ := attrView.GetCurrentView()
if nil != view {
sorts := map[string]int{}
for i, col := range view.Table.Columns {
Expand Down Expand Up @@ -224,7 +224,7 @@ func RenderRepoSnapshotAttributeView(indexID, avID string) (viewable av.Viewable
}
}

viewable, err = renderAttributeView(attrView)
viewable, err = renderAttributeView(attrView, "")
return
}

Expand Down Expand Up @@ -267,11 +267,11 @@ func RenderHistoryAttributeView(avID, created string) (viewable av.Viewable, att
}
}

viewable, err = renderAttributeView(attrView)
viewable, err = renderAttributeView(attrView, "")
return
}

func RenderAttributeView(avID string) (viewable av.Viewable, attrView *av.AttributeView, err error) {
func RenderAttributeView(avID, viewID string) (viewable av.Viewable, attrView *av.AttributeView, err error) {
waitForSyncingStorages()

if avJSONPath := av.GetAttributeViewDataPath(avID); !filelock.IsExist(avJSONPath) {
Expand All @@ -288,11 +288,11 @@ func RenderAttributeView(avID string) (viewable av.Viewable, attrView *av.Attrib
return
}

viewable, err = renderAttributeView(attrView)
viewable, err = renderAttributeView(attrView, viewID)
return
}

func renderAttributeView(attrView *av.AttributeView) (viewable av.Viewable, err error) {
func renderAttributeView(attrView *av.AttributeView, viewID string) (viewable av.Viewable, err error) {
if 1 > len(attrView.Views) {
view := av.NewView()
attrView.Views = append(attrView.Views, view)
Expand All @@ -304,14 +304,22 @@ func renderAttributeView(attrView *av.AttributeView) (viewable av.Viewable, err
}

var view *av.View
if "" != attrView.ViewID {
for _, v := range attrView.Views {
if v.ID == attrView.ViewID {
view = v
break
if "" != viewID {
view = attrView.GetView(viewID)
if nil != view && viewID != attrView.ViewID {
attrView.ViewID = viewID
if err = av.SaveAttributeView(attrView); nil != err {
logging.LogErrorf("save attribute view [%s] failed: %s", attrView.ID, err)
return
}
}
} else {
if "" != attrView.ViewID {
view, _ = attrView.GetCurrentView()
}
}

if nil == view {
view = attrView.Views[0]
}

Expand Down Expand Up @@ -639,7 +647,7 @@ func setAttributeViewName(operation *Operation) (err error) {
return
}

view, err := attrView.GetView()
view, err := attrView.GetCurrentView()
if nil != err {
return
}
Expand All @@ -665,7 +673,7 @@ func setAttributeViewFilters(operation *Operation) (err error) {
return
}

view, err := attrView.GetView()
view, err := attrView.GetCurrentView()
if nil != err {
return
}
Expand Down Expand Up @@ -711,7 +719,7 @@ func setAttributeViewSorts(operation *Operation) (err error) {
return
}

view, err := attrView.GetView()
view, err := attrView.GetCurrentView()
if nil != err {
return
}
Expand Down Expand Up @@ -747,7 +755,7 @@ func setAttributeViewColumnCalc(operation *Operation) (err error) {
return
}

view, err := attrView.GetView()
view, err := attrView.GetCurrentView()
if nil != err {
return
}
Expand Down Expand Up @@ -818,7 +826,7 @@ func addAttributeViewBlock(blockID string, operation *Operation, tree *parse.Tre
return
}

view, err := attrView.GetView()
view, err := attrView.GetCurrentView()
if nil != err {
return
}
Expand Down Expand Up @@ -888,7 +896,7 @@ func (tx *Transaction) removeAttributeViewBlock(operation *Operation) (err error
return
}

view, err := attrView.GetView()
view, err := attrView.GetCurrentView()
if nil != err {
return
}
Expand Down Expand Up @@ -961,7 +969,7 @@ func setAttributeViewColWidth(operation *Operation) (err error) {
return
}

view, err := attrView.GetView()
view, err := attrView.GetCurrentView()
if nil != err {
return
}
Expand Down Expand Up @@ -994,7 +1002,7 @@ func setAttributeViewColWrap(operation *Operation) (err error) {
return
}

view, err := attrView.GetView()
view, err := attrView.GetCurrentView()
if nil != err {
return
}
Expand Down Expand Up @@ -1027,7 +1035,7 @@ func setAttributeViewColHidden(operation *Operation) (err error) {
return
}

view, err := attrView.GetView()
view, err := attrView.GetCurrentView()
if nil != err {
return
}
Expand Down Expand Up @@ -1060,7 +1068,7 @@ func setAttributeViewColPin(operation *Operation) (err error) {
return
}

view, err := attrView.GetView()
view, err := attrView.GetCurrentView()
if nil != err {
return
}
Expand Down Expand Up @@ -1118,7 +1126,7 @@ func sortAttributeViewRow(operation *Operation) (err error) {
return
}

view, err := attrView.GetView()
view, err := attrView.GetCurrentView()
if nil != err {
return
}
Expand Down Expand Up @@ -1166,7 +1174,7 @@ func sortAttributeViewColumn(operation *Operation) (err error) {
return
}

view, err := attrView.GetView()
view, err := attrView.GetCurrentView()
if nil != err {
return
}
Expand Down Expand Up @@ -1214,7 +1222,7 @@ func addAttributeViewColumn(operation *Operation) (err error) {
return
}

view, err := attrView.GetView()
view, err := attrView.GetCurrentView()
if nil != err {
return
}
Expand Down
2 changes: 1 addition & 1 deletion kernel/model/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -1910,7 +1910,7 @@ func exportTree(tree *parse.Tree, wysiwyg, expandKaTexMacros, keepFold bool,
return ast.WalkContinue
}

view, err := attrView.GetView()
view, err := attrView.GetCurrentView()
if nil != err {
logging.LogErrorf("get attribute view [%s] failed: %s", avID, err)
return ast.WalkContinue
Expand Down
2 changes: 1 addition & 1 deletion kernel/model/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ func renderTemplate(p, id string, preview bool) (string, error) {
}
} else {
// 预览时使用简单表格渲染
view, getErr := attrView.GetView()
view, getErr := attrView.GetCurrentView()
if nil != getErr {
logging.LogErrorf("get attribute view [%s] failed: %s", n.AttributeViewID, getErr)
return ast.WalkContinue
Expand Down
47 changes: 47 additions & 0 deletions kernel/model/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,10 @@ func performTx(tx *Transaction) (ret *TxErr) {
ret = tx.doReplaceAttrViewBlock(op)
case "updateAttrViewColTemplate":
ret = tx.doUpdateAttrViewColTemplate(op)
case "addAttrViewView":
ret = tx.doAddAttrViewView(op)
case "removeAttrViewView":
ret = tx.doRemoveAttrViewView(op)
}

if nil != ret {
Expand All @@ -257,6 +261,49 @@ func performTx(tx *Transaction) (ret *TxErr) {
return
}

func (tx *Transaction) doRemoveAttrViewView(operation *Operation) (ret *TxErr) {
var err error
avID := operation.AvID
attrView, err := av.ParseAttributeView(avID)
if nil != err {
logging.LogErrorf("parse attribute view [%s] failed: %s", avID, err)
return &TxErr{code: TxErrCodeBlockNotFound, id: avID}
}

viewID := operation.ID
for i, view := range attrView.Views {
if viewID == view.ID {
attrView.Views = append(attrView.Views[:i], attrView.Views[i+1:]...)
break
}
}

if err = av.SaveAttributeView(attrView); nil != err {
logging.LogErrorf("save attribute view [%s] failed: %s", avID, err)
return &TxErr{code: TxErrCodeWriteTree, msg: err.Error(), id: avID}
}
return
}

func (tx *Transaction) doAddAttrViewView(operation *Operation) (ret *TxErr) {
var err error
avID := operation.AvID
attrView, err := av.ParseAttributeView(avID)
if nil != err {
logging.LogErrorf("parse attribute view [%s] failed: %s", avID, err)
return &TxErr{code: TxErrCodeBlockNotFound, id: avID}
}

view := av.NewView()
attrView.Views = append(attrView.Views, view)
attrView.ViewID = view.ID
if err = av.SaveAttributeView(attrView); nil != err {
logging.LogErrorf("save attribute view [%s] failed: %s", avID, err)
return &TxErr{code: TxErrCodeWriteTree, msg: err.Error(), id: avID}
}
return
}

func (tx *Transaction) doMove(operation *Operation) (ret *TxErr) {
var err error
id := operation.ID
Expand Down

0 comments on commit e29e7f3

Please sign in to comment.