mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
separated attachments out of note detail
This commit is contained in:
parent
68921ee59b
commit
c918267750
@ -11,13 +11,13 @@ import treeCache from "./tree_cache.js";
|
|||||||
import NoteFull from "../entities/note_full.js";
|
import NoteFull from "../entities/note_full.js";
|
||||||
import noteDetailCode from './note_detail_code.js';
|
import noteDetailCode from './note_detail_code.js';
|
||||||
import noteDetailText from './note_detail_text.js';
|
import noteDetailText from './note_detail_text.js';
|
||||||
|
import noteDetailAttachment from './note_detail_attachment.js';
|
||||||
|
|
||||||
const $noteTitle = $("#note-title");
|
const $noteTitle = $("#note-title");
|
||||||
|
|
||||||
const $noteDetailComponents = $(".note-detail-component");
|
const $noteDetailComponents = $(".note-detail-component");
|
||||||
const $noteDetailSearch = $('#note-detail-search');
|
const $noteDetailSearch = $('#note-detail-search');
|
||||||
const $noteDetailRender = $('#note-detail-render');
|
const $noteDetailRender = $('#note-detail-render');
|
||||||
const $noteDetailAttachment = $('#note-detail-attachment');
|
|
||||||
|
|
||||||
const $protectButton = $("#protect-button");
|
const $protectButton = $("#protect-button");
|
||||||
const $unprotectButton = $("#unprotect-button");
|
const $unprotectButton = $("#unprotect-button");
|
||||||
@ -25,11 +25,6 @@ const $noteDetailWrapper = $("#note-detail-wrapper");
|
|||||||
const $noteIdDisplay = $("#note-id-display");
|
const $noteIdDisplay = $("#note-id-display");
|
||||||
const $labelList = $("#label-list");
|
const $labelList = $("#label-list");
|
||||||
const $labelListInner = $("#label-list-inner");
|
const $labelListInner = $("#label-list-inner");
|
||||||
const $attachmentFileName = $("#attachment-filename");
|
|
||||||
const $attachmentFileType = $("#attachment-filetype");
|
|
||||||
const $attachmentFileSize = $("#attachment-filesize");
|
|
||||||
const $attachmentDownload = $("#attachment-download");
|
|
||||||
const $attachmentOpen = $("#attachment-open");
|
|
||||||
const $searchString = $("#search-string");
|
const $searchString = $("#search-string");
|
||||||
|
|
||||||
let currentNote = null;
|
let currentNote = null;
|
||||||
@ -148,17 +143,6 @@ async function showRenderNote() {
|
|||||||
await bundleService.executeBundle(bundle);
|
await bundleService.executeBundle(bundle);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function showFileNote() {
|
|
||||||
const labels = await server.get('notes/' + currentNote.noteId + '/labels');
|
|
||||||
const labelMap = utils.toObject(labels, l => [l.name, l.value]);
|
|
||||||
|
|
||||||
$noteDetailAttachment.show();
|
|
||||||
|
|
||||||
$attachmentFileName.text(labelMap.original_file_name);
|
|
||||||
$attachmentFileSize.text(labelMap.file_size + " bytes");
|
|
||||||
$attachmentFileType.text(currentNote.mime);
|
|
||||||
}
|
|
||||||
|
|
||||||
function showSearchNote() {
|
function showSearchNote() {
|
||||||
$noteDetailSearch.show();
|
$noteDetailSearch.show();
|
||||||
|
|
||||||
@ -216,7 +200,7 @@ async function loadNoteToEditor(noteId) {
|
|||||||
await showRenderNote();
|
await showRenderNote();
|
||||||
}
|
}
|
||||||
else if (currentNote.type === 'file') {
|
else if (currentNote.type === 'file') {
|
||||||
await showFileNote();
|
await noteDetailAttachment.showFileNote();
|
||||||
}
|
}
|
||||||
else if (currentNote.type === 'text') {
|
else if (currentNote.type === 'text') {
|
||||||
await noteDetailText.showTextNote();
|
await noteDetailText.showTextNote();
|
||||||
@ -249,8 +233,8 @@ async function loadLabelList() {
|
|||||||
$labelListInner.html('');
|
$labelListInner.html('');
|
||||||
|
|
||||||
if (labels.length > 0) {
|
if (labels.length > 0) {
|
||||||
for (const attr of labels) {
|
for (const label of labels) {
|
||||||
$labelListInner.append(utils.formatLabel(attr) + " ");
|
$labelListInner.append(utils.formatLabel(label) + " ");
|
||||||
}
|
}
|
||||||
|
|
||||||
$labelList.show();
|
$labelList.show();
|
||||||
@ -283,25 +267,6 @@ function focus() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$attachmentDownload.click(() => utils.download(getAttachmentUrl()));
|
|
||||||
|
|
||||||
$attachmentOpen.click(() => {
|
|
||||||
if (utils.isElectron()) {
|
|
||||||
const open = require("open");
|
|
||||||
|
|
||||||
open(getAttachmentUrl());
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
window.location.href = getAttachmentUrl();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
function getAttachmentUrl() {
|
|
||||||
// electron needs absolute URL so we extract current host, port, protocol
|
|
||||||
return utils.getHost() + "/api/attachments/download/" + getCurrentNoteId()
|
|
||||||
+ "?protectedSessionId=" + encodeURIComponent(protectedSessionHolder.getProtectedSessionId());
|
|
||||||
}
|
|
||||||
|
|
||||||
messagingService.subscribeToMessages(syncData => {
|
messagingService.subscribeToMessages(syncData => {
|
||||||
if (syncData.some(sync => sync.entityName === 'notes' && sync.entityId === getCurrentNoteId())) {
|
if (syncData.some(sync => sync.entityName === 'notes' && sync.entityId === getCurrentNoteId())) {
|
||||||
infoService.showMessage('Reloading note because of background changes');
|
infoService.showMessage('Reloading note because of background changes');
|
||||||
|
48
src/public/javascripts/services/note_detail_attachment.js
Normal file
48
src/public/javascripts/services/note_detail_attachment.js
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
import utils from "./utils.js";
|
||||||
|
import server from "./server.js";
|
||||||
|
import protectedSessionHolder from "./protected_session_holder.js";
|
||||||
|
import noteDetailService from "./note_detail.js";
|
||||||
|
|
||||||
|
const $noteDetailAttachment = $('#note-detail-attachment');
|
||||||
|
|
||||||
|
const $attachmentFileName = $("#attachment-filename");
|
||||||
|
const $attachmentFileType = $("#attachment-filetype");
|
||||||
|
const $attachmentFileSize = $("#attachment-filesize");
|
||||||
|
const $attachmentDownload = $("#attachment-download");
|
||||||
|
const $attachmentOpen = $("#attachment-open");
|
||||||
|
|
||||||
|
async function showFileNote() {
|
||||||
|
const currentNote = noteDetailService.getCurrentNote();
|
||||||
|
|
||||||
|
const labels = await server.get('notes/' + currentNote.noteId + '/labels');
|
||||||
|
const labelMap = utils.toObject(labels, l => [l.name, l.value]);
|
||||||
|
|
||||||
|
$noteDetailAttachment.show();
|
||||||
|
|
||||||
|
$attachmentFileName.text(labelMap.original_file_name);
|
||||||
|
$attachmentFileSize.text(labelMap.file_size + " bytes");
|
||||||
|
$attachmentFileType.text(currentNote.mime);
|
||||||
|
}
|
||||||
|
|
||||||
|
$attachmentDownload.click(() => utils.download(getAttachmentUrl()));
|
||||||
|
|
||||||
|
$attachmentOpen.click(() => {
|
||||||
|
if (utils.isElectron()) {
|
||||||
|
const open = require("open");
|
||||||
|
|
||||||
|
open(getAttachmentUrl());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
window.location.href = getAttachmentUrl();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
function getAttachmentUrl() {
|
||||||
|
// electron needs absolute URL so we extract current host, port, protocol
|
||||||
|
return utils.getHost() + "/api/attachments/download/" + noteDetailService.getCurrentNoteId()
|
||||||
|
+ "?protectedSessionId=" + encodeURIComponent(protectedSessionHolder.getProtectedSessionId());
|
||||||
|
}
|
||||||
|
|
||||||
|
export default {
|
||||||
|
showFileNote
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user