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 {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-08-31 01:14:45 +08:00
|
|
|
import Protyle from "../protyle";
|
|
|
|
|
import {onGet} from "../protyle/util/onGet";
|
2022-05-26 15:18:53 +08:00
|
|
|
|
2022-08-31 01:14:45 +08:00
|
|
|
let historyEditor: Protyle
|
2022-08-29 23:49:12 +08:00
|
|
|
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");
|
2022-05-26 15:18:53 +08:00
|
|
|
}
|
2022-08-29 23:49:12 +08:00
|
|
|
const inputElement = element.querySelector(".b3-text-field") as HTMLInputElement;
|
2022-08-30 17:58:28 +08:00
|
|
|
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")
|
2022-08-31 01:14:45 +08:00
|
|
|
element.lastElementChild.lastElementChild.previousElementSibling.classList.add("fn__none");
|
|
|
|
|
element.lastElementChild.lastElementChild.classList.remove("fn__none");
|
2022-08-30 17:58:28 +08:00
|
|
|
} else {
|
|
|
|
|
opElement.setAttribute("disabled", "disabled")
|
|
|
|
|
notebookElement.setAttribute("disabled", "disabled")
|
2022-08-31 01:14:45 +08:00
|
|
|
element.lastElementChild.lastElementChild.previousElementSibling.classList.remove("fn__none");
|
|
|
|
|
element.lastElementChild.lastElementChild.classList.add("fn__none");
|
2022-08-30 17:58:28 +08:00
|
|
|
}
|
2022-08-29 23:49:12 +08:00
|
|
|
fetchPost("/api/history/searchHistory", {
|
2022-08-30 17:58:28 +08:00
|
|
|
notebook: notebookElement.value,
|
2022-08-29 23:49:12 +08:00
|
|
|
query: inputElement.value,
|
|
|
|
|
page: currentPage,
|
2022-08-30 17:58:28 +08:00
|
|
|
op: opElement.value,
|
|
|
|
|
type: parseInt(typeElement.value)
|
2022-05-26 15:18:53 +08:00
|
|
|
}, (response) => {
|
2022-08-30 00:16:47 +08:00
|
|
|
if (currentPage < response.data.pageCount) {
|
2022-08-29 23:49:12 +08:00
|
|
|
nextElement.removeAttribute("disabled");
|
|
|
|
|
} else {
|
|
|
|
|
nextElement.setAttribute("disabled", "disabled");
|
|
|
|
|
}
|
2022-05-26 15:18:53 +08:00
|
|
|
if (response.data.histories.length === 0) {
|
2022-08-31 01:14:45 +08:00
|
|
|
element.lastElementChild.lastElementChild.previousElementSibling.classList.add("fn__none");
|
|
|
|
|
element.lastElementChild.lastElementChild.classList.add("fn__none");
|
2022-08-29 23:49:12 +08:00
|
|
|
element.lastElementChild.firstElementChild.innerHTML = `<li class="b3-list--empty">${window.siyuan.languages.emptyContent}</li>`;
|
2022-05-26 15:18:53 +08:00
|
|
|
return;
|
|
|
|
|
}
|
2022-08-29 23:49:12 +08:00
|
|
|
let logsHTML = "";
|
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) => {
|
2022-08-30 17:58:28 +08:00
|
|
|
logsHTML += `<li title="${escapeHtml(docItem.title)}" data-type="${typeElement.value === "1" ? "assets" : "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">
|
2022-05-26 15:18:53 +08:00
|
|
|
<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-08-30 17:58:28 +08:00
|
|
|
if (typeElement.value === "1") {
|
2022-08-31 01:14:45 +08:00
|
|
|
element.lastElementChild.lastElementChild.previousElementSibling.innerHTML = renderAssetsPreview(item.items[0].path);
|
2022-08-30 17:58:28 +08:00
|
|
|
} else {
|
|
|
|
|
fetchPost("/api/history/getDocHistoryContent", {
|
2022-08-31 10:57:19 +08:00
|
|
|
historyPath: item.items[0].path,
|
|
|
|
|
k: inputElement.value
|
2022-08-30 17:58:28 +08:00
|
|
|
}, (contentResponse) => {
|
2022-08-31 10:50:34 +08:00
|
|
|
onGet(contentResponse, historyEditor.protyle, [Constants.CB_GET_HISTORY, Constants.CB_GET_HTML]);
|
2022-08-30 17:58:28 +08:00
|
|
|
});
|
|
|
|
|
}
|
2022-05-26 15:18:53 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
2022-08-29 23:49:12 +08:00
|
|
|
element.lastElementChild.firstElementChild.innerHTML = logsHTML;
|
2022-05-26 15:18:53 +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()) {
|
2022-07-20 11:23:51 +08:00
|
|
|
repoHTML += `<li class="b3-list-item b3-list-item--two">
|
2022-07-07 11:07:00 +08:00
|
|
|
<div class="b3-list-item__first">
|
2022-07-20 11:23:51 +08:00
|
|
|
<span class="b3-list-item__text">${escapeHtml(item.memo)}</span>
|
2022-07-07 11:07:00 +08:00
|
|
|
<span class="b3-chip b3-chip--secondary${item.tag ? "" : " fn__none"}">${item.tag}</span>
|
2022-07-20 11:23:51 +08:00
|
|
|
</div>
|
|
|
|
|
<div>
|
|
|
|
|
<span class="ft__smaller ft__on-surface">${item.hCreated}</span>
|
2022-07-07 11:07:00 +08:00
|
|
|
<span class="b3-list-item__meta">${item.hSize}</span>
|
2022-07-20 11:23:51 +08:00
|
|
|
<span class="b3-list-item__meta">${window.siyuan.languages.fileCount}${item.count}</span>
|
2022-07-07 11:07:00 +08:00
|
|
|
</div>
|
2022-07-20 11:23:51 +08:00
|
|
|
<div class="fn__flex" style="justify-content: flex-end;" data-id="${item.id}" data-tag="${item.tag}">${actionHTML}</div>
|
2022-07-07 11:07:00 +08:00
|
|
|
</li>`;
|
|
|
|
|
} else {
|
|
|
|
|
repoHTML += `<li class="b3-list-item b3-list-item--hide-action" data-id="${item.id}" data-tag="${item.tag}">
|
2022-07-17 10:52:31 +08:00
|
|
|
<div class="fn__flex-1">
|
|
|
|
|
<div class="b3-list-item__text">
|
|
|
|
|
${escapeHtml(item.memo)}
|
|
|
|
|
<span class="b3-chip b3-chip--secondary${item.tag ? "" : " fn__none"}">${item.tag}</span>
|
|
|
|
|
</div>
|
|
|
|
|
<div>
|
|
|
|
|
<span class="ft__smaller ft__on-surface">${item.hCreated}</span>
|
|
|
|
|
<span class="b3-list-item__meta">${item.hSize}</span>
|
|
|
|
|
<span class="b3-list-item__meta">${window.siyuan.languages.fileCount}${item.count}</span>
|
|
|
|
|
</div>
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-29 23:49:12 +08:00
|
|
|
const currentNotebookId = localStorage.getItem(Constants.LOCAL_HISTORYNOTEID);
|
|
|
|
|
let notebookSelectHTML = '';
|
|
|
|
|
window.siyuan.notebooks.forEach((item) => {
|
|
|
|
|
if (!item.closed) {
|
|
|
|
|
notebookSelectHTML += ` <option value="${item.id}"${item.id === currentNotebookId ? " selected" : ""}>${item.name}</option>`
|
|
|
|
|
}
|
|
|
|
|
});
|
2022-05-26 15:18:53 +08:00
|
|
|
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">
|
2022-08-30 23:12:24 +08:00
|
|
|
<div data-type="doc" class="item item--focus"><span class="item__text">${window.siyuan.languages.fileHistory}</span></div>
|
2022-05-26 15:18:53 +08:00
|
|
|
<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">
|
2022-08-29 23:49:12 +08:00
|
|
|
<div data-type="doc" class="history__repo fn__block" data-init="true">
|
|
|
|
|
<div class="fn__flex history__repoheader">
|
|
|
|
|
<span data-type="docprevious" class="block__icon b3-tooltips b3-tooltips__se" disabled="disabled" aria-label="${window.siyuan.languages.previousLabel}"><svg><use xlink:href='#iconLeft'></use></svg></span>
|
|
|
|
|
<span class="fn__space"></span>
|
|
|
|
|
<span data-type="docnext" 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>
|
2022-08-30 00:06:50 +08:00
|
|
|
<div style="position: relative">
|
|
|
|
|
<svg class="b3-form__icon-icon ft__on-surface"><use xlink:href="#iconSearch"></use></svg>
|
2022-08-29 23:49:12 +08:00
|
|
|
<input class="b3-text-field b3-form__icon-input">
|
|
|
|
|
</div>
|
|
|
|
|
<span class="fn__space"></span>
|
2022-08-30 17:58:28 +08:00
|
|
|
<select data-type="typeselect" class="b3-select" style="min-width: auto">
|
|
|
|
|
<option value="0" selected>${window.siyuan.languages.doc}</option>
|
|
|
|
|
<option value="1">${window.siyuan.languages.assets}</option>
|
|
|
|
|
</select>
|
|
|
|
|
<span class="fn__space"></span>
|
|
|
|
|
<select data-type="opselect" class="b3-select" style="min-width: auto">
|
2022-08-29 23:49:12 +08:00
|
|
|
<option value="all" selected>all</option>
|
|
|
|
|
<option value="clean">clean</option>
|
|
|
|
|
<option value="update">update</option>
|
|
|
|
|
<option value="delete">delete</option>
|
|
|
|
|
<option value="format">format</option>
|
|
|
|
|
<option value="sync">sync</option>
|
|
|
|
|
</select>
|
|
|
|
|
<span class="fn__space"></span>
|
2022-08-30 17:58:28 +08:00
|
|
|
<select data-type="notebookselect" class="b3-select" style="min-width: auto">
|
2022-08-29 23:49:12 +08:00
|
|
|
${notebookSelectHTML}
|
|
|
|
|
</select>
|
2022-08-30 00:16:47 +08:00
|
|
|
<span class="fn__space"></span>
|
|
|
|
|
<button data-type="rebuildIndex" class="b3-button b3-button--outline">${window.siyuan.languages.rebuildIndex}</button>
|
2022-08-29 23:49:12 +08:00
|
|
|
</div>
|
|
|
|
|
<div class="fn__flex fn__flex-1">
|
|
|
|
|
<ul style="width:200px;overflow: auto;" class="b3-list b3-list--background">
|
|
|
|
|
<li class="b3-list--empty">${window.siyuan.languages.emptyContent}</li>
|
|
|
|
|
</ul>
|
2022-08-31 01:14:45 +08:00
|
|
|
<div class="fn__flex-1 history__text"></div>
|
|
|
|
|
<div class="fn__flex-1 history__text"></div>
|
2022-08-29 23:49:12 +08:00
|
|
|
</div>
|
2022-05-26 15:18:53 +08:00
|
|
|
</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",
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const firstPanelElement = dialog.element.querySelector("#historyContainer [data-type=doc]") as HTMLElement;
|
2022-08-29 23:49:12 +08:00
|
|
|
firstPanelElement.querySelectorAll(".b3-select").forEach((itemElement) => {
|
|
|
|
|
itemElement.addEventListener("change", () => {
|
|
|
|
|
renderDoc(firstPanelElement, 1);
|
|
|
|
|
});
|
|
|
|
|
});
|
2022-08-30 00:06:50 +08:00
|
|
|
firstPanelElement.querySelector(".b3-text-field").addEventListener("input", (event: KeyboardEvent) => {
|
|
|
|
|
if (event.isComposing) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
renderDoc(firstPanelElement, 1);
|
|
|
|
|
});
|
|
|
|
|
firstPanelElement.querySelector(".b3-text-field").addEventListener("compositionend", () => {
|
|
|
|
|
renderDoc(firstPanelElement, 1);
|
|
|
|
|
});
|
2022-08-29 23:49:12 +08:00
|
|
|
renderDoc(firstPanelElement, 1);
|
2022-08-31 01:14:45 +08:00
|
|
|
historyEditor = new Protyle(firstPanelElement.lastElementChild.lastElementChild as HTMLElement, {
|
|
|
|
|
blockId: "",
|
|
|
|
|
action: [Constants.CB_GET_HISTORY],
|
|
|
|
|
render: {
|
|
|
|
|
background: false,
|
|
|
|
|
title: false,
|
|
|
|
|
gutter: false,
|
|
|
|
|
scroll: false,
|
|
|
|
|
breadcrumb: false,
|
|
|
|
|
breadcrumbDocName: false,
|
|
|
|
|
breadcrumbContext: false,
|
|
|
|
|
},
|
|
|
|
|
typewriterMode: false,
|
|
|
|
|
});
|
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-08-30 17:58:28 +08:00
|
|
|
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-08-30 00:06:50 +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", {
|
2022-08-30 21:22:59 +08:00
|
|
|
notebook: (firstPanelElement.querySelector('.b3-select[data-type="notebookselect"]') as HTMLSelectElement).value,
|
2022-05-26 15:18:53 +08:00
|
|
|
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-08-31 01:14:45 +08:00
|
|
|
firstPanelElement.lastElementChild.lastElementChild.previousElementSibling.innerHTML = renderAssetsPreview(dataPath);
|
2022-06-14 00:42:15 +08:00
|
|
|
} else if (type === "doc") {
|
|
|
|
|
fetchPost("/api/history/getDocHistoryContent", {
|
2022-08-31 10:57:19 +08:00
|
|
|
historyPath: dataPath,
|
|
|
|
|
k: (firstPanelElement.querySelector(".b3-text-field") as HTMLInputElement).value
|
2022-06-14 00:42:15 +08:00
|
|
|
}, (response) => {
|
2022-08-31 10:50:34 +08:00
|
|
|
onGet(response, historyEditor.protyle, [Constants.CB_GET_HISTORY, Constants.CB_GET_HTML]);
|
2022-06-14 00:42:15 +08:00
|
|
|
});
|
|
|
|
|
}
|
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");
|
2022-07-17 11:06:05 +08:00
|
|
|
genRepoDialog.bindInput(textareaElement, () => {
|
|
|
|
|
(btnsElement[1] as HTMLButtonElement).click();
|
|
|
|
|
});
|
2022-06-13 22:10:41 +08:00
|
|
|
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}, () => {
|
2022-07-20 11:23:51 +08:00
|
|
|
renderRepo(repoElement, type === "removeRepoTagSnapshot" ? -1 : -2);
|
2022-07-06 09:09:51 +08:00
|
|
|
});
|
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();
|
|
|
|
|
});
|
2022-07-17 11:06:05 +08:00
|
|
|
genTagDialog.bindInput(inputElement, () => {
|
|
|
|
|
(btnsElement[1] as HTMLButtonElement).click();
|
|
|
|
|
});
|
2022-07-05 11:58:20 +08:00
|
|
|
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-08-29 23:49:12 +08:00
|
|
|
} else if ((type === "docprevious" || type === "docnext") && target.getAttribute("disabled") !== "disabled") {
|
2022-08-30 00:16:47 +08:00
|
|
|
const currentPage = parseInt(firstPanelElement.getAttribute("data-page"));
|
2022-08-29 23:49:12 +08:00
|
|
|
renderDoc(firstPanelElement, type === "docprevious" ? currentPage - 1 : currentPage + 1);
|
|
|
|
|
break;
|
2022-08-30 00:16:47 +08:00
|
|
|
} else if (type === "rebuildIndex") {
|
2022-08-30 17:58:28 +08:00
|
|
|
fetchPost("/api/history/reindexHistory", {}, () => {
|
2022-08-30 00:16:47 +08:00
|
|
|
renderDoc(firstPanelElement, 1);
|
|
|
|
|
});
|
|
|
|
|
break;
|
2022-05-26 15:18:53 +08:00
|
|
|
}
|
|
|
|
|
target = target.parentElement;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|