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

61 lines
1.7 KiB
JavaScript
Raw Normal View History

import bundleService from "./bundle.js";
import server from "./server.js";
2019-05-04 06:16:41 +08:00
class NoteDetailRender {
/**
2019-05-09 01:55:24 +08:00
* @param {TabContext} ctx
2019-05-04 06:16:41 +08:00
*/
constructor(ctx) {
this.ctx = ctx;
2019-05-09 01:55:24 +08:00
this.$component = ctx.$tabContent.find('.note-detail-render');
this.$noteDetailRenderHelp = ctx.$tabContent.find('.note-detail-render-help');
this.$noteDetailRenderContent = ctx.$tabContent.find('.note-detail-render-content');
this.$renderButton = ctx.$tabContent.find('.render-button');
2019-05-04 06:16:41 +08:00
this.$renderButton.click(() => this.render()); // long form!
2019-05-04 06:16:41 +08:00
}
2019-05-12 18:58:55 +08:00
async render() {
2019-05-19 16:30:00 +08:00
const attributes = await this.ctx.attributes.getAttributes();
2019-05-04 06:16:41 +08:00
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
const $result = await bundleService.executeBundle(bundle, this.ctx.note, this.ctx);
if ($result) {
this.$noteDetailRenderContent.append($result);
}
2019-05-04 06:16:41 +08:00
}
}
2018-05-27 07:58:08 +08:00
2019-05-04 06:16:41 +08:00
getContent() {}
show() {}
2019-05-04 06:16:41 +08:00
focus() {}
onNoteChange() {}
cleanup() {
this.$noteDetailRenderContent.empty();
}
scrollToTop() {
this.$component.scrollTop(0);
}
}
2019-05-04 06:16:41 +08:00
export default NoteDetailRender;