mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-01-06 16:58:49 +01:00
This commit is contained in:
parent
ca891b6440
commit
25728e3564
4 changed files with 64 additions and 50 deletions
|
|
@ -2,6 +2,55 @@ import {transaction} from "../../wysiwyg/transaction";
|
|||
import {hasClosestBlock, hasClosestByClassName} from "../../util/hasClosest";
|
||||
import {openMenuPanel} from "./openMenuPanel";
|
||||
|
||||
export const genCellValue = (colType: TAVCol, value: string | {
|
||||
content: string,
|
||||
color: string
|
||||
}[]) => {
|
||||
let cellValue: IAVCellValue;
|
||||
if (typeof value === "string") {
|
||||
if (colType === "number") {
|
||||
if (value) {
|
||||
cellValue = {
|
||||
type: colType,
|
||||
number: {
|
||||
content: parseFloat(value),
|
||||
isNotEmpty: true
|
||||
}
|
||||
};
|
||||
} else {
|
||||
cellValue = {
|
||||
type: colType,
|
||||
number: {
|
||||
isNotEmpty: false
|
||||
}
|
||||
};
|
||||
}
|
||||
} else if (colType === "text") {
|
||||
cellValue = {
|
||||
type: colType,
|
||||
text: {
|
||||
content: value
|
||||
}
|
||||
};
|
||||
} else if (colType === "mSelect" || colType === "select") {
|
||||
return cellValue = {
|
||||
type: colType,
|
||||
mSelect: [{
|
||||
content: value,
|
||||
color: ""
|
||||
}]
|
||||
};
|
||||
}
|
||||
return cellValue;
|
||||
}
|
||||
if (colType === "mSelect" || colType === "select") {
|
||||
return cellValue = {
|
||||
type: colType,
|
||||
mSelect: value
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
export const popTextCell = (protyle: IProtyle, cellElement: HTMLElement) => {
|
||||
const type = cellElement.parentElement.parentElement.firstElementChild.querySelector(`[data-col-id="${cellElement.getAttribute("data-col-id")}"]`).getAttribute("data-dtype") as TAVCol;
|
||||
const cellRect = cellElement.getBoundingClientRect();
|
||||
|
|
|
|||
|
|
@ -2,7 +2,8 @@ import {hasClosestBlock} from "../../util/hasClosest";
|
|||
import {Menu} from "../../../plugin/Menu";
|
||||
import {transaction} from "../../wysiwyg/transaction";
|
||||
import {fetchPost} from "../../../util/fetch";
|
||||
import {genCellValue, setFilter} from "./filter";
|
||||
import {getDefaultOperatorByType, setFilter} from "./filter";
|
||||
import {genCellValue} from "./cell";
|
||||
|
||||
export const getColIconByType = (type: TAVCol) => {
|
||||
switch (type) {
|
||||
|
|
@ -155,7 +156,7 @@ export const showColMenu = (protyle: IProtyle, blockElement: HTMLElement, cellEl
|
|||
if (!filter) {
|
||||
filter = {
|
||||
column: colId,
|
||||
operator: "Contains",
|
||||
operator: getDefaultOperatorByType(type),
|
||||
value: genCellValue(type, "")
|
||||
};
|
||||
avData.view.filters.push(filter);
|
||||
|
|
|
|||
|
|
@ -4,53 +4,14 @@ import {hasClosestByClassName} from "../../util/hasClosest";
|
|||
import {getColIconByType} from "./col";
|
||||
import {setPosition} from "../../../util/setPosition";
|
||||
import {objEquals} from "../../../util/functions";
|
||||
import {genCellValue} from "./cell";
|
||||
|
||||
export const genCellValue = (colType: TAVCol, value: string | {
|
||||
content: string,
|
||||
color: string
|
||||
}[]) => {
|
||||
let cellValue: IAVCellValue;
|
||||
if (typeof value === "string") {
|
||||
if (colType === "number") {
|
||||
if (value) {
|
||||
cellValue = {
|
||||
type: colType,
|
||||
number: {
|
||||
content: parseFloat(value),
|
||||
isNotEmpty: true
|
||||
}
|
||||
};
|
||||
} else {
|
||||
cellValue = {
|
||||
type: colType,
|
||||
number: {
|
||||
isNotEmpty: false
|
||||
}
|
||||
};
|
||||
}
|
||||
} else if (colType === "text") {
|
||||
cellValue = {
|
||||
type: colType,
|
||||
text: {
|
||||
content: value
|
||||
}
|
||||
};
|
||||
} else if (colType === "mSelect" || colType === "select") {
|
||||
return cellValue = {
|
||||
type: colType,
|
||||
mSelect: [{
|
||||
content: value,
|
||||
color: ""
|
||||
}]
|
||||
};
|
||||
}
|
||||
return cellValue;
|
||||
export const getDefaultOperatorByType = (type: TAVCol) => {
|
||||
if (type === "number" || type === "select") {
|
||||
return "=";
|
||||
}
|
||||
if (colType === "mSelect" || colType === "select") {
|
||||
return cellValue = {
|
||||
type: colType,
|
||||
mSelect: value
|
||||
};
|
||||
if (type === "text" || type === "mSelect") {
|
||||
return "Contains";
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -94,6 +55,9 @@ export const setFilter = (options: {
|
|||
});
|
||||
}
|
||||
});
|
||||
if (mSelect.length === 0) {
|
||||
mSelect.push({color: "", content: ""});
|
||||
}
|
||||
cellValue = genCellValue(options.filter.value.type, mSelect);
|
||||
}
|
||||
const newFilter: IAVFilter = {
|
||||
|
|
@ -298,7 +262,7 @@ export const addFilter = (options: {
|
|||
const cellValue = genCellValue(column.type, "");
|
||||
options.data.view.filters.push({
|
||||
column: column.id,
|
||||
operator: "Contains",
|
||||
operator: getDefaultOperatorByType(column.type),
|
||||
value: cellValue,
|
||||
});
|
||||
transaction(options.protyle, [{
|
||||
|
|
@ -315,7 +279,7 @@ export const addFilter = (options: {
|
|||
const filterElement = options.menuElement.querySelector(`[data-id="${column.id}"] .b3-chip`) as HTMLElement;
|
||||
setFilter({
|
||||
filter: {
|
||||
operator: "Contains",
|
||||
operator: getDefaultOperatorByType(column.type),
|
||||
column: column.id,
|
||||
value: cellValue
|
||||
},
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import {transaction} from "../../wysiwyg/transaction";
|
|||
import {hasClosestByClassName} from "../../util/hasClosest";
|
||||
import {confirmDialog} from "../../../dialog/confirmDialog";
|
||||
import {upDownHint} from "../../../util/upDownHint";
|
||||
import {genCellValue} from "./filter";
|
||||
import {genCellValue} from "./cell";
|
||||
|
||||
const filterSelectHTML = (key: string, options: { name: string, color: string }[]) => {
|
||||
let html = "";
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue