mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
wip attachment widget
This commit is contained in:
parent
fa406d3ded
commit
53aebf1448
@ -1,5 +1,3 @@
|
|||||||
import TypeWidget from "./type_widget.js";
|
|
||||||
import server from "../../services/server.js";
|
|
||||||
import utils from "../../services/utils.js";
|
import utils from "../../services/utils.js";
|
||||||
import AttachmentActionsWidget from "../buttons/attachments_actions.js";
|
import AttachmentActionsWidget from "../buttons/attachments_actions.js";
|
||||||
import BasicWidget from "./basic_widget.js";
|
import BasicWidget from "./basic_widget.js";
|
||||||
@ -36,7 +34,16 @@ const TPL = `
|
|||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<div class="attachment-detail-wrapper"></div>
|
<div class="attachment-detail-wrapper">
|
||||||
|
<div class="attachment-title-line">
|
||||||
|
<h4 class="attachment-title"></h4>
|
||||||
|
<div class="attachment-details"></div>
|
||||||
|
<div style="flex: 1 1;">
|
||||||
|
<div class="attachment-actions-container"></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="attachment-content"></div>
|
||||||
|
</div>
|
||||||
</div>`;
|
</div>`;
|
||||||
|
|
||||||
export default class AttachmentDetailWidget extends BasicWidget {
|
export default class AttachmentDetailWidget extends BasicWidget {
|
||||||
@ -44,56 +51,27 @@ export default class AttachmentDetailWidget extends BasicWidget {
|
|||||||
super();
|
super();
|
||||||
|
|
||||||
this.attachment = attachment;
|
this.attachment = attachment;
|
||||||
|
this.attachmentActionsWidget = new AttachmentActionsWidget(attachment);
|
||||||
|
this.child(this.attachmentActionsWidget);
|
||||||
}
|
}
|
||||||
|
|
||||||
doRender() {
|
doRender() {
|
||||||
this.$widget = $(TPL);
|
this.$widget = $(TPL);
|
||||||
this.$wrapper = this.$widget.find('.attachment-detail-wrapper');
|
this.$wrapper = this.$widget.find('.attachment-detail-wrapper');
|
||||||
|
this.$wrapper.find('.attachment-title').text(this.attachment.title);
|
||||||
|
this.$wrapper.find('.attachment-details')
|
||||||
|
.text(`Role: ${this.attachment.role}, Size: ${utils.formatSize(this.attachment.contentLength)}`);
|
||||||
|
this.$wrapper.find('.attachment-actions-container').append(this.attachmentActionsWidget.render());
|
||||||
|
this.$wrapper.find('.attachment-content').append(this.renderContent());
|
||||||
|
|
||||||
super.doRender();
|
super.doRender();
|
||||||
}
|
}
|
||||||
|
|
||||||
async doRefresh(note) {
|
renderContent() {
|
||||||
this.$list.empty();
|
if (this.attachment.content) {
|
||||||
this.children = [];
|
return $("<pre>").text(this.attachment.content);
|
||||||
|
} else if (this.attachment.role === 'image') {
|
||||||
const attachments = await server.get(`notes/${this.noteId}/attachments?includeContent=true`);
|
return `<img src="api/notes/${this.attachment.parentId}/images/${this.attachment.attachmentId}/${encodeURIComponent(this.attachment.title)}?${this.attachment.utcDateModified}">`;
|
||||||
|
|
||||||
if (attachments.length === 0) {
|
|
||||||
this.$list.html("<strong>This note has no attachments.</strong>");
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const attachment of attachments) {
|
|
||||||
const attachmentActionsWidget = new AttachmentActionsWidget(attachment);
|
|
||||||
this.child(attachmentActionsWidget);
|
|
||||||
|
|
||||||
this.$list.append(
|
|
||||||
$('<div class="attachment-detail-wrapper">')
|
|
||||||
.append(
|
|
||||||
$('<div class="attachment-title-line">')
|
|
||||||
.append($('<h4>').append($('<span class="attachment-title">').text(attachment.title)))
|
|
||||||
.append(
|
|
||||||
$('<div class="attachment-details">')
|
|
||||||
.text(`Role: ${attachment.role}, Size: ${utils.formatSize(attachment.contentLength)}`)
|
|
||||||
)
|
|
||||||
.append($('<div style="flex: 1 1;">')) // spacer
|
|
||||||
.append(attachmentActionsWidget.render())
|
|
||||||
)
|
|
||||||
.append(
|
|
||||||
$('<div class="attachment-content">')
|
|
||||||
.append(this.renderContent(attachment))
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
renderContent(attachment) {
|
|
||||||
if (attachment.content) {
|
|
||||||
return $("<pre>").text(attachment.content);
|
|
||||||
} else if (attachment.role === 'image') {
|
|
||||||
return `<img src="api/notes/${attachment.parentId}/images/${attachment.attachmentId}/${encodeURIComponent(attachment.title)}?${attachment.utcDateModified}">`;
|
|
||||||
} else {
|
} else {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import BasicWidget from "../basic_widget.js";
|
import BasicWidget from "../basic_widget.js";
|
||||||
import server from "../../services/server.js";
|
import server from "../../services/server.js";
|
||||||
|
import dialogService from "../../services/dialog.js";
|
||||||
|
|
||||||
const TPL = `
|
const TPL = `
|
||||||
<div class="dropdown attachment-actions">
|
<div class="dropdown attachment-actions">
|
||||||
@ -39,9 +40,12 @@ export default class AttachmentActionsWidget extends BasicWidget {
|
|||||||
|
|
||||||
doRender() {
|
doRender() {
|
||||||
this.$widget = $(TPL);
|
this.$widget = $(TPL);
|
||||||
|
this.$widget.on('click', '.dropdown-item', () => this.$widget.find("[data-toggle='dropdown']").dropdown('toggle'));
|
||||||
}
|
}
|
||||||
|
|
||||||
async deleteAttachmentCommand() {
|
async deleteAttachmentCommand() {
|
||||||
await server.remove(`notes/${this.attachment.parentId}/attachments/${this.attachment.attachmentId}`);
|
if (await dialogService.confirm(`Are you sure you want to delete attachment '${this.attachment.title}'?`)) {
|
||||||
|
await server.remove(`notes/${this.attachment.parentId}/attachments/${this.attachment.attachmentId}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -234,8 +234,6 @@ export default class NoteRevisionsDialog extends BasicWidget {
|
|||||||
|
|
||||||
const fullNoteRevision = await server.get(`notes/${revisionItem.noteId}/revisions/${revisionItem.noteRevisionId}`);
|
const fullNoteRevision = await server.get(`notes/${revisionItem.noteId}/revisions/${revisionItem.noteRevisionId}`);
|
||||||
|
|
||||||
console.log(fullNoteRevision);
|
|
||||||
|
|
||||||
if (revisionItem.type === 'text') {
|
if (revisionItem.type === 'text') {
|
||||||
this.$content.html(fullNoteRevision.content);
|
this.$content.html(fullNoteRevision.content);
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ import TypeWidget from "./type_widget.js";
|
|||||||
import server from "../../services/server.js";
|
import server from "../../services/server.js";
|
||||||
import utils from "../../services/utils.js";
|
import utils from "../../services/utils.js";
|
||||||
import AttachmentActionsWidget from "../buttons/attachments_actions.js";
|
import AttachmentActionsWidget from "../buttons/attachments_actions.js";
|
||||||
|
import AttachmentDetailWidget from "../attachment_detail.js";
|
||||||
|
|
||||||
const TPL = `
|
const TPL = `
|
||||||
<div class="attachments note-detail-printable">
|
<div class="attachments note-detail-printable">
|
||||||
@ -9,34 +10,6 @@ const TPL = `
|
|||||||
.attachments {
|
.attachments {
|
||||||
padding: 15px;
|
padding: 15px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.attachment-wrapper {
|
|
||||||
margin-bottom: 20px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.attachment-title-line {
|
|
||||||
display: flex;
|
|
||||||
align-items: baseline;
|
|
||||||
}
|
|
||||||
|
|
||||||
.attachment-details {
|
|
||||||
margin-left: 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.attachment-content pre {
|
|
||||||
max-height: 400px;
|
|
||||||
background: var(--accented-background-color);
|
|
||||||
padding: 10px;
|
|
||||||
margin-top: 10px;
|
|
||||||
margin-bottom: 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.attachment-content img {
|
|
||||||
margin: 10px;
|
|
||||||
max-height: 300px;
|
|
||||||
max-width: 90%;
|
|
||||||
object-fit: contain;
|
|
||||||
}
|
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<div class="attachment-list"></div>
|
<div class="attachment-list"></div>
|
||||||
@ -65,36 +38,10 @@ export default class AttachmentsTypeWidget extends TypeWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (const attachment of attachments) {
|
for (const attachment of attachments) {
|
||||||
const attachmentActionsWidget = new AttachmentActionsWidget(attachment);
|
const attachmentDetailWidget = new AttachmentDetailWidget(attachment);
|
||||||
this.child(attachmentActionsWidget);
|
this.child(attachmentDetailWidget);
|
||||||
|
|
||||||
this.$list.append(
|
this.$list.append(attachmentDetailWidget.render());
|
||||||
$('<div class="attachment-wrapper">')
|
|
||||||
.append(
|
|
||||||
$('<div class="attachment-title-line">')
|
|
||||||
.append($('<h4>').append($('<span class="attachment-title">').text(attachment.title)))
|
|
||||||
.append(
|
|
||||||
$('<div class="attachment-details">')
|
|
||||||
.text(`Role: ${attachment.role}, Size: ${utils.formatSize(attachment.contentLength)}`)
|
|
||||||
)
|
|
||||||
.append($('<div style="flex: 1 1;">')) // spacer
|
|
||||||
.append(attachmentActionsWidget.render())
|
|
||||||
)
|
|
||||||
.append(
|
|
||||||
$('<div class="attachment-content">')
|
|
||||||
.append(this.renderContent(attachment))
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
renderContent(attachment) {
|
|
||||||
if (attachment.content) {
|
|
||||||
return $("<pre>").text(attachment.content);
|
|
||||||
} else if (attachment.role === 'image') {
|
|
||||||
return `<img src="api/notes/${attachment.parentId}/images/${attachment.attachmentId}/${encodeURIComponent(attachment.title)}?${attachment.utcDateModified}">`;
|
|
||||||
} else {
|
|
||||||
return '';
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user