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 filtering database date fields by start or end date https://github.com/siyuan-note/siyuan/issues/15537
Danielbbf38ece23cc
diff --git a/app/appearance/langs/ar.json b/app/appearance/langs/ar.jsonindex bf8f0fe73c..018ea74354 100644--- a/app/appearance/langs/ar.json+++ b/app/appearance/langs/ar.json@@ -1,4 +1,5 @@{+ "startDate": "تاريخ البدء","addToDictionary": "إضافة إلى القاموس","addToDictionaryFailed": "تعذرت إضافة الكلمة إلى القاموس","freezeDrag": "اسحب لضبط نطاق الأعمدة المجمدة",diff --git a/app/appearance/langs/de.json b/app/appearance/langs/de.jsonindex 8358581fd8..94f3f8bb13 100644--- a/app/appearance/langs/de.json+++ b/app/appearance/langs/de.json@@ -1,4 +1,5 @@{+ "startDate": "Startdatum","addToDictionary": "Zum Wörterbuch hinzufügen","addToDictionaryFailed": "Das Wort konnte nicht zum Wörterbuch hinzugefügt werden","freezeDrag": "Ziehen, um den eingefrorenen Spaltenbereich anzupassen",diff --git a/app/appearance/langs/en.json b/app/appearance/langs/en.jsonindex 65d7e9833e..f6aa92bdfa 100644--- a/app/appearance/langs/en.json+++ b/app/appearance/langs/en.json@@ -1,4 +1,5 @@{+ "startDate": "Start date","addToDictionary": "Add to dictionary","addToDictionaryFailed": "Failed to add the word to the dictionary","freezeDrag": "Drag to adjust the frozen column range",diff --git a/app/appearance/langs/es.json b/app/appearance/langs/es.jsonindex 1748eb23ec..137b1c893e 100644--- a/app/appearance/langs/es.json+++ b/app/appearance/langs/es.json@@ -1,4 +1,5 @@{+ "startDate": "Fecha de inicio","addToDictionary": "Añadir al diccionario","addToDictionaryFailed": "No se pudo añadir la palabra al diccionario","freezeDrag": "Arrastra para ajustar el intervalo de columnas inmovilizadas",diff --git a/app/appearance/langs/fr.json b/app/appearance/langs/fr.jsonindex fc67ff68c7..91c77db618 100644--- a/app/appearance/langs/fr.json+++ b/app/appearance/langs/fr.json@@ -1,4 +1,5 @@{+ "startDate": "Date de début","addToDictionary": "Ajouter au dictionnaire","addToDictionaryFailed": "Impossible d'ajouter le mot au dictionnaire","freezeDrag": "Faites glisser pour ajuster la plage de colonnes gelées",diff --git a/app/appearance/langs/he.json b/app/appearance/langs/he.jsonindex 43be9b0a1e..07c4995cb3 100644--- a/app/appearance/langs/he.json+++ b/app/appearance/langs/he.json@@ -1,4 +1,5 @@{+ "startDate": "תאריך התחלה","addToDictionary": "הוספה למילון","addToDictionaryFailed": "לא ניתן להוסיף את המילה למילון","freezeDrag": "גרור כדי להתאים את טווח העמודות הקפואות",diff --git a/app/appearance/langs/hi.json b/app/appearance/langs/hi.jsonindex f2a52b952a..9381536ad5 100644--- a/app/appearance/langs/hi.json+++ b/app/appearance/langs/hi.json@@ -1,4 +1,5 @@{+ "startDate": "प्रारंभ तिथि","addToDictionary": "शब्दकोश में जोड़ें","addToDictionaryFailed": "शब्द को शब्दकोश में नहीं जोड़ा जा सका","freezeDrag": "फ़्रीज़ किए गए कॉलम की सीमा समायोजित करने के लिए खींचें",diff --git a/app/appearance/langs/id.json b/app/appearance/langs/id.jsonindex 30cded73aa..feea2d62d4 100644--- a/app/appearance/langs/id.json+++ b/app/appearance/langs/id.json@@ -1,4 +1,5 @@{+ "startDate": "Tanggal mulai","addToDictionary": "Tambahkan ke kamus","addToDictionaryFailed": "Kata gagal ditambahkan ke kamus","freezeDrag": "Seret untuk menyesuaikan rentang kolom beku",diff --git a/app/appearance/langs/it.json b/app/appearance/langs/it.jsonindex 052ab1923e..cf53692e5d 100644--- a/app/appearance/langs/it.json+++ b/app/appearance/langs/it.json@@ -1,4 +1,5 @@{+ "startDate": "Data di inizio","addToDictionary": "Aggiungi al dizionario","addToDictionaryFailed": "Impossibile aggiungere la parola al dizionario","freezeDrag": "Trascina per regolare l'intervallo delle colonne bloccate",diff --git a/app/appearance/langs/ja.json b/app/appearance/langs/ja.jsonindex 81767580b3..036968da4c 100644--- a/app/appearance/langs/ja.json+++ b/app/appearance/langs/ja.json@@ -1,4 +1,5 @@{+ "startDate": "開始日","addToDictionary": "辞書に追加","addToDictionaryFailed": "単語を辞書に追加できませんでした","freezeDrag": "ドラッグして固定範囲を調整",diff --git a/app/appearance/langs/ko.json b/app/appearance/langs/ko.jsonindex cae2927971..a5a859e5df 100644--- a/app/appearance/langs/ko.json+++ b/app/appearance/langs/ko.json@@ -1,4 +1,5 @@{+ "startDate": "시작일","addToDictionary": "사전에 추가","addToDictionaryFailed": "단어를 사전에 추가하지 못했습니다","freezeDrag": "드래그하여 고정 열 범위 조정",diff --git a/app/appearance/langs/nl.json b/app/appearance/langs/nl.jsonindex 595228717c..dd07a22e92 100644--- a/app/appearance/langs/nl.json+++ b/app/appearance/langs/nl.json@@ -1,4 +1,5 @@{+ "startDate": "Begindatum","addToDictionary": "Toevoegen aan woordenboek","addToDictionaryFailed": "Het woord kon niet aan het woordenboek worden toegevoegd","freezeDrag": "Sleep om het bereik van bevroren kolommen aan te passen",diff --git a/app/appearance/langs/pl.json b/app/appearance/langs/pl.jsonindex 3e0d132454..5f45e4c51e 100644--- a/app/appearance/langs/pl.json+++ b/app/appearance/langs/pl.json@@ -1,4 +1,5 @@{+ "startDate": "Data rozpoczęcia","addToDictionary": "Dodaj do słownika","addToDictionaryFailed": "Nie udało się dodać słowa do słownika","freezeDrag": "Przeciągnij, aby dostosować zakres zablokowanych kolumn",diff --git a/app/appearance/langs/pt-BR.json b/app/appearance/langs/pt-BR.jsonindex 1e08d1d1f3..d42621d563 100644--- a/app/appearance/langs/pt-BR.json+++ b/app/appearance/langs/pt-BR.json@@ -1,4 +1,5 @@{+ "startDate": "Data inicial","addToDictionary": "Adicionar ao dicionário","addToDictionaryFailed": "Não foi possível adicionar a palavra ao dicionário","freezeDrag": "Arraste para ajustar o intervalo de colunas congeladas",diff --git a/app/appearance/langs/ru.json b/app/appearance/langs/ru.jsonindex 2cc7b0014a..2944e183ad 100644--- a/app/appearance/langs/ru.json+++ b/app/appearance/langs/ru.json@@ -1,4 +1,5 @@{+ "startDate": "Дата начала","addToDictionary": "Добавить в словарь","addToDictionaryFailed": "Не удалось добавить слово в словарь","freezeDrag": "Перетащите, чтобы настроить диапазон закреплённых столбцов",diff --git a/app/appearance/langs/sk.json b/app/appearance/langs/sk.jsonindex ce9d187263..34aca36a73 100644--- a/app/appearance/langs/sk.json+++ b/app/appearance/langs/sk.json@@ -1,4 +1,5 @@{+ "startDate": "Dátum začiatku","addToDictionary": "Pridať do slovníka","addToDictionaryFailed": "Slovo sa nepodarilo pridať do slovníka","freezeDrag": "Potiahnutím upravíte rozsah ukotvených stĺpcov",diff --git a/app/appearance/langs/th.json b/app/appearance/langs/th.jsonindex 70c5081bf5..55ad1cdbff 100644--- a/app/appearance/langs/th.json+++ b/app/appearance/langs/th.json@@ -1,4 +1,5 @@{+ "startDate": "วันที่เริ่มต้น","addToDictionary": "เพิ่มลงในพจนานุกรม","addToDictionaryFailed": "ไม่สามารถเพิ่มคำลงในพจนานุกรมได้","freezeDrag": "ลากเพื่อปรับช่วงคอลัมน์ที่ตรึง",diff --git a/app/appearance/langs/tr.json b/app/appearance/langs/tr.jsonindex a9227ba4e7..222d62ada4 100644--- a/app/appearance/langs/tr.json+++ b/app/appearance/langs/tr.json@@ -1,4 +1,5 @@{+ "startDate": "Başlangıç tarihi","addToDictionary": "Sözlüğe ekle","addToDictionaryFailed": "Sözcük sözlüğe eklenemedi","freezeDrag": "Dondurulmuş sütun aralığını ayarlamak için sürükleyin",diff --git a/app/appearance/langs/uk.json b/app/appearance/langs/uk.jsonindex 786374e823..6b9f07aa46 100644--- a/app/appearance/langs/uk.json+++ b/app/appearance/langs/uk.json@@ -1,4 +1,5 @@{+ "startDate": "Дата початку","addToDictionary": "Додати до словника","addToDictionaryFailed": "Не вдалося додати слово до словника","freezeDrag": "Перетягніть, щоб налаштувати діапазон закріплених стовпців",diff --git a/app/appearance/langs/zh-CN.json b/app/appearance/langs/zh-CN.jsonindex b5f1474323..c148e2eba2 100644--- a/app/appearance/langs/zh-CN.json+++ b/app/appearance/langs/zh-CN.json@@ -1,4 +1,5 @@{+ "startDate": "开始时间","addToDictionary": "添加到词典","addToDictionaryFailed": "无法将单词添加到词典","freezeDrag": "拖拽调整冻结范围",diff --git a/app/appearance/langs/zh-TW.json b/app/appearance/langs/zh-TW.jsonindex 6811c5adb3..13d4856da1 100644--- a/app/appearance/langs/zh-TW.json+++ b/app/appearance/langs/zh-TW.json@@ -1,4 +1,5 @@{+ "startDate": "開始日期","addToDictionary": "加入字典","addToDictionaryFailed": "無法將單字加入字典","freezeDrag": "拖曳調整凍結範圍",diff --git a/app/src/assets/scss/business/_av.scss b/app/src/assets/scss/business/_av.scssindex 8bfbe82679..dd7d3fb056 100644--- a/app/src/assets/scss/business/_av.scss+++ b/app/src/assets/scss/business/_av.scss@@ -1328,6 +1328,22 @@min-width: 60px;}+ .av__filter-date-controls {+ display: inline-flex;+ align-items: center;+ flex: 1;+ flex-wrap: wrap;+ gap: 6px;+ min-width: 60px;+ }++ .av__filter-date-config {+ display: inline-flex;+ align-items: center;+ flex-wrap: wrap;+ gap: 6px;+ }+&.av__filter-panel {min-width: 340px;max-width: 80vw;diff --git a/app/src/protyle/render/av/filter.ts b/app/src/protyle/render/av/filter.tsindex cfb7d0b271..8b9275e125 100644--- a/app/src/protyle/render/av/filter.ts+++ b/app/src/protyle/render/av/filter.ts@@ -593,7 +593,15 @@ const genInlineFilterHTML = (filter: IAVFilter, colData: IAVColumn, path: stringconst isChecked = filterValue?.checkbox?.checked;valueHTML = `<select class="b3-select" data-type="filterValue" data-path="${path}"><option value="true" ${isChecked ? "selected" : ""}>${window.siyuan.languages.checked}</option><option value="false" ${!isChecked ? "selected" : ""}>${window.siyuan.languages.unchecked}</option></select>`;} else if (["date", "created", "updated"].includes(valueType)) {- valueHTML = genInlineDateHTML(filter, valueType, path);+ const dateHTML = genInlineDateHTML(filter, valueType, path);+ valueHTML = dateHTML.valueHTML;+ const endpointSelect = valueType === "date"+ ? `<select class="b3-select" data-type="dateEndpoint" data-path="${path}">+<option value="start"${filter.dateEndpoint !== "end" ? " selected" : ""}>${window.siyuan.languages.startDate}</option>+<option value="end"${filter.dateEndpoint === "end" ? " selected" : ""}>${window.siyuan.languages.endDate}</option>+</select>`+ : "";+ return `<span class="av__filter-date-controls">${quantifierSelect}<span class="av__filter-date-config${valueHidden}">${endpointSelect}${dateHTML.modeHTML}</span>${operatorSelect}<span class="av__filter-value${valueHidden}" data-type="valueContainer" data-path="${path}">${valueHTML}</span></span>`;} else if (valueType === "select" || valueType === "mSelect") {const {trigger, dropdown} = genInlineSelectHTML(filter, valueColumn, path, valueType);valueHTML = trigger;@@ -611,11 +619,15 @@ const genInlineFilterHTML = (filter: IAVFilter, colData: IAVColumn, path: string};// genInlineDateHTML 生成日期类型的内联控件(绝对/相对切换 + Is between 结束日期)。-const genInlineDateHTML = (filter: IAVFilter, valueType: TAVCol, path: string): string => {+const genInlineDateHTML = (filter: IAVFilter, valueType: TAVCol, path: string): {+ modeHTML: string,+ valueHTML: string,+} => {const dateValue = getFilterCellValue(filter)?.[valueType as "date"];const showToday1 = !filter.relativeDate?.direction;const showToday2 = !filter.relativeDate2?.direction;const isBetween = filter.operator === "Is between";+ const isRelative = !!filter.relativeDate;// formatAbsDate 把时间戳格式化为 yyyy-MM-dd;空值/非法值返回 "",避免 <input type="date"> 报 "Invalid Date"。// 0 也视作空值:created/updated 类型的 content 经后端 int64 往返后 null 会变成 0,@@ -628,32 +640,39 @@ const genInlineDateHTML = (filter: IAVFilter, valueType: TAVCol, path: string):return dayObj.isValid() ? dayObj.format("YYYY-MM-DD") : "";};- const dateBlock = (suffix: "" | "2", relativeDate: IAVRelativeDate, dateVal: any, showToday: boolean): string => {- const dateTypeSel = `<select class="b3-select" data-type="dateType${suffix}" data-path="${path}">-<option value="time"${!relativeDate ? " selected" : ""}>${window.siyuan.languages.includeTime}</option>-<option value="custom"${relativeDate ? " selected" : ""}>${window.siyuan.languages.relativeToToday}</option>+ const modeHTML = `<select class="b3-select" data-type="dateType" data-path="${path}">+<option value="time"${!isRelative ? " selected" : ""}>${window.siyuan.languages.includeTime}</option>+<option value="custom"${isRelative ? " selected" : ""}>${window.siyuan.languages.relativeToToday}</option></select>`;- const absDate = `<input value="${(dateVal && (dateVal.isNotEmpty || (suffix === "2" ? dateVal.isNotEmpty2 : valueType !== "date"))) ? formatAbsDate(suffix === "2" ? dateVal.content2 : dateVal.content) : ""}" type="date" max="9999-12-31" class="b3-text-field b3-text-field--text" data-type="absDate${suffix}" data-path="${path}" style="${relativeDate ? "display:none;" : ""}">`;- const relDir = `<select class="b3-select" data-type="dataDirection${suffix}" data-path="${path}" style="${!relativeDate ? "display:none;" : ""}">++ const dateBlock = (suffix: "" | "2", relativeDate: IAVRelativeDate, dateVal: any, showToday: boolean): string => {+ const hasAbsoluteValue = suffix === "2"+ ? dateVal?.isNotEmpty2+ : dateVal && (dateVal.isNotEmpty || valueType !== "date");+ const absDate = `<input value="${hasAbsoluteValue ? formatAbsDate(suffix === "2" ? dateVal.content2 : dateVal.content) : ""}" type="date" max="9999-12-31" class="b3-text-field b3-text-field--text" data-type="absDate${suffix}" data-path="${path}" style="${isRelative ? "display:none;" : ""}">`;+ const relDir = `<select class="b3-select" data-type="dataDirection${suffix}" data-path="${path}" style="${!isRelative ? "display:none;" : ""}"><option value="-1"${relativeDate?.direction === -1 ? " selected" : ""}>${window.siyuan.languages.pastDate}</option><option value="1"${relativeDate?.direction === 1 ? " selected" : ""}>${window.siyuan.languages.nextDate}</option><option value="0"${showToday ? " selected" : ""}>${window.siyuan.languages.current}</option></select>`;// “当前”方向下数量 count 无意义(后端按单位取今天/本周/本月/今年),故仅隐藏 relCount;// 但单位 relUnit 必须保留,以便用户选择天/周/月/年- const relCount = `<input type="number" min="1" step="1" value="${relativeDate?.count || 1}" class="b3-text-field b3-text-field--text av__filter-num" data-type="relCount${suffix}" data-path="${path}" style="${(!relativeDate || showToday) ? "display:none;" : ""}">`;- const relUnit = `<select class="b3-select" data-type="relUnit${suffix}" data-path="${path}" style="${!relativeDate ? "display:none;" : ""}">+ const relCount = `<input type="number" min="1" step="1" value="${relativeDate?.count || 1}" class="b3-text-field b3-text-field--text av__filter-num" data-type="relCount${suffix}" data-path="${path}" style="${(!isRelative || showToday) ? "display:none;" : ""}">`;+ const relUnit = `<select class="b3-select" data-type="relUnit${suffix}" data-path="${path}" style="${!isRelative ? "display:none;" : ""}"><option value="0"${relativeDate?.unit === 0 ? " selected" : ""}>${window.siyuan.languages.day}</option><option value="1"${(!relativeDate || relativeDate?.unit === 1) ? " selected" : ""}>${window.siyuan.languages.week}</option><option value="2"${relativeDate?.unit === 2 ? " selected" : ""}>${window.siyuan.languages.month}</option><option value="3"${relativeDate?.unit === 3 ? " selected" : ""}>${window.siyuan.languages.year}</option></select>`;- return `<span class="av__filter-date-row">${dateTypeSel}${absDate}${relDir}${relCount}${relUnit}</span>`;+ return `<span class="av__filter-date-row">${absDate}${relDir}${relCount}${relUnit}</span>`;};const filter1 = dateBlock("", filter.relativeDate, dateValue, showToday1);const filter2 = dateBlock("2", filter.relativeDate2, dateValue, showToday2);- return `<span class="av__filter-date-col">${filter1}<span data-type="filter2Wrap" data-path="${path}" style="${isBetween ? "" : "display:none;"}">${filter2}</span></span>`;+ return {+ modeHTML,+ valueHTML: `<span class="av__filter-date-col">${filter1}<span data-type="filter2Wrap" data-path="${path}" style="${isBetween ? "" : "display:none;"}">${filter2}</span></span>`,+ };};// genInlineSelectHTML 生成 select/mSelect 的内联多选 chip 列表 + 搜索。@@ -919,6 +938,10 @@ export const bindInlineFilterEvents = (panelElement: HTMLElement, data: IAV, prorelativeDate,relativeDate2,};+ const dateEndpointSel = rowElement.querySelector('[data-type="dateEndpoint"]') as HTMLSelectElement;+ if (dateEndpointSel?.value === "end") {+ newFilter.dateEndpoint = "end";+ }if (quantifierSel) {newFilter.quantifier = quantifierSel.value;}@@ -1056,10 +1079,10 @@ export const bindInlineFilterEvents = (panelElement: HTMLElement, data: IAV, pro(valueType === "relation" && !isRollup &&(isExactRelationOperator(newOp) !== isExactRelationOperator(oldOp)));saveRow(row, path, structureChange);- } else if (type === "quantifier" || type?.startsWith("dataDirection") || type?.startsWith("dateType")) {+ } else if (type === "quantifier" || type === "dateEndpoint" || type?.startsWith("dataDirection") || type === "dateType") {// 量化器、日期方向、日期类型变化:保存。dateType 切换绝对/相对、dataDirection 切换“当前/前/后”// 都会改变 relCount/relUnit 的显示状态,需重渲染- if (type === "dateType" || type === "dateType2" || type?.startsWith("dataDirection")) {+ if (type === "dateType" || type?.startsWith("dataDirection")) {saveRow(row, path, true);} else {saveRow(row, path, false);diff --git a/app/src/types/index.d.ts b/app/src/types/index.d.tsindex 3b9d4d35b5..b37a204f90 100644--- a/app/src/types/index.d.ts+++ b/app/src/types/index.d.ts@@ -1119,6 +1119,7 @@ interface IAVFilter {value?: IAVCellValue, // 叶子节点:过滤值relativeDate?: IAVRelativeDate, // 叶子节点:相对时间relativeDate2?: IAVRelativeDate, // 叶子节点:第二个相对时间+ dateEndpoint?: "start" | "end", // 叶子节点:日期端点,默认为开始时间combination?: "and" | "or", // 分组节点:子条件组合方式filters?: IAVFilter[], // 分组节点:子节点(递归)}diff --git a/kernel/av/filter.go b/kernel/av/filter.goindex b9b7ecffa3..eb1f33ef54 100644--- a/kernel/av/filter.go+++ b/kernel/av/filter.go@@ -36,6 +36,7 @@ type ViewFilter struct {Value *Value `json:"value"` // 过滤值,叶子节点有效RelativeDate *RelativeDate `json:"relativeDate,omitempty"` // 相对时间,叶子节点有效RelativeDate2 *RelativeDate `json:"relativeDate2,omitempty"` // 第二个相对时间,叶子节点有效+ DateEndpoint DateEndpoint `json:"dateEndpoint,omitempty"` // 日期端点,叶子节点有效Combination FilterCombination `json:"combination,omitempty"` // 组合方式,分组节点有效Filters []*ViewFilter `json:"filters,omitempty"` // 子节点,分组节点有效(递归)}@@ -303,6 +304,7 @@ func CloneFilters(filters []*ViewFilter) (ret []*ViewFilter) {Value: f.Value,RelativeDate: f.RelativeDate,RelativeDate2: f.RelativeDate2,+ DateEndpoint: f.DateEndpoint,Combination: f.Combination,}if 0 < len(f.Filters) {@@ -650,7 +652,7 @@ func (value *Value) Filter(filter *ViewFilter, attrView *AttributeView, itemID s}for _, content := range value.Rollup.Contents {- if content.filter(filter.Value.Rollup.Contents[0], filter.RelativeDate, filter.RelativeDate2, filter.Operator) {+ if content.filter(filter.Value.Rollup.Contents[0], filter.RelativeDate, filter.RelativeDate2, filter.Operator, filter.DateEndpoint) {return true}}@@ -696,7 +698,7 @@ func (value *Value) Filter(filter *ViewFilter, attrView *AttributeView, itemID s}for _, content := range value.Rollup.Contents {- if !content.filter(filter.Value.Rollup.Contents[0], filter.RelativeDate, filter.RelativeDate2, filter.Operator) {+ if !content.filter(filter.Value.Rollup.Contents[0], filter.RelativeDate, filter.RelativeDate2, filter.Operator, filter.DateEndpoint) {return false}}@@ -739,7 +741,7 @@ func (value *Value) Filter(filter *ViewFilter, attrView *AttributeView, itemID s}for _, content := range value.Rollup.Contents {- if content.filter(filter.Value.Rollup.Contents[0], filter.RelativeDate, filter.RelativeDate2, filter.Operator) {+ if content.filter(filter.Value.Rollup.Contents[0], filter.RelativeDate, filter.RelativeDate2, filter.Operator, filter.DateEndpoint) {return false}}@@ -776,16 +778,16 @@ func (value *Value) Filter(filter *ViewFilter, attrView *AttributeView, itemID sswitch filter.Operator {case FilterOperatorContains:- if relationValue.filter(filterValue, filter.RelativeDate, filter.RelativeDate2, filter.Operator) {+ if relationValue.filter(filterValue, filter.RelativeDate, filter.RelativeDate2, filter.Operator, filter.DateEndpoint) {return true}case FilterOperatorDoesNotContain:- ret := relationValue.filter(filterValue, filter.RelativeDate, filter.RelativeDate2, filter.Operator)+ ret := relationValue.filter(filterValue, filter.RelativeDate, filter.RelativeDate2, filter.Operator, filter.DateEndpoint)if !ret {return false}default:- if relationValue.filter(filterValue, filter.RelativeDate, filter.RelativeDate2, filter.Operator) {+ if relationValue.filter(filterValue, filter.RelativeDate, filter.RelativeDate2, filter.Operator, filter.DateEndpoint) {return true}}@@ -946,7 +948,7 @@ func (value *Value) Filter(filter *ViewFilter, attrView *AttributeView, itemID sreturn true}}- return value.filter(filter.Value, filter.RelativeDate, filter.RelativeDate2, filter.Operator)+ return value.filter(filter.Value, filter.RelativeDate, filter.RelativeDate2, filter.Operator, filter.DateEndpoint)}// isRollupFilterValueEmpty 判断汇总筛选是否缺少比较值,相对日期仅依赖相对时间配置。@@ -959,7 +961,7 @@ func isRollupFilterValueEmpty(filter *ViewFilter) bool {return nil == v || reflect.ValueOf(v).IsNil()}-func (value *Value) filter(other *Value, relativeDate, relativeDate2 *RelativeDate, operator FilterOperator) bool {+func (value *Value) filter(other *Value, relativeDate, relativeDate2 *RelativeDate, operator FilterOperator, dateEndpoint DateEndpoint) bool {switch operator {case FilterOperatorIsEmpty:return value.IsEmpty()@@ -1009,6 +1011,11 @@ func (value *Value) filter(other *Value, relativeDate, relativeDate2 *RelativeDareturn false}+ valueContent, valueIsNotEmpty := value.Date.GetByEndpoint(dateEndpoint)+ if !valueIsNotEmpty {+ return false+ }+if nil != relativeDate { // 使用相对时间比较// 非 Is between 时前端不会下发 relativeDate2,为 nil 时复用第一段作为安全默认,避免空指针secondRelativeDate := relativeDate2@@ -1017,13 +1024,13 @@ func (value *Value) filter(other *Value, relativeDate, relativeDate2 *RelativeDa}relativeTimeStart, relativeTimeEnd := calcRelativeTimeRegion(relativeDate.Count, relativeDate.Unit, relativeDate.Direction)relativeTimeStart2, relativeTimeEnd2 := calcRelativeTimeRegion(secondRelativeDate.Count, secondRelativeDate.Unit, secondRelativeDate.Direction)- return filterRelativeTime(value.Date.Content, value.Date.IsNotEmpty, operator, relativeTimeStart, relativeTimeEnd, relativeDate.Direction, relativeTimeStart2, relativeTimeEnd2, secondRelativeDate.Direction)+ return filterRelativeTime(valueContent, valueIsNotEmpty, operator, relativeTimeStart, relativeTimeEnd, relativeDate.Direction, relativeTimeStart2, relativeTimeEnd2, secondRelativeDate.Direction)}// 使用具体时间比较if nil == other.Date {return true}- return filterTime(value.Date.Content, value.Date.IsNotEmpty, other.Date.Content, other.Date.Content2, operator)+ return filterTime(valueContent, valueIsNotEmpty, other.Date.Content, other.Date.Content2, operator)}case KeyTypeCreated:if nil != value.Created {diff --git a/kernel/av/filter_test.go b/kernel/av/filter_test.goindex 15f447a42a..7f8f8e826a 100644--- a/kernel/av/filter_test.go+++ b/kernel/av/filter_test.go@@ -185,6 +185,156 @@ func TestRollupRelativeDateFilter(t *testing.T) {}}+func TestDateEndpointFilter(t *testing.T) {+ start := time.Date(2025, time.August, 10, 12, 0, 0, 0, time.Local)+ end := time.Date(2025, time.August, 12, 12, 0, 0, 0, time.Local)+ value := &Value{+ Type: KeyTypeDate,+ Date: &ValueDate{+ Content: start.UnixMilli(),+ IsNotEmpty: true,+ Content2: end.UnixMilli(),+ IsNotEmpty2: true,+ HasEndDate: true,+ },+ }+ startFilterValue := &Value{+ Type: KeyTypeDate,+ Date: &ValueDate{Content: start.UnixMilli(), IsNotEmpty: true},+ }+ endFilterValue := &Value{+ Type: KeyTypeDate,+ Date: &ValueDate{Content: end.UnixMilli(), IsNotEmpty: true},+ }++ if !value.filter(startFilterValue, nil, nil, FilterOperatorIsEqual, DateEndpointStart) {+ t.Fatalf("start endpoint should match the start date")+ }+ if value.filter(startFilterValue, nil, nil, FilterOperatorIsEqual, DateEndpointEnd) {+ t.Fatalf("end endpoint should not match the start date")+ }+ if !value.filter(endFilterValue, nil, nil, FilterOperatorIsEqual, DateEndpointEnd) {+ t.Fatalf("end endpoint should match the end date")+ }+ if !value.filter(startFilterValue, nil, nil, FilterOperatorIsEqual, DateEndpoint("")) {+ t.Fatalf("missing endpoint should default to the start date")+ }++ value.Date.HasEndDate = false+ if !value.filter(startFilterValue, nil, nil, FilterOperatorIsEqual, DateEndpointEnd) {+ t.Fatalf("end endpoint should fall back to the start date when the end date is disabled")+ }++ value.Date.HasEndDate = true+ value.Date.IsNotEmpty2 = false+ value.Date.Content2 = 0+ if value.filter(startFilterValue, nil, nil, FilterOperatorIsNotEqual, DateEndpointEnd) {+ t.Fatalf("an enabled but empty end date should not participate in ordinary comparisons")+ }+}++func TestDateEndpointRelativeAndBetweenFilter(t *testing.T) {+ now := time.Now()+ today := time.Date(now.Year(), now.Month(), now.Day(), 12, 0, 0, 0, now.Location())+ yesterday := today.AddDate(0, 0, -1)+ value := &Value{+ Type: KeyTypeDate,+ Date: &ValueDate{+ Content: yesterday.UnixMilli(),+ IsNotEmpty: true,+ Content2: today.UnixMilli(),+ IsNotEmpty2: true,+ HasEndDate: true,+ },+ }+ relativeDate := &RelativeDate{Count: 1, Unit: RelativeDateUnitDay, Direction: RelativeDateDirectionThis}+ if value.filter(&Value{Type: KeyTypeDate}, relativeDate, nil, FilterOperatorIsEqual, DateEndpointStart) {+ t.Fatalf("yesterday's start date should not match today")+ }+ if !value.filter(&Value{Type: KeyTypeDate}, relativeDate, nil, FilterOperatorIsEqual, DateEndpointEnd) {+ t.Fatalf("today's end date should match the relative today filter")+ }++ betweenValue := &Value{+ Type: KeyTypeDate,+ Date: &ValueDate{+ Content: today.AddDate(0, 0, -2).UnixMilli(),+ IsNotEmpty: true,+ Content2: today.AddDate(0, 0, 2).UnixMilli(),+ IsNotEmpty2: true,+ HasEndDate: true,+ },+ }+ betweenFilterValue := &Value{+ Type: KeyTypeDate,+ Date: &ValueDate{+ Content: today.AddDate(0, 0, 1).UnixMilli(),+ IsNotEmpty: true,+ Content2: today.AddDate(0, 0, 3).UnixMilli(),+ IsNotEmpty2: true,+ HasEndDate: true,+ },+ }+ if betweenValue.filter(betweenFilterValue, nil, nil, FilterOperatorIsBetween, DateEndpointStart) {+ t.Fatalf("start endpoint should be outside the comparison boundaries")+ }+ if !betweenValue.filter(betweenFilterValue, nil, nil, FilterOperatorIsBetween, DateEndpointEnd) {+ t.Fatalf("end endpoint should be inside the comparison boundaries")+ }+}++func TestRollupDateEndpointFilter(t *testing.T) {+ relationKey := NewKey("relation", "关联", "", KeyTypeRelation)+ relationKey.Relation = &Relation{AvID: "target"}+ rollupKey := NewKey("rollup", "汇总", "", KeyTypeRollup)+ rollupKey.Rollup = &Rollup{RelationKeyID: relationKey.ID, KeyID: "date"}+ attrView := &AttributeView{KeyValues: []*KeyValues{+ {Key: relationKey, Values: []*Value{{+ KeyID: relationKey.ID, BlockID: "source-item", Type: KeyTypeRelation,+ Relation: &ValueRelation{BlockIDs: []string{"target-item"}},+ }}},+ {Key: rollupKey},+ }}++ start := time.Date(2025, time.August, 10, 12, 0, 0, 0, time.Local)+ end := time.Date(2025, time.August, 12, 12, 0, 0, 0, time.Local)+ targetDate := &Value{+ KeyID: "date", BlockID: "target-item", Type: KeyTypeDate,+ Date: &ValueDate{+ Content: start.UnixMilli(),+ IsNotEmpty: true,+ Content2: end.UnixMilli(),+ IsNotEmpty2: true,+ HasEndDate: true,+ },+ }+ targetView := &AttributeView{KeyValues: []*KeyValues{{Key: NewKey("date", "日期", "", KeyTypeDate), Values: []*Value{targetDate}}}}++ for _, test := range []struct {+ qualifier FilterQuantifier+ expected bool+ }{+ {qualifier: FilterQuantifierAny, expected: true},+ {qualifier: FilterQuantifierAll, expected: true},+ {qualifier: FilterQuantifierNone, expected: false},+ } {+ value := &Value{KeyID: rollupKey.ID, BlockID: "source-item", Type: KeyTypeRollup, Rollup: &ValueRollup{}}+ filter := &ViewFilter{+ Qualifier: test.qualifier,+ Operator: FilterOperatorIsEqual,+ DateEndpoint: DateEndpointEnd,+ Value: &Value{Type: KeyTypeRollup, Rollup: &ValueRollup{Contents: []*Value{{+ Type: KeyTypeDate,+ Date: &ValueDate{Content: end.UnixMilli(), IsNotEmpty: true},+ }}}},+ }+ actual := value.Filter(filter, attrView, "source-item", map[string]Collection{}, map[string]*AttributeView{"target": targetView})+ if actual != test.expected {+ t.Fatalf("unexpected %s rollup endpoint result: expected %t, got %t", test.qualifier, test.expected, actual)+ }+ }+}+func TestRemoveFiltersByColumn(t *testing.T) {// 树结构:root(AND) → [leaf(c1), group(OR) → [leaf(c2), leaf(c1)]]root := group(FilterCombinationAnd, leaf("c1"), group(FilterCombinationOr, leaf("c2"), leaf("c1")))@@ -418,7 +568,9 @@ func TestRenameSelectOptionInFilters(t *testing.T) {}func TestCloneFilters(t *testing.T) {- original := []*ViewFilter{group(FilterCombinationAnd, leaf("c1"), group(FilterCombinationOr, leaf("c2")))}+ endpointLeaf := leaf("c1")+ endpointLeaf.DateEndpoint = DateEndpointEnd+ original := []*ViewFilter{group(FilterCombinationAnd, endpointLeaf, group(FilterCombinationOr, leaf("c2")))}cloned := CloneFilters(original)if len(cloned) != len(original) {t.Fatalf("clone length mismatch")@@ -432,6 +584,9 @@ func TestCloneFilters(t *testing.T) {if len(cloned[0].Filters[1].Filters) != 1 {t.Fatalf("nested group children not cloned")}+ if DateEndpointEnd != cloned[0].Filters[0].DateEndpoint {+ t.Fatalf("date endpoint not cloned")+ }}func TestPruneInvalidColumnFilters(t *testing.T) {diff --git a/kernel/av/value.go b/kernel/av/value.goindex 451cf97aaa..01fae61afc 100644--- a/kernel/av/value.go+++ b/kernel/av/value.go@@ -624,6 +624,25 @@ type ValueDate struct {FormattedContent string `json:"formattedContent"`}+// DateEndpoint 描述日期筛选或排序使用的时间端点。+type DateEndpoint string++const (+ DateEndpointStart DateEndpoint = "start"+ DateEndpointEnd DateEndpoint = "end"+)++// GetByEndpoint 获取指定端点的时间和值状态,未启用结束时间时回退到开始时间。+func (date *ValueDate) GetByEndpoint(endpoint DateEndpoint) (content int64, isNotEmpty bool) {+ if nil == date {+ return+ }+ if DateEndpointEnd == endpoint && date.HasEndDate {+ return date.Content2, date.IsNotEmpty2+ }+ return date.Content, date.IsNotEmpty+}+type DateFormat stringconst (