This commit is contained in:
parent
2d72443d28
commit
86fab2b36a
1 changed files with 110 additions and 24 deletions
|
@ -1,6 +1,6 @@
|
|||
import {Menu} from "../../../plugin/Menu";
|
||||
import {transaction} from "../../wysiwyg/transaction";
|
||||
import {fetchPost} from "../../../util/fetch";
|
||||
import {fetchPost, fetchSyncPost} from "../../../util/fetch";
|
||||
import {getDefaultOperatorByType, setFilter} from "./filter";
|
||||
import {genCellValue} from "./cell";
|
||||
import {getPropertiesHTML, openMenuPanel} from "./openMenuPanel";
|
||||
|
@ -14,6 +14,7 @@ import {Constants} from "../../../constants";
|
|||
import * as dayjs from "dayjs";
|
||||
import {setPosition} from "../../../util/setPosition";
|
||||
import {duplicateNameAddOne} from "../../../util/functions";
|
||||
import {Dialog} from "../../../dialog";
|
||||
|
||||
export const duplicateCol = (options: {
|
||||
protyle: IProtyle,
|
||||
|
@ -845,30 +846,78 @@ export const showColMenu = (protyle: IProtyle, blockElement: Element, cellElemen
|
|||
menu.addItem({
|
||||
icon: "iconTrashcan",
|
||||
label: window.siyuan.languages.delete,
|
||||
click() {
|
||||
const newUpdated = dayjs().format("YYYYMMDDHHmmss");
|
||||
transaction(protyle, [{
|
||||
action: "removeAttrViewCol",
|
||||
id: colId,
|
||||
async click() {
|
||||
if (type === "relation") {
|
||||
const response = await fetchSyncPost("/api/av/getAttributeView", {id: avID})
|
||||
const colData = response.data.av.keyValues.find((item: {
|
||||
key: { id: string }
|
||||
}) => item.key.id === colId);
|
||||
if (colData.key.relation?.isTwoWay) {
|
||||
const relResponse = await fetchSyncPost("/api/av/getAttributeView", {id: colData.key.relation.avID})
|
||||
const dialog = new Dialog({
|
||||
title: window.siyuan.languages.removeCol.replace("${x}", colData.key.name),
|
||||
content: `<div class="b3-dialog__content">
|
||||
${window.siyuan.languages.confirmRemoveRelationField.replace("${x}", relResponse.data.av.name)}
|
||||
<div class="fn__hr--b"></div>
|
||||
<button class="fn__block b3-button b3-button--error">${window.siyuan.languages.delete}</button>
|
||||
<div class="fn__hr"></div>
|
||||
<button class="fn__block b3-button b3-button--warning">${window.siyuan.languages.removeButKeepRelationField}</button>
|
||||
<div class="fn__hr"></div>
|
||||
<button class="fn__block b3-button b3-button--info">${window.siyuan.languages.cancel}</button>
|
||||
</div>`,
|
||||
});
|
||||
dialog.element.addEventListener("click", (event) => {
|
||||
let target = event.target as HTMLElement;
|
||||
while (target && !target.isSameNode(dialog.element)) {
|
||||
if (target.classList.contains("b3-button--error")) {
|
||||
removeColByMenu({
|
||||
protyle,
|
||||
colId,
|
||||
avID,
|
||||
blockID,
|
||||
oldValue,
|
||||
type,
|
||||
cellElement,
|
||||
blockElement,
|
||||
removeDest: true
|
||||
})
|
||||
dialog.destroy();
|
||||
break;
|
||||
} else if (target.classList.contains("b3-button--warning")) {
|
||||
removeColByMenu({
|
||||
protyle,
|
||||
colId,
|
||||
avID,
|
||||
blockID,
|
||||
oldValue,
|
||||
type,
|
||||
cellElement,
|
||||
blockElement,
|
||||
removeDest: false
|
||||
})
|
||||
dialog.destroy();
|
||||
break;
|
||||
} else if (target.classList.contains("b3-button--info")) {
|
||||
dialog.destroy();
|
||||
break;
|
||||
}
|
||||
target = target.parentElement;
|
||||
}
|
||||
})
|
||||
return
|
||||
}
|
||||
}
|
||||
removeColByMenu({
|
||||
protyle,
|
||||
colId,
|
||||
avID,
|
||||
}, {
|
||||
action: "doUpdateUpdated",
|
||||
id: blockID,
|
||||
data: newUpdated,
|
||||
}], [{
|
||||
action: "addAttrViewCol",
|
||||
name: oldValue,
|
||||
avID,
|
||||
type: type,
|
||||
id: colId,
|
||||
previousID: cellElement.previousElementSibling?.getAttribute("data-col-id") || "",
|
||||
}, {
|
||||
action: "doUpdateUpdated",
|
||||
id: blockID,
|
||||
data: blockElement.getAttribute("updated")
|
||||
}]);
|
||||
removeAttrViewColAnimation(blockElement, colId);
|
||||
blockElement.setAttribute("updated", newUpdated);
|
||||
blockID,
|
||||
oldValue,
|
||||
type,
|
||||
cellElement,
|
||||
blockElement,
|
||||
removeDest: false
|
||||
})
|
||||
}
|
||||
});
|
||||
menu.addSeparator();
|
||||
|
@ -908,6 +957,43 @@ export const showColMenu = (protyle: IProtyle, blockElement: Element, cellElemen
|
|||
}
|
||||
};
|
||||
|
||||
const removeColByMenu = (options: {
|
||||
protyle: IProtyle,
|
||||
colId: string,
|
||||
avID: string,
|
||||
blockID: string,
|
||||
oldValue: string,
|
||||
type: TAVCol,
|
||||
cellElement: HTMLElement,
|
||||
blockElement: Element,
|
||||
removeDest: boolean
|
||||
}) => {
|
||||
const newUpdated = dayjs().format("YYYYMMDDHHmmss");
|
||||
transaction(options.protyle, [{
|
||||
action: "removeAttrViewCol",
|
||||
id: options.colId,
|
||||
avID: options.avID,
|
||||
removeDest: options.removeDest
|
||||
}, {
|
||||
action: "doUpdateUpdated",
|
||||
id: options.blockID,
|
||||
data: newUpdated,
|
||||
}], [{
|
||||
action: "addAttrViewCol",
|
||||
name: options.oldValue,
|
||||
avID: options.avID,
|
||||
type: options.type,
|
||||
id: options.colId,
|
||||
previousID: options.cellElement.previousElementSibling?.getAttribute("data-col-id") || "",
|
||||
}, {
|
||||
action: "doUpdateUpdated",
|
||||
id: options.blockID,
|
||||
data: options.blockElement.getAttribute("updated")
|
||||
}]);
|
||||
removeAttrViewColAnimation(options.blockElement, options.colId);
|
||||
options.blockElement.setAttribute("updated", newUpdated);
|
||||
}
|
||||
|
||||
export const removeCol = (options: {
|
||||
protyle: IProtyle,
|
||||
data: IAV,
|
||||
|
|
Loading…
Add table
Reference in a new issue