Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
{"version":3,"file":"grader.min.js","sources":["../../src/grades/grader.js"],"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\n * @copyright  2019 Andrew Nicols <andrew@nicols.co.uk>\n * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\nimport * as Selectors from './grader/selectors';\nimport Repository from 'mod_forum/repository';\nimport Templates from 'core/templates';\nimport * as Grader from '../local/grades/grader';\nimport Notification from 'core/notification';\nimport CourseRepository from 'core_course/repository';\nimport {relativeUrl} from 'core/url';\n\nconst templateNames = {\n    contentRegion: 'mod_forum/grades/grader/discussion/posts',\n};\n\n/**\n * Curried function with CMID set, this is then used in unified grader as a fetch a users content.\n *\n * @param {Number} cmid\n * @param {Bool} experimentalDisplayMode\n * @return {Function}\n */\nconst getContentForUserIdFunction = (cmid, experimentalDisplayMode) => (userid) => {\n    /**\n     * Given the parent function is called with the second param set execute the partially executed function.\n     *\n     * @param {Number} userid\n     */\n    return Repository.getDiscussionByUserID(userid, cmid)\n        .then(context => {\n            // Rebuild the returned data for the template.\n            context.discussions = context.discussions.map(discussionPostMapper);\n            context.experimentaldisplaymode = experimentalDisplayMode ? true : false;\n\n            return Templates.render(templateNames.contentRegion, context);\n        })\n        .catch(Notification.exception);\n};\n\n/**\n * Curried function with CMID set, this is then used in unified grader as a fetch users call.\n * The function curried fetches all users in a course for a given CMID.\n *\n * @param {Number} courseID\n * @param {Number} groupID\n * @param {Boolean} onlyActive Whether to fetch only the active enrolled users or all enrolled users in the course.\n * @return {Array} Array of users for a given context.\n */\nconst getGradableUsersForCourseidFunction = (courseID, groupID, onlyActive) => async() => {\n    const context = await CourseRepository.getGradableUsersFromCourseID(courseID, groupID, onlyActive);\n\n    return context.users;\n};\n\n\nconst findGradableNode = node => node.closest(Selectors.gradableItem);\n\n/**\n * For a discussion we need to manipulate it's posts to hide certain UI elements.\n *\n * @param {Object} discussion\n * @return {Array} name, id, posts\n */\nconst discussionPostMapper = (discussion) => {\n    // Map postid => post.\n    const parentMap = new Map();\n    discussion.posts.parentposts.forEach(post => parentMap.set(post.id, post));\n    const userPosts = discussion.posts.userposts.map(post => {\n        post.readonly = true;\n        post.hasreplies = false;\n        post.replies = [];\n\n        const parent = post.parentid ? parentMap.get(post.parentid) : null;\n        if (parent) {\n            parent.hasreplies = false;\n            parent.replies = [];\n            parent.readonly = true;\n            post.parentauthorname = parent.author.fullname;\n        }\n\n        return {\n            parent,\n            post\n        };\n    });\n\n    return {\n        ...discussion,\n        posts: userPosts,\n    };\n};\n\n/**\n * Launch the Grader.\n *\n * @param {HTMLElement} rootNode the root HTML element describing what is to be graded\n * @param {object} param\n * @param {bool} [param.focusOnClose=null]\n */\nconst launchWholeForumGrading = async(rootNode, {\n    focusOnClose = null,\n} = {}) => {\n    const data = rootNode.dataset;\n    const gradingPanelFunctions = await Grader.getGradingPanelFunctions(\n        'mod_forum',\n        data.contextid,\n        data.gradingComponent,\n        data.gradingComponentSubtype,\n        data.gradableItemtype\n    );\n\n    const groupID = data.group ? data.group : 0;\n    const onlyActive = data.gradeOnlyActiveUsers;\n\n    await Grader.launch(\n        getGradableUsersForCourseidFunction(data.courseId, groupID, onlyActive),\n        getContentForUserIdFunction(data.cmid, data.experimentalDisplayMode == \"1\"),\n        gradingPanelFunctions.getter,\n        gradingPanelFunctions.setter,\n        {\n            groupid: data.groupid,\n            initialUserId: data.initialuserid,\n            moduleName: data.name,\n            courseName: data.courseName,\n            courseUrl: relativeUrl('/course/view.php', {id: data.courseId}),\n            sendStudentNotifications: data.sendStudentNotifications,\n            focusOnClose,\n        }\n    );\n};\n\n/**\n * Launch the Grader.\n *\n * @param {HTMLElement} rootNode the root HTML element describing what is to be graded\n * @param {object} param\n * @param {bool} [param.focusOnClose=null]\n */\nconst launchViewGrading = async(rootNode, {\n    focusOnClose = null,\n} = {}) => {\n    const data = rootNode.dataset;\n    const gradingPanelFunctions = await Grader.getGradingPanelFunctions(\n        'mod_forum',\n        data.contextid,\n        data.gradingComponent,\n        data.gradingComponentSubtype,\n        data.gradableItemtype\n    );\n\n    await Grader.view(\n        gradingPanelFunctions.getter,\n        data.userid,\n        data.name,\n        {\n            focusOnClose,\n        }\n    );\n};\n\n/**\n * Register listeners to launch the grading panel.\n */\nexport const registerLaunchListeners = () => {\n    document.addEventListener('click', async(e) => {\n        if (e.target.matches(Selectors.launch)) {\n            const rootNode = findGradableNode(e.target);\n\n            if (!rootNode) {\n                throw Error('Unable to find a gradable item');\n            }\n\n            if (rootNode.matches(Selectors.gradableItems.wholeForum)) {\n                // Note: The preventDefault must be before any async function calls because the function becomes async\n                // at that point and the default action is implemented.\n                e.preventDefault();\n                try {\n                    await launchWholeForumGrading(rootNode, {\n                        focusOnClose: e.target,\n                    });\n                } catch (error) {\n                    Notification.exception(error);\n                }\n            } else {\n                throw Error('Unable to find a valid gradable item');\n            }\n        }\n        if (e.target.matches(Selectors.viewGrade)) {\n            e.preventDefault();\n            const rootNode = findGradableNode(e.target);\n\n            if (!rootNode) {\n                throw Error('Unable to find a gradable item');\n            }\n\n            if (rootNode.matches(Selectors.gradableItems.wholeForum)) {\n                // Note: The preventDefault must be before any async function calls because the function becomes async\n                // at that point and the default action is implemented.\n                e.preventDefault();\n                try {\n                    await launchViewGrading(rootNode, {\n                        focusOnClose: e.target,\n                    });\n                } catch (error) {\n                    Notification.exception(error);\n                }\n            } else {\n                throw Error('Unable to find a valid gradable item');\n            }\n        }\n    });\n};\n"],"names":["templateNames","getContentForUserIdFunction","cmid","experimentalDisplayMode","userid","Repository","getDiscussionByUserID","then","context","discussions","map","discussionPostMapper","experimentaldisplaymode","Templates","render","catch","Notification","exception","getGradableUsersForCourseidFunction","courseID","groupID","onlyActive","async","CourseRepository","getGradableUsersFromCourseID","users","findGradableNode","node","closest","Selectors","gradableItem","discussion","parentMap","Map","posts","parentposts","forEach","post","set","id","userPosts","userposts","readonly","hasreplies","replies","parent","parentid","get","parentauthorname","author","fullname","document","addEventListener","e","target","matches","launch","rootNode","Error","gradableItems","wholeForum","preventDefault","focusOnClose","data","dataset","gradingPanelFunctions","Grader","getGradingPanelFunctions","contextid","gradingComponent","gradingComponentSubtype","gradableItemtype","group","gradeOnlyActiveUsers","courseId","getter","setter","groupid","initialUserId","initialuserid","moduleName","name","courseName","courseUrl","sendStudentNotifications","launchWholeForumGrading","error","viewGrade","view","launchViewGrading"],"mappings":";;;;;;;mYA8BMA,4BACa,2CAUbC,4BAA8B,CAACC,KAAMC,0BAA6BC,QAM7DC,oBAAWC,sBAAsBF,OAAQF,MAC3CK,MAAKC,UAEFA,QAAQC,YAAcD,QAAQC,YAAYC,IAAIC,sBAC9CH,QAAQI,0BAA0BT,wBAE3BU,mBAAUC,OAAOd,4BAA6BQ,YAExDO,MAAMC,sBAAaC,WAYtBC,oCAAsC,CAACC,SAAUC,QAASC,aAAeC,gBACrDC,qBAAiBC,6BAA6BL,SAAUC,QAASC,aAExEI,MAIbC,iBAAmBC,MAAQA,KAAKC,QAAQC,UAAUC,cAQlDnB,qBAAwBoB,mBAEpBC,UAAY,IAAIC,IACtBF,WAAWG,MAAMC,YAAYC,SAAQC,MAAQL,UAAUM,IAAID,KAAKE,GAAIF,cAC9DG,UAAYT,WAAWG,MAAMO,UAAU/B,KAAI2B,OAC7CA,KAAKK,UAAW,EAChBL,KAAKM,YAAa,EAClBN,KAAKO,QAAU,SAETC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