mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-05-04 10:01:56 +08:00
🎨 Database block support specified view https://github.com/siyuan-note/siyuan/issues/10443
This commit is contained in:
parent
3ce6e4824b
commit
cb726e0118
@ -91,6 +91,10 @@ func addAttributeViewValues(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
avID := arg["avID"].(string)
|
avID := arg["avID"].(string)
|
||||||
|
viewID := ""
|
||||||
|
if viewIDArg := arg["viewID"]; nil != viewIDArg {
|
||||||
|
viewID = viewIDArg.(string)
|
||||||
|
}
|
||||||
var srcIDs []string
|
var srcIDs []string
|
||||||
for _, v := range arg["srcIDs"].([]interface{}) {
|
for _, v := range arg["srcIDs"].([]interface{}) {
|
||||||
srcIDs = append(srcIDs, v.(string))
|
srcIDs = append(srcIDs, v.(string))
|
||||||
@ -101,7 +105,7 @@ func addAttributeViewValues(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
isDetached := arg["isDetached"].(bool)
|
isDetached := arg["isDetached"].(bool)
|
||||||
|
|
||||||
err := model.AddAttributeViewBlock(nil, srcIDs, avID, previousID, isDetached)
|
err := model.AddAttributeViewBlock(nil, srcIDs, avID, viewID, previousID, isDetached)
|
||||||
if nil != err {
|
if nil != err {
|
||||||
ret.Code = -1
|
ret.Code = -1
|
||||||
ret.Msg = err.Error()
|
ret.Msg = err.Error()
|
||||||
@ -194,10 +198,14 @@ func sortAttributeViewCol(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
avID := arg["avID"].(string)
|
avID := arg["avID"].(string)
|
||||||
|
viewID := ""
|
||||||
|
if viewIDArg := arg["viewID"]; nil != viewIDArg {
|
||||||
|
viewID = viewIDArg.(string)
|
||||||
|
}
|
||||||
keyID := arg["keyID"].(string)
|
keyID := arg["keyID"].(string)
|
||||||
previousKeyID := arg["previousKeyID"].(string)
|
previousKeyID := arg["previousKeyID"].(string)
|
||||||
|
|
||||||
err := model.SortAttributeViewKey(avID, keyID, previousKeyID)
|
err := model.SortAttributeViewKey(avID, viewID, keyID, previousKeyID)
|
||||||
if nil != err {
|
if nil != err {
|
||||||
ret.Code = -1
|
ret.Code = -1
|
||||||
ret.Msg = err.Error()
|
ret.Msg = err.Error()
|
||||||
|
@ -43,7 +43,8 @@ func exportAttributeView(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
avID := arg["id"].(string)
|
avID := arg["id"].(string)
|
||||||
zipPath, err := model.ExportAv2CSV(avID)
|
viewID := arg["viewID"].(string)
|
||||||
|
zipPath, err := model.ExportAv2CSV(avID, viewID)
|
||||||
if nil != err {
|
if nil != err {
|
||||||
ret.Code = 1
|
ret.Code = 1
|
||||||
ret.Msg = err.Error()
|
ret.Msg = err.Error()
|
||||||
|
@ -376,14 +376,26 @@ func (av *AttributeView) GetView(viewID string) (ret *View) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (av *AttributeView) GetCurrentView() (ret *View, err error) {
|
func (av *AttributeView) GetCurrentView(viewID string) (ret *View, err error) {
|
||||||
|
if "" != viewID {
|
||||||
|
ret = av.GetView(viewID)
|
||||||
|
if nil != ret {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for _, v := range av.Views {
|
for _, v := range av.Views {
|
||||||
if v.ID == av.ViewID {
|
if v.ID == av.ViewID {
|
||||||
ret = v
|
ret = v
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
err = ErrViewNotFound
|
|
||||||
|
if 1 > len(av.Views) {
|
||||||
|
err = ErrViewNotFound
|
||||||
|
return
|
||||||
|
}
|
||||||
|
ret = av.Views[0]
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -400,7 +400,8 @@ func GetBlockAttributeViewKeys(blockID string) (ret []*BlockAttributeViewKeys) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Attribute Panel - Database sort attributes by view column order https://github.com/siyuan-note/siyuan/issues/9319
|
// Attribute Panel - Database sort attributes by view column order https://github.com/siyuan-note/siyuan/issues/9319
|
||||||
view, _ := attrView.GetCurrentView()
|
viewID := attrs[av.NodeAttrView]
|
||||||
|
view, _ := attrView.GetCurrentView(viewID)
|
||||||
if nil != view {
|
if nil != view {
|
||||||
sorts := map[string]int{}
|
sorts := map[string]int{}
|
||||||
for i, col := range view.Table.Columns {
|
for i, col := range view.Table.Columns {
|
||||||
@ -580,11 +581,7 @@ func renderAttributeView(attrView *av.AttributeView, viewID string, page, pageSi
|
|||||||
|
|
||||||
var view *av.View
|
var view *av.View
|
||||||
if "" != viewID {
|
if "" != viewID {
|
||||||
view = attrView.GetView(viewID)
|
view, _ = attrView.GetCurrentView(viewID)
|
||||||
if nil == view {
|
|
||||||
view, _ = attrView.GetCurrentView()
|
|
||||||
}
|
|
||||||
|
|
||||||
if nil != view && view.ID != attrView.ViewID {
|
if nil != view && view.ID != attrView.ViewID {
|
||||||
attrView.ViewID = view.ID
|
attrView.ViewID = view.ID
|
||||||
if err = av.SaveAttributeView(attrView); nil != err {
|
if err = av.SaveAttributeView(attrView); nil != err {
|
||||||
@ -593,9 +590,7 @@ func renderAttributeView(attrView *av.AttributeView, viewID string, page, pageSi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if "" != attrView.ViewID {
|
view = attrView.GetView(attrView.ViewID)
|
||||||
view, _ = attrView.GetCurrentView()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if nil == view {
|
if nil == view {
|
||||||
@ -1073,7 +1068,7 @@ func hideAttrViewName(operation *Operation) (err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
viewID := operation.ID
|
viewID := operation.ViewID
|
||||||
view := attrView.GetView(viewID)
|
view := attrView.GetView(viewID)
|
||||||
if nil == view {
|
if nil == view {
|
||||||
logging.LogErrorf("get view [%s] failed: %s", viewID, err)
|
logging.LogErrorf("get view [%s] failed: %s", viewID, err)
|
||||||
@ -1279,7 +1274,7 @@ func (tx *Transaction) doSortAttrViewView(operation *Operation) (ret *TxErr) {
|
|||||||
return &TxErr{code: TxErrWriteAttributeView, id: operation.AvID, msg: err.Error()}
|
return &TxErr{code: TxErrWriteAttributeView, id: operation.AvID, msg: err.Error()}
|
||||||
}
|
}
|
||||||
|
|
||||||
viewID := operation.ID
|
viewID := operation.ViewID
|
||||||
previewViewID := operation.PreviousID
|
previewViewID := operation.PreviousID
|
||||||
|
|
||||||
if viewID == previewViewID {
|
if viewID == previewViewID {
|
||||||
@ -1325,11 +1320,11 @@ func (tx *Transaction) doRemoveAttrViewView(operation *Operation) (ret *TxErr) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if 1 >= len(attrView.Views) {
|
if 1 >= len(attrView.Views) {
|
||||||
logging.LogWarnf("can't remove last view [%s] of attribute view [%s]", operation.ID, avID)
|
logging.LogWarnf("can't remove last view [%s] of attribute view [%s]", operation.ViewID, avID)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
viewID := operation.ID
|
viewID := operation.ViewID
|
||||||
var index int
|
var index int
|
||||||
for i, view := range attrView.Views {
|
for i, view := range attrView.Views {
|
||||||
if viewID == view.ID {
|
if viewID == view.ID {
|
||||||
@ -1419,7 +1414,7 @@ func (tx *Transaction) doDuplicateAttrViewView(operation *Operation) (ret *TxErr
|
|||||||
}
|
}
|
||||||
|
|
||||||
view := av.NewTableView()
|
view := av.NewTableView()
|
||||||
view.ID = operation.ID
|
view.ID = operation.ViewID
|
||||||
attrView.Views = append(attrView.Views, view)
|
attrView.Views = append(attrView.Views, view)
|
||||||
attrView.ViewID = view.ID
|
attrView.ViewID = view.ID
|
||||||
|
|
||||||
@ -1482,7 +1477,7 @@ func (tx *Transaction) doAddAttrViewView(operation *Operation) (ret *TxErr) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
view := av.NewTableView()
|
view := av.NewTableView()
|
||||||
view.ID = operation.ID
|
view.ID = operation.ViewID
|
||||||
attrView.Views = append(attrView.Views, view)
|
attrView.Views = append(attrView.Views, view)
|
||||||
attrView.ViewID = view.ID
|
attrView.ViewID = view.ID
|
||||||
|
|
||||||
@ -1508,7 +1503,7 @@ func (tx *Transaction) doSetAttrViewViewName(operation *Operation) (ret *TxErr)
|
|||||||
return &TxErr{code: TxErrWriteAttributeView, id: avID}
|
return &TxErr{code: TxErrWriteAttributeView, id: avID}
|
||||||
}
|
}
|
||||||
|
|
||||||
viewID := operation.ID
|
viewID := operation.ViewID
|
||||||
view := attrView.GetView(viewID)
|
view := attrView.GetView(viewID)
|
||||||
if nil == view {
|
if nil == view {
|
||||||
logging.LogErrorf("get view [%s] failed: %s", viewID, err)
|
logging.LogErrorf("get view [%s] failed: %s", viewID, err)
|
||||||
@ -1532,7 +1527,7 @@ func (tx *Transaction) doSetAttrViewViewIcon(operation *Operation) (ret *TxErr)
|
|||||||
return &TxErr{code: TxErrWriteAttributeView, id: avID}
|
return &TxErr{code: TxErrWriteAttributeView, id: avID}
|
||||||
}
|
}
|
||||||
|
|
||||||
viewID := operation.ID
|
viewID := operation.ViewID
|
||||||
view := attrView.GetView(viewID)
|
view := attrView.GetView(viewID)
|
||||||
if nil == view {
|
if nil == view {
|
||||||
logging.LogErrorf("get view [%s] failed: %s", viewID, err)
|
logging.LogErrorf("get view [%s] failed: %s", viewID, err)
|
||||||
@ -1580,7 +1575,7 @@ func setAttributeViewFilters(operation *Operation) (err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
view, err := attrView.GetCurrentView()
|
view, err := attrView.GetCurrentView(operation.ViewID)
|
||||||
if nil != err {
|
if nil != err {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -1628,7 +1623,7 @@ func setAttributeViewSorts(operation *Operation) (err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
view, err := attrView.GetCurrentView()
|
view, err := attrView.GetCurrentView(operation.ID)
|
||||||
if nil != err {
|
if nil != err {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -1664,7 +1659,7 @@ func setAttributeViewPageSize(operation *Operation) (err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
view, err := attrView.GetCurrentView()
|
view, err := attrView.GetCurrentView(operation.ID)
|
||||||
if nil != err {
|
if nil != err {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -1692,7 +1687,7 @@ func setAttributeViewColumnCalc(operation *Operation) (err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
view, err := attrView.GetCurrentView()
|
view, err := attrView.GetCurrentView(operation.ViewID)
|
||||||
if nil != err {
|
if nil != err {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -1723,14 +1718,14 @@ func setAttributeViewColumnCalc(operation *Operation) (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (tx *Transaction) doInsertAttrViewBlock(operation *Operation) (ret *TxErr) {
|
func (tx *Transaction) doInsertAttrViewBlock(operation *Operation) (ret *TxErr) {
|
||||||
err := AddAttributeViewBlock(tx, operation.SrcIDs, operation.AvID, operation.PreviousID, operation.IsDetached)
|
err := AddAttributeViewBlock(tx, operation.SrcIDs, operation.AvID, operation.ViewID, operation.PreviousID, operation.IsDetached)
|
||||||
if nil != err {
|
if nil != err {
|
||||||
return &TxErr{code: TxErrWriteAttributeView, id: operation.AvID, msg: err.Error()}
|
return &TxErr{code: TxErrWriteAttributeView, id: operation.AvID, msg: err.Error()}
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func AddAttributeViewBlock(tx *Transaction, srcIDs []string, avID, previousBlockID string, isDetached bool) (err error) {
|
func AddAttributeViewBlock(tx *Transaction, srcIDs []string, avID, viewID, previousBlockID string, isDetached bool) (err error) {
|
||||||
for _, id := range srcIDs {
|
for _, id := range srcIDs {
|
||||||
var tree *parse.Tree
|
var tree *parse.Tree
|
||||||
if !isDetached {
|
if !isDetached {
|
||||||
@ -1746,14 +1741,14 @@ func AddAttributeViewBlock(tx *Transaction, srcIDs []string, avID, previousBlock
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if avErr := addAttributeViewBlock(avID, previousBlockID, id, isDetached, tree, tx); nil != avErr {
|
if avErr := addAttributeViewBlock(avID, viewID, previousBlockID, id, isDetached, tree, tx); nil != avErr {
|
||||||
return avErr
|
return avErr
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func addAttributeViewBlock(avID, previousBlockID, blockID string, isDetached bool, tree *parse.Tree, tx *Transaction) (err error) {
|
func addAttributeViewBlock(avID, viewID, previousBlockID, blockID string, isDetached bool, tree *parse.Tree, tx *Transaction) (err error) {
|
||||||
var node *ast.Node
|
var node *ast.Node
|
||||||
if !isDetached {
|
if !isDetached {
|
||||||
node = treenode.GetNodeInTree(tree, blockID)
|
node = treenode.GetNodeInTree(tree, blockID)
|
||||||
@ -1803,7 +1798,7 @@ func addAttributeViewBlock(avID, previousBlockID, blockID string, isDetached boo
|
|||||||
blockValues.Values = append(blockValues.Values, blockValue)
|
blockValues.Values = append(blockValues.Values, blockValue)
|
||||||
|
|
||||||
// 如果存在过滤条件,则将过滤条件应用到新添加的块上
|
// 如果存在过滤条件,则将过滤条件应用到新添加的块上
|
||||||
view, _ := attrView.GetCurrentView()
|
view, _ := attrView.GetCurrentView(viewID)
|
||||||
if nil != view && (0 < len(view.Table.Filters) || 0 < len(view.Table.Sorts)) {
|
if nil != view && (0 < len(view.Table.Filters) || 0 < len(view.Table.Sorts)) {
|
||||||
viewable, _ := renderAttributeViewTable(attrView, view)
|
viewable, _ := renderAttributeViewTable(attrView, view)
|
||||||
viewable.FilterRows(attrView)
|
viewable.FilterRows(attrView)
|
||||||
@ -1998,7 +1993,7 @@ func setAttributeViewColWidth(operation *Operation) (err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
view, err := attrView.GetCurrentView()
|
view, err := attrView.GetCurrentView(operation.ViewID)
|
||||||
if nil != err {
|
if nil != err {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -2031,7 +2026,7 @@ func setAttributeViewColWrap(operation *Operation) (err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
view, err := attrView.GetCurrentView()
|
view, err := attrView.GetCurrentView(operation.ViewID)
|
||||||
if nil != err {
|
if nil != err {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -2064,7 +2059,7 @@ func setAttributeViewColHidden(operation *Operation) (err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
view, err := attrView.GetCurrentView()
|
view, err := attrView.GetCurrentView(operation.ViewID)
|
||||||
if nil != err {
|
if nil != err {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -2097,7 +2092,7 @@ func setAttributeViewColPin(operation *Operation) (err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
view, err := attrView.GetCurrentView()
|
view, err := attrView.GetCurrentView(operation.ViewID)
|
||||||
if nil != err {
|
if nil != err {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -2155,7 +2150,7 @@ func sortAttributeViewRow(operation *Operation) (err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
view, err := attrView.GetCurrentView()
|
view, err := attrView.GetCurrentView(operation.ViewID)
|
||||||
if nil != err {
|
if nil != err {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -2192,20 +2187,20 @@ func sortAttributeViewRow(operation *Operation) (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (tx *Transaction) doSortAttrViewColumn(operation *Operation) (ret *TxErr) {
|
func (tx *Transaction) doSortAttrViewColumn(operation *Operation) (ret *TxErr) {
|
||||||
err := SortAttributeViewKey(operation.AvID, operation.ID, operation.PreviousID)
|
err := SortAttributeViewKey(operation.AvID, operation.ViewID, operation.ID, operation.PreviousID)
|
||||||
if nil != err {
|
if nil != err {
|
||||||
return &TxErr{code: TxErrWriteAttributeView, id: operation.AvID, msg: err.Error()}
|
return &TxErr{code: TxErrWriteAttributeView, id: operation.AvID, msg: err.Error()}
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func SortAttributeViewKey(avID, keyID, previousKeyID string) (err error) {
|
func SortAttributeViewKey(avID, viewID, keyID, previousKeyID string) (err error) {
|
||||||
attrView, err := av.ParseAttributeView(avID)
|
attrView, err := av.ParseAttributeView(avID)
|
||||||
if nil != err {
|
if nil != err {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
view, err := attrView.GetCurrentView()
|
view, err := attrView.GetCurrentView(viewID)
|
||||||
if nil != err {
|
if nil != err {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -56,7 +56,7 @@ import (
|
|||||||
"github.com/siyuan-note/siyuan/kernel/util"
|
"github.com/siyuan-note/siyuan/kernel/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ExportAv2CSV(avID string) (zipPath string, err error) {
|
func ExportAv2CSV(avID, viewID string) (zipPath string, err error) {
|
||||||
// Database block supports export as CSV https://github.com/siyuan-note/siyuan/issues/10072
|
// Database block supports export as CSV https://github.com/siyuan-note/siyuan/issues/10072
|
||||||
|
|
||||||
attrView, err := av.ParseAttributeView(avID)
|
attrView, err := av.ParseAttributeView(avID)
|
||||||
@ -64,7 +64,7 @@ func ExportAv2CSV(avID string) (zipPath string, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
view, err := attrView.GetCurrentView()
|
view, err := attrView.GetCurrentView(viewID)
|
||||||
if nil != err {
|
if nil != err {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -2243,7 +2243,8 @@ func exportTree(tree *parse.Tree, wysiwyg, expandKaTexMacros, keepFold bool,
|
|||||||
return ast.WalkContinue
|
return ast.WalkContinue
|
||||||
}
|
}
|
||||||
|
|
||||||
view, err := attrView.GetCurrentView()
|
viewID := n.IALAttr(av.NodeAttrView)
|
||||||
|
view, err := attrView.GetCurrentView(viewID)
|
||||||
if nil != err {
|
if nil != err {
|
||||||
logging.LogErrorf("get attribute view [%s] failed: %s", avID, err)
|
logging.LogErrorf("get attribute view [%s] failed: %s", avID, err)
|
||||||
return ast.WalkContinue
|
return ast.WalkContinue
|
||||||
|
@ -299,7 +299,8 @@ func renderTemplate(p, id string, preview bool) (string, error) {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// 预览时使用简单表格渲染
|
// 预览时使用简单表格渲染
|
||||||
view, getErr := attrView.GetCurrentView()
|
viewID := n.IALAttr(av.NodeAttrView)
|
||||||
|
view, getErr := attrView.GetCurrentView(viewID)
|
||||||
if nil != getErr {
|
if nil != getErr {
|
||||||
logging.LogErrorf("get attribute view [%s] failed: %s", n.AttributeViewID, getErr)
|
logging.LogErrorf("get attribute view [%s] failed: %s", n.AttributeViewID, getErr)
|
||||||
return ast.WalkContinue
|
return ast.WalkContinue
|
||||||
|
@ -1231,6 +1231,7 @@ type Operation struct {
|
|||||||
DeckID string `json:"deckID"` // 用于添加/删除闪卡
|
DeckID string `json:"deckID"` // 用于添加/删除闪卡
|
||||||
|
|
||||||
AvID string `json:"avID"` // 属性视图 ID
|
AvID string `json:"avID"` // 属性视图 ID
|
||||||
|
ViewID string `json:"viewID"` // 属性视图视图 ID
|
||||||
SrcIDs []string `json:"srcIDs"` // 用于将块拖拽到属性视图中
|
SrcIDs []string `json:"srcIDs"` // 用于将块拖拽到属性视图中
|
||||||
IsDetached bool `json:"isDetached"` // 用于标识是否是脱离块,仅存在于属性视图中
|
IsDetached bool `json:"isDetached"` // 用于标识是否是脱离块,仅存在于属性视图中
|
||||||
Name string `json:"name"` // 属性视图列名
|
Name string `json:"name"` // 属性视图列名
|
||||||
|
Loading…
Reference in New Issue
Block a user