diff --git a/app/src/config/account.ts b/app/src/config/account.ts index 6e9606b90..76e245c3b 100644 --- a/app/src/config/account.ts +++ b/app/src/config/account.ts @@ -53,7 +53,7 @@ ${window.siyuan.languages.account2}
- +
`; if (window.siyuan.user.userSiYuanProExpireTime === -1) { activeSubscriptionHTML = ""; diff --git a/app/src/util/history.ts b/app/src/util/history.ts index 95c0529ac..34fc86e24 100644 --- a/app/src/util/history.ts +++ b/app/src/util/history.ts @@ -9,26 +9,38 @@ import {isMobile} from "./functions"; import {hasClosestByClassName} from "../protyle/util/hasClosest"; import {renderAssetsPreview} from "../asset/renderAssets"; -const renderDoc = (notebook: INotebook, element: HTMLElement) => { - if (!notebook || !notebook.id) { - return; +const renderDoc = (element: HTMLElement, currentPage: number) => { + 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 { + previousElement.setAttribute("disabled", "disabled"); } - fetchPost("/api/history/getDocHistory", { - notebook: notebook.id + const inputElement = element.querySelector(".b3-text-field") as HTMLInputElement; + const selectElements = element.querySelectorAll(".b3-select"); + window.localStorage.setItem(Constants.LOCAL_HISTORYNOTEID, (selectElements[1] as HTMLSelectElement).value); + fetchPost("/api/history/searchHistory", { + notebook: (selectElements[1] as HTMLSelectElement).value, + query: inputElement.value, + page: currentPage, + op: (selectElements[0] as HTMLSelectElement).value, + type: 0 }, (response) => { - const switchHTML = `
  • - ${unicode2Emoji(notebook.icon || Constants.SIYUAN_IMAGE_NOTE)} - ${escapeHtml(notebook.name)} - - - -
  • `; + if (currentPage < response.data.pageCount) { + nextElement.removeAttribute("disabled"); + } else { + nextElement.setAttribute("disabled", "disabled"); + } + if (response.data.histories.length === 0) { - element.lastElementChild.innerHTML = ""; - element.firstElementChild.innerHTML = `${switchHTML}
  • ${window.siyuan.languages.emptyContent}
  • `; + element.lastElementChild.lastElementChild.innerHTML = ""; + element.lastElementChild.firstElementChild.innerHTML = `
  • ${window.siyuan.languages.emptyContent}
  • `; return; } - let logsHTML = switchHTML; + + let logsHTML = ""; response.data.histories.forEach((item: { items: { path: string, title: string }[], hCreated: string }, index: number) => { logsHTML += `
  • 0 ? "" : " fn__hidden"}"> @@ -50,13 +62,13 @@ const renderDoc = (notebook: INotebook, element: HTMLElement) => { if (index === 0) { fetchPost("/api/history/getDocHistoryContent", { historyPath: item.items[0].path - }, (response) => { - element.lastElementChild.innerHTML = response.data.content; + }, (contentResponse) => { + element.lastElementChild.lastElementChild.innerHTML = contentResponse.data.content; }); } } }); - element.firstElementChild.innerHTML = logsHTML; + element.lastElementChild.firstElementChild.innerHTML = logsHTML; }); }; @@ -228,6 +240,13 @@ export const openHistory = () => { return; } + const currentNotebookId = localStorage.getItem(Constants.LOCAL_HISTORYNOTEID); + let notebookSelectHTML = ''; + window.siyuan.notebooks.forEach((item) => { + if (!item.closed) { + notebookSelectHTML += ` ` + } + }); const dialog = new Dialog({ content: `
    @@ -237,11 +256,36 @@ export const openHistory = () => {
    ${window.siyuan.languages.dataSnapshot}
    -
    -
      -
    • ${window.siyuan.languages.emptyContent}
    • -
    - +
    +
    + + + +
    +
    + + +
    + + + + +
    +
    +
      +
    • ${window.siyuan.languages.emptyContent}
    • +
    + +
      @@ -277,33 +321,14 @@ export const openHistory = () => { width: "80vw", height: "80vh", }); - let currentNotebook: INotebook = { - name: window.siyuan.languages.newFileTip, - id: "", - closed: true, - icon: "", - sort: 0 - }; - const currentNotebookId = localStorage.getItem(Constants.LOCAL_HISTORYNOTEID); - window.siyuan.notebooks.find((item) => { - if (!item.closed) { - if (!currentNotebook.id) { - currentNotebook = item; - } - if (currentNotebookId) { - if (item.id === currentNotebookId) { - currentNotebook = item; - return true; - } - } else { - currentNotebook = item; - return true; - } - } - }); const firstPanelElement = dialog.element.querySelector("#historyContainer [data-type=doc]") as HTMLElement; - renderDoc(currentNotebook, firstPanelElement); + firstPanelElement.querySelectorAll(".b3-select").forEach((itemElement) => { + itemElement.addEventListener("change", () => { + renderDoc(firstPanelElement, 1); + }); + }); + renderDoc(firstPanelElement, 1); const repoElement = dialog.element.querySelector('#historyContainer [data-type="repo"]'); const selectElement = repoElement.querySelector(".b3-select") as HTMLSelectElement; selectElement.addEventListener("change", () => { @@ -342,27 +367,7 @@ export const openHistory = () => { } }); break; - } else if (type === "switchNotebook") { - window.siyuan.menus.menu.remove(); - window.siyuan.notebooks.forEach(item => { - if (!item.closed) { - window.siyuan.menus.menu.append(new MenuItem({ - label: item.name, - click: () => { - if (item.id === currentNotebook.id) { - return; - } - currentNotebook = item; - window.localStorage.setItem(Constants.LOCAL_HISTORYNOTEID, item.id); - renderDoc(item, firstPanelElement); - } - }).element); - } - }); - window.siyuan.menus.menu.popup({x: event.clientX, y: event.clientY}); - window.siyuan.menus.menu.element.style.zIndex = "310"; - break; - } else if (target.classList.contains("b3-list-item__action") && type === "rollback" && !window.siyuan.config.readonly) { + } else if (target.classList.contains("b3-list-item__action") && type === "rollback" && !window.siyuan.config.readonly) { confirmDialog("⚠️ " + window.siyuan.languages.rollback, `${window.siyuan.languages.rollbackConfirm.replace("${date}", target.parentElement.textContent.trim())}`, () => { const dataType = target.parentElement.getAttribute("data-type"); if (dataType === "assets") { @@ -371,7 +376,7 @@ export const openHistory = () => { }); } else if (dataType === "doc") { fetchPost("/api/history/rollbackDocHistory", { - notebook: currentNotebook.id, + notebook: (firstPanelElement.querySelectorAll(".b3-select")[1] as HTMLSelectElement).value, historyPath: target.parentElement.getAttribute("data-path") }); } else if (dataType === "notebook") { @@ -492,6 +497,10 @@ export const openHistory = () => { const currentPage = parseInt(repoElement.getAttribute("data-page")); renderRepo(repoElement, type === "previous" ? currentPage - 1 : currentPage + 1); break; + } else if ((type === "docprevious" || type === "docnext") && target.getAttribute("disabled") !== "disabled") { + const currentPage = parseInt(repoElement.getAttribute("data-page")); + renderDoc(firstPanelElement, type === "docprevious" ? currentPage - 1 : currentPage + 1); + break; } target = target.parentElement; }