diff --git a/app/src/protyle/render/av/openMenuPanel.ts b/app/src/protyle/render/av/openMenuPanel.ts index 71411c90b..e80627b54 100644 --- a/app/src/protyle/render/av/openMenuPanel.ts +++ b/app/src/protyle/render/av/openMenuPanel.ts @@ -765,7 +765,12 @@ export const openMenuPanel = (options: { event.stopPropagation(); break; } else if (type === "goSearchRollupCol") { - goSearchRollupCol(avID, target); + goSearchRollupCol({ + target, + data, + protyle: options.protyle, + colId: menuElement.querySelector(".b3-menu__item").getAttribute("data-col-id") + }); event.preventDefault(); event.stopPropagation(); break; diff --git a/app/src/protyle/render/av/rollup.ts b/app/src/protyle/render/av/rollup.ts index d30377903..1b57ea333 100644 --- a/app/src/protyle/render/av/rollup.ts +++ b/app/src/protyle/render/av/rollup.ts @@ -4,27 +4,44 @@ import {upDownHint} from "../../../util/upDownHint"; import {fetchPost} from "../../../util/fetch"; import {escapeHtml} from "../../../util/escape"; import {transaction} from "../../wysiwyg/transaction"; -import {updateCellsValue} from "./cell"; -import {updateAttrViewCellAnimation} from "./action"; -import {focusBlock} from "../../util/selection"; +import {genIconHTML} from "../util"; +import {unicode2Emoji} from "../../../emoji"; +import {getColIconByType} from "./col"; + +const updateCol = (protyle: IProtyle, data: IAV, colId: string, itemElement: HTMLElement) => { + const colData = data.view.columns.find((item) => { + if (item.id === colId) { + return true; + } + }) + transaction(protyle, [{ + action: "updateAttrViewColRollup", + id: colId, + avID: data.id, + parentID: itemElement.dataset.colId, + // keyID: "", + // data: "", + }], [{ + action: "updateAttrViewColRollup", + // operation.AvID 汇总列所在 av + // operation.ID 汇总列 ID + // operation.ParentID 汇总列基于的关联列 ID + // operation.KeyID 目标列 ID + // operation.Data 计算方式 + }]) +} const genSearchList = (element: Element, keyword: string, avId: string, cb?: () => void) => { - fetchPost("/api/av/searchAttributeViewNonRelationKey", {keyword}, (response) => { + fetchPost("/api/av/searchAttributeViewNonRelationKey", { + avID: avId, + keyword + }, (response) => { let html = ""; - response.data.results.forEach((item: { - avID: string - avName: string - blockID: string - hPath: string - }, index: number) => { - html += `
-
-
- ${escapeHtml(item.avName || window.siyuan.languages.title)} -
-
${escapeHtml(item.hPath)}
-
- + response.data.nonRelationKeys.forEach((item: IAVColumn, index: number) => { + html += `
+ ${item.icon ? unicode2Emoji(item.icon, "b3-list-item__graphic", true) : ``} + ${genIconHTML()} + ${escapeHtml(item.name || window.siyuan.languages.title)}
`; }); element.innerHTML = html; @@ -34,7 +51,12 @@ const genSearchList = (element: Element, keyword: string, avId: string, cb?: () }); }; -export const goSearchRollupCol = (avId: string, target: HTMLElement) => { +export const goSearchRollupCol = (options: { + target: HTMLElement, + data: IAV, + protyle: IProtyle, + colId: string +}) => { window.siyuan.menus.menu.remove(); const menu = new Menu(); menu.addItem({ @@ -61,24 +83,24 @@ export const goSearchRollupCol = (avId: string, target: HTMLElement) => { if (event.key === "Enter") { event.preventDefault(); event.stopPropagation(); - // setDatabase(avId, target, listElement.querySelector(".b3-list-item--focus")); + updateCol(options.protyle, options.data, options.colId, listElement.querySelector(".b3-list-item--focus")); window.siyuan.menus.menu.remove(); } }); inputElement.addEventListener("input", (event) => { event.stopPropagation(); - genSearchList(listElement, inputElement.value, avId); + genSearchList(listElement, inputElement.value, options.data.id); }); element.lastElementChild.addEventListener("click", (event) => { const listItemElement = hasClosestByClassName(event.target as HTMLElement, "b3-list-item"); if (listItemElement) { event.stopPropagation(); - // setDatabase(avId, target, listItemElement); + updateCol(options.protyle, options.data, options.colId, listItemElement); window.siyuan.menus.menu.remove(); } }); - genSearchList(listElement, "", avId, () => { - const rect = target.getBoundingClientRect(); + genSearchList(listElement, "", options.data.id, () => { + const rect = options.target.getBoundingClientRect(); menu.open({ x: rect.left, y: rect.bottom, diff --git a/app/src/protyle/wysiwyg/transaction.ts b/app/src/protyle/wysiwyg/transaction.ts index 8c1ac0fd1..f9ccf52ab 100644 --- a/app/src/protyle/wysiwyg/transaction.ts +++ b/app/src/protyle/wysiwyg/transaction.ts @@ -724,7 +724,7 @@ export const onTransaction = (protyle: IProtyle, operation: IOperation, isUndo: "setAttrViewSorts", "setAttrViewColCalc", "removeAttrViewCol", "updateAttrViewColNumberFormat", "removeAttrViewBlock", "replaceAttrViewBlock", "updateAttrViewColTemplate", "setAttrViewColPin", "addAttrViewView", "removeAttrViewView", "setAttrViewViewName", "setAttrViewViewIcon", "duplicateAttrViewView", "sortAttrViewView", - "updateAttrViewColRelation", "setAttrViewPageSize"].includes(operation.action)) { + "updateAttrViewColRelation", "setAttrViewPageSize", "updateAttrViewColRollup"].includes(operation.action)) { refreshAV(protyle, operation, isUndo); } else if (operation.action === "doUpdateUpdated") { updateElements.forEach(item => { diff --git a/app/src/types/index.d.ts b/app/src/types/index.d.ts index 0fca83448..25efb5299 100644 --- a/app/src/types/index.d.ts +++ b/app/src/types/index.d.ts @@ -50,6 +50,7 @@ type TOperation = | "sortAttrViewView" | "setAttrViewPageSize" | "updateAttrViewColRelation" + | "updateAttrViewColRollup" type TBazaarType = "templates" | "icons" | "widgets" | "themes" | "plugins" type TCardType = "doc" | "notebook" | "all" type TEventBus = "ws-main" | "sync-start" | "sync-end" | "sync-fail" |