MDL-66074 mod_forum: Make initial user id optional
This commit is contained in:
committed by
Mathew May
parent
eaee64778b
commit
aa04b722f3
+1
-1
@@ -1,2 +1,2 @@
|
||||
define ("mod_forum/local/grades/grader",["exports","core/templates","./local/grader/selectors","./local/grader/user_picker","mod_forum/local/layout/fullscreen","./local/grader/gradingpanel","core/toast","core/str"],function(a,b,c,d,e,f,g,h){"use strict";Object.defineProperty(a,"__esModule",{value:!0});Object.defineProperty(a,"getGradingPanelFunctions",{enumerable:!0,get:function get(){return f.default}});a.launch=void 0;b=i(b);c=i(c);d=i(d);f=i(f);function i(a){return a&&a.__esModule?a:{default:a}}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={grader:{app:"mod_forum/local/grades/grader"}},q=function(a,d){var e=a.querySelector(c.default.regions.pickerRegion);b.default.replaceNodeContents(e,d,"")},r=function(a,b){return[a,b]},s=function(a,d,e){return function(){var f=o(regeneratorRuntime.mark(function f(g){var h,i,k,l,m,n,o,p,q,s;return regeneratorRuntime.wrap(function(f){while(1){switch(f.prev=f.next){case 0:f.next=2;return Promise.all([d(g.id).then(r),e(g.id)]);case 2:h=f.sent;i=j(h,2);k=j(i[0],2);l=k[0];m=k[1];n=i[1];b.default.replaceNodeContents(a.querySelector(c.default.regions.moduleReplace),l,m);f.next=11;return b.default.render(n.templatename,n.grade).then(r);case 11:o=f.sent;p=j(o,2);q=p[0];s=p[1];b.default.replaceNodeContents(a.querySelector(c.default.regions.gradingPanel),q,s);case 16:case"end":return f.stop();}}},f)}));return function(){return f.apply(this,arguments)}}()},t=function(a,b,d){var e=a.getContainer();e.addEventListener("click",function(f){if(f.target.closest(c.default.buttons.toggleFullscreen)){f.stopImmediatePropagation();f.preventDefault();a.toggleFullscreen();return}if(f.target.closest(c.default.buttons.closeGrader)){f.stopImmediatePropagation();f.preventDefault();a.close();return}if(f.target.closest(c.default.buttons.saveGrade)){d(b.currentUser)}})},u=function(a,b){return function(){var d=o(regeneratorRuntime.mark(function d(e){var f;return regeneratorRuntime.wrap(function(d){while(1){switch(d.prev=d.next){case 0:d.prev=0;d.next=3;return b(e.id,a.querySelector(c.default.regions.gradingPanel));case 3:f=d.sent;d.t0=g.add;d.next=7;return(0,h.get_string)("grades:gradesavedfor","mod_forum",e);case 7:d.t1=d.sent;(0,d.t0)(d.t1);return d.abrupt("return",f);case 12:d.prev=12;d.t2=d["catch"](0);throw d.t2;case 15:case"end":return d.stop();}}},d,null,[[0,12]])}));return function(){return d.apply(this,arguments)}}()},v=function(){var a=o(regeneratorRuntime.mark(function a(c,f,g,h){var i,k,l,m,n,o,r,v,w,x,y,z,A,B=arguments;return regeneratorRuntime.wrap(function(a){while(1){switch(a.prev=a.next){case 0:i=4<B.length&&B[4]!==void 0?B[4]:{},k=i.initialUserId,l=void 0===k?0:k,m=i.moduleName;a.next=3;return Promise.all([(0,e.createLayout)({fullscreen:!1,showLoader:!1}),b.default.render(p.grader.app,{moduleName:m}),c()]);case 3:n=a.sent;o=j(n,3);r=o[0];v=o[1];w=o[2];x=r.getContainer();y=u(x,h);b.default.replaceNodeContents(x,v,"");z=s(x,f,g);a.next=14;return(0,d.default)(w,l,z,y);case 14:A=a.sent;t(r,A,y);q(x,A.rootNode);case 17:case"end":return a.stop();}}},a)}));return function(){return a.apply(this,arguments)}}();a.launch=v});
|
||||
define ("mod_forum/local/grades/grader",["exports","core/templates","./local/grader/selectors","./local/grader/user_picker","mod_forum/local/layout/fullscreen","./local/grader/gradingpanel","core/toast","core/str"],function(a,b,c,d,e,f,g,h){"use strict";Object.defineProperty(a,"__esModule",{value:!0});Object.defineProperty(a,"getGradingPanelFunctions",{enumerable:!0,get:function get(){return f.default}});a.launch=void 0;b=i(b);c=i(c);d=i(d);f=i(f);function i(a){return a&&a.__esModule?a:{default:a}}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={grader:{app:"mod_forum/local/grades/grader"}},q=function(a,d){var e=a.querySelector(c.default.regions.pickerRegion);b.default.replaceNodeContents(e,d,"")},r=function(a,b){return[a,b]},s=function(a,d,e){return function(){var f=o(regeneratorRuntime.mark(function f(g){var h,i,k,l,m,n,o,p,q,s;return regeneratorRuntime.wrap(function(f){while(1){switch(f.prev=f.next){case 0:f.next=2;return Promise.all([d(g.id).then(r),e(g.id)]);case 2:h=f.sent;i=j(h,2);k=j(i[0],2);l=k[0];m=k[1];n=i[1];b.default.replaceNodeContents(a.querySelector(c.default.regions.moduleReplace),l,m);f.next=11;return b.default.render(n.templatename,n.grade).then(r);case 11:o=f.sent;p=j(o,2);q=p[0];s=p[1];b.default.replaceNodeContents(a.querySelector(c.default.regions.gradingPanel),q,s);case 16:case"end":return f.stop();}}},f)}));return function(){return f.apply(this,arguments)}}()},t=function(a,b,d){var e=a.getContainer();e.addEventListener("click",function(f){if(f.target.closest(c.default.buttons.toggleFullscreen)){f.stopImmediatePropagation();f.preventDefault();a.toggleFullscreen();return}if(f.target.closest(c.default.buttons.closeGrader)){f.stopImmediatePropagation();f.preventDefault();a.close();return}if(f.target.closest(c.default.buttons.saveGrade)){d(b.currentUser)}})},u=function(a,b){return function(){var d=o(regeneratorRuntime.mark(function d(e){var f;return regeneratorRuntime.wrap(function(d){while(1){switch(d.prev=d.next){case 0:d.prev=0;d.next=3;return b(e.id,a.querySelector(c.default.regions.gradingPanel));case 3:f=d.sent;d.t0=g.add;d.next=7;return(0,h.get_string)("grades:gradesavedfor","mod_forum",e);case 7:d.t1=d.sent;(0,d.t0)(d.t1);return d.abrupt("return",f);case 12:d.prev=12;d.t2=d["catch"](0);throw d.t2;case 15:case"end":return d.stop();}}},d,null,[[0,12]])}));return function(){return d.apply(this,arguments)}}()},v=function(){var a=o(regeneratorRuntime.mark(function a(c,f,g,h){var i,k,l,m,n,o,r,v,w,x,y,z,A,B=arguments;return regeneratorRuntime.wrap(function(a){while(1){switch(a.prev=a.next){case 0:i=4<B.length&&B[4]!==void 0?B[4]:{},k=i.initialUserId,l=void 0===k?null:k,m=i.moduleName;a.next=3;return Promise.all([(0,e.createLayout)({fullscreen:!1,showLoader:!1}),b.default.render(p.grader.app,{moduleName:m}),c()]);case 3:n=a.sent;o=j(n,3);r=o[0];v=o[1];w=o[2];x=r.getContainer();y=u(x,h);b.default.replaceNodeContents(x,v,"");z=s(x,f,g);a.next=14;return(0,d.default)(w,z,y,{initialUserId:l});case 14:A=a.sent;t(r,A,y);q(x,A.rootNode);case 17:case"end":return a.stop();}}},a)}));return function(){return a.apply(this,arguments)}}();a.launch=v});
|
||||
//# sourceMappingURL=grader.min.js.map
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -118,7 +118,7 @@ const getSaveUserGradeFunction = (root, setGradeForUser) => {
|
||||
* @param {Function} setGradeForUser A function to set the grade for a specific user
|
||||
*/
|
||||
export const launch = async(getListOfUsers, getContentForUser, getGradeForUser, setGradeForUser, {
|
||||
initialUserId = 0, moduleName
|
||||
initialUserId = null, moduleName
|
||||
} = {}) => {
|
||||
|
||||
const [
|
||||
@@ -140,9 +140,11 @@ export const launch = async(getListOfUsers, getContentForUser, getGradeForUser,
|
||||
// Fetch the userpicker for display.
|
||||
const userPicker = await getUserPicker(
|
||||
userList,
|
||||
initialUserId,
|
||||
updateUserContent,
|
||||
saveGradeFunction
|
||||
saveGradeFunction,
|
||||
{
|
||||
initialUserId,
|
||||
},
|
||||
);
|
||||
|
||||
// Register all event listeners.
|
||||
|
||||
@@ -33,27 +33,37 @@ class UserPicker {
|
||||
* Constructor for the User Picker.
|
||||
*
|
||||
* @param {Array} userList List of users
|
||||
* @param {Number} initialUserId The ID of the initial user to display
|
||||
* @param {Function} showUserCallback The callback used to display the user
|
||||
* @param {Function} preChangeUserCallback The callback to use before changing user
|
||||
* @param {Bool} render Whether to render on instantiation
|
||||
*/
|
||||
constructor(userList, initialUserId, showUserCallback, preChangeUserCallback, render = true) {
|
||||
constructor(userList, showUserCallback, preChangeUserCallback) {
|
||||
this.userList = userList;
|
||||
this.showUserCallback = showUserCallback;
|
||||
this.preChangeUserCallback = preChangeUserCallback;
|
||||
|
||||
// Determine the current index.
|
||||
this.currentUserIndex = userList.findIndex(user => {
|
||||
return user.id === parseInt(initialUserId);
|
||||
});
|
||||
this.currentUserIndex = 0;
|
||||
|
||||
// Ensure that render is bound correctly.
|
||||
this.render = this.render.bind(this);
|
||||
this.setUserId = this.setUserId.bind(this);
|
||||
}
|
||||
|
||||
if (render) {
|
||||
this.render();
|
||||
/**
|
||||
* Set the current userid without rendering the change.
|
||||
* To show the user, call showUser too.
|
||||
*
|
||||
* @param {Number} userId
|
||||
*/
|
||||
setUserId(userId) {
|
||||
// Determine the current index based on the user ID.
|
||||
const userIndex = this.userList.findIndex(user => {
|
||||
return user.id === parseInt(userId);
|
||||
});
|
||||
|
||||
if (userIndex === -1) {
|
||||
throw Error(`User with id ${userId} not found`);
|
||||
}
|
||||
|
||||
this.currentUserIndex = userIndex;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -164,13 +174,19 @@ class UserPicker {
|
||||
* Create a new user picker.
|
||||
*
|
||||
* @param {Array} users The list of users
|
||||
* @param {Number} currentUserID The userid of the current user
|
||||
* @param {Function} showUserCallback The function to call to show a specific user
|
||||
* @param {Function} preChangeUserCallback The fucntion to call to save the grade for the current user
|
||||
* @param {Number} [currentUserID] The userid of the current user
|
||||
* @returns {UserPicker}
|
||||
*/
|
||||
export default async(users, currentUserID, showUserCallback, preChangeUserCallback) => {
|
||||
const userPicker = new UserPicker(users, currentUserID, showUserCallback, preChangeUserCallback, false);
|
||||
export default async(users, showUserCallback, preChangeUserCallback, {
|
||||
initialUserId = null,
|
||||
} = {}
|
||||
) => {
|
||||
const userPicker = new UserPicker(users, showUserCallback, preChangeUserCallback);
|
||||
if (initialUserId) {
|
||||
userPicker.setUserId(initialUserId);
|
||||
}
|
||||
await userPicker.render();
|
||||
|
||||
return userPicker;
|
||||
|
||||
Reference in New Issue
Block a user