An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
: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.scssindex 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.tsindex 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.tsindex 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.tsindex 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.tsindex 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.tsindex 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: stringdiff --git a/kernel/av/layout_gallery.go b/kernel/av/layout_gallery.goindex 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.goindex 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.goindex 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) (retreturn}+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 *TxErrview.Gallery.CardSize = masterView.Gallery.CardSizeview.Gallery.FitImage = masterView.Gallery.FitImageview.Gallery.DisplayFieldName = masterView.Gallery.DisplayFieldName+ view.Gallery.DisplayEmptyFields = masterView.Gallery.DisplayEmptyFieldsview.Gallery.ShowIcon = masterView.Gallery.ShowIconview.Gallery.WrapField = masterView.Gallery.WrapFieldcase av.LayoutTypeKanban:@@ -3631,6 +3664,7 @@ func (tx *Transaction) doDuplicateAttrViewView(operation *Operation) (ret *TxErrview.Kanban.CardSize = masterView.Kanban.CardSizeview.Kanban.FitImage = masterView.Kanban.FitImageview.Kanban.DisplayFieldName = masterView.Kanban.DisplayFieldName+ view.Kanban.DisplayEmptyFields = masterView.Kanban.DisplayEmptyFieldsview.Kanban.FillColBackgroundColor = masterView.Kanban.FillColBackgroundColorview.Kanban.ShowIcon = masterView.Kanban.ShowIconview.Kanban.WrapField = masterView.Kanban.WrapFielddiff --git a/kernel/model/transaction.go b/kernel/model/transaction.goindex 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.goindex 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, querygroupView.Gallery.CardSize = view.Gallery.CardSizegroupView.Gallery.FitImage = view.Gallery.FitImagegroupView.Gallery.DisplayFieldName = view.Gallery.DisplayFieldName+ groupView.Gallery.DisplayEmptyFields = view.Gallery.DisplayEmptyFieldscase 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, querygroupView.Kanban.CardSize = view.Kanban.CardSizegroupView.Kanban.FitImage = view.Kanban.FitImagegroupView.Kanban.DisplayFieldName = view.Kanban.DisplayFieldName+ groupView.Kanban.DisplayEmptyFields = view.Kanban.DisplayEmptyFieldsgroupView.Kanban.FillColBackgroundColor = view.Kanban.FillColBackgroundColor}if nil != err {diff --git a/kernel/sql/av_gallery.go b/kernel/sql/av_gallery.goindex 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, queryCardSize: 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.goindex 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, queryCardSize: 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{},