From 28a790f7eb996779ab1cc9843ef21877944023aa Mon Sep 17 00:00:00 2001 From: Vanessa Date: Sat, 30 Mar 2024 12:11:34 +0800 Subject: [PATCH] :art: fix https://github.com/siyuan-note/siyuan/issues/10796 --- app/src/protyle/render/av/calc.ts | 48 +++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 6 deletions(-) diff --git a/app/src/protyle/render/av/calc.ts b/app/src/protyle/render/av/calc.ts index de8b640e9..559fee18a 100644 --- a/app/src/protyle/render/av/calc.ts +++ b/app/src/protyle/render/av/calc.ts @@ -1,6 +1,7 @@ import {Menu} from "../../../plugin/Menu"; import {transaction} from "../../wysiwyg/transaction"; import {hasClosestBlock, hasClosestByClassName} from "../../util/hasClosest"; +import {fetchSyncPost} from "../../../util/fetch"; const calcItem = (options: { menu: Menu, @@ -74,17 +75,17 @@ const calcItem = (options: { }); }; -export const openCalcMenu = (protyle: IProtyle, calcElement: HTMLElement, panelData?: { +export const openCalcMenu = async (protyle: IProtyle, calcElement: HTMLElement, panelData?: { data: IAV, colId: string, blockID: string }) => { let rowElement: HTMLElement | false; let type; - let colId; - let avId; - let oldOperator; - let blockID; + let colId: string; + let avId: string; + let oldOperator: string; + let blockID: string; if (panelData) { avId = panelData.data.id; type = calcElement.dataset.colType as TAVCol; @@ -250,7 +251,42 @@ export const openCalcMenu = (protyle: IProtyle, calcElement: HTMLElement, panelD target: calcElement }); } - if (["number", "template"].includes(type)) { + let rollupIsNumber = false + if (type === "rollup") { + let relationKeyID: string + let keyID: string + let avData = panelData?.data + if (!avData) { + const avResponse = await fetchSyncPost("api/av/renderAttributeView", {id: avId}); + avData = avResponse.data; + } + avData.view.columns.find((item) => { + if (item.id === colId) { + relationKeyID = item.rollup?.relationKeyID; + keyID = item.rollup?.keyID; + return true + } + }) + if (relationKeyID && keyID) { + let relationAvId: string + avData.view.columns.find((item) => { + if (item.id === relationKeyID) { + relationAvId = item.relation?.avID; + return true + } + }) + if (relationAvId) { + const colResponse = await fetchSyncPost("api/av/getAttributeView", {id: relationAvId}) + colResponse.data.av.keyValues.find((item: { key: { id: string, name: string, type: TAVCol } }) => { + if (item.key.id === keyID) { + rollupIsNumber = item.key.type === "number" + return true + } + }) + } + } + } + if (["number", "template"].includes(type) || rollupIsNumber) { calcItem({ menu, protyle,