Vanessa 2022-07-05 22:56:30 +08:00
parent 7180e66654
commit 0a0356f6f2

View file

@ -104,11 +104,57 @@ const renderAssets = (element: HTMLElement) => {
}); });
}; };
const renderRepoItem = (response: IWebSocketData, element: Element, type: string) => {
if (response.data.snapshots.length === 0) {
element.lastElementChild.innerHTML = `<li class="b3-list--empty">${window.siyuan.languages.emptyContent}</li>`;
return;
}
let actionHTML = `<span class="b3-list-item__action b3-tooltips b3-tooltips__w" data-type="uploadSnapshot" aria-label="${window.siyuan.languages.upload}"><svg><use xlink:href="#iconUpload"></use></svg></span>`
if (type === "download") {
actionHTML = `<span class="b3-list-item__action b3-tooltips b3-tooltips__w" data-type="downloadSnapshot" aria-label="${window.siyuan.languages.download}"><svg><use xlink:href="#iconDownload"></use></svg></span>`
}
let repoHTML = "";
response.data.snapshots.forEach((item: { memo: string, id: string, hCreated: string, count: number, hSize: string, tag: string }) => {
repoHTML += `<li class="b3-list-item b3-list-item--hide-action" data-id="${item.id}" data-tag="${item.tag}">
<div class="b3-list-item__text">
${item.hCreated}<span class="fn__space"></span>
${escapeHtml(item.memo)}
<span class="b3-list-item__meta">${item.hSize}</span>
<span class="b3-list-item__meta">${window.siyuan.languages.fileCount}${item.count}</span>
</div>
${actionHTML}
<span class="b3-list-item__action b3-tooltips b3-tooltips__w" data-type="genTag" aria-label="${window.siyuan.languages.createSnapshot}">
<svg><use xlink:href="#iconAdd"></use></svg>
</span>
<span class="b3-list-item__action b3-tooltips b3-tooltips__w" data-type="rollback" aria-label="${window.siyuan.languages.rollback}">
<svg><use xlink:href="#iconUndo"></use></svg>
</span>
</li>`;
});
element.lastElementChild.innerHTML = `${repoHTML}`;
}
const renderRepo = (element: Element, currentPage: number) => { const renderRepo = (element: Element, currentPage: number) => {
element.setAttribute("data-init", "true");
element.setAttribute("data-page", currentPage.toString());
const previousElement = element.querySelector('[data-type="previous"]'); const previousElement = element.querySelector('[data-type="previous"]');
const nextElement = element.querySelector('[data-type="next"]'); const nextElement = element.querySelector('[data-type="next"]');
if (currentPage < 0) {
if (currentPage === -1) {
fetchPost("/api/repo/getRepoTagSnapshots", {}, (response) => {
renderRepoItem(response, element, "upload");
})
}
if (currentPage === -2) {
fetchPost("/api/repo/getCloudRepoTagSnapshots", {}, (response) => {
renderRepoItem(response, element, "download");
})
}
previousElement.classList.add("fn__none")
nextElement.classList.add("fn__none")
} else {
previousElement.classList.remove("fn__none")
nextElement.classList.remove("fn__none")
element.setAttribute("data-init", "true");
element.setAttribute("data-page", currentPage.toString());
if (currentPage > 1) { if (currentPage > 1) {
previousElement.removeAttribute("disabled"); previousElement.removeAttribute("disabled");
} else { } else {
@ -120,33 +166,9 @@ const renderRepo = (element: Element, currentPage: number) => {
} else { } else {
nextElement.setAttribute("disabled", "disabled"); nextElement.setAttribute("disabled", "disabled");
} }
if (response.data.snapshots.length === 0) { renderRepoItem(response, element, "upload");
element.lastElementChild.innerHTML = `<li class="b3-list--empty">${window.siyuan.languages.emptyContent}</li>`; });
return;
} }
let repoHTML = "";
response.data.snapshots.forEach((item: { memo: string, id: string, hCreated: string, count: number, hSize: string }) => {
repoHTML += `<li class="b3-list-item b3-list-item--hide-action" data-id="${item.id}">
<div class="b3-list-item__text">
${item.hCreated}<span class="fn__space"></span>${escapeHtml(item.memo)}<span class="b3-list-item__meta">${item.hSize}</span>
</div>
<span class="b3-list-item__action b3-tooltips b3-tooltips__w" data-type="uploadSnapshot" aria-label="${window.siyuan.languages.upload}">
<svg><use xlink:href="#iconUpload"></use></svg>
</span>
<span class="b3-list-item__action b3-tooltips b3-tooltips__w" data-type="downloadSnapshot" aria-label="${window.siyuan.languages.download}">
<svg><use xlink:href="#iconDownload"></use></svg>
</span>
<span class="b3-list-item__action b3-tooltips b3-tooltips__w" data-type="genTag" aria-label="${window.siyuan.languages.createSnapshot}">
<svg><use xlink:href="#iconAdd"></use></svg>
</span>
<span class="b3-list-item__action b3-tooltips b3-tooltips__w" data-type="rollback" aria-label="${window.siyuan.languages.rollback}">
<svg><use xlink:href="#iconUndo"></use></svg>
</span>
<span class="counter">${item.count}</span>
</li>`;
});
element.lastElementChild.innerHTML = `${repoHTML}`;
});
}; };
const renderRmNotebook = (element: HTMLElement) => { const renderRmNotebook = (element: HTMLElement) => {
@ -222,10 +244,9 @@ export const openHistory = () => {
<span data-type="next" class="block__icon b3-tooltips b3-tooltips__se" disabled="disabled" aria-label="${window.siyuan.languages.nextLabel}"><svg><use xlink:href='#iconRight'></use></svg></span> <span data-type="next" class="block__icon b3-tooltips b3-tooltips__se" disabled="disabled" aria-label="${window.siyuan.languages.nextLabel}"><svg><use xlink:href='#iconRight'></use></svg></span>
<div class="fn__flex-1"></div> <div class="fn__flex-1"></div>
<select class="b3-select"> <select class="b3-select">
<option value="">${window.siyuan.languages.localRepo}</option> <option value="0">${window.siyuan.languages.localRepo}</option>
<option value="">${window.siyuan.languages.localRepo}</option> <option value="1">${window.siyuan.languages.localSnapshotRepo}</option>
<option value="">${window.siyuan.languages.localSnapshotRepo}</option> <option value="2">${window.siyuan.languages.cloudSnapshotRepo}</option>
<option value="">${window.siyuan.languages.cloudSnapshotRepo}</option>
</select> </select>
<span class="fn__space"></span> <span class="fn__space"></span>
<button class="b3-button b3-button--outline" data-type="genRepo"> <button class="b3-button b3-button--outline" data-type="genRepo">
@ -269,6 +290,17 @@ export const openHistory = () => {
const firstPanelElement = dialog.element.querySelector("#historyContainer [data-type=doc]") as HTMLElement; const firstPanelElement = dialog.element.querySelector("#historyContainer [data-type=doc]") as HTMLElement;
renderDoc(currentNotebook, firstPanelElement); renderDoc(currentNotebook, firstPanelElement);
const repoElement = dialog.element.querySelector('#historyContainer [data-type="repo"]'); const repoElement = dialog.element.querySelector('#historyContainer [data-type="repo"]');
const selectElement = repoElement.querySelector(".b3-select") as HTMLSelectElement;
selectElement.addEventListener("change", () => {
const value = selectElement.value;
if (value === "0") {
renderRepo(repoElement, 1);
} else if (value === "1") {
renderRepo(repoElement, -1);
} else if (value === "2") {
renderRepo(repoElement, -2);
}
})
dialog.element.addEventListener("click", (event) => { dialog.element.addEventListener("click", (event) => {
let target = event.target as HTMLElement; let target = event.target as HTMLElement;
while (target && !target.isEqualNode(dialog.element)) { while (target && !target.isEqualNode(dialog.element)) {
@ -397,9 +429,15 @@ export const openHistory = () => {
}); });
break; break;
} else if (type === "uploadSnapshot") { } else if (type === "uploadSnapshot") {
// TODO fetchPost("/api/repo/uploadCloudSnapshot", {
tag: target.parentElement.getAttribute("data-tag"),
id: target.parentElement.getAttribute("data-id")
});
} else if (type === "downloadSnapshot") { } else if (type === "downloadSnapshot") {
// TODO fetchPost("/api/repo/downloadCloudSnapshot", {
tag: target.parentElement.getAttribute("data-tag"),
id: target.parentElement.getAttribute("data-id")
})
} else if (type === "genTag") { } else if (type === "genTag") {
const genTagDialog = new Dialog({ const genTagDialog = new Dialog({
title: window.siyuan.languages.snapshotMemo, title: window.siyuan.languages.snapshotMemo,