This commit is contained in:
parent
29306d39d1
commit
b72fffd9e6
2 changed files with 89 additions and 26 deletions
|
@ -1,4 +1,6 @@
|
|||
{
|
||||
"setDueTime": "设置到期时间",
|
||||
"showCardDay": "要在多少天后显示卡片?",
|
||||
"forgetCount": "遗忘次数",
|
||||
"lastReviewTime": "最后复习时间",
|
||||
"cardStatus": "卡片状态",
|
||||
|
|
|
@ -61,6 +61,7 @@ export const genCardHTML = (options: {
|
|||
<span class="fn__flex-1 fn__flex-center toolbar__text">${window.siyuan.languages.riffCard}</span>
|
||||
<div data-type="count" class="${options.cardsData.cards.length === 0 ? "fn__none" : "fn__flex"}">${genCardCount(options.cardsData)}</span></div>
|
||||
<svg class="toolbar__icon" data-id="${options.id || ""}" data-cardtype="${options.cardType}" data-type="filter"><use xlink:href="#iconFilter"></use></svg>
|
||||
<svg class="toolbar__icon" data-type="more"><use xlink:href="#iconMore"></use></svg>
|
||||
<svg class="toolbar__icon" data-type="close"><use xlink:href="#iconCloseRound"></use></svg>
|
||||
</div>`;
|
||||
/// #else
|
||||
|
@ -199,7 +200,6 @@ export const bindCardEvent = async (options: {
|
|||
});
|
||||
}
|
||||
options.element.setAttribute("data-key", Constants.DIALOG_OPENCARD);
|
||||
genCardCount(options.cardsData, index);
|
||||
const actionElements = options.element.querySelectorAll(".card__action");
|
||||
if (options.index === 0) {
|
||||
actionElements[0].firstElementChild.setAttribute("disabled", "disabled");
|
||||
|
@ -210,7 +210,7 @@ export const bindCardEvent = async (options: {
|
|||
const filterElement = options.element.querySelector('[data-type="filter"]');
|
||||
const fetchNewRound = () => {
|
||||
const currentCardType = filterElement.getAttribute("data-cardtype");
|
||||
const docId = filterElement.getAttribute("data-id");
|
||||
const docId = filterElement.getAttribute("data-id");
|
||||
fetchPost(currentCardType === "all" ? "/api/riff/getRiffDueCards" :
|
||||
(currentCardType === "doc" ? "/api/riff/getTreeRiffDueCards" : "/api/riff/getNotebookRiffDueCards"), {
|
||||
rootID: docId,
|
||||
|
@ -236,11 +236,12 @@ export const bindCardEvent = async (options: {
|
|||
});
|
||||
};
|
||||
|
||||
countElement.innerHTML = genCardCount(options.cardsData, index);
|
||||
options.element.addEventListener("click", (event: MouseEvent) => {
|
||||
const target = event.target as HTMLElement;
|
||||
let type = "";
|
||||
const currentCard = options.cardsData.cards[index];
|
||||
const docId = filterElement.getAttribute("data-id");
|
||||
const docId = filterElement.getAttribute("data-id");
|
||||
if (typeof event.detail === "string") {
|
||||
if (["1", "j", "a"].includes(event.detail)) {
|
||||
type = "1";
|
||||
|
@ -280,26 +281,85 @@ export const bindCardEvent = async (options: {
|
|||
const menu = new Menu();
|
||||
menu.addItem({
|
||||
icon: "iconClock",
|
||||
label: window.siyuan.languages.updatedTime,
|
||||
label: window.siyuan.languages.setDueTime,
|
||||
click() {
|
||||
|
||||
}
|
||||
});
|
||||
menu.addItem({
|
||||
icon: "iconRefresh",
|
||||
label: window.siyuan.languages.reset,
|
||||
click() {
|
||||
fetchPost("/api/riff/resetRiffCards", {
|
||||
type: filterElement.getAttribute("data-cardtype"),
|
||||
id: docId,
|
||||
deckID: Constants.QUICK_DECK_ID,
|
||||
blockIDs: [currentCard.blockID],
|
||||
}, () => {
|
||||
// currentCard.
|
||||
// genCardCount(options.cardsData, index);
|
||||
const dialog = new Dialog({
|
||||
title: window.siyuan.languages.setDueTime,
|
||||
content: `<div class="b3-dialog__content">
|
||||
<div class="b3-label__text">${window.siyuan.languages.showCardDay}</div>
|
||||
<div class="fn__hr"></div>
|
||||
<input class="b3-text-field fn__block" value="1" type="number" step="1" min="1">
|
||||
</div>
|
||||
<div class="b3-dialog__action">
|
||||
<button class="b3-button b3-button--cancel">${window.siyuan.languages.cancel}</button><div class="fn__space"></div>
|
||||
<button class="b3-button b3-button--text">${window.siyuan.languages.confirm}</button>
|
||||
</div>`,
|
||||
width: isMobile() ? "92vw" : "520px",
|
||||
});
|
||||
const inputElement = dialog.element.querySelector("input") as HTMLInputElement;
|
||||
const btnsElement = dialog.element.querySelectorAll(".b3-button");
|
||||
dialog.bindInput(inputElement, () => {
|
||||
(btnsElement[1] as HTMLButtonElement).click();
|
||||
});
|
||||
inputElement.focus();
|
||||
inputElement.select();
|
||||
btnsElement[0].addEventListener("click", () => {
|
||||
dialog.destroy();
|
||||
});
|
||||
btnsElement[1].addEventListener("click", () => {
|
||||
fetchPost("/api/riff/batchSetRiffCardsDueTime", {
|
||||
cardDues: [{
|
||||
id: currentCard.blockID,
|
||||
due: dayjs().day(parseInt(inputElement.value)).format("YYYYMMDDHHmmss")
|
||||
}]
|
||||
}, () => {
|
||||
actionElements[0].classList.add("fn__none");
|
||||
actionElements[1].classList.remove("fn__none");
|
||||
if (currentCard.state === 0) {
|
||||
options.cardsData.unreviewedNewCardCount--;
|
||||
} else {
|
||||
options.cardsData.unreviewedOldCardCount--;
|
||||
}
|
||||
options.element.dispatchEvent(new CustomEvent("click", {detail: "0"}));
|
||||
options.cardsData.cards.splice(index, 1);
|
||||
index--;
|
||||
dialog.destroy();
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
if (currentCard.state !== 0) {
|
||||
menu.addItem({
|
||||
icon: "iconRefresh",
|
||||
label: window.siyuan.languages.reset,
|
||||
click() {
|
||||
fetchPost("/api/riff/resetRiffCards", {
|
||||
type: filterElement.getAttribute("data-cardtype"),
|
||||
id: docId,
|
||||
deckID: Constants.QUICK_DECK_ID,
|
||||
blockIDs: [currentCard.blockID],
|
||||
}, () => {
|
||||
const minLang = window.siyuan.languages._time["1m"].replace("%s", "")
|
||||
currentCard.lapses = 0;
|
||||
currentCard.lastReview = -62135596800000;
|
||||
currentCard.reps = 0;
|
||||
currentCard.state = 0;
|
||||
currentCard.nextDues = {
|
||||
1: minLang,
|
||||
2: minLang.replace("1", "5"),
|
||||
3: minLang.replace("1", "10"),
|
||||
4: window.siyuan.languages._time["1d"].replace("%s", "").replace("1", "6")
|
||||
};
|
||||
actionElements[1].querySelectorAll(".b3-button").forEach((element, btnIndex) => {
|
||||
element.previousElementSibling.textContent = currentCard.nextDues[btnIndex];
|
||||
});
|
||||
options.cardsData.unreviewedOldCardCount--;
|
||||
options.cardsData.unreviewedNewCardCount++;
|
||||
countElement.innerHTML = genCardCount(options.cardsData, index);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
menu.addItem({
|
||||
icon: "iconTrashcan",
|
||||
label: `${window.siyuan.languages.remove} <b>${window.siyuan.languages.riffCard}</b>`,
|
||||
|
@ -329,28 +389,29 @@ export const bindCardEvent = async (options: {
|
|||
<div class="fn__flex-1">${window.siyuan.languages.forgetCount}</div>
|
||||
<div class="fn__space"></div>
|
||||
<div>${currentCard.lapses}</div>
|
||||
</div>
|
||||
<div class="fn__flex${currentCard.lastReview > 0 ? "" : " fn__none"}">
|
||||
</div><div class="fn__flex${currentCard.lastReview > 0 ? "" : " fn__none"}">
|
||||
<div class="fn__flex-1">${window.siyuan.languages.lastReviewTime}</div>
|
||||
<div class="fn__space"></div>
|
||||
<div>${dayjs(currentCard.lastReview).format("YYYY-MM-DD")}</div>
|
||||
</div>
|
||||
<div class="fn__flex">
|
||||
</div><div class="fn__flex">
|
||||
<div class="fn__flex-1">${window.siyuan.languages.revisionCount}</div>
|
||||
<div class="fn__space"></div>
|
||||
<div>${currentCard.reps}</div>
|
||||
</div>
|
||||
<div class="fn__flex">
|
||||
</div><div class="fn__flex">
|
||||
<div class="fn__flex-1">${window.siyuan.languages.cardStatus}</div>
|
||||
<div class="fn__space"></div>
|
||||
<div class="${window.siyuan.languages.cardStatus === 0 ? "ft__primary" : "ft__success"}">${window.siyuan.languages.cardStatus === 0 ? window.siyuan.languages.flashcardNewCard : window.siyuan.languages.flashcardReviewCard}</div>
|
||||
<div class="${currentCard.state === 0 ? "ft__primary" : "ft__success"}">${currentCard.state === 0 ? window.siyuan.languages.flashcardNewCard : window.siyuan.languages.flashcardReviewCard}</div>
|
||||
</div>`,
|
||||
});
|
||||
/// #if MOBILE
|
||||
menu.fullscreen();
|
||||
/// #else
|
||||
const rect = target.getBoundingClientRect();
|
||||
menu.open({
|
||||
x: rect.left,
|
||||
y: rect.bottom
|
||||
});
|
||||
/// #endif
|
||||
return;
|
||||
}
|
||||
/// #if !MOBILE
|
||||
|
|
Loading…
Add table
Reference in a new issue