mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-05-02 14:49:58 +08:00
This commit is contained in:
parent
bcf7853add
commit
a7d0506cf2
@ -1,34 +1,13 @@
|
||||
import * as dayjs from "dayjs";
|
||||
import {hasClosestByClassName} from "../../util/hasClosest";
|
||||
import {updateCellsValue} from "./cell";
|
||||
import {genCellValueByElement, updateCellsValue} from "./cell";
|
||||
|
||||
export const getDateHTML = (data: IAVTable, cellElements: HTMLElement[]) => {
|
||||
let hasEndDate = true;
|
||||
let cellValue: IAVCell;
|
||||
cellElements.forEach((cellElement) => {
|
||||
data.rows.find(row => {
|
||||
if ((hasClosestByClassName(cellElement, "av__row") as HTMLElement).dataset.id === row.id) {
|
||||
row.cells.find(cell => {
|
||||
if (cell.id === cellElement.dataset.id) {
|
||||
if (!cell.value || !cell.value.date || !cell.value.date.hasEndDate) {
|
||||
hasEndDate = false;
|
||||
}
|
||||
cellValue = cell;
|
||||
return true;
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
});
|
||||
});
|
||||
if (!cellValue) {
|
||||
hasEndDate = false;
|
||||
}
|
||||
const isNotTime = !cellValue || cellValue?.value?.date?.isNotTime;
|
||||
export const getDateHTML = (cellElements: HTMLElement[]) => {
|
||||
const cellValue = genCellValueByElement("date", cellElements[0]).date;
|
||||
const isNotTime = cellValue.isNotTime;
|
||||
let value = "";
|
||||
const currentDate = new Date().getTime();
|
||||
if (cellValue?.value?.date?.isNotEmpty) {
|
||||
value = dayjs(cellValue.value.date.content).format(isNotTime ? "YYYY-MM-DD" : "YYYY-MM-DD HH:mm");
|
||||
if (cellValue.isNotEmpty) {
|
||||
value = dayjs(cellValue.content).format(isNotTime ? "YYYY-MM-DD" : "YYYY-MM-DD HH:mm");
|
||||
const year = value.split("-")[0];
|
||||
if (year.length !== 4) {
|
||||
value = new Array(4 - year.length).fill(0).join("") + value;
|
||||
@ -37,24 +16,24 @@ export const getDateHTML = (data: IAVTable, cellElements: HTMLElement[]) => {
|
||||
value = dayjs(currentDate).format(isNotTime ? "YYYY-MM-DD" : "YYYY-MM-DD HH:mm");
|
||||
}
|
||||
let value2 = "";
|
||||
if (cellValue?.value?.date?.isNotEmpty2) {
|
||||
value2 = dayjs(cellValue.value.date.content2).format(isNotTime ? "YYYY-MM-DD" : "YYYY-MM-DD HH:mm");
|
||||
if (cellValue.isNotEmpty2) {
|
||||
value2 = dayjs(cellValue.content2).format(isNotTime ? "YYYY-MM-DD" : "YYYY-MM-DD HH:mm");
|
||||
const year = value.split("-")[0];
|
||||
if (year.length !== 4) {
|
||||
value = new Array(4 - year.length).fill(0).join("") + value;
|
||||
}
|
||||
} else if (hasEndDate) {
|
||||
} else if (cellValue.hasEndDate) {
|
||||
value2 = dayjs(currentDate).format(isNotTime ? "YYYY-MM-DD" : "YYYY-MM-DD HH:mm");
|
||||
}
|
||||
return `<div class="b3-menu__items">
|
||||
<div>
|
||||
<input type="${isNotTime ? "date" : "datetime-local"}" max="${isNotTime ? "9999-12-31" : "9999-12-31 23:59"}" value="${value}" data-value="${dayjs(cellValue?.value?.date?.content || currentDate).format("YYYY-MM-DD HH:mm")}" class="b3-text-field fn__size200" style="margin-top: 4px;"><br>
|
||||
<input type="${isNotTime ? "date" : "datetime-local"}" max="${isNotTime ? "9999-12-31" : "9999-12-31 23:59"}" value="${value2}" data-value="${cellValue?.value?.date?.isNotEmpty2 ? dayjs(cellValue.value.date.content2).format("YYYY-MM-DD HH:mm") : ""}" style="margin-top: 8px;margin-bottom: 4px" class="b3-text-field fn__size200${hasEndDate ? "" : " fn__none"}">
|
||||
<input type="${isNotTime ? "date" : "datetime-local"}" max="${isNotTime ? "9999-12-31" : "9999-12-31 23:59"}" value="${value}" data-value="${dayjs(cellValue.content || currentDate).format("YYYY-MM-DD HH:mm")}" class="b3-text-field fn__size200" style="margin-top: 4px;"><br>
|
||||
<input type="${isNotTime ? "date" : "datetime-local"}" max="${isNotTime ? "9999-12-31" : "9999-12-31 23:59"}" value="${value2}" data-value="${cellValue.isNotEmpty2 ? dayjs(cellValue.content2).format("YYYY-MM-DD HH:mm") : ""}" style="margin-top: 8px;margin-bottom: 4px" class="b3-text-field fn__size200${cellValue.hasEndDate ? "" : " fn__none"}">
|
||||
<button class="b3-menu__separator"></button>
|
||||
<label class="b3-menu__item">
|
||||
<span class="fn__flex-center">${window.siyuan.languages.endDate}</span>
|
||||
<span class="fn__space fn__flex-1"></span>
|
||||
<input type="checkbox" class="b3-switch b3-switch--menu"${hasEndDate ? " checked" : ""}>
|
||||
<input type="checkbox" class="b3-switch b3-switch--menu"${cellValue.hasEndDate ? " checked" : ""}>
|
||||
</label>
|
||||
<label class="b3-menu__item">
|
||||
<span class="fn__flex-center">${window.siyuan.languages.includeTime}</span>
|
||||
|
@ -96,7 +96,7 @@ export const openMenuPanel = (options: {
|
||||
}
|
||||
html = getEditHTML({protyle: options.protyle, data, colId: options.colId, isCustomAttr});
|
||||
} else if (options.type === "date") {
|
||||
html = getDateHTML(data.view, options.cellElements);
|
||||
html = getDateHTML(options.cellElements);
|
||||
} else if (options.type === "rollup") {
|
||||
html = `<div class="b3-menu__items">${getRollupHTML({data, cellElements: options.cellElements})}</div>`;
|
||||
} else if (options.type === "relation") {
|
||||
|
Loading…
Reference in New Issue
Block a user