Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:sparkles: Support displaying empty fields in database card and kanban views https://github.com/siyuan-note/siyuan/issues/15689

Danielb821f4622cee
diff --git a/app/src/assets/scss/business/_av.scss b/app/src/assets/scss/business/_av.scss
index f3830ea1da..6e2e75593b 100644
--- a/app/src/assets/scss/business/_av.scss
+++ b/app/src/assets/scss/business/_av.scss
@@ -514,11 +514,12 @@
}
}
- &--edit .av__gallery-field[data-empty="true"] .av__gallery-tip {
+ &--edit .av__gallery-field[data-empty="true"] .av__gallery-tip,
+ .av--display-empty-fields & .av__gallery-field[data-empty="true"] .av__gallery-tip {
display: block;
}
- &:not(.av__gallery-fields--edit) [data-empty="true"] {
+ .av:not(.av--display-empty-fields) &:not(.av__gallery-fields--edit) [data-empty="true"] {
display: none;
}
}
diff --git a/app/src/protyle/render/av/gallery/render.ts b/app/src/protyle/render/av/gallery/render.ts
index 1510667981..54a45ebf28 100644
--- a/app/src/protyle/render/av/gallery/render.ts
+++ b/app/src/protyle/render/av/gallery/render.ts
@@ -97,6 +97,7 @@ const renderGroupGallery = (options: ITableOptions) => {
export const afterRenderGallery = (options: ITableOptions) => {
const view = options.data.view as IAVGallery;
+ options.blockElement.classList.toggle("av--display-empty-fields", view.displayEmptyFields);
if (view.coverFrom === 1 || view.coverFrom === 3) {
processRender(options.blockElement);
}
@@ -128,16 +129,18 @@ export const afterRenderGallery = (options: ITableOptions) => {
if (restoredItem) {
updateHeader(restoredItem);
}
- options.resetData.editIds.find(selectId => {
- let itemElement = options.blockElement.querySelector(`.av__body[data-group-id="${selectId.groupId}"] .av__gallery-item[data-id="${selectId.fieldId}"]`) as HTMLElement;
- if (!itemElement) {
- itemElement = options.blockElement.querySelector(`.av__gallery-item[data-id="${selectId.fieldId}"]`) as HTMLElement;
- }
- if (itemElement) {
- itemElement.querySelector(".av__gallery-fields").classList.add("av__gallery-fields--edit");
- itemElement.querySelector('.protyle-icon[data-type="av-gallery-edit"]').setAttribute("aria-label", window.siyuan.languages.hideEmptyFields);
- }
- });
+ if (!view.displayEmptyFields) {
+ options.resetData.editIds.find(selectId => {
+ let itemElement = options.blockElement.querySelector(`.av__body[data-group-id="${selectId.groupId}"] .av__gallery-item[data-id="${selectId.fieldId}"]`) as HTMLElement;
+ if (!itemElement) {
+ itemElement = options.blockElement.querySelector(`.av__gallery-item[data-id="${selectId.fieldId}"]`) as HTMLElement;
+ }
+ if (itemElement) {
+ itemElement.querySelector(".av__gallery-fields").classList.add("av__gallery-fields--edit");
+ itemElement.querySelector('.protyle-icon[data-type="av-gallery-edit"]')?.setAttribute("aria-label", window.siyuan.languages.hideEmptyFields);
+ }
+ });
+ }
Object.keys(options.resetData.pageSizes).forEach((groupId) => {
const bodyElement = options.blockElement.querySelector(`.av__body[data-group-id="${groupId === "unGroup" ? "" : groupId}"]`) as HTMLElement;
if (bodyElement) {
diff --git a/app/src/protyle/render/av/layout.ts b/app/src/protyle/render/av/layout.ts
index 914c9caa99..65214bf330 100644
--- a/app/src/protyle/render/av/layout.ts
+++ b/app/src/protyle/render/av/layout.ts
@@ -51,6 +51,11 @@ export const getLayoutHTML = (data: IAV) => {
<span class="fn__flex-center">${window.siyuan.languages.displayFieldName}</span>
<span class="fn__space fn__flex-1"></span>
<input data-type="toggle-gallery-name" type="checkbox" class="b3-switch b3-switch--menu" ${view.displayFieldName ? "checked" : ""}>
+</label>
+<label class="b3-menu__item">
+ <span class="fn__flex-center">${window.siyuan.languages.displayEmptyFields}</span>
+ <span class="fn__space fn__flex-1"></span>
+ <input data-type="toggle-gallery-empty" type="checkbox" class="b3-switch b3-switch--menu" ${view.displayEmptyFields ? "checked" : ""}>
</label>`;
}
html = `<div class="b3-menu__items">
@@ -215,6 +220,24 @@ export const bindLayoutEvent = (options: {
}]);
(options.data.view as IAVGallery).displayFieldName = checked;
});
+ const toggleEmptyElement = options.menuElement.querySelector('.b3-switch[data-type="toggle-gallery-empty"]') as HTMLInputElement;
+ toggleEmptyElement.addEventListener("change", () => {
+ const checked = toggleEmptyElement.checked;
+ transaction(options.protyle, [{
+ action: "setAttrViewDisplayEmptyFields",
+ avID,
+ blockID,
+ data: checked,
+ viewID
+ }], [{
+ action: "setAttrViewDisplayEmptyFields",
+ avID,
+ blockID,
+ data: !checked,
+ viewID
+ }]);
+ (options.data.view as IAVGallery | IAVKanban).displayEmptyFields = checked;
+ });
if (options.data.viewType === "gallery") {
return;
}
diff --git a/app/src/protyle/render/av/row.ts b/app/src/protyle/render/av/row.ts
index ff9d6d3bdc..7ffee338ad 100644
--- a/app/src/protyle/render/av/row.ts
+++ b/app/src/protyle/render/av/row.ts
@@ -93,8 +93,8 @@ ${cell.color ? `color:${cell.color};` : ""}">${renderCell(cell.value, options.ro
});
html += `</div>
<div class="av__gallery-actions">
- <span class="protyle-icon protyle-icon--first ariaLabel" data-position="4north" aria-label="${window.siyuan.languages.displayEmptyFields}" data-type="av-gallery-edit"><svg><use xlink:href="#iconEdit"></use></svg></span>
- <span class="protyle-icon protyle-icon--last ariaLabel" data-position="4north" aria-label="${window.siyuan.languages.more}" data-type="av-gallery-more"><svg><use xlink:href="#iconMore"></use></svg></span>
+ <span class="protyle-icon protyle-icon--first ariaLabel${kanbanData.displayEmptyFields ? " fn__none" : ""}" data-position="4north" aria-label="${window.siyuan.languages.displayEmptyFields}" data-type="av-gallery-edit"><svg><use xlink:href="#iconEdit"></use></svg></span>
+ <span class="protyle-icon${kanbanData.displayEmptyFields ? " protyle-icon--first" : ""} protyle-icon--last ariaLabel" data-position="4north" aria-label="${window.siyuan.languages.more}" data-type="av-gallery-more"><svg><use xlink:href="#iconMore"></use></svg></span>
</div>
</div>`;
return html;
@@ -159,8 +159,8 @@ ${cell.color ? `color:${cell.color};` : ""}">${renderCell(cell.value, options.ro
});
html += `</div>
<div class="av__gallery-actions">
- <span class="protyle-icon protyle-icon--first ariaLabel" data-position="4north" aria-label="${window.siyuan.languages.displayEmptyFields}" data-type="av-gallery-edit"><svg><use xlink:href="#iconEdit"></use></svg></span>
- <span class="protyle-icon protyle-icon--last ariaLabel" data-position="4north" aria-label="${window.siyuan.languages.more}" data-type="av-gallery-more"><svg><use xlink:href="#iconMore"></use></svg></span>
+ <span class="protyle-icon protyle-icon--first ariaLabel${kanbanData.displayEmptyFields ? " fn__none" : ""}" data-position="4north" aria-label="${window.siyuan.languages.displayEmptyFields}" data-type="av-gallery-edit"><svg><use xlink:href="#iconEdit"></use></svg></span>
+ <span class="protyle-icon${kanbanData.displayEmptyFields ? " protyle-icon--first" : ""} protyle-icon--last ariaLabel" data-position="4north" aria-label="${window.siyuan.languages.more}" data-type="av-gallery-more"><svg><use xlink:href="#iconMore"></use></svg></span>
</div>
</div>`;
return html;
diff --git a/app/src/protyle/wysiwyg/transaction.ts b/app/src/protyle/wysiwyg/transaction.ts
index 82df939773..91b4abca19 100644
--- a/app/src/protyle/wysiwyg/transaction.ts
+++ b/app/src/protyle/wysiwyg/transaction.ts
@@ -1164,7 +1164,7 @@ export const onTransaction = (protyle: IProtyle, operations: IOperation[], isUnd
"duplicateAttrViewKey", "setAttrViewViewDesc", "setAttrViewCoverFrom", "setAttrViewCoverFromAssetKeyID",
"setAttrViewBlockView", "setAttrViewCardSize", "setAttrViewCardAspectRatio", "hideAttrViewName", "setAttrViewShowIcon",
"setAttrViewWrapField", "setAttrViewGroup", "removeAttrViewGroup", "hideAttrViewGroup", "sortAttrViewGroup",
- "foldAttrViewGroup", "hideAttrViewAllGroups", "setAttrViewFitImage", "setAttrViewDisplayFieldName",
+ "foldAttrViewGroup", "hideAttrViewAllGroups", "setAttrViewFitImage", "setAttrViewDisplayFieldName", "setAttrViewDisplayEmptyFields",
"insertAttrViewBlock", "setAttrViewColDateFillSpecificTime", "setAttrViewFillColBackgroundColor", "setAttrViewUpdatedIncludeTime",
"setAttrViewCreatedIncludeTime"].includes(operation.action)) {
protyle.databaseAttributePanel?.refreshForOperation(operation);
diff --git a/app/src/types/index.d.ts b/app/src/types/index.d.ts
index 0c46e24597..4c0dcf26ea 100644
--- a/app/src/types/index.d.ts
+++ b/app/src/types/index.d.ts
@@ -77,6 +77,7 @@ type TOperation =
| "sortAttrViewGroup"
| "foldAttrViewGroup"
| "setAttrViewDisplayFieldName"
+ | "setAttrViewDisplayEmptyFields"
| "setAttrViewFillColBackgroundColor"
| "setAttrViewUpdatedIncludeTime"
| "setAttrViewCreatedIncludeTime"
@@ -1079,6 +1080,7 @@ interface IAVGallery extends IAVView {
cardSize: number; // 0:小卡片,1:中卡片,2:大卡片
cardAspectRatio: number;
displayFieldName: boolean;
+ displayEmptyFields: boolean;
fitImage: boolean;
cards: IAVGalleryItem[],
desc: string
@@ -1092,6 +1094,7 @@ interface IAVKanban extends IAVView {
cardSize: number; // 0:小卡片,1:中卡片,2:大卡片
cardAspectRatio: number;
displayFieldName: boolean;
+ displayEmptyFields: boolean;
fitImage: boolean;
cards: IAVGalleryItem[],
desc: string
diff --git a/kernel/av/layout_gallery.go b/kernel/av/layout_gallery.go
index 09e6184e87..6518240574 100644
--- a/kernel/av/layout_gallery.go
+++ b/kernel/av/layout_gallery.go
@@ -30,6 +30,7 @@ type LayoutGallery struct {
CardSize CardSize `json:"cardSize"` // 卡片大小,0:小卡片,1:中卡片,2:大卡片
FitImage bool `json:"fitImage"` // 是否适应封面图片大小
DisplayFieldName bool `json:"displayFieldName"` // 是否显示字段名称
+ DisplayEmptyFields bool `json:"displayEmptyFields"` // 是否显示空字段
CardFields []*ViewGalleryCardField `json:"fields"` // 卡片字段
@@ -96,6 +97,7 @@ type Gallery struct {
CardSize CardSize `json:"cardSize"` // 卡片大小
FitImage bool `json:"fitImage"` // 是否适应封面图片大小
DisplayFieldName bool `json:"displayFieldName"` // 是否显示字段名称
+ DisplayEmptyFields bool `json:"displayEmptyFields"` // 是否显示空字段
Fields []*GalleryField `json:"fields"` // 卡片字段
Cards []*GalleryCard `json:"cards"` // 卡片
CardCount int `json:"cardCount"` // 总卡片数
diff --git a/kernel/av/layout_kanban.go b/kernel/av/layout_kanban.go
index e52ceb7100..2ce83ed1e5 100644
--- a/kernel/av/layout_kanban.go
+++ b/kernel/av/layout_kanban.go
@@ -30,6 +30,7 @@ type LayoutKanban struct {
CardSize CardSize `json:"cardSize"` // 卡片大小,0:小卡片,1:中卡片,2:大卡片
FitImage bool `json:"fitImage"` // 是否适应封面图片大小
DisplayFieldName bool `json:"displayFieldName"` // 是否显示字段名称
+ DisplayEmptyFields bool `json:"displayEmptyFields"` // 是否显示空字段
FillColBackgroundColor bool `json:"fillColBackgroundColor"` // 是否填充列背景颜色
@@ -64,6 +65,7 @@ type Kanban struct {
CardSize CardSize `json:"cardSize"` // 卡片大小
FitImage bool `json:"fitImage"` // 是否适应封面图片大小
DisplayFieldName bool `json:"displayFieldName"` // 是否显示字段名称
+ DisplayEmptyFields bool `json:"displayEmptyFields"` // 是否显示空字段
FillColBackgroundColor bool `json:"fillColBackgroundColor"` // 是否填充列背景颜色
Fields []*KanbanField `json:"fields"` // 卡片字段
Cards []*KanbanCard `json:"cards"` // 卡片
diff --git a/kernel/model/attribute_view.go b/kernel/model/attribute_view.go
index 272a23f653..b1e37e37ff 100644
--- a/kernel/model/attribute_view.go
+++ b/kernel/model/attribute_view.go
@@ -1244,6 +1244,14 @@ func (tx *Transaction) doSetAttrViewDisplayFieldName(operation *Operation) (ret
return
}
+func (tx *Transaction) doSetAttrViewDisplayEmptyFields(operation *Operation) (ret *TxErr) {
+ err := setAttrViewDisplayEmptyFields(operation)
+ if err != nil {
+ return &TxErr{code: TxErrHandleAttributeView, id: operation.AvID, msg: err.Error()}
+ }
+ return
+}
+
func (tx *Transaction) doSetAttrViewFillColBackgroundColor(operation *Operation) (ret *TxErr) {
err := setAttrViewFillColBackgroundColor(operation)
if err != nil {
@@ -1276,6 +1284,30 @@ func setAttrViewDisplayFieldName(operation *Operation) (err error) {
return
}
+func setAttrViewDisplayEmptyFields(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.DisplayEmptyFields = operation.Data.(bool)
+ case av.LayoutTypeKanban:
+ view.Kanban.DisplayEmptyFields = operation.Data.(bool)
+ }
+
+ err = av.SaveAttributeView(attrView)
+ return
+}
+
func setAttrViewFillColBackgroundColor(operation *Operation) (err error) {
attrView, err := av.ParseAttributeView(operation.AvID)
if err != nil {
@@ -3612,6 +3644,7 @@ func (tx *Transaction) doDuplicateAttrViewView(operation *Operation) (ret *TxErr
view.Gallery.CardSize = masterView.Gallery.CardSize
view.Gallery.FitImage = masterView.Gallery.FitImage
view.Gallery.DisplayFieldName = masterView.Gallery.DisplayFieldName
+ view.Gallery.DisplayEmptyFields = masterView.Gallery.DisplayEmptyFields
view.Gallery.ShowIcon = masterView.Gallery.ShowIcon
view.Gallery.WrapField = masterView.Gallery.WrapField
case av.LayoutTypeKanban:
@@ -3631,6 +3664,7 @@ func (tx *Transaction) doDuplicateAttrViewView(operation *Operation) (ret *TxErr
view.Kanban.CardSize = masterView.Kanban.CardSize
view.Kanban.FitImage = masterView.Kanban.FitImage
view.Kanban.DisplayFieldName = masterView.Kanban.DisplayFieldName
+ view.Kanban.DisplayEmptyFields = masterView.Kanban.DisplayEmptyFields
view.Kanban.FillColBackgroundColor = masterView.Kanban.FillColBackgroundColor
view.Kanban.ShowIcon = masterView.Kanban.ShowIcon
view.Kanban.WrapField = masterView.Kanban.WrapField
diff --git a/kernel/model/transaction.go b/kernel/model/transaction.go
index 005b159b49..f1b7c49a22 100644
--- a/kernel/model/transaction.go
+++ b/kernel/model/transaction.go
@@ -380,6 +380,8 @@ func performTx(tx *Transaction) (ret *TxErr) {
ret = tx.doSetAttrViewFitImage(op)
case "setAttrViewDisplayFieldName":
ret = tx.doSetAttrViewDisplayFieldName(op)
+ case "setAttrViewDisplayEmptyFields":
+ ret = tx.doSetAttrViewDisplayEmptyFields(op)
case "setAttrViewFillColBackgroundColor":
ret = tx.doSetAttrViewFillColBackgroundColor(op)
case "setAttrViewShowIcon":
diff --git a/kernel/sql/av.go b/kernel/sql/av.go
index a5708b5f90..1ff3eb2e8e 100644
--- a/kernel/sql/av.go
+++ b/kernel/sql/av.go
@@ -53,6 +53,7 @@ func RenderGroupView(attrView *av.AttributeView, view, groupView *av.View, query
groupView.Gallery.CardSize = view.Gallery.CardSize
groupView.Gallery.FitImage = view.Gallery.FitImage
groupView.Gallery.DisplayFieldName = view.Gallery.DisplayFieldName
+ groupView.Gallery.DisplayEmptyFields = view.Gallery.DisplayEmptyFields
case av.LayoutTypeKanban:
err = copier.CopyWithOption(&groupView.Kanban.Fields, &view.Kanban.Fields, copier.Option{DeepCopy: true})
groupView.Kanban.ShowIcon = view.Kanban.ShowIcon
@@ -64,6 +65,7 @@ func RenderGroupView(attrView *av.AttributeView, view, groupView *av.View, query
groupView.Kanban.CardSize = view.Kanban.CardSize
groupView.Kanban.FitImage = view.Kanban.FitImage
groupView.Kanban.DisplayFieldName = view.Kanban.DisplayFieldName
+ groupView.Kanban.DisplayEmptyFields = view.Kanban.DisplayEmptyFields
groupView.Kanban.FillColBackgroundColor = view.Kanban.FillColBackgroundColor
}
if nil != err {
diff --git a/kernel/sql/av_gallery.go b/kernel/sql/av_gallery.go
index 563c8b77fe..5baaece9cf 100644
--- a/kernel/sql/av_gallery.go
+++ b/kernel/sql/av_gallery.go
@@ -33,6 +33,7 @@ func RenderAttributeViewGallery(attrView *av.AttributeView, view *av.View, query
CardSize: view.Gallery.CardSize,
FitImage: view.Gallery.FitImage,
DisplayFieldName: view.Gallery.DisplayFieldName,
+ DisplayEmptyFields: view.Gallery.DisplayEmptyFields,
Fields: []*av.GalleryField{},
Cards: []*av.GalleryCard{},
}
diff --git a/kernel/sql/av_kanban.go b/kernel/sql/av_kanban.go
index 239ac10355..b0b8e1cfa3 100644
--- a/kernel/sql/av_kanban.go
+++ b/kernel/sql/av_kanban.go
@@ -27,6 +27,7 @@ func RenderAttributeViewKanban(attrView *av.AttributeView, view *av.View, query
CardSize: view.Kanban.CardSize,
FitImage: view.Kanban.FitImage,
DisplayFieldName: view.Kanban.DisplayFieldName,
+ DisplayEmptyFields: view.Kanban.DisplayEmptyFields,
FillColBackgroundColor: view.Kanban.FillColBackgroundColor,
Fields: []*av.KanbanField{},
Cards: []*av.KanbanCard{},