MDL-66365 mod_forum: Add a modal to show a selected post in context
Part of MDL-66074
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
define ("mod_forum/grades/expandconversation",["exports","./grader/selectors","mod_forum/repository","core/notification","core/templates","core/modal_factory","core/modal_events"],function(a,b,c,d,e,f,g){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.registerEventListeners=void 0;b=i(b);c=h(c);e=h(e);f=i(f);g=i(g);function h(a){return a&&a.__esModule?a:{default:a}}function i(a){if(a&&a.__esModule){return a}else{var b={};if(null!=a){for(var c in a){if(Object.prototype.hasOwnProperty.call(a,c)){var d=Object.defineProperty&&Object.getOwnPropertyDescriptor?Object.getOwnPropertyDescriptor(a,c):{};if(d.get||d.set){Object.defineProperty(b,c,d)}else{b[c]=a[c]}}}}b.default=a;return b}}function j(a,b){return m(a)||l(a,b)||k()}function k(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}function l(a,b){var c=[],d=!0,e=!1,f=void 0;try{for(var g=a[Symbol.iterator](),h;!(d=(h=g.next()).done);d=!0){c.push(h.value);if(b&&c.length===b)break}}catch(a){e=!0;f=a}finally{try{if(!d&&null!=g["return"])g["return"]()}finally{if(e)throw f}}return c}function m(a){if(Array.isArray(a))return a}function n(a,b,c,d,e,f,g){try{var h=a[f](g),i=h.value}catch(a){c(a);return}if(h.done){b(i)}else{Promise.resolve(i).then(d,e)}}function o(a){return function(){var b=this,c=arguments;return new Promise(function(d,e){var h=a.apply(b,c);function f(a){n(h,d,e,f,g,"next",a)}function g(a){n(h,d,e,f,g,"throw",a)}f(void 0)})}}var p=function(a){return a.closest(b.expandConversation)},q=function(){var a=o(regeneratorRuntime.mark(function a(b){var d,h,i,k,l,m,n,o;return regeneratorRuntime.wrap(function(a){while(1){switch(a.prev=a.next){case 0:d=b.dataset.postid;h=b.dataset.discussionid;i=b.dataset.name;a.next=5;return Promise.all([c.default.getDiscussionPosts(parseInt(h)),f.create({title:i,large:!0,type:f.types.CANCEL})]);case 5:k=a.sent;l=j(k,2);m=l[0];n=l[1];n.getRoot().on(g.hidden,function(){n.destroy()});n.show();o=e.default.render("mod_forum/grades/grader/discussion/post_modal",m);n.setBody(o);o.then(function(){var a=n.getRoot()[0].querySelector("#p".concat(d));if(a){a.scrollIntoView({behavior:"smooth"})}return});case 14:case"end":return a.stop();}}},a)}));return function(){return a.apply(this,arguments)}}();a.registerEventListeners=function registerEventListeners(a){a.addEventListener("click",function(a){var b=p(a.target);if(b){a.preventDefault();try{q(b)}catch(a){(0,d.exception)(a)}}})}});
|
||||
//# sourceMappingURL=expandconversation.min.js.map
|
||||
File diff suppressed because one or more lines are too long
+1
-1
@@ -1,2 +1,2 @@
|
||||
define ("mod_forum/grades/grader/selectors",["exports"],function(a){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.default=void 0;a.default={launch:"[data-grade-action=\"launch\"]",gradableItem:"[data-gradable-itemtype]",gradableItems:{wholeForum:"[data-gradable-itemtype=\"forum\"]"}};return a.default});
|
||||
define ("mod_forum/grades/grader/selectors",["exports"],function(a){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.default=void 0;a.default={launch:"[data-grade-action=\"launch\"]",gradableItem:"[data-gradable-itemtype]",gradableItems:{wholeForum:"[data-gradable-itemtype=\"forum\"]"},expandConversation:"[data-action=\"view-context\"]",posts:"[data-region=\"posts\"]"};return a.default});
|
||||
//# sourceMappingURL=selectors.min.js.map
|
||||
|
||||
@@ -1 +1 @@
|
||||
{"version":3,"sources":["../../../src/grades/grader/selectors.js"],"names":["launch","gradableItem","gradableItems","wholeForum"],"mappings":"6JAuBe,CACXA,MAAM,CAAE,gCADG,CAEXC,YAAY,CAAE,0BAFH,CAGXC,aAAa,CAAE,CACXC,UAAU,CAAE,oCADD,CAHJ,C","sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see <http://www.gnu.org/licenses/>.\n\n/**\n * This module will tie together all of the different calls the gradable module will make.\n *\n * @module mod_forum/grades/grader/selectors\n * @package mod_forum\n * @copyright 2019 Andrew Nicols <[email protected]>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\nexport default {\n launch: '[data-grade-action=\"launch\"]',\n gradableItem: '[data-gradable-itemtype]',\n gradableItems: {\n wholeForum: '[data-gradable-itemtype=\"forum\"]',\n },\n};\n"],"file":"selectors.min.js"}
|
||||
{"version":3,"sources":["../../../src/grades/grader/selectors.js"],"names":["launch","gradableItem","gradableItems","wholeForum","expandConversation","posts"],"mappings":"6JAuBe,CACXA,MAAM,CAAE,gCADG,CAEXC,YAAY,CAAE,0BAFH,CAGXC,aAAa,CAAE,CACXC,UAAU,CAAE,oCADD,CAHJ,CAMXC,kBAAkB,CAAE,gCANT,CAOXC,KAAK,CAAE,yBAPI,C","sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see <http://www.gnu.org/licenses/>.\n\n/**\n * This module will tie together all of the different calls the gradable module will make.\n *\n * @module mod_forum/grades/grader/selectors\n * @package mod_forum\n * @copyright 2019 Andrew Nicols <[email protected]>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\nexport default {\n launch: '[data-grade-action=\"launch\"]',\n gradableItem: '[data-gradable-itemtype]',\n gradableItems: {\n wholeForum: '[data-gradable-itemtype=\"forum\"]',\n },\n expandConversation: '[data-action=\"view-context\"]',\n posts: '[data-region=\"posts\"]',\n};\n"],"file":"selectors.min.js"}
|
||||
+1
-1
@@ -1,2 +1,2 @@
|
||||
define ("mod_forum/repository",["core/ajax"],function(a){return{setDiscussionSubscriptionState:function setDiscussionSubscriptionState(b,c,d){return a.call([{methodname:"mod_forum_set_subscription_state",args:{forumid:b,discussionid:c,targetstate:d}}])[0]},addDiscussionPost:function addDiscussionPost(b,c,d,e,f,g){return a.call([{methodname:"mod_forum_add_discussion_post",args:{postid:b,message:d,messageformat:e,subject:c,options:[{name:"private",value:f},{name:"topreferredformat",value:g}]}}])[0]},setDiscussionLockState:function setDiscussionLockState(b,c,d){return a.call([{methodname:"mod_forum_set_lock_state",args:{forumid:b,discussionid:c,targetstate:d}}])[0]},setFavouriteDiscussionState:function setFavouriteDiscussionState(b,c,d){return a.call([{methodname:"mod_forum_toggle_favourite_state",args:{discussionid:c,targetstate:d}}])[0]},setPinDiscussionState:function setPinDiscussionState(b,c,d){return a.call([{methodname:"mod_forum_set_pin_state",args:{discussionid:c,targetstate:d}}])[0]},getDiscussionByUserID:function getDiscussionByUserID(b,c){var d=2<arguments.length&&arguments[2]!==void 0?arguments[2]:"modified",e=3<arguments.length&&arguments[3]!==void 0?arguments[3]:"DESC";return a.call([{methodname:"mod_forum_get_discussion_posts_by_userid",args:{userid:b,cmid:c,sortby:d,sortdirection:e}}])[0]}}});
|
||||
define ("mod_forum/repository",["core/ajax"],function(a){return{setDiscussionSubscriptionState:function setDiscussionSubscriptionState(b,c,d){return a.call([{methodname:"mod_forum_set_subscription_state",args:{forumid:b,discussionid:c,targetstate:d}}])[0]},addDiscussionPost:function addDiscussionPost(b,c,d,e,f,g){return a.call([{methodname:"mod_forum_add_discussion_post",args:{postid:b,message:d,messageformat:e,subject:c,options:[{name:"private",value:f},{name:"topreferredformat",value:g}]}}])[0]},setDiscussionLockState:function setDiscussionLockState(b,c,d){return a.call([{methodname:"mod_forum_set_lock_state",args:{forumid:b,discussionid:c,targetstate:d}}])[0]},setFavouriteDiscussionState:function setFavouriteDiscussionState(b,c,d){return a.call([{methodname:"mod_forum_toggle_favourite_state",args:{discussionid:c,targetstate:d}}])[0]},setPinDiscussionState:function setPinDiscussionState(b,c,d){return a.call([{methodname:"mod_forum_set_pin_state",args:{discussionid:c,targetstate:d}}])[0]},getDiscussionByUserID:function getDiscussionByUserID(b,c){var d=2<arguments.length&&arguments[2]!==void 0?arguments[2]:"modified",e=3<arguments.length&&arguments[3]!==void 0?arguments[3]:"DESC";return a.call([{methodname:"mod_forum_get_discussion_posts_by_userid",args:{userid:b,cmid:c,sortby:d,sortdirection:e}}])[0]},getDiscussionPosts:function getDiscussionPosts(b){return a.call([{methodname:"mod_forum_get_discussion_posts",args:{discussionid:b}}])[0]}}});
|
||||
//# sourceMappingURL=repository.min.js.map
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,102 @@
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* This module will tie together all of the different calls the gradable module will make.
|
||||
*
|
||||
* @module mod_forum/grades/expandconversation
|
||||
* @package mod_forum
|
||||
* @copyright 2019 Mathew May <mathew.solutions>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
import * as ForumSelectors from './grader/selectors';
|
||||
import Repository from 'mod_forum/repository';
|
||||
import {exception as showException} from "core/notification";
|
||||
import Templates from 'core/templates';
|
||||
import * as Modal from 'core/modal_factory';
|
||||
import * as ModalEvents from 'core/modal_events';
|
||||
|
||||
/**
|
||||
* Find the Node containing the gradable details from the provided node by searching up the tree.
|
||||
*
|
||||
* @param {HTMLElement} node
|
||||
* @returns {HTMLElement}
|
||||
*/
|
||||
const findGradableNode = node => node.closest(ForumSelectors.expandConversation);
|
||||
|
||||
/**
|
||||
* Show the post in context in a modal.
|
||||
*
|
||||
* @param {HTMLElement} rootNode The button thas clicked
|
||||
*/
|
||||
const showPostInContext = async rootNode => {
|
||||
const postId = rootNode.dataset.postid;
|
||||
const discussionId = rootNode.dataset.discussionid;
|
||||
const discussionName = rootNode.dataset.name;
|
||||
|
||||
const [
|
||||
allPosts,
|
||||
modal,
|
||||
] = await Promise.all([
|
||||
Repository.getDiscussionPosts(parseInt(discussionId)),
|
||||
Modal.create({
|
||||
title: discussionName,
|
||||
large: true,
|
||||
type: Modal.types.CANCEL
|
||||
}),
|
||||
]);
|
||||
|
||||
// Handle hidden event.
|
||||
modal.getRoot().on(ModalEvents.hidden, function() {
|
||||
// Destroy when hidden.
|
||||
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', allPosts);
|
||||
modal.setBody(templatePromise);
|
||||
// eslint-disable-next-line promise/catch-or-return
|
||||
templatePromise.then(() => {
|
||||
const relevantPost = modal.getRoot()[0].querySelector(`#p${postId}`);
|
||||
if (relevantPost) {
|
||||
relevantPost.scrollIntoView({behavior: "smooth"});
|
||||
}
|
||||
|
||||
return;
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Register event listeners for the expand conversations button.
|
||||
*
|
||||
* @param {HTMLElement} rootNode The root to listen to.
|
||||
*/
|
||||
export const registerEventListeners = rootNode => {
|
||||
rootNode.addEventListener('click', e => {
|
||||
const rootNode = findGradableNode(e.target);
|
||||
|
||||
if (rootNode) {
|
||||
e.preventDefault();
|
||||
|
||||
try {
|
||||
showPostInContext(rootNode);
|
||||
} catch (err) {
|
||||
showException(err);
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
@@ -27,4 +27,6 @@ export default {
|
||||
gradableItems: {
|
||||
wholeForum: '[data-gradable-itemtype="forum"]',
|
||||
},
|
||||
expandConversation: '[data-action="view-context"]',
|
||||
posts: '[data-region="posts"]',
|
||||
};
|
||||
|
||||
@@ -134,12 +134,29 @@ define(['core/ajax'], function(Ajax) {
|
||||
return Ajax.call([request])[0];
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the posts for the discussion ID provided.
|
||||
*
|
||||
* @param {number} discussionId
|
||||
* @return {*|Promise}
|
||||
*/
|
||||
var getDiscussionPosts = function(discussionId) {
|
||||
var request = {
|
||||
methodname: 'mod_forum_get_discussion_posts',
|
||||
args: {
|
||||
discussionid: discussionId,
|
||||
},
|
||||
};
|
||||
return Ajax.call([request])[0];
|
||||
};
|
||||
|
||||
return {
|
||||
setDiscussionSubscriptionState: setDiscussionSubscriptionState,
|
||||
addDiscussionPost: addDiscussionPost,
|
||||
setDiscussionLockState: setDiscussionLockState,
|
||||
setFavouriteDiscussionState: setFavouriteDiscussionState,
|
||||
setPinDiscussionState: setPinDiscussionState,
|
||||
getDiscussionByUserID: getDiscussionByUserID
|
||||
getDiscussionByUserID: getDiscussionByUserID,
|
||||
getDiscussionPosts: getDiscussionPosts,
|
||||
};
|
||||
});
|
||||
|
||||
@@ -43,6 +43,7 @@ $functions = array(
|
||||
'classpath' => 'mod/forum/externallib.php',
|
||||
'description' => 'Returns a list of forum posts for a discussion.',
|
||||
'type' => 'read',
|
||||
'ajax' => true,
|
||||
'capabilities' => 'mod/forum:viewdiscussion, mod/forum:viewqandawithoutposting',
|
||||
'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE)
|
||||
),
|
||||
|
||||
@@ -188,6 +188,8 @@ class mod_forum_external extends external_api {
|
||||
|
||||
$forumvault = $vaultfactory->get_forum_vault();
|
||||
$forum = $forumvault->get_from_id($discussion->get_forum_id());
|
||||
$context = $forum->get_context();
|
||||
self::validate_context($context);
|
||||
|
||||
$sortby = $params['sortby'];
|
||||
$sortdirection = $params['sortdirection'];
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
{{!
|
||||
This file is part of Moodle - http://moodle.org/
|
||||
|
||||
Moodle is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Moodle is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
}}
|
||||
{{!
|
||||
@template mod_forum/forum_discussion_post_modal
|
||||
|
||||
Template to render a single post from a discussion.
|
||||
|
||||
Classes required for JS:
|
||||
* none
|
||||
|
||||
Data attributes required for JS:
|
||||
* none
|
||||
|
||||
Example context (json):
|
||||
{
|
||||
}
|
||||
}}
|
||||
<div data-region="posts-modal">
|
||||
{{#posts}}
|
||||
{{> mod_forum/forum_discussion_modern_post_reply }}
|
||||
{{/posts}}
|
||||
</div>
|
||||
@@ -29,7 +29,7 @@
|
||||
{
|
||||
}
|
||||
}}
|
||||
<div data-region="posts">
|
||||
<div data-region="posts" id="post-region-{{uniqid}}">
|
||||
{{#discussions}}
|
||||
<div class="hr-sect mt-0">{{name}}</div>
|
||||
{{#posts}}
|
||||
@@ -66,7 +66,6 @@
|
||||
</div>
|
||||
</div>
|
||||
{{/starter}}
|
||||
|
||||
<hr>
|
||||
{{/posts}}
|
||||
{{/discussions}}
|
||||
@@ -76,6 +75,6 @@
|
||||
</div>
|
||||
{{#js}}
|
||||
require(['mod_forum/grades/expandconversation'], function(Conversation) {
|
||||
Conversation.registerEventListeners();
|
||||
Conversation.registerEventListeners(document.querySelector('#post-region-{{uniqid}}'));
|
||||
});
|
||||
{{/js}}
|
||||
|
||||
@@ -24,6 +24,6 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$plugin->version = 2019100104; // The current module version (Date: YYYYMMDDXX)
|
||||
$plugin->version = 2019100105; // The current module version (Date: YYYYMMDDXX)
|
||||
$plugin->requires = 2019051100; // Requires this Moodle version
|
||||
$plugin->component = 'mod_forum'; // Full name of the plugin (used for diagnostics)
|
||||
|
||||
Reference in New Issue
Block a user