mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 10:26:08 +01:00 
			
		
		
		
	book handling of protected notes
This commit is contained in:
		| @@ -3,7 +3,8 @@ import linkService from "./link.js"; | |||||||
| import utils from "./utils.js"; | import utils from "./utils.js"; | ||||||
| import treeCache from "./tree_cache.js"; | import treeCache from "./tree_cache.js"; | ||||||
| import renderService from "./render.js"; | import renderService from "./render.js"; | ||||||
| import zoom from "./zoom.js"; | import protectedSessionHolder from "./protected_session_holder.js"; | ||||||
|  | import protectedSessionService from "./protected_session.js"; | ||||||
|  |  | ||||||
| const MIN_ZOOM_LEVEL = 1; | const MIN_ZOOM_LEVEL = 1; | ||||||
| const MAX_ZOOM_LEVEL = 6; | const MAX_ZOOM_LEVEL = 6; | ||||||
| @@ -128,14 +129,16 @@ class NoteDetailBook { | |||||||
|  |  | ||||||
|     async renderIntoElement(note, $container) { |     async renderIntoElement(note, $container) { | ||||||
|         for (const childNote of await note.getChildNotes()) { |         for (const childNote of await note.getChildNotes()) { | ||||||
|  |             const type = this.getRenderingType(childNote); | ||||||
|  |  | ||||||
|             const $card = $('<div class="note-book-card">') |             const $card = $('<div class="note-book-card">') | ||||||
|                 .attr('data-note-id', childNote.noteId) |                 .attr('data-note-id', childNote.noteId) | ||||||
|                 .css("flex-basis", ZOOMS[this.zoomLevel].width) |                 .css("flex-basis", ZOOMS[this.zoomLevel].width) | ||||||
|                 .addClass("type-" + childNote.type) |                 .addClass("type-" + type) | ||||||
|                 .append($('<h5 class="note-book-title">').append(await linkService.createNoteLink(childNote.noteId, null, false))) |                 .append($('<h5 class="note-book-title">').append(await linkService.createNoteLink(childNote.noteId, null, false))) | ||||||
|                 .append($('<div class="note-book-content">') |                 .append($('<div class="note-book-content">') | ||||||
|                     .css("max-height", ZOOMS[this.zoomLevel].height) |                     .css("max-height", ZOOMS[this.zoomLevel].height) | ||||||
|                     .append(await this.getNoteContent(childNote))); |                     .append(await this.getNoteContent(type, childNote))); | ||||||
|  |  | ||||||
|             const childCount = childNote.getChildNoteIds().length; |             const childCount = childNote.getChildNoteIds().length; | ||||||
|  |  | ||||||
| @@ -153,8 +156,8 @@ class NoteDetailBook { | |||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     async getNoteContent(note) { |     async getNoteContent(type, note) { | ||||||
|         if (note.type === 'text') { |         if (type === 'text') { | ||||||
|             const fullNote = await server.get('notes/' + note.noteId); |             const fullNote = await server.get('notes/' + note.noteId); | ||||||
|  |  | ||||||
|             const $content = $("<div>").html(fullNote.content); |             const $content = $("<div>").html(fullNote.content); | ||||||
| @@ -166,7 +169,7 @@ class NoteDetailBook { | |||||||
|                 return $content; |                 return $content; | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|         else if (note.type === 'code') { |         else if (type === 'code') { | ||||||
|             const fullNote = await server.get('notes/' + note.noteId); |             const fullNote = await server.get('notes/' + note.noteId); | ||||||
|  |  | ||||||
|             if (fullNote.content.trim() === "") { |             if (fullNote.content.trim() === "") { | ||||||
| @@ -175,10 +178,10 @@ class NoteDetailBook { | |||||||
|  |  | ||||||
|             return $("<pre>").text(fullNote.content); |             return $("<pre>").text(fullNote.content); | ||||||
|         } |         } | ||||||
|         else if (note.type === 'image') { |         else if (type === 'image') { | ||||||
|             return $("<img>").attr("src", `api/images/${note.noteId}/${note.title}`); |             return $("<img>").attr("src", `api/images/${note.noteId}/${note.title}`); | ||||||
|         } |         } | ||||||
|         else if (note.type === 'file') { |         else if (type === 'file') { | ||||||
|             function getFileUrl() { |             function getFileUrl() { | ||||||
|                 // electron needs absolute URL so we extract current host, port, protocol |                 // electron needs absolute URL so we extract current host, port, protocol | ||||||
|                 return utils.getHost() + "/api/notes/" + note.noteId + "/download"; |                 return utils.getHost() + "/api/notes/" + note.noteId + "/download"; | ||||||
| @@ -207,13 +210,22 @@ class NoteDetailBook { | |||||||
|                 .append('   ') |                 .append('   ') | ||||||
|                 .append($openButton); |                 .append($openButton); | ||||||
|         } |         } | ||||||
|         else if (note.type === 'render') { |         else if (type === 'render') { | ||||||
|             const $el = $('<div>'); |             const $el = $('<div>'); | ||||||
|  |  | ||||||
|             await renderService.render(note, $el, this.ctx); |             await renderService.render(note, $el, this.ctx); | ||||||
|  |  | ||||||
|             return $el; |             return $el; | ||||||
|         } |         } | ||||||
|  |         else if (type === 'protected-session') { | ||||||
|  |             const $button = $(`<button class="btn btn-sm"><span class="jam jam-door"></span> Enter protected session</button>`) | ||||||
|  |                 .click(protectedSessionService.enterProtectedSession); | ||||||
|  |  | ||||||
|  |             return $("<div>") | ||||||
|  |                 .append("<div>This note is protected and to access it you need to enter password.</div>") | ||||||
|  |                 .append("<br/>") | ||||||
|  |                 .append($button); | ||||||
|  |         } | ||||||
|         else { |         else { | ||||||
|             return "<em>Content of this note cannot be displayed in the book format</em>"; |             return "<em>Content of this note cannot be displayed in the book format</em>"; | ||||||
|         } |         } | ||||||
| @@ -228,6 +240,21 @@ class NoteDetailBook { | |||||||
|         return this.isAutoBook() ? 3 : 1; |         return this.isAutoBook() ? 3 : 1; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     getRenderingType(childNote) { | ||||||
|  |         let type = childNote.type; | ||||||
|  |  | ||||||
|  |         if (childNote.isProtected) { | ||||||
|  |             if (protectedSessionHolder.isProtectedSessionAvailable()) { | ||||||
|  |                 protectedSessionHolder.touchProtectedSession(); | ||||||
|  |             } | ||||||
|  |             else { | ||||||
|  |                 type = 'protected-session'; | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         return type; | ||||||
|  |     } | ||||||
|  |  | ||||||
|     getContent() {} |     getContent() {} | ||||||
|  |  | ||||||
|     show() { |     show() { | ||||||
|   | |||||||
| @@ -202,7 +202,7 @@ function closeActiveDialog() { | |||||||
| } | } | ||||||
|  |  | ||||||
| function isHtmlEmpty(html) { | function isHtmlEmpty(html) { | ||||||
|     return $(html).text().trim().length === 0 && !html.toLowerCase().includes('<img'); |     return $("<div>").html(html).text().trim().length === 0 && !html.toLowerCase().includes('<img'); | ||||||
| } | } | ||||||
|  |  | ||||||
| export default { | export default { | ||||||
|   | |||||||
| @@ -825,10 +825,16 @@ a.external:not(.no-arrow):after, a[href^="http://"]:not(.no-arrow):after, a[href | |||||||
|     overflow: hidden; |     overflow: hidden; | ||||||
| } | } | ||||||
|  |  | ||||||
| .note-book-card.type-image .note-book-content, .note-book-card.type-file .note-book-content { | .note-book-card.type-image .note-book-content, .note-book-card.type-file .note-book-content, .note-book-card.type-protected-session .note-book-content { | ||||||
|     display: flex; |     display: flex; | ||||||
|     align-items: center; |     align-items: center; | ||||||
|     justify-content: center; |     justify-content: center; | ||||||
|  |     text-align: center; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | .note-book-card.type-image .note-book-content img { | ||||||
|  |     max-width: 100%; | ||||||
|  |     max-height: 100%; | ||||||
| } | } | ||||||
|  |  | ||||||
| .note-book-title { | .note-book-title { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user