A privacy-first, self-hosted, fully open source personal knowledge management software, written in typescript and golang. (PERSONAL FORK)
1import {Dialog} from "../dialog";
2import {fetchPost} from "../util/fetch";
3import {isMobile} from "../util/functions";
4import {escapeHtml} from "../util/escape";
5import {writeText} from "../protyle/util/compatibility";
6import {showMessage} from "../dialog/message";
7import {openModel} from "../mobile/menu/model";
8import {Constants} from "../constants";
9
10declare interface INotebookConf {
11 name: string,
12 box: string,
13 conf: {
14 refCreateSavePath: string
15 docCreateSavePath: string
16 dailyNoteSavePath: string
17 refCreateSaveBox: string;
18 docCreateSaveBox: string;
19 dailyNoteTemplatePath: string
20 }
21}
22
23export const genNotebookOption = (id: string, notebookId?: string) => {
24 let html = `<option value="">${window.siyuan.languages.currentNotebook}</option>`;
25 const helpIds: string[] = [];
26 Object.keys(Constants.HELP_PATH).forEach((key: "zh_CN") => {
27 helpIds.push(Constants.HELP_PATH[key]);
28 });
29 window.siyuan.notebooks.forEach((item) => {
30 if (helpIds.includes(item.id) || item.id === notebookId) {
31 return;
32 }
33 html += `<option value="${item.id}" ${id === item.id ? "selected" : ""}>${escapeHtml(item.name)}</option>`;
34 });
35 return html;
36};
37
38export const onGetnotebookconf = (data: INotebookConf) => {
39 const titleHTML = `<div class="fn__flex">${escapeHtml(data.name)}
40<div class="fn__space"></div>
41<button class="b3-button b3-button--small fn__flex-center">${window.siyuan.languages.copy} ID</button></div>`;
42 const contentHTML = `<div class="b3-dialog__content" style="background-color: var(--b3-theme-background);">
43<div class="b3-label config__item">
44 ${window.siyuan.languages.fileTree12}
45 <div class="b3-label__text">${window.siyuan.languages.fileTree13}</div>
46 <span class="fn__hr"></span>
47 <div class="fn__flex">
48 <select style="min-width: 200px" class="b3-select" id="docCreateSaveBox">${genNotebookOption(data.conf.docCreateSaveBox, data.box)}</select>
49 <div class="fn__space"></div>
50 <input class="b3-text-field fn__flex-1" id="docCreateSavePath" value="">
51 </div>
52</div>
53<div class="b3-label config__item">
54 ${window.siyuan.languages.fileTree5}
55 <div class="b3-label__text">${window.siyuan.languages.fileTree6}</div>
56 <span class="fn__hr"></span>
57 <div class="fn__flex">
58 <select style="min-width: 200px" class="b3-select" id="refCreateSaveBox">${genNotebookOption(data.conf.refCreateSaveBox, data.box)}</select>
59 <div class="fn__space"></div>
60 <input class="b3-text-field fn__flex-1" id="refCreateSavePath" value="">
61 </div>
62</div>
63<div class="b3-label">
64 ${window.siyuan.languages.fileTree11}
65 <div class="b3-label__text">${window.siyuan.languages.fileTree14}</div>
66 <div class="fn__hr"></div>
67 <input class="b3-text-field fn__flex-center fn__block" id="dailyNoteSavePath" value="">
68 <div class="fn__hr"></div>
69 <div class="b3-label__text">${window.siyuan.languages.fileTree15}</div>
70 <div class="fn__hr"></div>
71 <input class="b3-text-field fn__flex-center fn__block" id="dailyNoteTemplatePath" value="${data.conf.dailyNoteTemplatePath}">
72</div></div>`;
73 if (isMobile()) {
74 openModel({
75 title: titleHTML,
76 icon: "iconSettings",
77 html: `<div>${contentHTML}</div>`,
78 bindEvent() {
79 bindSettingEvent(document.querySelector("#model"), data);
80 }
81 });
82 } else {
83 const dialog = new Dialog({
84 width: "80vw",
85 title: titleHTML,
86 content: contentHTML
87 });
88 dialog.element.setAttribute("data-key", Constants.DIALOG_NOTEBOOKCONF);
89 bindSettingEvent(dialog.element, data);
90 }
91};
92
93const bindSettingEvent = (contentElement: Element, data: INotebookConf) => {
94 contentElement.querySelector(".b3-button--small").addEventListener("click", () => {
95 writeText(data.box);
96 showMessage(window.siyuan.languages.copied);
97 });
98 const dailyNoteSavePathElement = contentElement.querySelector("#dailyNoteSavePath") as HTMLInputElement;
99 dailyNoteSavePathElement.value = data.conf.dailyNoteSavePath;
100 const docCreateSavePathElement = contentElement.querySelector("#docCreateSavePath") as HTMLInputElement;
101 docCreateSavePathElement.value = data.conf.docCreateSavePath;
102 const refCreateSavePathElement = contentElement.querySelector("#refCreateSavePath") as HTMLInputElement;
103 refCreateSavePathElement.value = data.conf.refCreateSavePath;
104 const dailyNoteTemplatePathElement = contentElement.querySelector("#dailyNoteTemplatePath") as HTMLInputElement;
105 dailyNoteTemplatePathElement.value = data.conf.dailyNoteTemplatePath;
106 contentElement.querySelectorAll("input, select").forEach((item) => {
107 item.addEventListener("change", () => {
108 fetchPost("/api/notebook/setNotebookConf", {
109 notebook: data.box,
110 conf: {
111 refCreateSavePath: refCreateSavePathElement.value,
112 refCreateSaveBox: (contentElement.querySelector("#refCreateSaveBox") as HTMLInputElement).value,
113 docCreateSaveBox: (contentElement.querySelector("#docCreateSaveBox") as HTMLInputElement).value,
114 docCreateSavePath: docCreateSavePathElement.value,
115 dailyNoteSavePath: dailyNoteSavePathElement.value,
116 dailyNoteTemplatePath: dailyNoteTemplatePathElement.value,
117 }
118 });
119 });
120 });
121};