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
|
|
|
|
2018-11-08 17:30:35 +08:00
|
|
|
const $component = $('#note-detail-render');
|
2018-08-29 02:55:21 +08:00
|
|
|
const $noteDetailRenderHelp = $('#note-detail-render-help');
|
|
|
|
const $noteDetailRenderContent = $('#note-detail-render-content');
|
2018-05-27 07:27:47 +08:00
|
|
|
const $renderButton = $('#render-button');
|
|
|
|
|
2018-08-29 02:55:21 +08:00
|
|
|
async function render() {
|
2018-11-09 03:01:25 +08:00
|
|
|
const attributes = await attributeService.getAttributes();
|
2018-08-29 02:55:21 +08:00
|
|
|
const renderNotes = attributes.filter(attr =>
|
|
|
|
attr.type === 'relation'
|
|
|
|
&& attr.name === 'renderNote'
|
|
|
|
&& !!attr.value);
|
2018-03-28 09:36:01 +08:00
|
|
|
|
2018-11-08 17:30:35 +08:00
|
|
|
$component.show();
|
2018-05-27 07:27:47 +08:00
|
|
|
|
2018-08-29 02:55:21 +08:00
|
|
|
$noteDetailRenderContent.empty();
|
|
|
|
$noteDetailRenderContent.toggle(renderNotes.length > 0);
|
|
|
|
$noteDetailRenderHelp.toggle(renderNotes.length === 0);
|
2018-03-28 09:36:01 +08:00
|
|
|
|
2018-08-29 02:55:21 +08:00
|
|
|
for (const renderNote of renderNotes) {
|
|
|
|
const bundle = await server.get('script/bundle/' + renderNote.value);
|
2018-05-27 07:27:47 +08:00
|
|
|
|
2018-08-29 02:55:21 +08:00
|
|
|
$noteDetailRenderContent.append(bundle.html);
|
2018-05-27 07:58:08 +08:00
|
|
|
|
2018-08-29 05:08:56 +08:00
|
|
|
await bundleService.executeBundle(bundle, noteDetailService.getCurrentNote());
|
2018-05-27 07:27:47 +08:00
|
|
|
}
|
2018-05-27 07:58:08 +08:00
|
|
|
}
|
|
|
|
|
2018-05-27 07:27:47 +08:00
|
|
|
$renderButton.click(render);
|
|
|
|
|
2018-03-28 09:36:01 +08:00
|
|
|
export default {
|
2018-08-29 02:55:21 +08:00
|
|
|
show: render,
|
|
|
|
getContent: () => "",
|
2018-09-03 22:05:28 +08:00
|
|
|
focus: () => null,
|
2018-10-31 19:29:01 +08:00
|
|
|
onNoteChange: () => null,
|
2018-12-24 16:47:00 +08:00
|
|
|
cleanup: () => $noteDetailRenderContent.empty(),
|
|
|
|
scrollToTop: () => $component.scrollTop(0)
|
2018-03-28 09:36:01 +08:00
|
|
|
}
|