2018-03-28 09:36:01 +08:00
|
|
|
import bundleService from "./bundle.js";
|
|
|
|
import server from "./server.js";
|
|
|
|
import noteDetailService from "./note_detail.js";
|
2018-11-09 03:01:25 +08:00
|
|
|
import attributeService from "./attributes.js";
|
2018-03-28 09:36:01 +08:00
|
|
|
|
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);
|
|
|
|
}
|
2018-05-27 07:27:47 +08:00
|
|
|
|
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);
|
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-04 06:16:41 +08:00
|
|
|
await bundleService.executeBundle(bundle, noteDetailService.getActiveNote());
|
|
|
|
}
|
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() {}
|
|
|
|
|
|
|
|
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;
|