From 8dd1ebaaba7598da340d480a1a80648c6502f36a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20D=C3=A9niz=20Falc=C3=B3n?= Date: Tue, 14 May 2019 01:06:00 +0100 Subject: [PATCH] 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. --- analytics/classes/local/target/base.php | 4 +++- report/insights/amd/build/actions.min.js | 2 +- report/insights/amd/src/actions.js | 18 +++++++++++------- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/analytics/classes/local/target/base.php b/analytics/classes/local/target/base.php index 0ea5e8b8e29..3a5d9f291a9 100644 --- a/analytics/classes/local/target/base.php +++ b/analytics/classes/local/target/base.php @@ -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(); diff --git a/report/insights/amd/build/actions.min.js b/report/insights/amd/build/actions.min.js index 71cc939b182..98e554bd468 100644 --- a/report/insights/amd/build/actions.min.js +++ b/report/insights/amd/build/actions.min.js @@ -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)}})}}}); \ No newline at end of file +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)}})}}}); \ No newline at end of file diff --git a/report/insights/amd/src/actions.js b/report/insights/amd/src/actions.js index 3c98868fc90..833d32d0e16 100644 --- a/report/insights/amd/src/actions.js +++ b/report/insights/amd/src/actions.js @@ -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); }