first commit

This commit is contained in:
CHIEFSOFT\ameye
2024-09-30 18:11:26 -04:00
commit e592ca6823
27270 changed files with 5002257 additions and 0 deletions
+9
View File
@@ -0,0 +1,9 @@
define("report_insights/actions",["exports","core/str","core/ajax","core/notification","core/url","core/modal_events","core/modal_save_cancel"],(function(_exports,_str,_ajax,_notification,_url,_modal_events,_modal_save_cancel){function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}
/**
* Module to manage report insights actions that are executed using AJAX.
*
* @copyright 2017 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.initBulk=void 0,_ajax=_interopRequireDefault(_ajax),_notification=_interopRequireDefault(_notification),_url=_interopRequireDefault(_url),_modal_events=_interopRequireDefault(_modal_events),_modal_save_cancel=_interopRequireDefault(_modal_save_cancel);const executeAction=(predictionIds,predictionContainers,actionName)=>{var predictionids,actionname;(predictionids=predictionIds,actionname=actionName,_ajax.default.call([{methodname:"report_insights_action_executed",args:{actionname:actionname,predictionids:predictionids}}])[0]).then((()=>{const tableNode=(predictionContainers=>{for(const el of predictionContainers)if(el.closest("table"))return el.closest("table");return null})(predictionContainers);if(predictionContainers.forEach((el=>el.remove())),!tableNode.querySelector("tbody > tr")){const params={contextid:tableNode.closest("div.insight-container").dataset.contextId,modelid:tableNode.closest("div.insight-container").dataset.modelId};window.location.assign(_url.default.relativeUrl("report/insights/insights.php",params,!1))}})).catch(_notification.default.exception)};_exports.initBulk=rootNode=>{document.addEventListener("click",(e=>{const action=e.target.closest("".concat(rootNode," [data-bulk-actionname]"));if(!action)return;e.preventDefault();const actionName=action.dataset.bulkActionname,actionVisibleName=action.textContent.trim(),predictionContainers=Array.from(document.querySelectorAll('.insights-list input[data-togglegroup^="insight-bulk-action-"][data-toggle="slave"]:checked')).map((checkbox=>checkbox.closest("tr[data-prediction-id]"))),predictionIds=predictionContainers.map((el=>el.dataset.predictionId));if(0===predictionIds.length)return;const stringParams={action:actionVisibleName,nitems:predictionIds.length};_modal_save_cancel.default.create({title:actionVisibleName,body:(0,_str.get_string)("confirmbulkaction","report_insights",stringParams),buttons:{save:(0,_str.get_string)("confirm")},show:!0}).then((modal=>(modal.getRoot().on(_modal_events.default.save,(function(){return executeAction(predictionIds,predictionContainers,actionName)})),modal))).catch(_notification.default.exception)}))}}));
//# sourceMappingURL=actions.min.js.map
File diff suppressed because one or more lines are too long
+10
View File
@@ -0,0 +1,10 @@
/**
* Message users.
*
* @module report_insights/message_users
* @copyright 2019 David Monllao
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
define("report_insights/message_users",["jquery","core/str","core/log","core/modal_save_cancel","core/modal_events","core/templates","core/notification","core/ajax"],(function($,Str,Log,ModalSaveCancel,ModalEvents,Templates,Notification,Ajax){var SELECTORS_BULKACTIONSELECT="#formactionid",MessageUsers=function(rootNode,actionName){this.actionName=actionName,this.attachEventListeners(rootNode)};return MessageUsers.prototype.actionName=null,MessageUsers.prototype.modal=null,MessageUsers.prototype.attachEventListeners=function(rootNode){$(rootNode+" button[data-bulk-sendmessage]").on("click",function(e){e.preventDefault();var cTarget=$(e.currentTarget),users={},predictionToUserMapping=cTarget.data("prediction-to-user-id");return $('.insights-list input[data-togglegroup^="insight-bulk-action"][data-toggle="slave"]:checked').each((function(index,value){var predictionId=$(value).closest("tr[data-prediction-id]").data("prediction-id");if(void 0!==predictionToUserMapping[predictionId]){var userId=predictionToUserMapping[predictionId];users[predictionId]=userId}else Log.error("Unknown user for prediction "+predictionId)})),0===Object.keys(users).length||this.showSendMessage(users),this}.bind(this))},MessageUsers.prototype.showSendMessage=function(users){var userIds=new Set(Object.values(users));if(0==userIds.length)return $.Deferred().resolve().promise();var titlePromise=null;titlePromise=1==userIds.size?Str.get_string("sendbulkmessagesingle","core_message"):Str.get_string("sendbulkmessage","core_message",userIds.size),ModalSaveCancel.create({body:Templates.render("core_user/send_bulk_message",{}),title:titlePromise,buttons:{save:titlePromise},show:!0}).then(function(modal){return this.modal=modal,this.modal.getRoot().on(ModalEvents.hidden,function(){$(SELECTORS_BULKACTIONSELECT).focus(),this.modal.getRoot().remove()}.bind(this)),this.modal.getRoot().on(ModalEvents.save,this.submitSendMessage.bind(this,users)),this.modal}.bind(this))},MessageUsers.prototype.submitSendMessage=function(users){var messageText=this.modal.getRoot().find("form textarea").val(),messages=[];new Set(Object.values(users)).forEach((function(userId){messages.push({touserid:userId,text:messageText})}));var actionName=this.actionName,message=null;return Ajax.call([{methodname:"core_message_send_instant_messages",args:{messages:messages}}])[0].then((function(messageIds){return 1==messageIds.length?Str.get_string("sendbulkmessagesentsingle","core_message"):Str.get_string("sendbulkmessagesent","core_message",messageIds.length)})).then((function(msg){return message=msg,Ajax.call([{methodname:"report_insights_action_executed",args:{actionname:actionName,predictionids:Object.keys(users)}}])[0]})).then((function(){return Notification.addNotification({message:message,type:"success"}),!0})).catch(Notification.exception)},{init:function(rootNode,actionName){return new MessageUsers(rootNode,actionName)}}}));
//# sourceMappingURL=message_users.min.js.map
File diff suppressed because one or more lines are too long
+129
View File
@@ -0,0 +1,129 @@
// 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/>.
/**
* Module to manage report insights actions that are executed using AJAX.
*
* @copyright 2017 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* This module manages prediction actions that require AJAX requests.
*
* @module report_insights/actions
*/
import {get_string as getString} from 'core/str';
import Ajax from 'core/ajax';
import Notification from 'core/notification';
import Url from 'core/url';
import ModalEvents from 'core/modal_events';
import ModalSaveCancel from 'core/modal_save_cancel';
/**
* Executes the provided action.
*
* @param {Array} predictionids
* @param {String} actionname
* @return {Promise}
*/
const markActionExecuted = (predictionids, actionname) => Ajax.call([
{
methodname: 'report_insights_action_executed',
args: {
actionname,
predictionids,
},
}
])[0];
const getPredictionTable = (predictionContainers) => {
for (const el of predictionContainers) {
if (el.closest('table')) {
return el.closest('table');
}
}
return null;
};
const executeAction = (predictionIds, predictionContainers, actionName) => {
markActionExecuted(predictionIds, actionName).then(() => {
// Remove the selected elements from the list.
const tableNode = getPredictionTable(predictionContainers);
predictionContainers.forEach((el) => el.remove());
if (!tableNode.querySelector('tbody > tr')) {
const params = {
contextid: tableNode.closest('div.insight-container').dataset.contextId,
modelid: tableNode.closest('div.insight-container').dataset.modelId,
};
window.location.assign(Url.relativeUrl("report/insights/insights.php", params, false));
}
return;
}).catch(Notification.exception);
};
/**
* Attach on click handlers for bulk actions.
*
* @param {String} rootNode
* @access public
*/
export const initBulk = (rootNode) => {
document.addEventListener('click', (e) => {
const action = e.target.closest(`${rootNode} [data-bulk-actionname]`);
if (!action) {
return;
}
e.preventDefault();
const actionName = action.dataset.bulkActionname;
const actionVisibleName = action.textContent.trim();
const predictionContainers = Array.from(document.querySelectorAll(
'.insights-list input[data-togglegroup^="insight-bulk-action-"][data-toggle="slave"]:checked',
)).map((checkbox) => checkbox.closest('tr[data-prediction-id]'));
const predictionIds = predictionContainers.map((el) => el.dataset.predictionId);
if (predictionIds.length === 0) {
// No items selected message.
return;
}
const stringParams = {
action: actionVisibleName,
nitems: predictionIds.length,
};
ModalSaveCancel.create({
title: actionVisibleName,
body: getString('confirmbulkaction', 'report_insights', stringParams),
buttons: {
save: getString('confirm'),
},
show: true,
}).then((modal) => {
modal.getRoot().on(ModalEvents.save, function() {
// The action is now confirmed, sending an action for it.
return executeAction(predictionIds, predictionContainers, actionName);
});
return modal;
}).catch(Notification.exception);
});
};
+204
View File
@@ -0,0 +1,204 @@
// 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/>.
/**
* Message users.
*
* @module report_insights/message_users
* @copyright 2019 David Monllao
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
define(['jquery', 'core/str', 'core/log', 'core/modal_save_cancel', 'core/modal_events', 'core/templates',
'core/notification', 'core/ajax'],
function($, Str, Log, ModalSaveCancel, ModalEvents, Templates, Notification, Ajax) {
var SELECTORS = {
BULKACTIONSELECT: "#formactionid"
};
/**
* Constructor.
*
* @param {String} rootNode
* @param {String} actionName
*/
var MessageUsers = function(rootNode, actionName) {
this.actionName = actionName;
this.attachEventListeners(rootNode);
};
/**
* @var {String} actionName
* @private
*/
MessageUsers.prototype.actionName = null;
/**
* @var {Modal} modal
* @private
*/
MessageUsers.prototype.modal = null;
/**
* Attach the event listener to the send message bulk action.
* @param {String} rootNode
*/
MessageUsers.prototype.attachEventListeners = function(rootNode) {
$(rootNode + ' button[data-bulk-sendmessage]').on('click', function(e) {
e.preventDefault();
var cTarget = $(e.currentTarget);
// Using an associative array in case there is more than 1 prediction for the same user.
var users = {};
var predictionToUserMapping = cTarget.data('prediction-to-user-id');
var checkedSelector = '.insights-list input[data-togglegroup^="insight-bulk-action"][data-toggle="slave"]:checked';
$(checkedSelector).each(function(index, value) {
var predictionId = $(value).closest('tr[data-prediction-id]').data('prediction-id');
if (typeof predictionToUserMapping[predictionId] === 'undefined') {
Log.error('Unknown user for prediction ' + predictionId);
return;
}
var userId = predictionToUserMapping[predictionId];
users[predictionId] = userId;
});
if (Object.keys(users).length === 0) {
return this;
}
this.showSendMessage(users);
return this;
}.bind(this));
};
/**
* Show the send message popup.
*
* @method showSendMessage
* @private
* @param {Object} users Prediction id to user id mapping.
* @returns {Promise}
*/
MessageUsers.prototype.showSendMessage = function(users) {
var userIds = new Set(Object.values(users));
if (userIds.length == 0) {
// Nothing to do.
return $.Deferred().resolve().promise();
}
var titlePromise = null;
if (userIds.size == 1) {
titlePromise = Str.get_string('sendbulkmessagesingle', 'core_message');
} else {
titlePromise = Str.get_string('sendbulkmessage', 'core_message', userIds.size);
}
// eslint-disable-next-line promise/catch-or-return
ModalSaveCancel.create({
body: Templates.render('core_user/send_bulk_message', {}),
title: titlePromise,
buttons: {
save: titlePromise,
},
show: true,
})
.then(function(modal) {
// Keep a reference to the modal.
this.modal = modal;
// We want to focus on the action select when the dialog is closed.
this.modal.getRoot().on(ModalEvents.hidden, function() {
$(SELECTORS.BULKACTIONSELECT).focus();
this.modal.getRoot().remove();
}.bind(this));
this.modal.getRoot().on(ModalEvents.save, this.submitSendMessage.bind(this, users));
return this.modal;
}.bind(this));
};
/**
* Send a message to these users.
*
* @method submitSendMessage
* @private
* @param {Object} users Prediction id to user id mapping.
* @returns {Promise}
*/
MessageUsers.prototype.submitSendMessage = function(users) {
var messageText = this.modal.getRoot().find('form textarea').val();
var messages = [];
var userIds = new Set(Object.values(users));
userIds.forEach(function(userId) {
messages.push({touserid: userId, text: messageText});
});
var actionName = this.actionName;
var message = null;
return Ajax.call([{
methodname: 'core_message_send_instant_messages',
args: {messages: messages}
}])[0].then(function(messageIds) {
if (messageIds.length == 1) {
return Str.get_string('sendbulkmessagesentsingle', 'core_message');
} else {
return Str.get_string('sendbulkmessagesent', 'core_message', messageIds.length);
}
}).then(function(msg) {
// Save this for the following callback. Now that we got everything
// done we can flag this action as executed.
message = msg;
return Ajax.call([{
methodname: 'report_insights_action_executed',
args: {
actionname: actionName,
predictionids: Object.keys(users)
}
}])[0];
}).then(function() {
Notification.addNotification({
message: message,
type: "success"
});
return true;
}).catch(Notification.exception);
};
return /** @alias module:report_insights/message_users */ {
// Public variables and functions.
/**
* @method init
* @param {String} rootNode
* @param {String} actionName
* @returns {MessageUsers}
*/
'init': function(rootNode, actionName) {
return new MessageUsers(rootNode, actionName);
}
};
});