trilium/src/public/javascripts/services/note_detail_render.js

57 lines
1.6 KiB
JavaScript
Raw Normal View History

import bundleService from "./bundle.js";
import server from "./server.js";
import noteDetailService from "./note_detail.js";
import attributeService from "./attributes.js";
2019-05-04 06:16:41 +08:00
class NoteDetailRender {
/**
* @param {NoteContext} ctx
*/
constructor(ctx) {
this.ctx = ctx;
this.$component = ctx.$noteTabContent.find('.note-detail-render');
this.$noteDetailRenderHelp = ctx.$noteTabContent.find('.note-detail-render-help');
this.$noteDetailRenderContent = ctx.$noteTabContent.find('.note-detail-render-content');
this.$renderButton = ctx.$noteTabContent.find('.render-button');
this.$renderButton.click(this.show);
}
2019-05-04 06:16:41 +08:00
async show() {
const attributes = await attributeService.getAttributes();
const renderNotes = attributes.filter(attr =>
attr.type === 'relation'
&& attr.name === 'renderNote'
&& !!attr.value);
2019-05-04 06:16:41 +08:00
this.$component.show();
2019-05-04 06:16:41 +08:00
this.$noteDetailRenderContent.empty();
this.$noteDetailRenderContent.toggle(renderNotes.length > 0);
this.$noteDetailRenderHelp.toggle(renderNotes.length === 0);
2019-05-04 06:16:41 +08:00
for (const renderNote of renderNotes) {
const bundle = await server.get('script/bundle/' + renderNote.value);
2019-05-04 06:16:41 +08:00
this.$noteDetailRenderContent.append(bundle.html);
2018-05-27 07:58:08 +08:00
2019-05-04 06:16:41 +08:00
await bundleService.executeBundle(bundle, noteDetailService.getActiveNote());
}
}
2018-05-27 07:58:08 +08:00
2019-05-04 06:16:41 +08:00
getContent() {}
focus() {}
onNoteChange() {}
cleanup() {
this.$noteDetailRenderContent.empty();
}
scrollToTop() {
this.$component.scrollTop(0);
}
}
2019-05-04 06:16:41 +08:00
export default NoteDetailRender;