mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-20 16:40:13 +01:00
This commit is contained in:
parent
d0ee66c0fa
commit
da03d8473c
3 changed files with 64 additions and 29 deletions
|
|
@ -6,62 +6,69 @@ import {getDefaultOperatorByType, setFilter} from "./filter";
|
|||
import {genCellValue} from "./cell";
|
||||
import {openMenuPanel} from "./openMenuPanel";
|
||||
|
||||
export const duplicateCol = (protyle: IProtyle, type: TAVCol, avID: string, colId: string, newValue: string) => {
|
||||
export const duplicateCol = (options: {
|
||||
protyle: IProtyle,
|
||||
type: TAVCol,
|
||||
avID: string,
|
||||
nodeID: string,
|
||||
colId: string,
|
||||
newValue: string
|
||||
}) => {
|
||||
const id = Lute.NewNodeID();
|
||||
const nameMatch = newValue.match(/^(.*) \((\d+)\)$/);
|
||||
const nameMatch = options.newValue.match(/^(.*) \((\d+)\)$/);
|
||||
if (nameMatch) {
|
||||
newValue = `${nameMatch[1]} (${parseInt(nameMatch[2]) + 1})`;
|
||||
options.newValue = `${nameMatch[1]} (${parseInt(nameMatch[2]) + 1})`;
|
||||
} else {
|
||||
newValue = `${newValue} (1)`;
|
||||
options.newValue = `${options.newValue} (1)`;
|
||||
}
|
||||
if (["select", "mSelect"].includes(type)) {
|
||||
fetchPost("/api/av/renderAttributeView", {id: avID}, (response) => {
|
||||
if (["select", "mSelect"].includes(options.type)) {
|
||||
fetchPost("/api/av/renderAttributeView", {id: options.avID, nodeID: options.nodeID}, (response) => {
|
||||
const data = response.data as IAV;
|
||||
let colOptions;
|
||||
data.view.columns.find((item) => {
|
||||
if (item.id === colId) {
|
||||
if (item.id === options.colId) {
|
||||
colOptions = item.options;
|
||||
return true;
|
||||
}
|
||||
});
|
||||
transaction(protyle, [{
|
||||
transaction(options.protyle, [{
|
||||
action: "addAttrViewCol",
|
||||
name: newValue,
|
||||
avID,
|
||||
type,
|
||||
name: options.newValue,
|
||||
avID: options.avID,
|
||||
type: options.type,
|
||||
id
|
||||
}, {
|
||||
action: "sortAttrViewCol",
|
||||
avID,
|
||||
previousID: colId,
|
||||
avID: options.avID,
|
||||
previousID: options.colId,
|
||||
id
|
||||
}, {
|
||||
action: "updateAttrViewColOptions",
|
||||
id,
|
||||
avID,
|
||||
avID: options.avID,
|
||||
data: colOptions
|
||||
}], [{
|
||||
action: "removeAttrViewCol",
|
||||
id,
|
||||
avID,
|
||||
avID: options.avID,
|
||||
}]);
|
||||
});
|
||||
} else {
|
||||
transaction(protyle, [{
|
||||
transaction(options.protyle, [{
|
||||
action: "addAttrViewCol",
|
||||
name: newValue,
|
||||
avID,
|
||||
type,
|
||||
name: options.newValue,
|
||||
avID: options.avID,
|
||||
type: options.type,
|
||||
id
|
||||
}, {
|
||||
action: "sortAttrViewCol",
|
||||
avID,
|
||||
previousID: colId,
|
||||
avID: options.avID,
|
||||
previousID: options.colId,
|
||||
id
|
||||
}], [{
|
||||
action: "removeAttrViewCol",
|
||||
id,
|
||||
avID,
|
||||
avID: options.avID,
|
||||
}]);
|
||||
}
|
||||
};
|
||||
|
|
@ -255,6 +262,7 @@ export const showColMenu = (protyle: IProtyle, blockElement: HTMLElement, cellEl
|
|||
const type = cellElement.getAttribute("data-dtype") as TAVCol;
|
||||
const colId = cellElement.getAttribute("data-col-id");
|
||||
const avID = blockElement.getAttribute("data-av-id");
|
||||
const nodeID = blockElement.getAttribute("data-node-id");
|
||||
const menu = new Menu("av-header-cell", () => {
|
||||
const newValue = (window.siyuan.menus.menu.element.querySelector(".b3-text-field") as HTMLInputElement).value;
|
||||
if (newValue === cellElement.textContent.trim()) {
|
||||
|
|
@ -292,7 +300,10 @@ export const showColMenu = (protyle: IProtyle, blockElement: HTMLElement, cellEl
|
|||
icon: "iconUp",
|
||||
label: window.siyuan.languages.asc,
|
||||
click() {
|
||||
fetchPost("/api/av/renderAttributeView", {id: avID}, (response) => {
|
||||
fetchPost("/api/av/renderAttributeView", {
|
||||
id: avID,
|
||||
nodeID
|
||||
}, (response) => {
|
||||
transaction(protyle, [{
|
||||
action: "setAttrViewSorts",
|
||||
avID: response.data.id,
|
||||
|
|
@ -312,7 +323,10 @@ export const showColMenu = (protyle: IProtyle, blockElement: HTMLElement, cellEl
|
|||
icon: "iconDown",
|
||||
label: window.siyuan.languages.desc,
|
||||
click() {
|
||||
fetchPost("/api/av/renderAttributeView", {id: avID}, (response) => {
|
||||
fetchPost("/api/av/renderAttributeView", {
|
||||
id: avID,
|
||||
nodeID
|
||||
}, (response) => {
|
||||
transaction(protyle, [{
|
||||
action: "setAttrViewSorts",
|
||||
avID: response.data.id,
|
||||
|
|
@ -332,7 +346,10 @@ export const showColMenu = (protyle: IProtyle, blockElement: HTMLElement, cellEl
|
|||
icon: "iconFilter",
|
||||
label: window.siyuan.languages.filter,
|
||||
click() {
|
||||
fetchPost("/api/av/renderAttributeView", {id: avID}, (response) => {
|
||||
fetchPost("/api/av/renderAttributeView", {
|
||||
id: avID,
|
||||
nodeID
|
||||
}, (response) => {
|
||||
const avData = response.data as IAV;
|
||||
let filter: IAVFilter;
|
||||
avData.view.filters.find((item) => {
|
||||
|
|
@ -390,7 +407,14 @@ export const showColMenu = (protyle: IProtyle, blockElement: HTMLElement, cellEl
|
|||
icon: "iconCopy",
|
||||
label: window.siyuan.languages.duplicate,
|
||||
click() {
|
||||
duplicateCol(protyle, type, avID, colId, (window.siyuan.menus.menu.element.querySelector(".b3-text-field") as HTMLInputElement).value);
|
||||
duplicateCol({
|
||||
protyle,
|
||||
type,
|
||||
avID,
|
||||
nodeID,
|
||||
colId,
|
||||
newValue: (window.siyuan.menus.menu.element.querySelector(".b3-text-field") as HTMLInputElement).value
|
||||
});
|
||||
}
|
||||
});
|
||||
menu.addItem({
|
||||
|
|
|
|||
|
|
@ -23,7 +23,11 @@ export const openMenuPanel = (options: {
|
|||
}
|
||||
window.siyuan.menus.menu.remove();
|
||||
const avID = options.blockElement.getAttribute("data-av-id");
|
||||
fetchPost("/api/av/renderAttributeView", {id: avID}, (response) => {
|
||||
const nodeID = options.blockElement.getAttribute("data-node-id")
|
||||
fetchPost("/api/av/renderAttributeView", {
|
||||
id: avID,
|
||||
nodeID
|
||||
}, (response) => {
|
||||
const data = response.data as IAV;
|
||||
let html;
|
||||
if (options.type === "config") {
|
||||
|
|
@ -565,7 +569,14 @@ export const openMenuPanel = (options: {
|
|||
} else if (type === "duplicateCol") {
|
||||
const colId = menuElement.firstElementChild.getAttribute("data-col-id");
|
||||
const colData = data.view.columns.find((item: IAVColumn) => item.id === colId);
|
||||
duplicateCol(options.protyle, colData.type, avID, colId, colData.name);
|
||||
duplicateCol({
|
||||
protyle: options.protyle,
|
||||
type: colData.type,
|
||||
avID,
|
||||
colId,
|
||||
nodeID,
|
||||
newValue: colData.name
|
||||
});
|
||||
avPanelElement.remove();
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ export const avRender = (element: Element, cb?: () => void) => {
|
|||
if (e.getAttribute("data-render") === "true") {
|
||||
return;
|
||||
}
|
||||
fetchPost("/api/av/renderAttributeView", {id: e.getAttribute("data-av-id")}, (response) => {
|
||||
fetchPost("/api/av/renderAttributeView", {id: e.getAttribute("data-av-id"), nodeID: e.getAttribute("data-node-id")}, (response) => {
|
||||
const data = response.data.view as IAVTable;
|
||||
// header
|
||||
let tableHTML = '<div class="av__row av__row--header"><div class="av__firstcol"><svg style="height: 32px"><use xlink:href="#iconUncheck"></use></svg></div>';
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue