mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-01-04 15:58:49 +01:00
🎨 database
This commit is contained in:
parent
683e9a04ed
commit
0129825335
5 changed files with 32 additions and 15 deletions
|
|
@ -66,7 +66,7 @@ export const getCalcValue = (column: IAVColumn) => {
|
|||
export const genCellValue = (colType: TAVCol, value: string | {
|
||||
content: string,
|
||||
color: string
|
||||
}[] | { content?: number, content2?: number, hasEndDate?: boolean }) => {
|
||||
}[] | IAVCellDateValue) => {
|
||||
let cellValue: IAVCellValue;
|
||||
if (typeof value === "string") {
|
||||
if (colType === "number") {
|
||||
|
|
@ -106,7 +106,9 @@ export const genCellValue = (colType: TAVCol, value: string | {
|
|||
type: colType,
|
||||
date: {
|
||||
content: null,
|
||||
isNotEmpty: false,
|
||||
content2: null,
|
||||
isNotEmpty2: false,
|
||||
hasEndDate: false,
|
||||
}
|
||||
};
|
||||
|
|
@ -123,7 +125,7 @@ export const genCellValue = (colType: TAVCol, value: string | {
|
|||
} else if (colType === "date") {
|
||||
cellValue = {
|
||||
type: colType,
|
||||
date: value as { content?: number, content2?: number, hasEndDate?: boolean }
|
||||
date: value as IAVCellDateValue
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import * as dayjs from "dayjs";
|
|||
|
||||
export const getDateHTML = (data: IAVTable, cellElements: HTMLElement[]) => {
|
||||
let hasEndDate = true;
|
||||
let cellValue:IAVCell;
|
||||
let cellValue: IAVCell;
|
||||
cellElements.forEach((cellElement) => {
|
||||
data.rows.find(row => {
|
||||
if (cellElement.parentElement.dataset.id === row.id) {
|
||||
|
|
@ -24,11 +24,11 @@ export const getDateHTML = (data: IAVTable, cellElements: HTMLElement[]) => {
|
|||
hasEndDate = false;
|
||||
}
|
||||
let value = "";
|
||||
if (cellValue?.value?.date?.content) {
|
||||
if (cellValue?.value?.date?.isNotEmpty) {
|
||||
value = dayjs(cellValue.value.date.content).format("YYYY-MM-DDTHH:mm");
|
||||
}
|
||||
let value2 = "";
|
||||
if (cellValue?.value?.date?.content2) {
|
||||
if (cellValue?.value?.date?.isNotEmpty2) {
|
||||
value2 = dayjs(cellValue.value.date.content2).format("YYYY-MM-DDTHH:mm");
|
||||
}
|
||||
return `<div class="b3-menu__items">
|
||||
|
|
@ -128,7 +128,10 @@ export const setDateValue = (options: {
|
|||
cellData.value = {};
|
||||
}
|
||||
oldValue = Object.assign({}, cellData.value.date);
|
||||
cellData.value.date = Object.assign(cellData.value.date || {}, options.value);
|
||||
cellData.value.date = Object.assign(cellData.value.date || {
|
||||
isNotEmpty2: false,
|
||||
isNotEmpty: false
|
||||
}, options.value);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -61,6 +61,8 @@ export const setFilter = (options: {
|
|||
if (textElements.length > 0) {
|
||||
if (colData.type === "date") {
|
||||
cellValue = genCellValue(colData.type, {
|
||||
isNotEmpty2: textElements[1].value !== "",
|
||||
isNotEmpty: textElements[0].value !== "",
|
||||
content: new Date(textElements[0].value).getTime(),
|
||||
content2: new Date(textElements[1].value).getTime(),
|
||||
hasEndDate: operator === "Is between"
|
||||
|
|
@ -219,11 +221,11 @@ export const setFilter = (options: {
|
|||
} else if (colData.type === "date") {
|
||||
menu.addItem({
|
||||
iconHTML: "",
|
||||
label: `<input style="margin: 4px 0" value="${options.filter.value?.date.content ? dayjs(options.filter.value.date.content).format("YYYY-MM-DDTHH:mm") : ""}" type="datetime-local" class="b3-text-field fn__size200">`
|
||||
label: `<input style="margin: 4px 0" value="${options.filter.value?.date.isNotEmpty ? dayjs(options.filter.value.date.content).format("YYYY-MM-DDTHH:mm") : ""}" type="datetime-local" class="b3-text-field fn__size200">`
|
||||
});
|
||||
menu.addItem({
|
||||
iconHTML: "",
|
||||
label: `<input style="margin: 4px 0" value="${options.filter.value?.date.content2 ? dayjs(options.filter.value.date.content2).format("YYYY-MM-DDTHH:mm") : ""}" type="datetime-local" class="b3-text-field fn__size200">`
|
||||
label: `<input style="margin: 4px 0" value="${options.filter.value?.date.isNotEmpty2 ? dayjs(options.filter.value.date.content2).format("YYYY-MM-DDTHH:mm") : ""}" type="datetime-local" class="b3-text-field fn__size200">`
|
||||
});
|
||||
}
|
||||
menu.addItem({
|
||||
|
|
|
|||
|
|
@ -91,10 +91,10 @@ style="width: ${column.width || "200px"}">${getCalcValue(column) || '<svg><use x
|
|||
}
|
||||
} else if (cell.valueType === "date") {
|
||||
text = '<span class="av__celltext">';
|
||||
if (cell.value?.date.content) {
|
||||
if (cell.value?.date.isNotEmpty) {
|
||||
text += dayjs(cell.value.date.content).format("YYYY-MM-DD HH:mm");
|
||||
}
|
||||
if (cell.value?.date.hasEndDate && cell.value?.date.content && cell.value?.date.content2) {
|
||||
if (cell.value?.date.hasEndDate && cell.value?.date.isNotEmpty && cell.value?.date.isNotEmpty2) {
|
||||
text += `<svg style="margin-left: 5px"><use xlink:href="#iconForward"></use></svg>${dayjs(cell.value.date.content2).format("YYYY-MM-DD HH:mm")}`;
|
||||
}
|
||||
text += "</span>";
|
||||
|
|
@ -223,10 +223,10 @@ const genAVValueHTML = (value: IAVCellValue) => {
|
|||
});
|
||||
break;
|
||||
case "date":
|
||||
if (value.date.content) {
|
||||
if (value.date.isNotEmpty) {
|
||||
html = `<span data-content="${value.date.content}">${dayjs(value.date.content).format("YYYY-MM-DD HH:mm")}</span>`;
|
||||
}
|
||||
if (value.date.hasEndDate && value.date.content && value.date.content2) {
|
||||
if (value.date.hasEndDate && value.date.isNotEmpty2 && value.date.isNotEmpty) {
|
||||
html += `<svg class="custom-attr__avarrow"><use xlink:href="#iconForward"></use></svg><span data-content="${value.date.content2}">${dayjs(value.date.content2).format("YYYY-MM-DD HH:mm")}</span>`;
|
||||
}
|
||||
break;
|
||||
|
|
@ -285,6 +285,8 @@ class="fn__flex-1 fn__flex${["url", "text", "number"].includes(item.values[0].ty
|
|||
cellID: dateElement.dataset.id,
|
||||
value: {
|
||||
date: {
|
||||
isNotEmpty: textElements[0].value !== "",
|
||||
isNotEmpty2: textElements[1].value !== "",
|
||||
content: new Date(textElements[0].value).getTime(),
|
||||
content2: new Date(textElements[1].value).getTime(),
|
||||
hasEndDate
|
||||
|
|
@ -292,10 +294,10 @@ class="fn__flex-1 fn__flex${["url", "text", "number"].includes(item.values[0].ty
|
|||
}
|
||||
});
|
||||
let dataHTML = "";
|
||||
if (textElements[0].value) {
|
||||
if (textElements[0].value !== "") {
|
||||
dataHTML = `<span data-content="${new Date(textElements[0].value).getTime()}">${dayjs(textElements[0].value).format("YYYY-MM-DD HH:mm")}</span>`;
|
||||
}
|
||||
if (hasEndDate && textElements[0].value && textElements[1].value) {
|
||||
if (hasEndDate && textElements[0].value !== "" && textElements[1].value !== "") {
|
||||
dataHTML += `<svg class="custom-attr__avarrow"><use xlink:href="#iconForward"></use></svg><span data-content="${new Date(textElements[1].value).getTime()}">${dayjs(textElements[1].value).format("YYYY-MM-DD HH:mm")}</span>`;
|
||||
}
|
||||
dateElement.innerHTML = dataHTML;
|
||||
|
|
|
|||
10
app/src/types/index.d.ts
vendored
10
app/src/types/index.d.ts
vendored
|
|
@ -932,5 +932,13 @@ interface IAVCellValue {
|
|||
mSelect?: { content: string, color: string }[]
|
||||
block?: { content: string, id: string }
|
||||
url?: { content: string }
|
||||
date?: { content?: number, content2?: number, hasEndDate?: boolean }
|
||||
date?: IAVCellDateValue
|
||||
}
|
||||
|
||||
interface IAVCellDateValue {
|
||||
content?: number,
|
||||
isNotEmpty: boolean
|
||||
content2?: number,
|
||||
isNotEmpty2: boolean
|
||||
hasEndDate?: boolean
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue