mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-26 03:18:48 +01:00
Merge remote-tracking branch 'origin/dev' into dev
This commit is contained in:
commit
b1619fe155
5 changed files with 68 additions and 65 deletions
|
|
@ -47,7 +47,7 @@ func renderAttributeView(c *gin.Context) {
|
|||
view := map[string]interface{}{
|
||||
"id": v.ID,
|
||||
"name": v.Name,
|
||||
"type": v.CurrentLayoutType,
|
||||
"type": v.LayoutType,
|
||||
}
|
||||
|
||||
views = append(views, view)
|
||||
|
|
|
|||
|
|
@ -31,18 +31,18 @@ import (
|
|||
|
||||
// AttributeView 描述了属性视图的结构。
|
||||
type AttributeView struct {
|
||||
Spec int `json:"spec"` // 格式版本
|
||||
ID string `json:"id"` // 属性视图 ID
|
||||
Name string `json:"name"` // 属性视图名称
|
||||
KeyValues []*KeyValues `json:"keyValues"` // 属性视图属性列值
|
||||
CurrentViewID string `json:"currentViewID"` // 当前视图 ID
|
||||
Views []*View `json:"views"` // 视图
|
||||
Spec int `json:"spec"` // 格式版本
|
||||
ID string `json:"id"` // 属性视图 ID
|
||||
Name string `json:"name"` // 属性视图名称
|
||||
KeyValues []*KeyValues `json:"keyValues"` // 属性视图属性列值
|
||||
ViewID string `json:"viewID"` // 当前视图 ID
|
||||
Views []*View `json:"views"` // 视图
|
||||
}
|
||||
|
||||
// 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 {
|
||||
|
|
@ -130,9 +130,8 @@ type View struct {
|
|||
ID string `json:"id"` // 视图 ID
|
||||
Name string `json:"name"` // 视图名称
|
||||
|
||||
CurrentLayoutID string `json:"CurrentLayoutID"` // 当前布局 ID
|
||||
CurrentLayoutType LayoutType `json:"type"` // 当前布局类型
|
||||
Table *LayoutTable `json:"table,omitempty"` // 表格布局
|
||||
LayoutType LayoutType `json:"type"` // 当前布局类型
|
||||
Table *LayoutTable `json:"table,omitempty"` // 表格布局
|
||||
}
|
||||
|
||||
// LayoutType 描述了视图布局的类型。
|
||||
|
|
@ -144,15 +143,13 @@ const (
|
|||
|
||||
func NewView() *View {
|
||||
name := "Table"
|
||||
layoutID := ast.NewNodeID()
|
||||
return &View{
|
||||
ID: ast.NewNodeID(),
|
||||
Name: name,
|
||||
CurrentLayoutID: layoutID,
|
||||
CurrentLayoutType: LayoutTypeTable,
|
||||
ID: ast.NewNodeID(),
|
||||
Name: name,
|
||||
LayoutType: LayoutTypeTable,
|
||||
Table: &LayoutTable{
|
||||
Spec: 0,
|
||||
ID: layoutID,
|
||||
ID: ast.NewNodeID(),
|
||||
Filters: []*ViewFilter{},
|
||||
Sorts: []*ViewSort{},
|
||||
},
|
||||
|
|
@ -173,11 +170,11 @@ func NewAttributeView(id string) (ret *AttributeView) {
|
|||
view := NewView()
|
||||
key := NewKey("Block", KeyTypeBlock)
|
||||
ret = &AttributeView{
|
||||
Spec: 0,
|
||||
ID: id,
|
||||
KeyValues: []*KeyValues{{Key: key}},
|
||||
CurrentViewID: view.ID,
|
||||
Views: []*View{view},
|
||||
Spec: 0,
|
||||
ID: id,
|
||||
KeyValues: []*KeyValues{{Key: key}},
|
||||
ViewID: view.ID,
|
||||
Views: []*View{view},
|
||||
}
|
||||
view.Table.Columns = []*ViewTableColumn{{ID: key.ID}}
|
||||
return
|
||||
|
|
@ -185,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
|
||||
}
|
||||
|
|
@ -219,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 {
|
||||
|
|
|
|||
|
|
@ -44,9 +44,9 @@ func RenderAttributeView(avID string) (viewable av.Viewable, attrView *av.Attrib
|
|||
}
|
||||
|
||||
var view *av.View
|
||||
if "" != attrView.CurrentViewID {
|
||||
if "" != attrView.ViewID {
|
||||
for _, v := range attrView.Views {
|
||||
if v.ID == attrView.CurrentViewID {
|
||||
if v.ID == attrView.ViewID {
|
||||
view = v
|
||||
break
|
||||
}
|
||||
|
|
@ -55,7 +55,7 @@ func RenderAttributeView(avID string) (viewable av.Viewable, attrView *av.Attrib
|
|||
view = attrView.Views[0]
|
||||
}
|
||||
|
||||
switch view.CurrentLayoutType {
|
||||
switch view.LayoutType {
|
||||
case av.LayoutTypeTable:
|
||||
viewable, err = renderAttributeViewTable(attrView, view)
|
||||
}
|
||||
|
|
@ -68,7 +68,7 @@ func RenderAttributeView(avID string) (viewable av.Viewable, attrView *av.Attrib
|
|||
|
||||
func renderAttributeViewTable(attrView *av.AttributeView, view *av.View) (ret *av.Table, err error) {
|
||||
ret = &av.Table{
|
||||
ID: view.Table.ID,
|
||||
ID: view.ID,
|
||||
Name: view.Name,
|
||||
Columns: []*av.TableColumn{},
|
||||
Rows: []*av.TableRow{},
|
||||
|
|
@ -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
|
||||
}
|
||||
|
|
@ -184,7 +184,7 @@ func setAttributeViewFilters(operation *Operation) (err error) {
|
|||
return
|
||||
}
|
||||
|
||||
switch view.CurrentLayoutType {
|
||||
switch view.LayoutType {
|
||||
case av.LayoutTypeTable:
|
||||
if err = gulu.JSON.UnmarshalJSON(data, &view.Table.Filters); 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
|
||||
}
|
||||
|
|
@ -221,7 +221,7 @@ func setAttributeViewSorts(operation *Operation) (err error) {
|
|||
return
|
||||
}
|
||||
|
||||
switch view.CurrentLayoutType {
|
||||
switch view.LayoutType {
|
||||
case av.LayoutTypeTable:
|
||||
if err = gulu.JSON.UnmarshalJSON(data, &view.Table.Sorts); 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
|
||||
}
|
||||
|
|
@ -311,7 +311,7 @@ func addAttributeViewBlock(blockID string, operation *Operation, tree *parse.Tre
|
|||
return
|
||||
}
|
||||
|
||||
switch view.CurrentLayoutType {
|
||||
switch view.LayoutType {
|
||||
case av.LayoutTypeTable:
|
||||
if "" != operation.PreviousID {
|
||||
for i, id := range view.Table.RowIDs {
|
||||
|
|
@ -370,12 +370,12 @@ func setAttributeViewColWidth(operation *Operation) (err error) {
|
|||
return
|
||||
}
|
||||
|
||||
view, err := attrView.GetView(operation.ViewID)
|
||||
view, err := attrView.GetView()
|
||||
if nil != err {
|
||||
return
|
||||
}
|
||||
|
||||
switch view.CurrentLayoutType {
|
||||
switch view.LayoutType {
|
||||
case av.LayoutTypeTable:
|
||||
for _, column := range view.Table.Columns {
|
||||
if column.ID == operation.ID {
|
||||
|
|
@ -403,12 +403,12 @@ func setAttributeViewColWrap(operation *Operation) (err error) {
|
|||
return
|
||||
}
|
||||
|
||||
view, err := attrView.GetView(operation.ViewID)
|
||||
view, err := attrView.GetView()
|
||||
if nil != err {
|
||||
return
|
||||
}
|
||||
|
||||
switch view.CurrentLayoutType {
|
||||
switch view.LayoutType {
|
||||
case av.LayoutTypeTable:
|
||||
for _, column := range view.Table.Columns {
|
||||
if column.ID == operation.ID {
|
||||
|
|
@ -436,12 +436,12 @@ func setAttributeViewColHidden(operation *Operation) (err error) {
|
|||
return
|
||||
}
|
||||
|
||||
view, err := attrView.GetView(operation.ViewID)
|
||||
view, err := attrView.GetView()
|
||||
if nil != err {
|
||||
return
|
||||
}
|
||||
|
||||
switch view.CurrentLayoutType {
|
||||
switch view.LayoutType {
|
||||
case av.LayoutTypeTable:
|
||||
for _, column := range view.Table.Columns {
|
||||
if column.ID == operation.ID {
|
||||
|
|
@ -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
|
||||
}
|
||||
|
|
@ -487,7 +487,7 @@ func sortAttributeViewRow(operation *Operation) (err error) {
|
|||
return
|
||||
}
|
||||
|
||||
switch view.CurrentLayoutType {
|
||||
switch view.LayoutType {
|
||||
case av.LayoutTypeTable:
|
||||
view.Table.RowIDs = append(view.Table.RowIDs[:index], view.Table.RowIDs[index+1:]...)
|
||||
for i, r := range view.Table.RowIDs {
|
||||
|
|
@ -517,12 +517,12 @@ func sortAttributeViewColumn(operation *Operation) (err error) {
|
|||
return
|
||||
}
|
||||
|
||||
view, err := attrView.GetView(operation.ViewID)
|
||||
view, err := attrView.GetView()
|
||||
if nil != err {
|
||||
return
|
||||
}
|
||||
|
||||
switch view.CurrentLayoutType {
|
||||
switch view.LayoutType {
|
||||
case av.LayoutTypeTable:
|
||||
var col *av.ViewTableColumn
|
||||
var index, previousIndex int
|
||||
|
|
@ -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
|
||||
}
|
||||
|
|
@ -576,7 +576,7 @@ func addAttributeViewColumn(operation *Operation) (err error) {
|
|||
key := av.NewKey(operation.Name, keyType)
|
||||
attrView.KeyValues = append(attrView.KeyValues, &av.KeyValues{Key: key})
|
||||
|
||||
switch view.CurrentLayoutType {
|
||||
switch view.LayoutType {
|
||||
case av.LayoutTypeTable:
|
||||
view.Table.Columns = append(view.Table.Columns, &av.ViewTableColumn{ID: key.ID})
|
||||
}
|
||||
|
|
@ -638,7 +638,7 @@ func removeAttributeViewColumn(operation *Operation) (err error) {
|
|||
}
|
||||
|
||||
for _, view := range attrView.Views {
|
||||
switch view.CurrentLayoutType {
|
||||
switch view.LayoutType {
|
||||
case av.LayoutTypeTable:
|
||||
for i, column := range view.Table.Columns {
|
||||
if column.ID == operation.ID {
|
||||
|
|
|
|||
|
|
@ -1052,12 +1052,10 @@ 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"` // 属性视图列类型
|
||||
KeyID string `json:"keyID"` // 属性视列 ID
|
||||
RowID string `json:"rowID"` // 属性视图行 ID(块 ID)
|
||||
|
||||
discard bool // 用于标识是否在事务合并中丢弃
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue