2018-03-28 09:36:01 +08:00
|
|
|
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
|
|
|
|
2019-05-20 03:52:28 +08:00
|
|
|
this.$renderButton.click(() => this.render()); // long form!
|
2019-05-04 06:16:41 +08:00
|
|
|
}
|
2018-05-27 07:27:47 +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);
|
2018-03-28 09:36:01 +08:00
|
|
|
|
2019-05-04 06:16:41 +08:00
|
|
|
this.$component.show();
|
2018-05-27 07:27:47 +08:00
|
|
|
|
2019-05-04 06:16:41 +08:00
|
|
|
this.$noteDetailRenderContent.empty();
|
|
|
|
this.$noteDetailRenderContent.toggle(renderNotes.length > 0);
|
|
|
|
this.$noteDetailRenderHelp.toggle(renderNotes.length === 0);
|
2018-03-28 09:36:01 +08:00
|
|
|
|
2019-05-04 06:16:41 +08:00
|
|
|
for (const renderNote of renderNotes) {
|
|
|
|
const bundle = await server.get('script/bundle/' + renderNote.value);
|
2018-05-27 07:27:47 +08:00
|
|
|
|
2019-05-04 06:16:41 +08:00
|
|
|
this.$noteDetailRenderContent.append(bundle.html);
|
2018-05-27 07:58:08 +08:00
|
|
|
|
2019-05-20 03:52:28 +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:27:47 +08:00
|
|
|
}
|
2018-05-27 07:58:08 +08:00
|
|
|
|
2019-05-04 06:16:41 +08:00
|
|
|
getContent() {}
|
|
|
|
|
2019-08-26 01:11:42 +08:00
|
|
|
show() {}
|
|
|
|
|
2019-05-04 06:16:41 +08:00
|
|
|
focus() {}
|
|
|
|
|
|
|
|
onNoteChange() {}
|
|
|
|
|
|
|
|
cleanup() {
|
|
|
|
this.$noteDetailRenderContent.empty();
|
|
|
|
}
|
|
|
|
|
|
|
|
scrollToTop() {
|
|
|
|
this.$component.scrollTop(0);
|
|
|
|
}
|
|
|
|
}
|
2018-05-27 07:27:47 +08:00
|
|
|
|
2019-05-04 06:16:41 +08:00
|
|
|
export default NoteDetailRender;
|