This commit is contained in:
Vanessa 2023-02-03 17:10:32 +08:00
parent eacf25983e
commit 6e8a4bbf71
2 changed files with 40 additions and 20 deletions

View file

@ -97,12 +97,20 @@ const renderCompare = (element: HTMLElement) => {
} }
}; };
export const showDiff = (ids: string) => { export const showDiff = (data: { id: string, time: string }[]) => {
const idArray = ids.split(","); if (data.length !== 2) {
if (idArray.length !== 2) {
return; return;
} }
fetchPost("/api/repo/diffRepoSnapshots", {left: idArray[0], right: idArray[1]}, (response) => { let left
let right
if (data[0].time > data[1].time) {
left = data[1].id
right = data[0].id
} else {
left = data[0].id
right = data[1].id
}
fetchPost("/api/repo/diffRepoSnapshots", {left, right}, (response) => {
const dialog = new Dialog({ const dialog = new Dialog({
title: window.siyuan.languages.compare, title: window.siyuan.languages.compare,
content: `<div class="fn__flex" style="height: 100%"> content: `<div class="fn__flex" style="height: 100%">
@ -114,7 +122,7 @@ export const showDiff = (ids: string) => {
</span> </span>
<span style="padding-left: 4px" class="b3-list-item__text">${window.siyuan.languages.update}</span> <span style="padding-left: 4px" class="b3-list-item__text">${window.siyuan.languages.update}</span>
</li> </li>
<ul class="fn__none">${genItem(response.data.updatesRight, response.data.updatesLeft)}</ul> <ul class="fn__none">${genItem(response.data.updatesLeft, response.data.updatesRight)}</ul>
</ul> </ul>
<ul class="b3-list b3-list--background"> <ul class="b3-list b3-list--background">
<li class="b3-list-item"> <li class="b3-list-item">

View file

@ -89,7 +89,15 @@ const renderRepoItem = (response: IWebSocketData, element: Element, type: string
<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="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>`;
} }
let repoHTML = ""; let repoHTML = "";
response.data.snapshots.forEach((item: { memo: string, id: string, hCreated: string, count: number, hSize: string, tag: string, typesCount: { type: string, count: number }[] }) => { response.data.snapshots.forEach((item: {
memo: string,
id: string,
hCreated: string,
count: number,
hSize: string,
tag: string,
typesCount: { type: string, count: number }[]
}) => {
if (isMobile()) { if (isMobile()) {
repoHTML += `<li class="b3-list-item b3-list-item--two" data-type="repoitem"> repoHTML += `<li class="b3-list-item b3-list-item--two" data-type="repoitem">
<div class="b3-list-item__first"> <div class="b3-list-item__first">
@ -179,7 +187,10 @@ const renderRmNotebook = (element: HTMLElement) => {
return; return;
} }
let logsHTML = ""; let logsHTML = "";
response.data.histories.forEach((item: { items: { path: string, title: string }[], hCreated: string }, index: number) => { response.data.histories.forEach((item: {
items: { path: string, title: string }[],
hCreated: string
}, index: number) => {
logsHTML += `<li class="b3-list-item" style="padding-left: 0" data-type="rmtoggle"> logsHTML += `<li class="b3-list-item" style="padding-left: 0" data-type="rmtoggle">
<span style="padding-left: 8px" class="b3-list-item__toggle"><svg class="b3-list-item__arrow${index === 0 ? " b3-list-item__arrow--open" : ""}${item.items.length > 0 ? "" : " fn__hidden"}"><use xlink:href="#iconRight"></use></svg></span> <span style="padding-left: 8px" class="b3-list-item__toggle"><svg class="b3-list-item__arrow${index === 0 ? " b3-list-item__arrow--open" : ""}${item.items.length > 0 ? "" : " fn__hidden"}"><use xlink:href="#iconRight"></use></svg></span>
<span class="b3-list-item__text">${item.hCreated}</span> <span class="b3-list-item__text">${item.hCreated}</span>
@ -441,30 +452,31 @@ export const openHistory = () => {
break; break;
} else if (target.classList.contains("b3-list-item") && type === "repoitem") { } else if (target.classList.contains("b3-list-item") && type === "repoitem") {
const btnElement = dialog.element.querySelector(".b3-button[data-type='compare']"); const btnElement = dialog.element.querySelector(".b3-button[data-type='compare']");
const idstring = btnElement.getAttribute("data-ids"); const idJSON = JSON.parse(btnElement.getAttribute("data-ids") || "[]");
const ids = idstring ? idstring.split(",") : [];
const id = target.getAttribute("data-id"); const id = target.getAttribute("data-id");
if (target.classList.contains("b3-list-item--focus")) { if (target.classList.contains("b3-list-item--focus")) {
target.classList.remove("b3-list-item--focus"); target.classList.remove("b3-list-item--focus");
if (ids.includes(id)) { idJSON.forEach((item: { id: string, time: string }, index: number) => {
ids.splice(ids.indexOf(id), 1); if (id === item.id) {
} idJSON.splice(index, 1);
}
})
} else { } else {
target.classList.add("b3-list-item--focus"); target.classList.add("b3-list-item--focus");
if (!ids.includes(id)) { while (idJSON.length > 1) {
while (ids.length > 1) { if (idJSON[0].id !== id) {
const removeId = ids.splice(0, 1)[0]; target.parentElement.querySelector(`.b3-list-item[data-id="${idJSON.splice(0, 1)[0].id}"]`)?.classList.remove("b3-list-item--focus");
target.parentElement.querySelector(`.b3-list-item[data-id="${removeId}"]`)?.classList.remove("b3-list-item--focus");
} }
ids.push(id);
} }
idJSON.push({id, time: target.querySelector(".ft__smaller").textContent});
} }
if (ids.length === 2) {
if (idJSON.length === 2) {
btnElement.removeAttribute("disabled"); btnElement.removeAttribute("disabled");
} else { } else {
btnElement.setAttribute("disabled", "disabled"); btnElement.setAttribute("disabled", "disabled");
} }
btnElement.setAttribute("data-ids", ids.join(",")); btnElement.setAttribute("data-ids", JSON.stringify(idJSON));
break; break;
} else if (target.classList.contains("b3-list-item") && (type === "assets" || type === "doc")) { } else if (target.classList.contains("b3-list-item") && (type === "assets" || type === "doc")) {
const dataPath = target.getAttribute("data-path"); const dataPath = target.getAttribute("data-path");
@ -600,7 +612,7 @@ export const openHistory = () => {
}); });
break; break;
} else if (type === "compare") { } else if (type === "compare") {
showDiff(target.getAttribute("data-ids")); showDiff(JSON.parse(target.getAttribute("data-ids") || "[]"));
break; break;
} }
target = target.parentElement; target = target.parentElement;