\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\nimport * as ForumSelectors from './grader/selectors';\nimport Repository from 'mod_forum/repository';\nimport {exception as showException} from \"core/notification\";\nimport Templates from 'core/templates';\nimport * as Modal from 'core/modal_factory';\nimport * as ModalEvents from 'core/modal_events';\n\n/**\n * Find the Node containing the gradable details from the provided node by searching up the tree.\n *\n * @param {HTMLElement} node\n * @returns {HTMLElement}\n */\nconst findGradableNode = node => node.closest(ForumSelectors.expandConversation);\n\n/**\n * Show the post in context in a modal.\n *\n * @param {HTMLElement} rootNode The button that has been clicked\n */\nconst showPostInContext = async(rootNode) => {\n const postId = rootNode.dataset.postid;\n const discussionId = rootNode.dataset.discussionid;\n const discussionName = rootNode.dataset.name;\n\n const [\n allPosts,\n modal,\n ] = await Promise.all([\n Repository.getDiscussionPosts(parseInt(discussionId)),\n Modal.create({\n title: discussionName,\n large: true,\n type: Modal.types.CANCEL\n }),\n ]);\n\n const postsById = new Map(allPosts.posts.map(post => {\n post.readonly = true;\n post.hasreplies = false;\n post.replies = [];\n return [post.id, post];\n }));\n\n let posts = [];\n allPosts.posts.forEach(post => {\n if (post.parentid) {\n const parent = postsById.get(post.parentid);\n if (parent) {\n parent.hasreplies = true;\n parent.replies.push(post);\n } else {\n posts.push(post);\n }\n } else {\n posts.push(post);\n }\n });\n\n // Handle hidden event.\n modal.getRoot().on(ModalEvents.hidden, function() {\n // Destroy when hidden.\n modal.destroy();\n });\n\n modal.getRoot().on(ModalEvents.bodyRendered, () => {\n const relevantPost = modal.getRoot()[0].querySelector(`#p${postId}`);\n if (relevantPost) {\n relevantPost.scrollIntoView({behavior: \"smooth\"});\n }\n });\n\n modal.show();\n\n // Note: We do not use await here because it messes with the Modal transitions.\n const templatePromise = Templates.render('mod_forum/grades/grader/discussion/post_modal', {posts});\n modal.setBody(templatePromise);\n};\n\n/**\n * Register event listeners for the expand conversations button.\n *\n * @param {HTMLElement} rootNode The root to listen to.\n */\nexport const registerEventListeners = (rootNode) => {\n rootNode.addEventListener('click', (e) => {\n const rootNode = findGradableNode(e.target);\n\n if (rootNode) {\n e.preventDefault();\n\n try {\n showPostInContext(rootNode);\n } catch (err) {\n showException(err);\n }\n }\n });\n};\n"],"file":"expandconversation.min.js"}
\ No newline at end of file
diff --git a/mod/forum/amd/src/grades/expandconversation.js b/mod/forum/amd/src/grades/expandconversation.js
index face93f78b3..591cbe6d36b 100644
--- a/mod/forum/amd/src/grades/expandconversation.js
+++ b/mod/forum/amd/src/grades/expandconversation.js
@@ -58,12 +58,26 @@ const showPostInContext = async(rootNode) => {
}),
]);
- const userPosts = allPosts.posts.map((post) => {
- post.subject = null;
+ const postsById = new Map(allPosts.posts.map(post => {
post.readonly = true;
- post.html.rating = null;
+ post.hasreplies = false;
+ post.replies = [];
+ return [post.id, post];
+ }));
- return post;
+ let posts = [];
+ allPosts.posts.forEach(post => {
+ if (post.parentid) {
+ const parent = postsById.get(post.parentid);
+ if (parent) {
+ parent.hasreplies = true;
+ parent.replies.push(post);
+ } else {
+ posts.push(post);
+ }
+ } else {
+ posts.push(post);
+ }
});
// Handle hidden event.
@@ -72,20 +86,18 @@ const showPostInContext = async(rootNode) => {
modal.destroy();
});
- modal.show();
-
- // Note: We do not use await here because it messes with the Modal transitions.
- const templatePromise = Templates.render('mod_forum/grades/grader/discussion/post_modal', userPosts);
- modal.setBody(templatePromise);
- // eslint-disable-next-line promise/catch-or-return
- templatePromise.then(() => {
+ modal.getRoot().on(ModalEvents.bodyRendered, () => {
const relevantPost = modal.getRoot()[0].querySelector(`#p${postId}`);
if (relevantPost) {
relevantPost.scrollIntoView({behavior: "smooth"});
}
-
- return;
});
+
+ modal.show();
+
+ // Note: We do not use await here because it messes with the Modal transitions.
+ const templatePromise = Templates.render('mod_forum/grades/grader/discussion/post_modal', {posts});
+ modal.setBody(templatePromise);
};
/**
diff --git a/mod/forum/templates/grades/grader/discussion/post_modal.mustache b/mod/forum/templates/grades/grader/discussion/post_modal.mustache
index f402197c970..e03c700caeb 100644
--- a/mod/forum/templates/grades/grader/discussion/post_modal.mustache
+++ b/mod/forum/templates/grades/grader/discussion/post_modal.mustache
@@ -30,7 +30,7 @@
}
}}
- {{#.}}
- {{> mod_forum/forum_discussion_nested_v2_post_reply }}
- {{/.}}
+ {{#posts}}
+ {{> mod_forum/forum_discussion_nested_post }}
+ {{/posts}}