2022-05-26 15:18:53 +08:00
|
|
|
import {Dialog} from "../dialog";
|
|
|
|
|
import {confirmDialog} from "../dialog/confirmDialog";
|
|
|
|
|
import {fetchPost} from "./fetch";
|
|
|
|
|
import {Constants} from "../constants";
|
|
|
|
|
import {MenuItem} from "../menus/Menu";
|
|
|
|
|
import {unicode2Emoji} from "../emoji";
|
|
|
|
|
import {escapeHtml} from "./escape";
|
2022-06-13 22:10:41 +08:00
|
|
|
import {isMobile} from "./functions";
|
2022-06-14 00:42:15 +08:00
|
|
|
import {hasClosestByClassName} from "../protyle/util/hasClosest";
|
2022-07-16 23:20:50 +08:00
|
|
|
import {renderAssetsPreview} from "../asset/renderAssets";
|
2022-05-26 15:18:53 +08:00
|
|
|
|
|
|
|
|
const renderDoc = (notebook: INotebook, element: HTMLElement) => {
|
|
|
|
|
if (!notebook || !notebook.id) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
fetchPost("/api/history/getDocHistory", {
|
|
|
|
|
notebook: notebook.id
|
|
|
|
|
}, (response) => {
|
|
|
|
|
const switchHTML = `<li style="background-color: var(--b3-theme-background)" data-type="switchNotebook" data-menu="true" class="b3-list-item">
|
|
|
|
|
<span class="b3-list-item__icon">${unicode2Emoji(notebook.icon || Constants.SIYUAN_IMAGE_NOTE)}</span>
|
|
|
|
|
<span class="b3-list-item__text">${escapeHtml(notebook.name)}</span>
|
|
|
|
|
<span class="b3-list-item__action" data-type="switchNotebook">
|
|
|
|
|
<svg style="height: 10px"><use xlink:href="#iconDown"></use></svg>
|
|
|
|
|
</span>
|
|
|
|
|
</li>`;
|
|
|
|
|
if (response.data.histories.length === 0) {
|
|
|
|
|
element.lastElementChild.innerHTML = "";
|
|
|
|
|
element.firstElementChild.innerHTML = `${switchHTML}<li class="b3-list--empty">${window.siyuan.languages.emptyContent}</li>`;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
let logsHTML = switchHTML;
|
2022-06-13 23:35:38 +08:00
|
|
|
response.data.histories.forEach((item: { items: { path: string, title: string }[], hCreated: string }, index: number) => {
|
2022-06-13 22:10:41 +08:00
|
|
|
logsHTML += `<li class="b3-list-item" data-type="toggle" style="padding-left: 0">
|
2022-05-26 15:18:53 +08:00
|
|
|
<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>
|
2022-06-13 23:35:38 +08:00
|
|
|
<span class="b3-list-item__text">${item.hCreated}</span>
|
2022-05-26 15:18:53 +08:00
|
|
|
</li>`;
|
|
|
|
|
if (item.items.length > 0) {
|
|
|
|
|
logsHTML += `<ul class="${index === 0 ? "" : "fn__none"}">`;
|
|
|
|
|
item.items.forEach((docItem, docIndex) => {
|
|
|
|
|
logsHTML += `<li title="${escapeHtml(docItem.title)}" data-type="doc" data-path="${docItem.path}" class="b3-list-item b3-list-item--hide-action${(index === 0 && docIndex === 0) ? " b3-list-item--focus" : ""}" style="padding-left: 32px">
|
|
|
|
|
<span class="b3-list-item__text">${escapeHtml(docItem.title)}</span>
|
|
|
|
|
<span class="fn__space"></span>
|
2022-07-05 11:58:20 +08:00
|
|
|
<span class="b3-list-item__action b3-tooltips b3-tooltips__w" data-type="rollback" aria-label="${window.siyuan.languages.rollback}">
|
2022-05-26 15:18:53 +08:00
|
|
|
<svg><use xlink:href="#iconUndo"></use></svg>
|
|
|
|
|
</span>
|
|
|
|
|
</li>`;
|
|
|
|
|
});
|
|
|
|
|
logsHTML += "</ul>";
|
|
|
|
|
|
|
|
|
|
if (index === 0) {
|
|
|
|
|
fetchPost("/api/history/getDocHistoryContent", {
|
|
|
|
|
historyPath: item.items[0].path
|
|
|
|
|
}, (response) => {
|
|
|
|
|
element.lastElementChild.innerHTML = response.data.content;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
element.firstElementChild.innerHTML = logsHTML;
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
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 = `<li class="b3-list--empty">${window.siyuan.languages.emptyContent}</li>`;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
let logsHTML = "";
|
2022-06-13 23:39:03 +08:00
|
|
|
response.data.histories.forEach((item: { items: { path: string, title: string }[], hCreated: string }, index: number) => {
|
2022-06-13 22:10:41 +08:00
|
|
|
logsHTML += `<li class="b3-list-item" data-type="toggle" style="padding-left: 0">
|
2022-05-26 15:18:53 +08:00
|
|
|
<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>
|
2022-06-13 23:39:03 +08:00
|
|
|
<span class="b3-list-item__text">${item.hCreated}</span>
|
2022-05-26 15:18:53 +08:00
|
|
|
</li>`;
|
|
|
|
|
if (item.items.length > 0) {
|
|
|
|
|
logsHTML += `<ul class="${index === 0 ? "" : "fn__none"}">`;
|
|
|
|
|
item.items.forEach((docItem, docIndex) => {
|
|
|
|
|
logsHTML += `<li title="${escapeHtml(docItem.title)}" data-type="assets" data-path="${docItem.path}" class="b3-list-item b3-list-item--hide-action${(index === 0 && docIndex === 0) ? " b3-list-item--focus" : ""}" style="padding-left: 32px">
|
|
|
|
|
<span class="b3-list-item__text">${escapeHtml(docItem.title)}</span>
|
|
|
|
|
<span class="fn__space"></span>
|
2022-07-05 11:58:20 +08:00
|
|
|
<span class="b3-list-item__action b3-tooltips b3-tooltips__w" data-type="rollback" aria-label="${window.siyuan.languages.rollback}">
|
2022-05-26 15:18:53 +08:00
|
|
|
<svg><use xlink:href="#iconUndo"></use></svg>
|
|
|
|
|
</span>
|
|
|
|
|
</li>`;
|
|
|
|
|
});
|
|
|
|
|
logsHTML += "</ul>";
|
|
|
|
|
|
|
|
|
|
if (index === 0) {
|
2022-07-16 23:20:50 +08:00
|
|
|
element.lastElementChild.innerHTML = renderAssetsPreview(item.items[0].path);
|
2022-05-26 15:18:53 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
element.firstElementChild.innerHTML = logsHTML;
|
|
|
|
|
});
|
|
|
|
|
};
|
2022-06-13 22:45:04 +08:00
|
|
|
|
2022-07-05 22:56:30 +08:00
|
|
|
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;
|
2022-06-14 00:42:15 +08:00
|
|
|
}
|
2022-07-08 10:38:11 +08:00
|
|
|
let actionHTML = "";
|
2022-07-06 09:05:36 +08:00
|
|
|
if (type === "cloudTag") {
|
|
|
|
|
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>
|
|
|
|
|
<span class="b3-list-item__action b3-tooltips b3-tooltips__w" data-type="removeCloudRepoTagSnapshot" aria-label="${window.siyuan.languages.remove}"><svg><use xlink:href="#iconTrashcan"></use></svg></span>`;
|
|
|
|
|
} else if (type === "localTag") {
|
2022-07-06 00:34:38 +08:00
|
|
|
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>
|
2022-07-06 09:05:36 +08:00
|
|
|
<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="removeRepoTagSnapshot" aria-label="${window.siyuan.languages.remove}"><svg><use xlink:href="#iconTrashcan"></use></svg></span>`;
|
|
|
|
|
} else if (type === "local") {
|
|
|
|
|
actionHTML = `<span class="b3-list-item__action b3-tooltips b3-tooltips__w" data-type="genTag" aria-label="${window.siyuan.languages.tagSnapshot}"><svg><use xlink:href="#iconTags"></use></svg></span>
|
2022-07-06 00:35:39 +08:00
|
|
|
<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>`;
|
2022-07-05 22:56:30 +08:00
|
|
|
}
|
|
|
|
|
let repoHTML = "";
|
|
|
|
|
response.data.snapshots.forEach((item: { memo: string, id: string, hCreated: string, count: number, hSize: string, tag: string }) => {
|
2022-07-07 11:07:00 +08:00
|
|
|
if (isMobile()) {
|
|
|
|
|
repoHTML += `<li class="b3-list-item b3-list-item--two" data-id="${item.id}" data-tag="${item.tag}">
|
|
|
|
|
<div class="b3-list-item__first">
|
|
|
|
|
<span class="b3-chip b3-chip--secondary${item.tag ? "" : " fn__none"}">${item.tag}</span>
|
|
|
|
|
${item.hCreated}<span class="fn__space"></span>
|
|
|
|
|
<span class="b3-list-item__meta">${item.hSize}</span>
|
|
|
|
|
<span class="fn__flex-1"></span>
|
|
|
|
|
${actionHTML}
|
|
|
|
|
</div>
|
|
|
|
|
<span class="b3-list-item__meta">${escapeHtml(item.memo)}</span>
|
|
|
|
|
</li>`;
|
|
|
|
|
} else {
|
|
|
|
|
repoHTML += `<li class="b3-list-item b3-list-item--hide-action" data-id="${item.id}" data-tag="${item.tag}">
|
2022-07-05 11:58:20 +08:00
|
|
|
<div class="b3-list-item__text">
|
2022-07-05 23:58:38 +08:00
|
|
|
<span class="b3-chip b3-chip--secondary${item.tag ? "" : " fn__none"}">${item.tag}</span>
|
2022-07-05 22:56:30 +08:00
|
|
|
${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>
|
2022-07-05 11:58:20 +08:00
|
|
|
</div>
|
2022-07-05 22:56:30 +08:00
|
|
|
${actionHTML}
|
2022-06-13 22:10:41 +08:00
|
|
|
</li>`;
|
2022-07-07 11:07:00 +08:00
|
|
|
}
|
2022-06-13 22:10:41 +08:00
|
|
|
});
|
2022-07-05 22:56:30 +08:00
|
|
|
element.lastElementChild.innerHTML = `${repoHTML}`;
|
2022-07-06 00:35:39 +08:00
|
|
|
};
|
2022-07-05 22:56:30 +08:00
|
|
|
|
|
|
|
|
const renderRepo = (element: Element, currentPage: number) => {
|
2022-07-06 09:47:23 +08:00
|
|
|
element.lastElementChild.innerHTML = '<li style="position: relative;height: 100%;"><div class="fn__loading"><img width="64px" src="/stage/loading-pure.svg"></div></li>';
|
2022-07-05 22:56:30 +08:00
|
|
|
const previousElement = element.querySelector('[data-type="previous"]');
|
|
|
|
|
const nextElement = element.querySelector('[data-type="next"]');
|
|
|
|
|
if (currentPage < 0) {
|
|
|
|
|
if (currentPage === -1) {
|
|
|
|
|
fetchPost("/api/repo/getRepoTagSnapshots", {}, (response) => {
|
2022-07-06 09:05:36 +08:00
|
|
|
renderRepoItem(response, element, "localTag");
|
2022-07-06 00:35:39 +08:00
|
|
|
});
|
2022-07-05 22:56:30 +08:00
|
|
|
}
|
|
|
|
|
if (currentPage === -2) {
|
|
|
|
|
fetchPost("/api/repo/getCloudRepoTagSnapshots", {}, (response) => {
|
2022-07-06 09:05:36 +08:00
|
|
|
renderRepoItem(response, element, "cloudTag");
|
2022-07-06 00:35:39 +08:00
|
|
|
});
|
2022-07-05 22:56:30 +08:00
|
|
|
}
|
2022-07-06 00:35:39 +08:00
|
|
|
previousElement.classList.add("fn__none");
|
|
|
|
|
nextElement.classList.add("fn__none");
|
2022-07-05 22:56:30 +08:00
|
|
|
} else {
|
2022-07-06 00:35:39 +08:00
|
|
|
previousElement.classList.remove("fn__none");
|
|
|
|
|
nextElement.classList.remove("fn__none");
|
2022-07-05 22:56:30 +08:00
|
|
|
element.setAttribute("data-init", "true");
|
|
|
|
|
element.setAttribute("data-page", currentPage.toString());
|
|
|
|
|
if (currentPage > 1) {
|
|
|
|
|
previousElement.removeAttribute("disabled");
|
|
|
|
|
} else {
|
|
|
|
|
previousElement.setAttribute("disabled", "disabled");
|
|
|
|
|
}
|
|
|
|
|
fetchPost("/api/repo/getRepoSnapshots", {page: currentPage}, (response) => {
|
|
|
|
|
if (currentPage < response.data.pageCount) {
|
|
|
|
|
nextElement.removeAttribute("disabled");
|
|
|
|
|
} else {
|
|
|
|
|
nextElement.setAttribute("disabled", "disabled");
|
|
|
|
|
}
|
2022-07-06 09:05:36 +08:00
|
|
|
renderRepoItem(response, element, "local");
|
2022-07-05 22:56:30 +08:00
|
|
|
});
|
|
|
|
|
}
|
2022-06-13 22:10:41 +08:00
|
|
|
};
|
2022-05-26 15:18:53 +08:00
|
|
|
|
|
|
|
|
const renderRmNotebook = (element: HTMLElement) => {
|
|
|
|
|
element.setAttribute("data-init", "true");
|
|
|
|
|
fetchPost("/api/history/getNotebookHistory", {}, (response) => {
|
|
|
|
|
if (response.data.histories.length === 0) {
|
|
|
|
|
element.innerHTML = `<li class="b3-list--empty">${window.siyuan.languages.emptyContent}</li>`;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
let logsHTML = "";
|
2022-06-13 23:39:03 +08:00
|
|
|
response.data.histories.forEach((item: { items: { path: string, title: string }[], hCreated: string }, index: number) => {
|
2022-06-13 22:10:41 +08:00
|
|
|
logsHTML += `<li class="b3-list-item" style="padding-left: 0" data-type="toggle">
|
2022-05-26 15:18:53 +08:00
|
|
|
<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>
|
2022-06-13 23:39:03 +08:00
|
|
|
<span class="b3-list-item__text">${item.hCreated}</span>
|
2022-05-26 15:18:53 +08:00
|
|
|
</li>`;
|
|
|
|
|
if (item.items.length > 0) {
|
|
|
|
|
logsHTML += `<ul class="${index === 0 ? "" : "fn__none"}">`;
|
|
|
|
|
item.items.forEach((docItem) => {
|
|
|
|
|
logsHTML += `<li data-type="notebook" data-path="${docItem.path}" class="b3-list-item" style="padding-left: 32px">
|
|
|
|
|
<span class="b3-list-item__text">${escapeHtml(docItem.title)}</span>
|
|
|
|
|
<span class="fn__space"></span>
|
2022-07-05 11:58:20 +08:00
|
|
|
<span class="b3-list-item__action" data-type="rollback">
|
2022-05-26 15:18:53 +08:00
|
|
|
<svg><use xlink:href="#iconUndo"></use></svg><span class="fn__space"></span>${window.siyuan.languages.rollback}
|
|
|
|
|
</span>
|
|
|
|
|
</li>`;
|
|
|
|
|
});
|
|
|
|
|
logsHTML += "</ul>";
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
element.innerHTML = logsHTML;
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const openHistory = () => {
|
|
|
|
|
const exitDialog = window.siyuan.dialogs.find((item) => {
|
|
|
|
|
if (item.element.querySelector("#historyContainer")) {
|
|
|
|
|
item.destroy();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
if (exitDialog) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const dialog = new Dialog({
|
|
|
|
|
content: `<div class="fn__flex-column" style="height: 100%;">
|
|
|
|
|
<div class="layout-tab-bar fn__flex" style="border-radius: 4px 4px 0 0">
|
|
|
|
|
<div data-type="doc" class="item item--focus"><span class="item__text">${window.siyuan.languages.doc}</span></div>
|
|
|
|
|
<div data-type="assets" class="item"><span class="item__text">${window.siyuan.languages.assets}</span></div>
|
|
|
|
|
<div data-type="notebook" class="item"><span class="item__text">${window.siyuan.languages.removedNotebook}</span></div>
|
2022-06-13 23:35:38 +08:00
|
|
|
<div data-type="repo" class="item"><span class="item__text">${window.siyuan.languages.dataSnapshot}</span></div>
|
2022-05-26 15:18:53 +08:00
|
|
|
</div>
|
|
|
|
|
<div class="fn__flex-1 fn__flex" id="historyContainer">
|
|
|
|
|
<div data-type="doc" class="fn__flex fn__block" data-init="true">
|
|
|
|
|
<ul style="width:200px;overflow: auto;" class="b3-list b3-list--background">
|
|
|
|
|
<li class="b3-list--empty">${window.siyuan.languages.emptyContent}</li>
|
|
|
|
|
</ul>
|
|
|
|
|
<textarea class="fn__flex-1 b3-typography history__text" readonly></textarea>
|
|
|
|
|
</div>
|
|
|
|
|
<div data-type="assets" class="fn__flex fn__none">
|
|
|
|
|
<ul style="width:200px;overflow: auto;" class="b3-list b3-list--background">
|
|
|
|
|
<li class="b3-list--empty">${window.siyuan.languages.emptyContent}</li>
|
|
|
|
|
</ul>
|
|
|
|
|
<div class="fn__flex-1 history__asset"></div>
|
|
|
|
|
</div>
|
|
|
|
|
<ul data-type="notebook" style="background-color: var(--b3-theme-background);border-radius: 0 0 4px 4px" class="fn__none b3-list b3-list--background">
|
|
|
|
|
<li class="b3-list--empty">${window.siyuan.languages.emptyContent}</li>
|
|
|
|
|
</ul>
|
2022-06-13 22:45:04 +08:00
|
|
|
<div data-type="repo" class="fn__none history__repo">
|
|
|
|
|
<div class="fn__flex history__repoheader">
|
2022-07-03 16:37:44 +08:00
|
|
|
<span data-type="previous" class="block__icon b3-tooltips b3-tooltips__se" disabled="disabled" aria-label="${window.siyuan.languages.previousLabel}"><svg><use xlink:href='#iconLeft'></use></svg></span>
|
2022-06-13 22:45:04 +08:00
|
|
|
<span class="fn__space"></span>
|
2022-07-03 16:37:44 +08:00
|
|
|
<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>
|
2022-06-14 00:42:15 +08:00
|
|
|
<div class="fn__flex-1"></div>
|
2022-07-07 11:07:00 +08:00
|
|
|
<select class="b3-select" style="min-width: auto">
|
2022-07-05 23:24:02 +08:00
|
|
|
<option value="0">${window.siyuan.languages.localSnapshot}</option>
|
2022-07-05 23:11:53 +08:00
|
|
|
<option value="1">${window.siyuan.languages.localTagSnapshot}</option>
|
2022-07-05 23:16:53 +08:00
|
|
|
<option value="2">${window.siyuan.languages.cloudTagSnapshot}</option>
|
2022-07-05 17:00:50 +08:00
|
|
|
</select>
|
|
|
|
|
<span class="fn__space"></span>
|
2022-07-05 11:58:20 +08:00
|
|
|
<button class="b3-button b3-button--outline" data-type="genRepo">
|
|
|
|
|
<svg><use xlink:href="#iconAdd"></use></svg>${window.siyuan.languages.createSnapshot}
|
|
|
|
|
</button>
|
2022-06-13 22:45:04 +08:00
|
|
|
</div>
|
2022-07-05 11:58:20 +08:00
|
|
|
<ul style="background: var(--b3-theme-background);" class="b3-list b3-list--background fn__flex-1">
|
|
|
|
|
<li class="b3-list--empty">${window.siyuan.languages.emptyContent}</li>
|
|
|
|
|
</ul>
|
2022-06-13 22:10:41 +08:00
|
|
|
</div>
|
2022-05-26 15:18:53 +08:00
|
|
|
</div>
|
|
|
|
|
</div>`,
|
|
|
|
|
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);
|
2022-06-14 00:43:25 +08:00
|
|
|
const repoElement = dialog.element.querySelector('#historyContainer [data-type="repo"]');
|
2022-07-05 22:56:30 +08:00
|
|
|
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);
|
|
|
|
|
}
|
2022-07-06 00:35:39 +08:00
|
|
|
});
|
2022-05-26 15:18:53 +08:00
|
|
|
dialog.element.addEventListener("click", (event) => {
|
|
|
|
|
let target = event.target as HTMLElement;
|
|
|
|
|
while (target && !target.isEqualNode(dialog.element)) {
|
2022-06-14 00:43:25 +08:00
|
|
|
const type = target.getAttribute("data-type");
|
2022-05-26 15:18:53 +08:00
|
|
|
if (target.classList.contains("item")) {
|
|
|
|
|
target.parentElement.querySelector(".item--focus").classList.remove("item--focus");
|
|
|
|
|
Array.from(dialog.element.querySelector("#historyContainer").children).forEach((item: HTMLElement) => {
|
2022-06-13 22:10:41 +08:00
|
|
|
if (item.getAttribute("data-type") === type) {
|
2022-05-26 15:18:53 +08:00
|
|
|
item.classList.remove("fn__none");
|
|
|
|
|
item.classList.add("fn__block");
|
|
|
|
|
target.classList.add("item--focus");
|
|
|
|
|
if (item.getAttribute("data-init") !== "true") {
|
2022-06-13 22:10:41 +08:00
|
|
|
if (type === "assets") {
|
2022-05-26 15:18:53 +08:00
|
|
|
renderAssets(item);
|
2022-06-13 22:10:41 +08:00
|
|
|
} else if (type === "notebook") {
|
2022-05-26 15:18:53 +08:00
|
|
|
renderRmNotebook(item);
|
2022-06-13 22:10:41 +08:00
|
|
|
} else if (type === "repo") {
|
2022-06-14 00:42:15 +08:00
|
|
|
renderRepo(item, 1);
|
2022-05-26 15:18:53 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
item.classList.add("fn__none");
|
|
|
|
|
item.classList.remove("fn__block");
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
break;
|
2022-06-13 22:10:41 +08:00
|
|
|
} else if (type === "switchNotebook") {
|
2022-05-26 15:18:53 +08:00
|
|
|
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});
|
2022-06-18 22:47:53 +08:00
|
|
|
window.siyuan.menus.menu.element.style.zIndex = "310";
|
2022-05-26 15:18:53 +08:00
|
|
|
break;
|
2022-07-05 11:58:20 +08:00
|
|
|
} else if (target.classList.contains("b3-list-item__action") && type === "rollback" && !window.siyuan.config.readonly) {
|
2022-05-26 15:18:53 +08:00
|
|
|
confirmDialog("⚠️ " + window.siyuan.languages.rollback, `${window.siyuan.languages.rollbackConfirm.replace("${date}", target.parentElement.textContent.trim())}`, () => {
|
2022-06-14 00:43:25 +08:00
|
|
|
const dataType = target.parentElement.getAttribute("data-type");
|
2022-06-14 00:42:15 +08:00
|
|
|
if (dataType === "assets") {
|
2022-05-26 15:18:53 +08:00
|
|
|
fetchPost("/api/history/rollbackAssetsHistory", {
|
|
|
|
|
historyPath: target.parentElement.getAttribute("data-path")
|
|
|
|
|
});
|
2022-06-14 00:42:15 +08:00
|
|
|
} else if (dataType === "doc") {
|
2022-05-26 15:18:53 +08:00
|
|
|
fetchPost("/api/history/rollbackDocHistory", {
|
|
|
|
|
notebook: currentNotebook.id,
|
|
|
|
|
historyPath: target.parentElement.getAttribute("data-path")
|
|
|
|
|
});
|
2022-06-14 00:42:15 +08:00
|
|
|
} else if (dataType === "notebook") {
|
2022-05-26 15:18:53 +08:00
|
|
|
fetchPost("/api/history/rollbackNotebookHistory", {
|
|
|
|
|
historyPath: target.parentElement.getAttribute("data-path")
|
|
|
|
|
});
|
2022-06-14 00:42:15 +08:00
|
|
|
} else {
|
|
|
|
|
fetchPost("/api/repo/checkoutRepo", {
|
|
|
|
|
id: target.parentElement.getAttribute("data-id")
|
|
|
|
|
});
|
2022-05-26 15:18:53 +08:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
break;
|
2022-06-13 22:10:41 +08:00
|
|
|
} else if (type === "toggle") {
|
|
|
|
|
target.nextElementSibling.classList.toggle("fn__none");
|
|
|
|
|
target.firstElementChild.firstElementChild.classList.toggle("b3-list-item__arrow--open");
|
|
|
|
|
break;
|
2022-07-05 11:58:20 +08:00
|
|
|
} else if (target.classList.contains("b3-list-item") && (type === "assets" || type === "doc")) {
|
2022-05-26 15:18:53 +08:00
|
|
|
const dataPath = target.getAttribute("data-path");
|
2022-06-14 00:42:15 +08:00
|
|
|
if (type === "assets") {
|
2022-07-16 23:20:50 +08:00
|
|
|
firstPanelElement.nextElementSibling.lastElementChild.innerHTML = renderAssetsPreview(dataPath);
|
2022-06-14 00:42:15 +08:00
|
|
|
} else if (type === "doc") {
|
|
|
|
|
fetchPost("/api/history/getDocHistoryContent", {
|
|
|
|
|
historyPath: dataPath
|
|
|
|
|
}, (response) => {
|
|
|
|
|
firstPanelElement.lastElementChild.innerHTML = response.data.content;
|
|
|
|
|
});
|
|
|
|
|
}
|
2022-06-14 00:43:25 +08:00
|
|
|
let currentItem = hasClosestByClassName(target, "b3-list") as HTMLElement;
|
2022-06-14 00:42:15 +08:00
|
|
|
if (currentItem) {
|
2022-06-14 00:43:25 +08:00
|
|
|
currentItem = currentItem.querySelector(".b3-list-item--focus");
|
2022-05-26 15:18:53 +08:00
|
|
|
if (currentItem) {
|
|
|
|
|
currentItem.classList.remove("b3-list-item--focus");
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-06-14 00:42:15 +08:00
|
|
|
target.classList.add("b3-list-item--focus");
|
2022-05-26 15:18:53 +08:00
|
|
|
break;
|
2022-06-13 22:10:41 +08:00
|
|
|
} else if (type === "genRepo") {
|
|
|
|
|
const genRepoDialog = new Dialog({
|
2022-07-05 10:12:15 +08:00
|
|
|
title: window.siyuan.languages.snapshotMemo,
|
2022-06-13 22:10:41 +08:00
|
|
|
content: `<div class="b3-dialog__content">
|
2022-07-05 10:12:15 +08:00
|
|
|
<textarea class="b3-text-field fn__block" placeholder="${window.siyuan.languages.snapshotMemoTip}"></textarea>
|
2022-06-13 22:10:41 +08:00
|
|
|
</div>
|
|
|
|
|
<div class="b3-dialog__action">
|
|
|
|
|
<button class="b3-button b3-button--cancel">${window.siyuan.languages.cancel}</button><div class="fn__space"></div>
|
|
|
|
|
<button class="b3-button b3-button--text">${window.siyuan.languages.confirm}</button>
|
|
|
|
|
</div>`,
|
|
|
|
|
width: isMobile() ? "80vw" : "520px",
|
|
|
|
|
});
|
2022-07-05 10:12:15 +08:00
|
|
|
const textareaElement = genRepoDialog.element.querySelector("textarea");
|
|
|
|
|
textareaElement.focus();
|
2022-06-13 22:10:41 +08:00
|
|
|
const btnsElement = genRepoDialog.element.querySelectorAll(".b3-button");
|
|
|
|
|
btnsElement[0].addEventListener("click", () => {
|
|
|
|
|
genRepoDialog.destroy();
|
|
|
|
|
});
|
|
|
|
|
btnsElement[1].addEventListener("click", () => {
|
2022-07-05 10:12:15 +08:00
|
|
|
fetchPost("/api/repo/createSnapshot", {memo: textareaElement.value}, () => {
|
2022-06-14 00:43:25 +08:00
|
|
|
renderRepo(repoElement, 1);
|
|
|
|
|
});
|
2022-06-13 23:50:35 +08:00
|
|
|
genRepoDialog.destroy();
|
2022-06-13 22:10:41 +08:00
|
|
|
});
|
2022-06-14 00:42:15 +08:00
|
|
|
break;
|
2022-07-06 09:05:36 +08:00
|
|
|
} else if (type === "removeRepoTagSnapshot" || type === "removeCloudRepoTagSnapshot") {
|
2022-07-06 09:09:51 +08:00
|
|
|
const tag = target.parentElement.getAttribute("data-tag");
|
|
|
|
|
confirmDialog(window.siyuan.languages.delete, `${window.siyuan.languages.confirmDelete} <i>${tag}</i>?`, () => {
|
|
|
|
|
fetchPost("/api/repo/" + type, {tag}, () => {
|
|
|
|
|
if (target.parentElement.parentElement.childElementCount === 1) {
|
2022-07-08 10:38:11 +08:00
|
|
|
target.parentElement.parentElement.innerHTML = `<li class="b3-list--empty">${window.siyuan.languages.emptyContent}</li>`;
|
2022-07-06 09:09:51 +08:00
|
|
|
} else {
|
|
|
|
|
target.parentElement.remove();
|
|
|
|
|
}
|
|
|
|
|
});
|
2022-07-06 09:05:36 +08:00
|
|
|
});
|
2022-07-06 15:57:58 +08:00
|
|
|
break;
|
2022-07-05 17:00:50 +08:00
|
|
|
} else if (type === "uploadSnapshot") {
|
2022-07-05 22:56:30 +08:00
|
|
|
fetchPost("/api/repo/uploadCloudSnapshot", {
|
|
|
|
|
tag: target.parentElement.getAttribute("data-tag"),
|
|
|
|
|
id: target.parentElement.getAttribute("data-id")
|
|
|
|
|
});
|
2022-07-06 15:57:58 +08:00
|
|
|
break;
|
2022-07-05 17:00:50 +08:00
|
|
|
} else if (type === "downloadSnapshot") {
|
2022-07-05 22:56:30 +08:00
|
|
|
fetchPost("/api/repo/downloadCloudSnapshot", {
|
|
|
|
|
tag: target.parentElement.getAttribute("data-tag"),
|
|
|
|
|
id: target.parentElement.getAttribute("data-id")
|
2022-07-06 00:35:39 +08:00
|
|
|
});
|
2022-07-06 15:57:58 +08:00
|
|
|
break;
|
2022-07-05 11:58:20 +08:00
|
|
|
} else if (type === "genTag") {
|
|
|
|
|
const genTagDialog = new Dialog({
|
2022-07-05 23:11:53 +08:00
|
|
|
title: window.siyuan.languages.tagSnapshot,
|
2022-07-05 11:58:20 +08:00
|
|
|
content: `<div class="b3-dialog__content">
|
2022-07-05 23:11:53 +08:00
|
|
|
<input class="b3-text-field fn__block" placeholder="${window.siyuan.languages.tagSnapshotTip}">
|
2022-07-05 11:58:20 +08:00
|
|
|
</div>
|
|
|
|
|
<div class="b3-dialog__action">
|
|
|
|
|
<button class="b3-button b3-button--cancel">${window.siyuan.languages.cancel}</button><div class="fn__space"></div>
|
|
|
|
|
<button class="b3-button b3-button--text">${window.siyuan.languages.confirm}</button>
|
|
|
|
|
</div>`,
|
|
|
|
|
width: isMobile() ? "80vw" : "520px",
|
|
|
|
|
});
|
2022-07-05 23:11:53 +08:00
|
|
|
const inputElement = genTagDialog.element.querySelector(".b3-text-field") as HTMLInputElement;
|
|
|
|
|
inputElement.focus();
|
2022-07-05 11:58:20 +08:00
|
|
|
const btnsElement = genTagDialog.element.querySelectorAll(".b3-button");
|
|
|
|
|
btnsElement[0].addEventListener("click", () => {
|
|
|
|
|
genTagDialog.destroy();
|
|
|
|
|
});
|
|
|
|
|
btnsElement[1].addEventListener("click", () => {
|
|
|
|
|
fetchPost("/api/repo/tagSnapshot", {
|
|
|
|
|
id: target.parentElement.getAttribute("data-id"),
|
2022-07-05 23:11:53 +08:00
|
|
|
name: inputElement.value
|
2022-07-05 11:58:20 +08:00
|
|
|
}, () => {
|
|
|
|
|
renderRepo(repoElement, 1);
|
|
|
|
|
});
|
|
|
|
|
genTagDialog.destroy();
|
|
|
|
|
});
|
|
|
|
|
break;
|
2022-06-14 00:42:15 +08:00
|
|
|
} else if ((type === "previous" || type === "next") && target.getAttribute("disabled") !== "disabled") {
|
2022-06-14 00:43:25 +08:00
|
|
|
const currentPage = parseInt(repoElement.getAttribute("data-page"));
|
2022-06-14 00:42:15 +08:00
|
|
|
renderRepo(repoElement, type === "previous" ? currentPage - 1 : currentPage + 1);
|
|
|
|
|
break;
|
2022-05-26 15:18:53 +08:00
|
|
|
}
|
|
|
|
|
target = target.parentElement;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|