mirror of https://github.com/TriliumNext/Notes
wip attachment support
parent
2bc78ccafb
commit
5d6d9ab6d6
@ -0,0 +1,33 @@
|
||||
class FAttachment {
|
||||
constructor(froca, row) {
|
||||
this.froca = froca;
|
||||
|
||||
this.update(row);
|
||||
}
|
||||
|
||||
update(row) {
|
||||
/** @type {string} */
|
||||
this.attachmentId = row.attachmentId;
|
||||
/** @type {string} */
|
||||
this.parentId = row.parentId;
|
||||
/** @type {string} */
|
||||
this.role = row.role;
|
||||
/** @type {string} */
|
||||
this.mime = row.mime;
|
||||
/** @type {string} */
|
||||
this.title = row.title;
|
||||
/** @type {string} */
|
||||
this.dateModified = row.dateModified;
|
||||
/** @type {string} */
|
||||
this.utcDateModified = row.utcDateModified;
|
||||
/** @type {string} */
|
||||
this.utcDateScheduledForDeletionSince = row.utcDateScheduledForDeletionSince;
|
||||
|
||||
this.froca.attachments[this.attachmentId] = this;
|
||||
}
|
||||
|
||||
/** @returns {FNote} */
|
||||
getNote() {
|
||||
return this.froca.notes[this.parentId];
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,54 @@
|
||||
import TypeWidget from "./type_widget.js";
|
||||
import server from "../../services/server.js";
|
||||
import AttachmentDetailWidget from "../attachment_detail.js";
|
||||
|
||||
const TPL = `
|
||||
<div class="attachment-detail note-detail-printable">
|
||||
<style>
|
||||
.attachment-detail {
|
||||
padding: 15px;
|
||||
}
|
||||
</style>
|
||||
|
||||
<div class="attachment-wrapper"></div>
|
||||
</div>`;
|
||||
|
||||
export default class AttachmentDetailTypeWidget extends TypeWidget {
|
||||
static getType() {
|
||||
return "attachmentDetail";
|
||||
}
|
||||
|
||||
doRender() {
|
||||
this.$widget = $(TPL);
|
||||
this.$wrapper = this.$widget.find('.attachment-wrapper');
|
||||
|
||||
super.doRender();
|
||||
}
|
||||
|
||||
async doRefresh(note) {
|
||||
this.$wrapper.empty();
|
||||
this.children = [];
|
||||
this.renderedAttachmentIds = new Set();
|
||||
|
||||
const attachment = await server.get(`notes/${this.noteId}/attachments/${this.noteContext.viewScope.attachment.attachmentId}/?includeContent=true`);
|
||||
|
||||
if (!attachment) {
|
||||
this.$list.html("<strong>This attachment has been deleted.</strong>");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
const attachmentDetailWidget = new AttachmentDetailWidget(attachment);
|
||||
this.child(attachmentDetailWidget);
|
||||
|
||||
this.$list.append(attachmentDetailWidget.render());
|
||||
}
|
||||
|
||||
async entitiesReloadedEvent({loadResults}) {
|
||||
const attachmentChange = loadResults.getAttachments().find(att => att.attachmentId === this.attachment.attachmentId);
|
||||
|
||||
if (attachmentChange.isDeleted) {
|
||||
this.refresh(); // all other updates are handled within AttachmentDetailWidget
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue