From a165cac78e044cf0fd4dd06b8eabdfc8a57f6cea Mon Sep 17 00:00:00 2001 From: Vanessa Date: Tue, 30 Aug 2022 17:58:28 +0800 Subject: [PATCH] :art: https://github.com/siyuan-note/siyuan/issues/4901 --- app/src/asset/renderAssets.ts | 2 +- app/src/assets/scss/_function.scss | 6 -- app/src/util/history.ts | 100 ++++++++++------------------- 3 files changed, 36 insertions(+), 72 deletions(-) diff --git a/app/src/asset/renderAssets.ts b/app/src/asset/renderAssets.ts index 521177956..7c1053a82 100644 --- a/app/src/asset/renderAssets.ts +++ b/app/src/asset/renderAssets.ts @@ -13,6 +13,6 @@ export const renderAssetsPreview = (pathString: string) => { } else if (Constants.SIYUAN_ASSETS_VIDEO.includes(type)) { return ``; } else { - return ""; + return pathString; } }; diff --git a/app/src/assets/scss/_function.scss b/app/src/assets/scss/_function.scss index 6ce98a884..2ff18ac7a 100644 --- a/app/src/assets/scss/_function.scss +++ b/app/src/assets/scss/_function.scss @@ -158,12 +158,6 @@ color: var(--b3-theme-on-background); } - &__asset { - background-color: var(--b3-theme-background); - padding: 16px; - border-radius: 0 0 4px 0; - } - &__repo { background-color: var(--b3-theme-background); display: flex; diff --git a/app/src/util/history.ts b/app/src/util/history.ts index 42b8ce8d7..3a28fa79e 100644 --- a/app/src/util/history.ts +++ b/app/src/util/history.ts @@ -17,27 +17,34 @@ const renderDoc = (element: HTMLElement, currentPage: number) => { previousElement.setAttribute("disabled", "disabled"); } 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); + const opElement = element.querySelector('.b3-select[data-type="opselect"]') as HTMLSelectElement; + const typeElement = element.querySelector('.b3-select[data-type="typeselect"]') as HTMLSelectElement; + const notebookElement = element.querySelector('.b3-select[data-type="notebookselect"]') as HTMLSelectElement; + window.localStorage.setItem(Constants.LOCAL_HISTORYNOTEID, notebookElement.value); + if (typeElement.value === "0") { + opElement.removeAttribute("disabled") + notebookElement.removeAttribute("disabled") + } else { + opElement.setAttribute("disabled", "disabled") + notebookElement.setAttribute("disabled", "disabled") + } fetchPost("/api/history/searchHistory", { - notebook: (selectElements[1] as HTMLSelectElement).value, + notebook: notebookElement.value, query: inputElement.value, page: currentPage, - op: (selectElements[0] as HTMLSelectElement).value, - type: 0 + op: opElement.value, + type: parseInt(typeElement.value) }, (response) => { if (currentPage < response.data.pageCount) { nextElement.removeAttribute("disabled"); } else { nextElement.setAttribute("disabled", "disabled"); } - if (response.data.histories.length === 0) { element.lastElementChild.lastElementChild.innerHTML = ""; element.lastElementChild.firstElementChild.innerHTML = `
  • ${window.siyuan.languages.emptyContent}
  • `; return; } - let logsHTML = ""; response.data.histories.forEach((item: { items: { path: string, title: string }[], hCreated: string }, index: number) => { logsHTML += `
  • @@ -47,7 +54,7 @@ const renderDoc = (element: HTMLElement, currentPage: number) => { if (item.items.length > 0) { logsHTML += `"; - if (index === 0) { - fetchPost("/api/history/getDocHistoryContent", { - historyPath: item.items[0].path - }, (contentResponse) => { - element.lastElementChild.lastElementChild.innerHTML = contentResponse.data.content; - }); + if (typeElement.value === "1") { + element.lastElementChild.lastElementChild.innerHTML = renderAssetsPreview(item.items[0].path); + } else { + fetchPost("/api/history/getDocHistoryContent", { + historyPath: item.items[0].path + }, (contentResponse) => { + element.lastElementChild.lastElementChild.innerHTML = contentResponse.data.content; + }); + } } } }); @@ -70,42 +80,6 @@ const renderDoc = (element: HTMLElement, currentPage: number) => { }); }; -const renderAssets = (element: HTMLElement) => { - element.setAttribute("data-init", "true"); - fetchPost("/api/history/getAssetsHistory", {}, (response) => { - if (response.data.histories.length === 0) { - element.lastElementChild.innerHTML = ""; - element.firstElementChild.innerHTML = `
  • ${window.siyuan.languages.emptyContent}
  • `; - return; - } - let logsHTML = ""; - response.data.histories.forEach((item: { items: { path: string, title: string }[], hCreated: string }, index: number) => { - logsHTML += `
  • - 0 ? "" : " fn__hidden"}"> - ${item.hCreated} -
  • `; - if (item.items.length > 0) { - logsHTML += `"; - - if (index === 0) { - element.lastElementChild.innerHTML = renderAssetsPreview(item.items[0].path); - } - } - }); - element.firstElementChild.innerHTML = logsHTML; - }); -}; - const renderRepoItem = (response: IWebSocketData, element: Element, type: string) => { if (response.data.snapshots.length === 0) { element.lastElementChild.innerHTML = `
  • ${window.siyuan.languages.emptyContent}
  • `; @@ -248,8 +222,7 @@ export const openHistory = () => { const dialog = new Dialog({ content: `
    -
    ${window.siyuan.languages.doc}
    -
    ${window.siyuan.languages.assets}
    +
    ${window.siyuan.languages.dataHistory}
    ${window.siyuan.languages.removedNotebook}
    ${window.siyuan.languages.dataSnapshot}
    @@ -265,7 +238,12 @@ export const openHistory = () => {
    - + + + + + - ${notebookSelectHTML} @@ -284,15 +262,9 @@ export const openHistory = () => { - +
    -
    - -
    -
    @@ -362,9 +334,7 @@ export const openHistory = () => { item.classList.add("fn__block"); target.classList.add("item--focus"); if (item.getAttribute("data-init") !== "true") { - if (type === "assets") { - renderAssets(item); - } else if (type === "notebook") { + if (type === "notebook") { renderRmNotebook(item); } else if (type === "repo") { renderRepo(item, 1); @@ -511,7 +481,7 @@ export const openHistory = () => { renderDoc(firstPanelElement, type === "docprevious" ? currentPage - 1 : currentPage + 1); break; } else if (type === "rebuildIndex") { - fetchPost("/api/history/reindexHistory", {}, ()=> { + fetchPost("/api/history/reindexHistory", {}, () => { renderDoc(firstPanelElement, 1); }); break;