mirror of
https://github.com/zadam/trilium.git
synced 2025-10-19 06:38:59 +02:00
chore(client/print): load nota into forca
This commit is contained in:
parent
e83eacb18b
commit
54724b8c58
@ -1 +1,19 @@
|
||||
console.log("Print script is here.");
|
||||
import FNote from "./entities/fnote";
|
||||
|
||||
async function main() {
|
||||
const noteId = window.location.pathname.split("/")[2];
|
||||
const froca = (await import("./services/froca")).default;
|
||||
const note = await froca.getNote(noteId);
|
||||
|
||||
if (!note) return;
|
||||
|
||||
if (note.type === "book") {
|
||||
handleCollection(note);
|
||||
}
|
||||
}
|
||||
|
||||
function handleCollection(note: FNote) {
|
||||
console.log("Rendering collection.");
|
||||
}
|
||||
|
||||
main();
|
||||
|
@ -40,20 +40,23 @@ class FrocaImpl implements Froca {
|
||||
|
||||
constructor() {
|
||||
this.initializedPromise = this.loadInitialTree();
|
||||
this.#clear();
|
||||
}
|
||||
|
||||
async loadInitialTree() {
|
||||
const resp = await server.get<SubtreeResponse>("tree");
|
||||
|
||||
// clear the cache only directly before adding new content which is important for e.g., switching to protected session
|
||||
this.#clear();
|
||||
this.addResp(resp);
|
||||
}
|
||||
|
||||
#clear() {
|
||||
this.notes = {};
|
||||
this.branches = {};
|
||||
this.attributes = {};
|
||||
this.attachments = {};
|
||||
this.blobPromises = {};
|
||||
|
||||
this.addResp(resp);
|
||||
}
|
||||
|
||||
async loadSubTree(subTreeNoteId: string) {
|
||||
|
@ -70,26 +70,26 @@ async function setupProtectedSession(password: string) {
|
||||
protectedSessionHolder.enableProtectedSession();
|
||||
}
|
||||
|
||||
ws.subscribeToMessages(async (message) => {
|
||||
if (message.type === "protectedSessionLogin") {
|
||||
await reloadData();
|
||||
// ws.subscribeToMessages(async (message) => {
|
||||
// if (message.type === "protectedSessionLogin") {
|
||||
// await reloadData();
|
||||
|
||||
await appContext.triggerEvent("frocaReloaded", {});
|
||||
// await appContext.triggerEvent("frocaReloaded", {});
|
||||
|
||||
appContext.triggerEvent("protectedSessionStarted", {});
|
||||
// appContext.triggerEvent("protectedSessionStarted", {});
|
||||
|
||||
appContext.triggerCommand("closeProtectedSessionPasswordDialog");
|
||||
// appContext.triggerCommand("closeProtectedSessionPasswordDialog");
|
||||
|
||||
if (protectedSessionDeferred !== null) {
|
||||
protectedSessionDeferred.resolve(true);
|
||||
protectedSessionDeferred = null;
|
||||
}
|
||||
// if (protectedSessionDeferred !== null) {
|
||||
// protectedSessionDeferred.resolve(true);
|
||||
// protectedSessionDeferred = null;
|
||||
// }
|
||||
|
||||
toastService.showMessage(t("protected_session.started"));
|
||||
} else if (message.type === "protectedSessionLogout") {
|
||||
utils.reloadFrontendApp(`Protected session logout`);
|
||||
}
|
||||
});
|
||||
// toastService.showMessage(t("protected_session.started"));
|
||||
// } else if (message.type === "protectedSessionLogout") {
|
||||
// utils.reloadFrontendApp(`Protected session logout`);
|
||||
// }
|
||||
// });
|
||||
|
||||
async function protectNote(noteId: string, protect: boolean, includingSubtree: boolean) {
|
||||
await enterProtectedSession();
|
||||
@ -106,29 +106,29 @@ function makeToast(message: Message, title: string, text: string): ToastOptions
|
||||
};
|
||||
}
|
||||
|
||||
ws.subscribeToMessages(async (message) => {
|
||||
if (!("taskType" in message) || message.taskType !== "protectNotes") {
|
||||
return;
|
||||
}
|
||||
// ws.subscribeToMessages(async (message) => {
|
||||
// if (!("taskType" in message) || message.taskType !== "protectNotes") {
|
||||
// return;
|
||||
// }
|
||||
|
||||
const isProtecting = message.data?.protect;
|
||||
const title = isProtecting ? t("protected_session.protecting-title") : t("protected_session.unprotecting-title");
|
||||
// const isProtecting = message.data?.protect;
|
||||
// const title = isProtecting ? t("protected_session.protecting-title") : t("protected_session.unprotecting-title");
|
||||
|
||||
if (message.type === "taskError") {
|
||||
toastService.closePersistent(message.taskId);
|
||||
toastService.showError(message.message);
|
||||
} else if (message.type === "taskProgressCount") {
|
||||
const count = message.progressCount;
|
||||
const text = isProtecting ? t("protected_session.protecting-in-progress", { count }) : t("protected_session.unprotecting-in-progress-count", { count });
|
||||
toastService.showPersistent(makeToast(message, title, text));
|
||||
} else if (message.type === "taskSucceeded") {
|
||||
const text = isProtecting ? t("protected_session.protecting-finished-successfully") : t("protected_session.unprotecting-finished-successfully");
|
||||
const toast = makeToast(message, title, text);
|
||||
toast.closeAfter = 3000;
|
||||
// if (message.type === "taskError") {
|
||||
// toastService.closePersistent(message.taskId);
|
||||
// toastService.showError(message.message);
|
||||
// } else if (message.type === "taskProgressCount") {
|
||||
// const count = message.progressCount;
|
||||
// const text = isProtecting ? t("protected_session.protecting-in-progress", { count }) : t("protected_session.unprotecting-in-progress-count", { count });
|
||||
// toastService.showPersistent(makeToast(message, title, text));
|
||||
// } else if (message.type === "taskSucceeded") {
|
||||
// const text = isProtecting ? t("protected_session.protecting-finished-successfully") : t("protected_session.unprotecting-finished-successfully");
|
||||
// const toast = makeToast(message, title, text);
|
||||
// toast.closeAfter = 3000;
|
||||
|
||||
toastService.showPersistent(toast);
|
||||
}
|
||||
});
|
||||
// toastService.showPersistent(toast);
|
||||
// }
|
||||
// });
|
||||
|
||||
export default {
|
||||
protectNote,
|
||||
|
@ -122,17 +122,17 @@ async function resolveNotePathToSegments(notePath: string, hoistedNoteId = "root
|
||||
}
|
||||
}
|
||||
|
||||
ws.subscribeToMessages((message) => {
|
||||
if (message.type === "openNote") {
|
||||
appContext.tabManager.activateOrOpenNote(message.noteId);
|
||||
// ws.subscribeToMessages((message) => {
|
||||
// if (message.type === "openNote") {
|
||||
// appContext.tabManager.activateOrOpenNote(message.noteId);
|
||||
|
||||
if (utils.isElectron()) {
|
||||
const currentWindow = utils.dynamicRequire("@electron/remote").getCurrentWindow();
|
||||
// if (utils.isElectron()) {
|
||||
// const currentWindow = utils.dynamicRequire("@electron/remote").getCurrentWindow();
|
||||
|
||||
currentWindow.show();
|
||||
}
|
||||
}
|
||||
});
|
||||
// currentWindow.show();
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
|
||||
function getParentProtectedStatus(node: Fancytree.FancytreeNode) {
|
||||
return hoistedNoteService.isHoistedNode(node) ? false : node.getParent().data.isProtected;
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
window.glob = {
|
||||
device: "<%= device %>",
|
||||
baseApiUrl: 'api/',
|
||||
baseApiUrl: "<%= baseApiUrl %>",
|
||||
activeDialog: null,
|
||||
maxEntityChangeIdAtLoad: <%= maxEntityChangeIdAtLoad %>,
|
||||
maxEntityChangeSyncIdAtLoad: <%= maxEntityChangeSyncIdAtLoad %>,
|
||||
|
@ -21,6 +21,8 @@
|
||||
document.getElementsByTagName("body")[0].style.display = "none";
|
||||
</script>
|
||||
|
||||
<%- include("./partials/windowGlobal.ejs", locals) %>
|
||||
|
||||
<!-- Required for correct loading of scripts in Electron -->
|
||||
<script>if (typeof module === 'object') {window.module = module; module = undefined;}</script>
|
||||
|
||||
|
@ -1,14 +0,0 @@
|
||||
import { Request, Response } from "express";
|
||||
import assetPath from "../../services/asset_path";
|
||||
import app_path from "../../services/app_path";
|
||||
import { getCurrentLocale } from "../../services/i18n";
|
||||
|
||||
export function getPrintablePage(req: Request, res: Response) {
|
||||
const { noteId } = req.params;
|
||||
|
||||
res.render("print", {
|
||||
assetPath: assetPath,
|
||||
appPath: app_path,
|
||||
currentLocale: getCurrentLocale()
|
||||
});
|
||||
}
|
@ -16,9 +16,19 @@ import type { Request, Response } from "express";
|
||||
import type BNote from "../becca/entities/bnote.js";
|
||||
import { getCurrentLocale } from "../services/i18n.js";
|
||||
|
||||
type View = "desktop" | "mobile" | "print";
|
||||
|
||||
function index(req: Request, res: Response) {
|
||||
const options = optionService.getOptionMap();
|
||||
const view = getView(req);
|
||||
renderView(req, res, view);
|
||||
}
|
||||
|
||||
export function printIndex(req: Request, res: Response) {
|
||||
renderView(req, res, "print");
|
||||
}
|
||||
|
||||
function renderView(req: Request, res: Response, view: View) {
|
||||
const options = optionService.getOptionMap();
|
||||
|
||||
//'overwrite' set to false (default) => the existing token will be re-used and validated
|
||||
//'validateOnReuse' set to false => if validation fails, generate a new token instead of throwing an error
|
||||
@ -57,8 +67,9 @@ function index(req: Request, res: Response) {
|
||||
isProtectedSessionAvailable: protectedSessionService.isProtectedSessionAvailable(),
|
||||
maxContentWidth: Math.max(640, parseInt(options.maxContentWidth)),
|
||||
triliumVersion: packageJson.version,
|
||||
assetPath: assetPath,
|
||||
appPath: appPath,
|
||||
assetPath: view !== "print" ? assetPath : "../" + assetPath,
|
||||
appPath: view !== "print" ? appPath : "../" + appPath,
|
||||
baseApiUrl: view !== "print" ? 'api/' : "../api/",
|
||||
currentLocale: getCurrentLocale()
|
||||
});
|
||||
}
|
||||
@ -122,5 +133,6 @@ function getAppCssNoteIds() {
|
||||
}
|
||||
|
||||
export default {
|
||||
index
|
||||
index,
|
||||
printIndex
|
||||
};
|
||||
|
@ -72,7 +72,6 @@ import etapiBackupRoute from "../etapi/backup.js";
|
||||
import etapiMetricsRoute from "../etapi/metrics.js";
|
||||
import apiDocsRoute from "./api_docs.js";
|
||||
import { apiResultHandler, apiRoute, asyncApiRoute, asyncRoute, route, router, uploadMiddlewareWithErrorHandling } from "./route_api.js";
|
||||
import { getPrintablePage } from "./api/print.js";
|
||||
|
||||
const GET = "get",
|
||||
PST = "post",
|
||||
@ -82,6 +81,7 @@ const GET = "get",
|
||||
|
||||
function register(app: express.Application) {
|
||||
route(GET, "/", [auth.checkAuth, csrfMiddleware], indexRoute.index);
|
||||
route(GET, "/print/:noteId", [ auth.checkAuth ], indexRoute.printIndex);
|
||||
route(GET, "/login", [auth.checkAppInitialized, auth.checkPasswordSet], loginRoute.loginPage);
|
||||
route(GET, "/set-password", [auth.checkAppInitialized, auth.checkPasswordNotSet], loginRoute.setPasswordPage);
|
||||
|
||||
@ -387,9 +387,6 @@ function register(app: express.Application) {
|
||||
// API Documentation
|
||||
apiDocsRoute(app);
|
||||
|
||||
// Printing route
|
||||
route(GET, "/print/:noteId", [ auth.checkAuth ], getPrintablePage);
|
||||
|
||||
app.use("", router);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user