mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-01-30 20:25:17 +01:00
♻️ Refactor av data structure
This commit is contained in:
parent
e66fc9c096
commit
ba396a5573
4 changed files with 36 additions and 29 deletions
|
|
@ -41,8 +41,8 @@ type AttributeView struct {
|
|||
|
||||
// KeyValues 描述了属性视图属性列值的结构。
|
||||
type KeyValues struct {
|
||||
Key *Key `json:"key"` // 属性视图属性列
|
||||
Values []*Value `json:"values"` // 属性视图属性列值
|
||||
Key *Key `json:"key"` // 属性视图属性列
|
||||
Values []*Value `json:"values,omitempty"` // 属性视图属性列值
|
||||
}
|
||||
|
||||
type KeyType string
|
||||
|
|
@ -65,7 +65,7 @@ type Key struct {
|
|||
|
||||
// 以下是某些列类型的特有属性
|
||||
|
||||
Options []*KeySelectOption `json:"options"` // 选项列表
|
||||
Options []*KeySelectOption `json:"options,omitempty"` // 选项列表
|
||||
}
|
||||
|
||||
func NewKey(name string, keyType KeyType) *Key {
|
||||
|
|
@ -182,21 +182,29 @@ func NewAttributeView(id string) (ret *AttributeView) {
|
|||
|
||||
func ParseAttributeView(avID string) (ret *AttributeView, err error) {
|
||||
avJSONPath := getAttributeViewDataPath(avID)
|
||||
toCreate := false
|
||||
if !gulu.File.IsExist(avJSONPath) {
|
||||
ret = NewAttributeView(avID)
|
||||
return
|
||||
toCreate = true
|
||||
}
|
||||
|
||||
data, err := filelock.ReadFile(avJSONPath)
|
||||
if nil != err {
|
||||
logging.LogErrorf("read attribute view [%s] failed: %s", avID, err)
|
||||
return
|
||||
}
|
||||
if !toCreate {
|
||||
data, readErr := filelock.ReadFile(avJSONPath)
|
||||
if nil != readErr {
|
||||
logging.LogErrorf("read attribute view [%s] failed: %s", avID, readErr)
|
||||
return
|
||||
}
|
||||
|
||||
ret = &AttributeView{}
|
||||
if err = gulu.JSON.UnmarshalJSON(data, ret); nil != err {
|
||||
logging.LogErrorf("unmarshal attribute view [%s] failed: %s", avID, err)
|
||||
return
|
||||
ret = &AttributeView{}
|
||||
if err = gulu.JSON.UnmarshalJSON(data, ret); nil != err {
|
||||
logging.LogErrorf("unmarshal attribute view [%s] failed: %s", avID, err)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
if err = SaveAttributeView(ret); nil != err {
|
||||
logging.LogErrorf("save attribute view [%s] failed: %s", avID, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
@ -216,9 +224,9 @@ func SaveAttributeView(av *AttributeView) (err error) {
|
|||
return
|
||||
}
|
||||
|
||||
func (av *AttributeView) GetView(viewID string) (ret *View, err error) {
|
||||
func (av *AttributeView) GetView() (ret *View, err error) {
|
||||
for _, v := range av.Views {
|
||||
if v.ID == viewID {
|
||||
if v.ID == av.ViewID {
|
||||
ret = v
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,10 +37,10 @@ type LayoutTable struct {
|
|||
type ViewTableColumn struct {
|
||||
ID string `json:"id"` // 列 ID
|
||||
|
||||
Wrap bool `json:"wrap"` // 是否换行
|
||||
Hidden bool `json:"hidden"` // 是否隐藏
|
||||
Width string `json:"width"` // 列宽度
|
||||
Calc *ColumnCalc `json:"calc"` // 计算
|
||||
Wrap bool `json:"wrap"` // 是否换行
|
||||
Hidden bool `json:"hidden"` // 是否隐藏
|
||||
Width string `json:"width"` // 列宽度
|
||||
Calc *ColumnCalc `json:"calc,omitempty"` // 计算
|
||||
}
|
||||
|
||||
type Calculable interface {
|
||||
|
|
|
|||
|
|
@ -173,7 +173,7 @@ func setAttributeViewFilters(operation *Operation) (err error) {
|
|||
return
|
||||
}
|
||||
|
||||
view, err := attrView.GetView(operation.ViewID)
|
||||
view, err := attrView.GetView()
|
||||
if nil != err {
|
||||
return
|
||||
}
|
||||
|
|
@ -210,7 +210,7 @@ func setAttributeViewSorts(operation *Operation) (err error) {
|
|||
return
|
||||
}
|
||||
|
||||
view, err := attrView.GetView(operation.ViewID)
|
||||
view, err := attrView.GetView()
|
||||
if nil != err {
|
||||
return
|
||||
}
|
||||
|
|
@ -272,7 +272,7 @@ func addAttributeViewBlock(blockID string, operation *Operation, tree *parse.Tre
|
|||
return
|
||||
}
|
||||
|
||||
view, err := attrView.GetView(operation.ViewID)
|
||||
view, err := attrView.GetView()
|
||||
if nil != err {
|
||||
return
|
||||
}
|
||||
|
|
@ -370,7 +370,7 @@ func setAttributeViewColWidth(operation *Operation) (err error) {
|
|||
return
|
||||
}
|
||||
|
||||
view, err := attrView.GetView(operation.ViewID)
|
||||
view, err := attrView.GetView()
|
||||
if nil != err {
|
||||
return
|
||||
}
|
||||
|
|
@ -403,7 +403,7 @@ func setAttributeViewColWrap(operation *Operation) (err error) {
|
|||
return
|
||||
}
|
||||
|
||||
view, err := attrView.GetView(operation.ViewID)
|
||||
view, err := attrView.GetView()
|
||||
if nil != err {
|
||||
return
|
||||
}
|
||||
|
|
@ -436,7 +436,7 @@ func setAttributeViewColHidden(operation *Operation) (err error) {
|
|||
return
|
||||
}
|
||||
|
||||
view, err := attrView.GetView(operation.ViewID)
|
||||
view, err := attrView.GetView()
|
||||
if nil != err {
|
||||
return
|
||||
}
|
||||
|
|
@ -469,7 +469,7 @@ func sortAttributeViewRow(operation *Operation) (err error) {
|
|||
return
|
||||
}
|
||||
|
||||
view, err := attrView.GetView(operation.ViewID)
|
||||
view, err := attrView.GetView()
|
||||
if nil != err {
|
||||
return
|
||||
}
|
||||
|
|
@ -517,7 +517,7 @@ func sortAttributeViewColumn(operation *Operation) (err error) {
|
|||
return
|
||||
}
|
||||
|
||||
view, err := attrView.GetView(operation.ViewID)
|
||||
view, err := attrView.GetView()
|
||||
if nil != err {
|
||||
return
|
||||
}
|
||||
|
|
@ -565,7 +565,7 @@ func addAttributeViewColumn(operation *Operation) (err error) {
|
|||
return
|
||||
}
|
||||
|
||||
view, err := attrView.GetView(operation.ViewID)
|
||||
view, err := attrView.GetView()
|
||||
if nil != err {
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1052,7 +1052,6 @@ type Operation struct {
|
|||
DeckID string `json:"deckID"` // 用于添加/删除闪卡
|
||||
|
||||
AvID string `json:"avID"` // 属性视图 ID
|
||||
ViewID string `json:"viewID"` // 属性视图的视图 ID
|
||||
SrcIDs []string `json:"srcIDs"` // 用于将块拖拽到属性视图中
|
||||
Name string `json:"name"` // 属性视图列名
|
||||
Typ string `json:"type"` // 属性视图列类型
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue