MDL-60407 report_insights: Fix redirect when action on last prediction
authorVíctor Déniz Falcón <victor@moodle.com>
Tue, 14 May 2019 00:06:00 +0000 (01:06 +0100)
committerVíctor Déniz Falcón <victor@moodle.com>
Tue, 14 May 2019 00:06:00 +0000 (01:06 +0100)
When an actions is taken on the last prediction, the predictions
list page is reloaded.

analytics/classes/local/target/base.php
report/insights/amd/build/actions.min.js
report/insights/amd/src/actions.js

index 0ea5e8b..3a5d9f2 100644 (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();
 
index 71cc939..98e554b 100644 (file)
Binary files a/report/insights/amd/build/actions.min.js and b/report/insights/amd/build/actions.min.js differ
index 3c98868..833d32d 100644 (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);
                 }