mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-17 15:10:12 +01:00
🎨 Update av
This commit is contained in:
parent
fb85f7d36e
commit
f91d6cbce9
3 changed files with 52 additions and 13 deletions
|
|
@ -24,10 +24,12 @@ import (
|
||||||
"github.com/88250/gulu"
|
"github.com/88250/gulu"
|
||||||
"github.com/88250/lute/ast"
|
"github.com/88250/lute/ast"
|
||||||
"github.com/88250/lute/parse"
|
"github.com/88250/lute/parse"
|
||||||
|
"github.com/jinzhu/copier"
|
||||||
"github.com/siyuan-note/logging"
|
"github.com/siyuan-note/logging"
|
||||||
"github.com/siyuan-note/siyuan/kernel/av"
|
"github.com/siyuan-note/siyuan/kernel/av"
|
||||||
"github.com/siyuan-note/siyuan/kernel/sql"
|
"github.com/siyuan-note/siyuan/kernel/sql"
|
||||||
"github.com/siyuan-note/siyuan/kernel/treenode"
|
"github.com/siyuan-note/siyuan/kernel/treenode"
|
||||||
|
"github.com/siyuan-note/siyuan/kernel/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
func RenderAttributeView(avID string) (ret *av.AttributeView, err error) {
|
func RenderAttributeView(avID string) (ret *av.AttributeView, err error) {
|
||||||
|
|
@ -225,6 +227,14 @@ func (tx *Transaction) doSetAttrViewColumnWidth(operation *Operation) (ret *TxEr
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (tx *Transaction) doSetAttrView(operation *Operation) (ret *TxErr) {
|
||||||
|
err := setAttributeView(operation)
|
||||||
|
if nil != err {
|
||||||
|
return &TxErr{code: TxErrWriteAttributeView, id: operation.ParentID, msg: err.Error()}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func addAttributeViewColumn(name string, typ string, avID string) (err error) {
|
func addAttributeViewColumn(name string, typ string, avID string) (err error) {
|
||||||
attrView, err := av.ParseAttributeView(avID)
|
attrView, err := av.ParseAttributeView(avID)
|
||||||
if nil != err {
|
if nil != err {
|
||||||
|
|
@ -327,12 +337,12 @@ func sortAttributeViewColumn(columnID, previousColumnID, avID string) (err error
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
attrView.Columns = insertElement(attrView.Columns, previousIndex, col)
|
attrView.Columns = util.InsertElement(attrView.Columns, previousIndex, col)
|
||||||
|
|
||||||
for _, row := range attrView.Rows {
|
for _, row := range attrView.Rows {
|
||||||
cel := row.Cells[index]
|
cel := row.Cells[index]
|
||||||
row.Cells = append(row.Cells[:index], row.Cells[index+1:]...)
|
row.Cells = append(row.Cells[:index], row.Cells[index+1:]...)
|
||||||
row.Cells = insertElement(row.Cells, previousIndex, cel)
|
row.Cells = util.InsertElement(row.Cells, previousIndex, cel)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = av.SaveAttributeView(attrView)
|
err = av.SaveAttributeView(attrView)
|
||||||
|
|
@ -365,22 +375,12 @@ func sortAttributeViewRow(rowID, previousRowID, avID string) (err error) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
attrView.Rows = insertElement(attrView.Rows, previousIndex, row)
|
attrView.Rows = util.InsertElement(attrView.Rows, previousIndex, row)
|
||||||
|
|
||||||
err = av.SaveAttributeView(attrView)
|
err = av.SaveAttributeView(attrView)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 0 <= index <= len(a)
|
|
||||||
func insertElement[T any](rows []T, index int, value T) []T {
|
|
||||||
if len(rows) == index { // nil or empty slice or after last element
|
|
||||||
return append(rows, value)
|
|
||||||
}
|
|
||||||
rows = append(rows[:index+1], rows[index:]...) // index < len(a)
|
|
||||||
rows[index] = value
|
|
||||||
return rows
|
|
||||||
}
|
|
||||||
|
|
||||||
func setAttributeViewColHidden(hidden bool, columnID, avID string) (err error) {
|
func setAttributeViewColHidden(hidden bool, columnID, avID string) (err error) {
|
||||||
attrView, err := av.ParseAttributeView(avID)
|
attrView, err := av.ParseAttributeView(avID)
|
||||||
if nil != err {
|
if nil != err {
|
||||||
|
|
@ -432,6 +432,31 @@ func setAttributeViewColWidth(width, columnID, avID string) (err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func setAttributeView(operation *Operation) (err error) {
|
||||||
|
avID := operation.ID
|
||||||
|
attrView, err := av.ParseAttributeView(avID)
|
||||||
|
if nil != err {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
data, err := gulu.JSON.MarshalJSON(operation.Data)
|
||||||
|
if nil != err {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
newAttrView := &av.AttributeView{}
|
||||||
|
if err = gulu.JSON.UnmarshalJSON(data, newAttrView); nil != err {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = copier.Copy(attrView, newAttrView); nil != err {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err = av.SaveAttributeView(attrView)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func removeAttributeViewBlock(blockID, avID string) (ret *av.AttributeView, err error) {
|
func removeAttributeViewBlock(blockID, avID string) (ret *av.AttributeView, err error) {
|
||||||
ret, err = av.ParseAttributeView(avID)
|
ret, err = av.ParseAttributeView(avID)
|
||||||
if nil != err {
|
if nil != err {
|
||||||
|
|
|
||||||
|
|
@ -238,6 +238,8 @@ func performTx(tx *Transaction) (ret *TxErr) {
|
||||||
ret = tx.doSetAttrViewColumnWrap(op)
|
ret = tx.doSetAttrViewColumnWrap(op)
|
||||||
case "setAttrViewColWidth":
|
case "setAttrViewColWidth":
|
||||||
ret = tx.doSetAttrViewColumnWidth(op)
|
ret = tx.doSetAttrViewColumnWidth(op)
|
||||||
|
case "setAttrView":
|
||||||
|
ret = tx.doSetAttrView(op)
|
||||||
}
|
}
|
||||||
|
|
||||||
if nil != ret {
|
if nil != ret {
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,18 @@ import (
|
||||||
"github.com/88250/lute/html"
|
"github.com/88250/lute/html"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// InsertElement inserts a new element value at the specified index position.
|
||||||
|
// 0 <= index <= len(a)
|
||||||
|
func InsertElement[T any](ret []T, index int, value T) []T {
|
||||||
|
if len(ret) == index { // nil or empty slice or after last element
|
||||||
|
return append(ret, value)
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = append(ret[:index+1], ret[index:]...) // index < len(a)
|
||||||
|
ret[index] = value
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
func EscapeHTML(s string) string {
|
func EscapeHTML(s string) string {
|
||||||
if strings.Contains(s, "&") {
|
if strings.Contains(s, "&") {
|
||||||
return s
|
return s
|
||||||
Loading…
Add table
Add a link
Reference in a new issue