Vanessa 2024-10-17 18:42:17 +08:00
parent f1b77a059d
commit 31520cbde7
2 changed files with 70 additions and 22 deletions

View file

@ -911,33 +911,41 @@ export const showColMenu = (protyle: IProtyle, blockElement: Element, cellElemen
export const removeCol = (options: { export const removeCol = (options: {
protyle: IProtyle, protyle: IProtyle,
data: IAV, data: IAV,
previousID: string,
colData: IAVColumn,
avID: string, avID: string,
blockID: string, blockID: string,
isCustomAttr: boolean isCustomAttr: boolean
menuElement: HTMLElement, menuElement: HTMLElement,
blockElement: Element blockElement: Element
avPanelElement: Element avPanelElement: Element
tabRect: DOMRect tabRect: DOMRect,
isTwoWay: boolean
}) => { }) => {
const colId = options.menuElement.querySelector(".b3-menu__item").getAttribute("data-col-id"); const colId = options.menuElement.querySelector(".b3-menu__item").getAttribute("data-col-id");
let previousID = "";
const colData = options.data.view.columns.find((item: IAVColumn, index) => {
if (item.id === colId) {
previousID = options.data.view.columns[index - 1]?.id;
options.data.view.columns.splice(index, 1);
return true;
}
});
const newUpdated = dayjs().format("YYYYMMDDHHmmss"); const newUpdated = dayjs().format("YYYYMMDDHHmmss");
transaction(options.protyle, [{ transaction(options.protyle, [{
action: "removeAttrViewCol", action: "removeAttrViewCol",
id: colId, id: colId,
avID: options.avID, avID: options.avID,
removeDest: options.isTwoWay
}, { }, {
action: "doUpdateUpdated", action: "doUpdateUpdated",
id: options.blockID, id: options.blockID,
data: newUpdated, data: newUpdated,
}], [{ }], [{
action: "addAttrViewCol", action: "addAttrViewCol",
name: options.colData.name, name: colData.name,
avID: options.avID, avID: options.avID,
type: options.colData.type, type: colData.type,
id: colId, id: colId,
previousID:options.previousID previousID: previousID
}, { }, {
action: "doUpdateUpdated", action: "doUpdateUpdated",
id: options.blockID, id: options.blockID,

View file

@ -1083,33 +1083,35 @@ export const openMenuPanel = (options: {
event.stopPropagation(); event.stopPropagation();
break; break;
} else if (type === "removeCol") { } else if (type === "removeCol") {
if (!isCustomAttr) {
tabRect = options.blockElement.querySelector(".av__views").getBoundingClientRect(); tabRect = options.blockElement.querySelector(".av__views").getBoundingClientRect();
}
const colId = menuElement.querySelector(".b3-menu__item").getAttribute("data-col-id"); const colId = menuElement.querySelector(".b3-menu__item").getAttribute("data-col-id");
let previousID = ""; const colData = data.view.columns.find((item: IAVColumn) => {
const colData = data.view.columns.find((item: IAVColumn, index) => {
if (item.id === colId) { if (item.id === colId) {
previousID = data.view.columns[index - 1]?.id;
data.view.columns.splice(index, 1);
return true; return true;
} }
}); });
if (isCustomAttr || (colData.type === "relation" && colData.relation.isTwoWay)) { const isTwoWay = colData.type === "relation" && colData.relation?.isTwoWay
if (isCustomAttr || isTwoWay) {
const dialog = new Dialog({ const dialog = new Dialog({
title: window.siyuan.languages.removeCol.replace("${x}", menuElement.querySelector("input").value), title: isTwoWay ? window.siyuan.languages.removeCol.replace("${x}", menuElement.querySelector("input").value) : window.siyuan.languages.deleteOpConfirm,
content: `<div class="b3-dialog__content"> content: `<div class="b3-dialog__content">
${window.siyuan.languages.confirmRemoveRelationField.replace("${x}", (menuElement.querySelector('.b3-text-field[data-type="colName"]') as HTMLInputElement).value)} ${isTwoWay ? window.siyuan.languages.confirmRemoveRelationField.replace("${x}", menuElement.querySelector('.b3-menu__item[data-type="goSearchAV"] .b3-menu__accelerator').textContent) : window.siyuan.languages.removeCol.replace("${x}", menuElement.querySelector("input").value)}
</div> <div class="fn__hr--b"></div>
<div class="b3-dialog__action"> <button class="fn__block b3-button b3-button--error">${window.siyuan.languages.delete}</button>
<button class="b3-button b3-button--error">${window.siyuan.languages.delete}</button> <div class="fn__hr"></div>
<button class="b3-button b3-button--warning">${window.siyuan.languages.removeButKeepRelationField}</button> <button class="fn__block b3-button b3-button--warning${isTwoWay ? "" : " fn__none"}">${window.siyuan.languages.removeButKeepRelationField}</button>
<button class="b3-button b3-button--cancel">${window.siyuan.languages.cancel}</button> <div class="fn__hr"></div>
<button class="fn__block b3-button b3-button--info">${window.siyuan.languages.cancel}</button>
</div>`, </div>`,
}); });
} else { dialog.element.addEventListener("click", (event) => {
let target = event.target as HTMLElement;
while (target && !target.isSameNode(dialog.element)) {
if (target.classList.contains("b3-button--error")) {
removeCol({ removeCol({
protyle: options.protyle, protyle: options.protyle,
previousID,
colData,
data, data,
avID, avID,
blockID, blockID,
@ -1117,7 +1119,45 @@ export const openMenuPanel = (options: {
isCustomAttr, isCustomAttr,
blockElement: options.blockElement, blockElement: options.blockElement,
avPanelElement, avPanelElement,
tabRect tabRect,
isTwoWay: true
});
dialog.destroy();
break;
} else if (target.classList.contains("b3-button--warning")) {
removeCol({
protyle: options.protyle,
data,
avID,
blockID,
menuElement,
isCustomAttr,
blockElement: options.blockElement,
avPanelElement,
tabRect,
isTwoWay: false
});
dialog.destroy();
break;
} else if (target.classList.contains("b3-button--info")) {
dialog.destroy();
break;
}
target = target.parentElement;
}
})
} else {
removeCol({
protyle: options.protyle,
data,
avID,
blockID,
menuElement,
isCustomAttr,
blockElement: options.blockElement,
avPanelElement,
tabRect,
isTwoWay: false
}); });
} }
event.preventDefault(); event.preventDefault();