MDL-60407 report_insights: Fix redirect when action on last prediction

When an actions is taken on the last prediction, the predictions
list page is reloaded.
This commit is contained in:
Víctor Déniz Falcón
2019-05-14 01:06:00 +01:00
parent 6a7451ff1b
commit 8dd1ebaaba
3 changed files with 15 additions and 9 deletions
+3 -1
View File
@@ -130,8 +130,10 @@ abstract class base extends \core_analytics\calculable {
global $PAGE;
$predictionid = $prediction->get_prediction_data()->id;
$contextid = $prediction->get_prediction_data()->contextid;
$modelid = $prediction->get_prediction_data()->modelid;
$PAGE->requires->js_call_amd('report_insights/actions', 'init', array($predictionid));
$PAGE->requires->js_call_amd('report_insights/actions', 'init', array($predictionid, $contextid, $modelid));
$actions = array();
+1 -1
View File
@@ -1 +1 @@
define(["jquery","core/ajax","core/notification"],function(a,b,c){return{init:function(d){a("a[data-prediction-methodname][data-prediction-id="+d+"]").on("click",function(e){e.preventDefault();var f=a(e.currentTarget),g=f.attr("data-prediction-methodname"),h=f.closest("tr");if(h.length>0){var i=b.call([{methodname:g,args:{predictionid:d}}])[0];i.done(function(){h[0].remove(),a(".insights-list tr").length<2&&(document.referrer?window.location.assign(document.referrer):window.location.reload(!0))}).fail(c.exception)}})}}});
define(["jquery","core/ajax","core/notification","core/url"],function(a,b,c,d){return{init:function(e,f,g){a("a[data-prediction-methodname][data-prediction-id="+e+"]").on("click",function(h){h.preventDefault();var i=a(h.currentTarget),j=i.attr("data-prediction-methodname"),k=i.closest("tr");if(k.length>0){var l=b.call([{methodname:j,args:{predictionid:e}}])[0];l.done(function(){if(k[0].remove(),a(".insights-list tr").length<2){var b={contextid:f,modelid:g},c=a.param(b);window.location.assign(d.relativeUrl("report/insights/insights.php?"+c))}}).fail(c.exception)}})}}});
+11 -7
View File
@@ -26,7 +26,7 @@
*
* @module report_insights/actions
*/
define(['jquery', 'core/ajax', 'core/notification'], function($, Ajax, Notification) {
define(['jquery', 'core/ajax', 'core/notification', 'core/url'], function($, Ajax, Notification, Url) {
return {
@@ -34,9 +34,11 @@ define(['jquery', 'core/ajax', 'core/notification'], function($, Ajax, Notificat
* Attach on click handlers to hide predictions.
*
* @param {Number} predictionId The prediction id.
* @param {Number} contextId The context in which the prediction was made.
* @param {Number} modelId The model id model with which the prediction was made.
* @access public
*/
init: function(predictionId) {
init: function(predictionId, contextId, modelId) {
// Select the prediction with the provided id ensuring that an external function is set as method name.
$('a[data-prediction-methodname][data-prediction-id=' + predictionId + ']').on('click', function(e) {
@@ -57,11 +59,13 @@ define(['jquery', 'core/ajax', 'core/notification'], function($, Ajax, Notificat
// Move back if no remaining predictions.
if ($('.insights-list tr').length < 2) {
if (document.referrer) {
window.location.assign(document.referrer);
} else {
window.location.reload(true);
}
var params = {
contextid: contextId,
modelid: modelId
};
var queryparams = $.param(params);
window.location.assign(Url.relativeUrl("report/insights/insights.php?" + queryparams));
}
}).fail(Notification.exception);
}