mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-09-22 00:20:47 +02:00
🎨 Database gallery view https://github.com/siyuan-note/siyuan/issues/10414
This commit is contained in:
parent
526e436fbc
commit
809e8c151c
4 changed files with 40 additions and 6 deletions
|
@ -97,12 +97,13 @@ type ViewGalleryCardField struct {
|
|||
type Gallery struct {
|
||||
*BaseInstance
|
||||
|
||||
CoverFrom CoverFrom `json:"coverFrom"` // 封面来源
|
||||
CoverFromAssetKeyID string `json:"coverFromAssetKeyID,omitempty"` // 资源字段 ID,CoverFrom 为 CoverFromAssetField 时有效
|
||||
CardSize CardSize `json:"cardSize"` // 卡片大小
|
||||
FitImage bool `json:"fitImage"` // 是否适应封面图片大小
|
||||
ShowIcon bool `json:"showIcon"` // 是否显示字段图标
|
||||
WrapField bool `json:"wrapField"` // 是否换行字段内容
|
||||
CoverFrom CoverFrom `json:"coverFrom"` // 封面来源
|
||||
CoverFromAssetKeyID string `json:"coverFromAssetKeyID,omitempty"` // 资源字段 ID,CoverFrom 为 CoverFromAssetField 时有效
|
||||
CardAspectRatio CardAspectRatio `json:"cardAspectRatio"` // 卡片宽高比
|
||||
CardSize CardSize `json:"cardSize"` // 卡片大小
|
||||
FitImage bool `json:"fitImage"` // 是否适应封面图片大小
|
||||
ShowIcon bool `json:"showIcon"` // 是否显示字段图标
|
||||
WrapField bool `json:"wrapField"` // 是否换行字段内容
|
||||
|
||||
Fields []*GalleryField `json:"fields"` // 画廊字段
|
||||
Cards []*GalleryCard `json:"cards"` // 画廊卡片
|
||||
|
|
|
@ -44,6 +44,36 @@ import (
|
|||
"github.com/xrash/smetrics"
|
||||
)
|
||||
|
||||
func (tx *Transaction) doSetAttrViewCardAspectRatio(operation *Operation) (ret *TxErr) {
|
||||
err := setAttrViewCardSize(operation)
|
||||
if err != nil {
|
||||
return &TxErr{code: TxErrWriteAttributeView, id: operation.AvID, msg: err.Error()}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func setAttrViewCardAspectRatio(operation *Operation) (err error) {
|
||||
attrView, err := av.ParseAttributeView(operation.AvID)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
view, err := getAttrViewViewByBlockID(attrView, operation.BlockID)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
switch view.LayoutType {
|
||||
case av.LayoutTypeTable:
|
||||
return
|
||||
case av.LayoutTypeGallery:
|
||||
view.Gallery.CardAspectRatio = av.CardAspectRatio(operation.Data.(float64))
|
||||
}
|
||||
|
||||
err = av.SaveAttributeView(attrView)
|
||||
return
|
||||
}
|
||||
|
||||
func (tx *Transaction) doSetAttrViewBlockView(operation *Operation) (ret *TxErr) {
|
||||
err := SetDatabaseBlockView(operation.BlockID, operation.AvID, operation.ID)
|
||||
if err != nil {
|
||||
|
|
|
@ -292,6 +292,8 @@ func performTx(tx *Transaction) (ret *TxErr) {
|
|||
ret = tx.doChangeAttrViewLayout(op)
|
||||
case "setAttrViewBlockView":
|
||||
ret = tx.doSetAttrViewBlockView(op)
|
||||
case "setAttrViewCardAspectRatio":
|
||||
ret = tx.doSetAttrViewCardAspectRatio(op)
|
||||
}
|
||||
|
||||
if nil != ret {
|
||||
|
|
|
@ -27,6 +27,7 @@ func RenderAttributeViewGallery(attrView *av.AttributeView, view *av.View, query
|
|||
},
|
||||
CoverFrom: view.Gallery.CoverFrom,
|
||||
CoverFromAssetKeyID: view.Gallery.CoverFromAssetKeyID,
|
||||
CardAspectRatio: view.Gallery.CardAspectRatio,
|
||||
CardSize: view.Gallery.CardSize,
|
||||
FitImage: view.Gallery.FitImage,
|
||||
ShowIcon: view.Gallery.ShowIcon,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue