mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-21 09:00:12 +01:00
♻️ Refactor av
This commit is contained in:
parent
67b8566047
commit
28095c5ef7
6 changed files with 112 additions and 87 deletions
|
|
@ -16,7 +16,7 @@
|
||||||
|
|
||||||
package av
|
package av
|
||||||
|
|
||||||
// BaseLayout 描述了布局的基础结构,包含通用的过滤、排序和分页信息。
|
// BaseLayout 描述了布局的基础结构。
|
||||||
type BaseLayout struct {
|
type BaseLayout struct {
|
||||||
Spec int `json:"spec"` // 布局格式版本
|
Spec int `json:"spec"` // 布局格式版本
|
||||||
ID string `json:"id"` // 布局 ID
|
ID string `json:"id"` // 布局 ID
|
||||||
|
|
@ -24,3 +24,32 @@ type BaseLayout struct {
|
||||||
Sorts []*ViewSort `json:"sorts"` // 排序规则
|
Sorts []*ViewSort `json:"sorts"` // 排序规则
|
||||||
PageSize int `json:"pageSize"` // 每页行数
|
PageSize int `json:"pageSize"` // 每页行数
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// BaseValue 描述了字段值的基础结构。
|
||||||
|
type BaseValue struct {
|
||||||
|
ID string `json:"id"` // 字段值 ID
|
||||||
|
Value *Value `json:"value"` // 字段值
|
||||||
|
ValueType KeyType `json:"valueType"` // 字段值类型
|
||||||
|
}
|
||||||
|
|
||||||
|
// BaseInstance 描述了实例的基础结构。
|
||||||
|
type BaseInstance struct {
|
||||||
|
ID string `json:"id"` // ID
|
||||||
|
Icon string `json:"icon"` // 图标
|
||||||
|
Name string `json:"name"` // 名称
|
||||||
|
Desc string `json:"desc"` // 描述
|
||||||
|
HideAttrViewName bool `json:"hideAttrViewName"` // 是否隐藏属性视图名称
|
||||||
|
Filters []*ViewFilter `json:"filters"` // 过滤规则
|
||||||
|
Sorts []*ViewSort `json:"sorts"` // 排序规则
|
||||||
|
PageSize int `json:"pageSize"` // 每页项目
|
||||||
|
}
|
||||||
|
|
||||||
|
// BaseInstanceField 描述了实例字段的基础结构。
|
||||||
|
type BaseInstanceField struct {
|
||||||
|
ID string `json:"id"` // ID
|
||||||
|
Name string `json:"name"` // 字段名
|
||||||
|
Type KeyType `json:"type"` // 字段类型
|
||||||
|
Icon string `json:"icon"` // 字段图标
|
||||||
|
Hidden bool `json:"hidden"` // 是否隐藏
|
||||||
|
Desc string `json:"desc"` // 字段描述
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -38,17 +38,11 @@ type ViewGalleryCardField struct {
|
||||||
|
|
||||||
// Gallery 描述了画廊实例的结构。
|
// Gallery 描述了画廊实例的结构。
|
||||||
type Gallery struct {
|
type Gallery struct {
|
||||||
ID string `json:"id"` // 画廊布局 ID
|
*BaseInstance
|
||||||
Icon string `json:"icon"` // 画廊图标
|
|
||||||
Name string `json:"name"` // 画廊名称
|
|
||||||
Desc string `json:"desc"` // 画廊描述
|
|
||||||
HideAttrViewName bool `json:"hideAttrViewName"` // 是否隐藏属性视图名称
|
|
||||||
Filters []*ViewFilter `json:"filters"` // 过滤规则
|
|
||||||
Sorts []*ViewSort `json:"sorts"` // 排序规则
|
|
||||||
Fields []*GalleryField `json:"fields"` // 画廊字段
|
Fields []*GalleryField `json:"fields"` // 画廊字段
|
||||||
Cards []*GalleryCard `json:"cards"` // 画廊卡片
|
Cards []*GalleryCard `json:"cards"` // 画廊卡片
|
||||||
CardCount int `json:"cardCount"` // 画廊总卡片数
|
CardCount int `json:"cardCount"` // 画廊总卡片数
|
||||||
PageSize int `json:"pageSize"` // 每页卡片数
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GalleryCard 描述了画廊实例卡片的结构。
|
// GalleryCard 描述了画廊实例卡片的结构。
|
||||||
|
|
@ -61,12 +55,7 @@ type GalleryCard struct {
|
||||||
|
|
||||||
// GalleryField 描述了画廊实例卡片字段的结构。
|
// GalleryField 描述了画廊实例卡片字段的结构。
|
||||||
type GalleryField struct {
|
type GalleryField struct {
|
||||||
ID string `json:"id"` // 字段 ID
|
*BaseInstanceField
|
||||||
Name string `json:"name"` // 字段名
|
|
||||||
Type KeyType `json:"type"` // 字段类型
|
|
||||||
Icon string `json:"icon"` // 字段图标
|
|
||||||
Hidden bool `json:"hidden"` // 是否隐藏
|
|
||||||
Desc string `json:"desc"` // 字段描述
|
|
||||||
|
|
||||||
// 以下是某些字段类型的特有属性
|
// 以下是某些字段类型的特有属性
|
||||||
|
|
||||||
|
|
@ -80,9 +69,7 @@ type GalleryField struct {
|
||||||
|
|
||||||
// GalleryFieldValue 描述了画廊实例字段值的结构。
|
// GalleryFieldValue 描述了画廊实例字段值的结构。
|
||||||
type GalleryFieldValue struct {
|
type GalleryFieldValue struct {
|
||||||
ID string `json:"id"` // 字段值 ID
|
*BaseValue
|
||||||
Value *Value `json:"value"` // 字段值
|
|
||||||
ValueType KeyType `json:"valueType"` // 字段值类型
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (card *GalleryCard) GetBlockValue() (ret *Value) {
|
func (card *GalleryCard) GetBlockValue() (ret *Value) {
|
||||||
|
|
|
||||||
|
|
@ -42,30 +42,20 @@ type ViewTableColumn struct {
|
||||||
|
|
||||||
// Table 描述了表格实例的结构。
|
// Table 描述了表格实例的结构。
|
||||||
type Table struct {
|
type Table struct {
|
||||||
ID string `json:"id"` // 表格布局 ID
|
*BaseInstance
|
||||||
Icon string `json:"icon"` // 表格图标
|
|
||||||
Name string `json:"name"` // 表格名称
|
|
||||||
Desc string `json:"desc"` // 表格描述
|
|
||||||
HideAttrViewName bool `json:"hideAttrViewName"` // 是否隐藏属性视图名称
|
|
||||||
Filters []*ViewFilter `json:"filters"` // 过滤规则
|
|
||||||
Sorts []*ViewSort `json:"sorts"` // 排序规则
|
|
||||||
Columns []*TableColumn `json:"columns"` // 表格列
|
Columns []*TableColumn `json:"columns"` // 表格列
|
||||||
Rows []*TableRow `json:"rows"` // 表格行
|
Rows []*TableRow `json:"rows"` // 表格行
|
||||||
RowCount int `json:"rowCount"` // 表格总行数
|
RowCount int `json:"rowCount"` // 表格总行数
|
||||||
PageSize int `json:"pageSize"` // 每页行数
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TableColumn 描述了表格实例列的结构。
|
// TableColumn 描述了表格实例列的结构。
|
||||||
type TableColumn struct {
|
type TableColumn struct {
|
||||||
ID string `json:"id"` // 列 ID
|
*BaseInstanceField
|
||||||
Name string `json:"name"` // 列名
|
|
||||||
Type KeyType `json:"type"` // 列类型
|
|
||||||
Icon string `json:"icon"` // 列图标
|
|
||||||
Wrap bool `json:"wrap"` // 是否换行
|
Wrap bool `json:"wrap"` // 是否换行
|
||||||
Hidden bool `json:"hidden"` // 是否隐藏
|
|
||||||
Pin bool `json:"pin"` // 是否固定
|
Pin bool `json:"pin"` // 是否固定
|
||||||
Width string `json:"width"` // 列宽度
|
Width string `json:"width"` // 列宽度
|
||||||
Desc string `json:"desc"` // 列描述
|
|
||||||
Calc *ColumnCalc `json:"calc"` // 计算
|
Calc *ColumnCalc `json:"calc"` // 计算
|
||||||
|
|
||||||
// 以下是某些列类型的特有属性
|
// 以下是某些列类型的特有属性
|
||||||
|
|
@ -86,9 +76,8 @@ type TableRow struct {
|
||||||
|
|
||||||
// TableCell 描述了表格实例单元格的结构。
|
// TableCell 描述了表格实例单元格的结构。
|
||||||
type TableCell struct {
|
type TableCell struct {
|
||||||
ID string `json:"id"` // 单元格 ID
|
*BaseValue
|
||||||
Value *Value `json:"value"` // 单元格值
|
|
||||||
ValueType KeyType `json:"valueType"` // 单元格值类型
|
|
||||||
Color string `json:"color"` // 单元格颜色
|
Color string `json:"color"` // 单元格颜色
|
||||||
BgColor string `json:"bgColor"` // 单元格背景颜色
|
BgColor string `json:"bgColor"` // 单元格背景颜色
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1599,6 +1599,10 @@ func (tx *Transaction) doAddAttrViewView(operation *Operation) (ret *TxErr) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if "" == operation.Layout {
|
||||||
|
operation.Layout = av.LayoutTypeTable
|
||||||
|
}
|
||||||
|
|
||||||
var view *av.View
|
var view *av.View
|
||||||
switch operation.Layout {
|
switch operation.Layout {
|
||||||
case av.LayoutTypeTable:
|
case av.LayoutTypeTable:
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ import (
|
||||||
|
|
||||||
func RenderAttributeViewGallery(attrView *av.AttributeView, view *av.View, query string) (ret *av.Gallery) {
|
func RenderAttributeViewGallery(attrView *av.AttributeView, view *av.View, query string) (ret *av.Gallery) {
|
||||||
ret = &av.Gallery{
|
ret = &av.Gallery{
|
||||||
|
BaseInstance: &av.BaseInstance{
|
||||||
ID: view.ID,
|
ID: view.ID,
|
||||||
Icon: view.Icon,
|
Icon: view.Icon,
|
||||||
Name: view.Name,
|
Name: view.Name,
|
||||||
|
|
@ -21,6 +22,7 @@ func RenderAttributeViewGallery(attrView *av.AttributeView, view *av.View, query
|
||||||
HideAttrViewName: view.HideAttrViewName,
|
HideAttrViewName: view.HideAttrViewName,
|
||||||
Filters: view.Gallery.Filters,
|
Filters: view.Gallery.Filters,
|
||||||
Sorts: view.Gallery.Sorts,
|
Sorts: view.Gallery.Sorts,
|
||||||
|
},
|
||||||
Fields: []*av.GalleryField{},
|
Fields: []*av.GalleryField{},
|
||||||
Cards: []*av.GalleryCard{},
|
Cards: []*av.GalleryCard{},
|
||||||
}
|
}
|
||||||
|
|
@ -35,12 +37,14 @@ func RenderAttributeViewGallery(attrView *av.AttributeView, view *av.View, query
|
||||||
}
|
}
|
||||||
|
|
||||||
ret.Fields = append(ret.Fields, &av.GalleryField{
|
ret.Fields = append(ret.Fields, &av.GalleryField{
|
||||||
|
BaseInstanceField: &av.BaseInstanceField{
|
||||||
ID: key.ID,
|
ID: key.ID,
|
||||||
Name: key.Name,
|
Name: key.Name,
|
||||||
Type: key.Type,
|
Type: key.Type,
|
||||||
Icon: key.Icon,
|
Icon: key.Icon,
|
||||||
Hidden: field.Hidden,
|
Hidden: field.Hidden,
|
||||||
Desc: key.Desc,
|
Desc: key.Desc,
|
||||||
|
},
|
||||||
Options: key.Options,
|
Options: key.Options,
|
||||||
NumberFormat: key.NumberFormat,
|
NumberFormat: key.NumberFormat,
|
||||||
Template: key.Template,
|
Template: key.Template,
|
||||||
|
|
@ -103,17 +107,21 @@ func RenderAttributeViewGallery(attrView *av.AttributeView, view *av.View, query
|
||||||
for _, keyValues := range card {
|
for _, keyValues := range card {
|
||||||
if keyValues.Key.ID == field.ID {
|
if keyValues.Key.ID == field.ID {
|
||||||
fieldValue = &av.GalleryFieldValue{
|
fieldValue = &av.GalleryFieldValue{
|
||||||
|
BaseValue: &av.BaseValue{
|
||||||
ID: keyValues.Values[0].ID,
|
ID: keyValues.Values[0].ID,
|
||||||
Value: keyValues.Values[0],
|
Value: keyValues.Values[0],
|
||||||
ValueType: field.Type,
|
ValueType: field.Type,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if nil == fieldValue {
|
if nil == fieldValue {
|
||||||
fieldValue = &av.GalleryFieldValue{
|
fieldValue = &av.GalleryFieldValue{
|
||||||
|
BaseValue: &av.BaseValue{
|
||||||
ID: ast.NewNodeID(),
|
ID: ast.NewNodeID(),
|
||||||
ValueType: field.Type,
|
ValueType: field.Type,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
galleryCard.ID = cardID
|
galleryCard.ID = cardID
|
||||||
|
|
|
||||||
|
|
@ -28,15 +28,17 @@ import (
|
||||||
|
|
||||||
func RenderAttributeViewTable(attrView *av.AttributeView, view *av.View, query string) (ret *av.Table) {
|
func RenderAttributeViewTable(attrView *av.AttributeView, view *av.View, query string) (ret *av.Table) {
|
||||||
ret = &av.Table{
|
ret = &av.Table{
|
||||||
|
BaseInstance: &av.BaseInstance{
|
||||||
ID: view.ID,
|
ID: view.ID,
|
||||||
Icon: view.Icon,
|
Icon: view.Icon,
|
||||||
Name: view.Name,
|
Name: view.Name,
|
||||||
Desc: view.Desc,
|
Desc: view.Desc,
|
||||||
HideAttrViewName: view.HideAttrViewName,
|
HideAttrViewName: view.HideAttrViewName,
|
||||||
Columns: []*av.TableColumn{},
|
|
||||||
Rows: []*av.TableRow{},
|
|
||||||
Filters: view.Table.Filters,
|
Filters: view.Table.Filters,
|
||||||
Sorts: view.Table.Sorts,
|
Sorts: view.Table.Sorts,
|
||||||
|
},
|
||||||
|
Columns: []*av.TableColumn{},
|
||||||
|
Rows: []*av.TableRow{},
|
||||||
}
|
}
|
||||||
|
|
||||||
// 组装列
|
// 组装列
|
||||||
|
|
@ -49,10 +51,14 @@ func RenderAttributeViewTable(attrView *av.AttributeView, view *av.View, query s
|
||||||
}
|
}
|
||||||
|
|
||||||
ret.Columns = append(ret.Columns, &av.TableColumn{
|
ret.Columns = append(ret.Columns, &av.TableColumn{
|
||||||
|
BaseInstanceField: &av.BaseInstanceField{
|
||||||
ID: key.ID,
|
ID: key.ID,
|
||||||
Name: key.Name,
|
Name: key.Name,
|
||||||
Type: key.Type,
|
Type: key.Type,
|
||||||
Icon: key.Icon,
|
Icon: key.Icon,
|
||||||
|
Hidden: col.Hidden,
|
||||||
|
Desc: key.Desc,
|
||||||
|
},
|
||||||
Options: key.Options,
|
Options: key.Options,
|
||||||
NumberFormat: key.NumberFormat,
|
NumberFormat: key.NumberFormat,
|
||||||
Template: key.Template,
|
Template: key.Template,
|
||||||
|
|
@ -60,9 +66,7 @@ func RenderAttributeViewTable(attrView *av.AttributeView, view *av.View, query s
|
||||||
Rollup: key.Rollup,
|
Rollup: key.Rollup,
|
||||||
Date: key.Date,
|
Date: key.Date,
|
||||||
Wrap: col.Wrap,
|
Wrap: col.Wrap,
|
||||||
Hidden: col.Hidden,
|
|
||||||
Width: col.Width,
|
Width: col.Width,
|
||||||
Desc: key.Desc,
|
|
||||||
Pin: col.Pin,
|
Pin: col.Pin,
|
||||||
Calc: col.Calc,
|
Calc: col.Calc,
|
||||||
})
|
})
|
||||||
|
|
@ -121,17 +125,21 @@ func RenderAttributeViewTable(attrView *av.AttributeView, view *av.View, query s
|
||||||
for _, keyValues := range row {
|
for _, keyValues := range row {
|
||||||
if keyValues.Key.ID == col.ID {
|
if keyValues.Key.ID == col.ID {
|
||||||
tableCell = &av.TableCell{
|
tableCell = &av.TableCell{
|
||||||
|
BaseValue: &av.BaseValue{
|
||||||
ID: keyValues.Values[0].ID,
|
ID: keyValues.Values[0].ID,
|
||||||
Value: keyValues.Values[0],
|
Value: keyValues.Values[0],
|
||||||
ValueType: col.Type,
|
ValueType: col.Type,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if nil == tableCell {
|
if nil == tableCell {
|
||||||
tableCell = &av.TableCell{
|
tableCell = &av.TableCell{
|
||||||
|
BaseValue: &av.BaseValue{
|
||||||
ID: ast.NewNodeID(),
|
ID: ast.NewNodeID(),
|
||||||
ValueType: col.Type,
|
ValueType: col.Type,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tableRow.ID = rowID
|
tableRow.ID = rowID
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue