From ac7e57ce5d2abe6663e0538a17c379af01596ef3 Mon Sep 17 00:00:00 2001 From: Vanessa Date: Wed, 27 Nov 2024 09:40:45 +0800 Subject: [PATCH] :art: https://github.com/siyuan-note/siyuan/issues/13193 --- app/src/assets/scss/business/_history.scss | 5 ++ app/src/history/doc.ts | 85 ++++++++++++++-------- app/src/history/history.ts | 16 ++-- 3 files changed, 66 insertions(+), 40 deletions(-) diff --git a/app/src/assets/scss/business/_history.scss b/app/src/assets/scss/business/_history.scss index bdd8db552..42081171b 100644 --- a/app/src/assets/scss/business/_history.scss +++ b/app/src/assets/scss/business/_history.scss @@ -1,4 +1,9 @@ .history { + &__action { + overflow: auto; + border-bottom: 1px solid var(--b3-border-color); + } + &__text { background-color: var(--b3-theme-background); padding: 16px; diff --git a/app/src/history/doc.ts b/app/src/history/doc.ts index 83b041f59..b439cd532 100644 --- a/app/src/history/doc.ts +++ b/app/src/history/doc.ts @@ -15,7 +15,6 @@ let isLoading = false; const renderDoc = (element: HTMLElement, currentPage: number, id: string) => { const previousElement = element.querySelector('[data-type="docprevious"]'); const nextElement = element.querySelector('[data-type="docnext"]'); - element.setAttribute("data-page", currentPage.toString()); if (currentPage > 1) { previousElement.removeAttribute("disabled"); } else { @@ -23,8 +22,9 @@ const renderDoc = (element: HTMLElement, currentPage: number, id: string) => { } const opElement = element.querySelector('.b3-select[data-type="opselect"]') as HTMLSelectElement; const listElement = element.querySelector(".b3-list--background"); + element.querySelector('.protyle-title__input').classList.add("fn__none"); element.querySelector('.history__text[data-type="docPanel"]').classList.add("fn__none"); - element.querySelector('.history__text[data-type="mdPanel"]').classList.remove("fn__none"); + element.querySelector('.history__text[data-type="mdPanel"]').classList.add("fn__none"); fetchPost("/api/history/searchHistory", { query: id, page: currentPage, @@ -36,7 +36,16 @@ const renderDoc = (element: HTMLElement, currentPage: number, id: string) => { } else { nextElement.setAttribute("disabled", "disabled"); } - nextElement.nextElementSibling.nextElementSibling.textContent = `${currentPage}/${response.data.pageCount || 1}`; + const pageNumElement = element.querySelector('[data-type="jumpRepoPage"]') + if (response.data.pageCount > 1) { + pageNumElement.removeAttribute("disabled"); + } else { + pageNumElement.setAttribute("disabled", "disabled"); + } + pageNumElement.setAttribute("data-totalpage", response.data.pageCount.toString()); + pageNumElement.textContent = currentPage.toString(); + const pageInfoElement = nextElement.nextElementSibling.nextElementSibling; + pageInfoElement.textContent = window.siyuan.languages.pageCountAndHistoryCount.replace("${x}", response.data.pageCount).replace("${y}", response.data.totalCount); if (response.data.histories.length === 0) { listElement.innerHTML = `
  • ${window.siyuan.languages.emptyContent}
  • `; return; @@ -61,40 +70,38 @@ export const openDocHistory = (options: { notebookId: string, pathString: string }) => { - const contentHTML = `
    + const contentHTML = `
    +
    + + + + + ${window.siyuan.languages.pageCountAndHistoryCount} + +
    + +
    +
    +
    • ${window.siyuan.languages.emptyContent}
    -
    +
    `; const dialog = new Dialog({ - title:`
    - ${isMobile() ? "" : options.pathString} - -
    - - - - - - - 1/1 - ${isMobile() ? '' : ""} -
    `, + title: options.pathString, content: contentHTML, width: isMobile() ? "100vw" : "90vw", height: isMobile() ? "100vh" : "80vh", @@ -127,13 +134,13 @@ export const openDocHistory = (options: { typewriterMode: false, }); disabledProtyle(historyEditor.protyle); + const pageNumElement = dialog.element.querySelector('[data-type="jumpRepoPage"]') + const titleElement = dialog.element.querySelector(".protyle-title__input") dialog.element.addEventListener("click", (event) => { let target = event.target as HTMLElement; while (target && !target.isEqualNode(dialog.element)) { const type = target.getAttribute("data-type"); - if (type === "close") { - dialog.destroy(); - } else if (type === "rollback" && !isLoading) { + if (type === "rollback" && !isLoading) { getHistoryPath(target.parentElement, opElement.value, options.id, (item) => { const dataPath = item.path; isLoading = false; @@ -168,7 +175,8 @@ export const openDocHistory = (options: { action: [Constants.CB_GET_HISTORY, Constants.CB_GET_HTML], }); } - dialog.element.querySelector(".protyle-title__input").textContent = item.title; + titleElement.textContent = item.title; + titleElement.classList.remove("fn__none") isLoading = false; }); target.parentElement.querySelector(".b3-list-item--focus")?.classList.remove("b3-list-item--focus"); @@ -178,11 +186,24 @@ export const openDocHistory = (options: { event.preventDefault(); break; } else if ((type === "docprevious" || type === "docnext") && target.getAttribute("disabled") !== "disabled") { - const currentPage = parseInt(dialog.element.getAttribute("data-page")); + const currentPage = parseInt(pageNumElement.textContent); renderDoc(dialog.element, type === "docprevious" ? currentPage - 1 : currentPage + 1, options.id); event.stopPropagation(); event.preventDefault(); break; + } else if (type === "jumpRepoPage") { + const totalPage = parseInt(target.getAttribute("data-totalpage") || "1"); + confirmDialog( + window.siyuan.languages.jumpToPage.replace("${x}", totalPage), + ``, + (confirmD) => { + const inputElement = confirmD.element.querySelector(".b3-text-field") as HTMLInputElement; + if (inputElement.value === "") { + return; + } + renderDoc(dialog.element, Math.max(1, Math.min(parseInt(inputElement.value), totalPage)), options.id); + } + ); } target = target.parentElement; } diff --git a/app/src/history/history.ts b/app/src/history/history.ts index 21e4f3ecc..98924edbe 100644 --- a/app/src/history/history.ts +++ b/app/src/history/history.ts @@ -354,7 +354,7 @@ export const openHistory = (app: App) => {
    -
    +
    @@ -409,7 +409,7 @@ export const openHistory = (app: App) => {
  • ${window.siyuan.languages.emptyContent}
  • -
    +
    @@ -839,9 +839,9 @@ const bindEvent = (app: App, element: Element, dialog?: Dialog) => { if (totalPage > 1) { confirmDialog( window.siyuan.languages.jumpToPage.replace("${x}", totalPage), - ``, - (dialog: Dialog) => { - const inputElement = dialog.element.querySelector(".b3-text-field") as HTMLInputElement; + ``, + (confirmD) => { + const inputElement = confirmD.element.querySelector(".b3-text-field") as HTMLInputElement; if (inputElement.value === "") { return; } @@ -858,9 +858,9 @@ const bindEvent = (app: App, element: Element, dialog?: Dialog) => { if (totalPage > 1) { confirmDialog( window.siyuan.languages.jumpToPage.replace("${x}", totalPage), - ``, - (dialog: Dialog) => { - const inputElement = dialog.element.querySelector(".b3-text-field") as HTMLInputElement; + ``, + (confirmD) => { + const inputElement = confirmD.element.querySelector(".b3-text-field") as HTMLInputElement; if (inputElement.value === "") { return; }