浏览代码

HUE-3228 [dashboard] Support auto refresh

Romain Rigaux 8 年之前
父节点
当前提交
0d2f50a

+ 10 - 8
apps/search/src/search/static/search/js/search.ko.js

@@ -1537,11 +1537,13 @@ var SearchViewModel = function (collection_json, query_json, initial_json) {
   self.hasRetrievedResults = ko.observable(true);
   self.hasRetrievedResults = ko.observable(true);
   self.asyncSearchesCounter = ko.observableArray([]);
   self.asyncSearchesCounter = ko.observableArray([]);
   self.asyncSearchesCounter.subscribe(function(newVal) {
   self.asyncSearchesCounter.subscribe(function(newVal) {
-  if (newVal.length == 0) {
-    self.isRetrievingResults(false);
-    self.hasRetrievedResults(true);
-    $('.btn-loading').button('reset');
-  }
+    if (newVal.length == 0) {
+      self.isRetrievingResults(false);
+      self.hasRetrievedResults(true);
+      $('.btn-loading').button('reset');
+
+      huePubSub.publish('check.autorefresh');
+    }
   });
   });
 
 
   self.showCores = ko.observable(false);
   self.showCores = ko.observable(false);
@@ -1870,8 +1872,8 @@ var SearchViewModel = function (collection_json, query_json, initial_json) {
                   result: data,
                   result: data,
                   status: 'running',
                   status: 'running',
                   progress: 0,
                   progress: 0,
-               }));
-               self.checkStatus(self.collection);
+              }));
+              self.checkStatus(self.collection);
             }
             }
           }
           }
           catch (e) {
           catch (e) {
@@ -1911,7 +1913,7 @@ var SearchViewModel = function (collection_json, query_json, initial_json) {
   };
   };
 
 
   self._make_grid_result = function(data, callback) {
   self._make_grid_result = function(data, callback) {
-    if (typeof callback === "function") {
+    if (typeof callback === "function") { // For Solr Auto refresh
       callback(data);
       callback(data);
     }
     }
 
 

+ 11 - 4
apps/search/src/search/templates/common_search.mako

@@ -3559,16 +3559,20 @@ $(document).ready(function () {
   });
   });
 
 
   viewModel.collection.autorefreshSeconds.subscribe(function (value) {
   viewModel.collection.autorefreshSeconds.subscribe(function (value) {
-    if (viewModel.collection.autorefresh()) {
-      window.clearTimeout(_refreshTimeout);
-      refresh();
-    }
+    checkAutoRefresh();
   });
   });
 
 
   if (viewModel.collection.autorefresh()) {
   if (viewModel.collection.autorefresh()) {
     refresh();
     refresh();
   }
   }
 
 
+  function checkAutoRefresh() {
+    if (viewModel.collection.autorefresh()) {
+      window.clearTimeout(_refreshTimeout);
+      refresh();
+    }
+  }
+
   function refresh() {
   function refresh() {
     _refreshTimeout = window.setTimeout(function () {
     _refreshTimeout = window.setTimeout(function () {
       if (viewModel.collection.autorefresh()) {
       if (viewModel.collection.autorefresh()) {
@@ -3577,6 +3581,9 @@ $(document).ready(function () {
     }, ($.isNumeric(viewModel.collection.autorefreshSeconds()) ? viewModel.collection.autorefreshSeconds() * 1 : 60) * 1000)
     }, ($.isNumeric(viewModel.collection.autorefreshSeconds()) ? viewModel.collection.autorefreshSeconds() * 1 : 60) * 1000)
   }
   }
 
 
+  huePubSub.subscribe('check.autorefresh', function () {
+    checkAutoRefresh();
+  });
 
 
   $("#addFacetDemiModal").on("hidden", function () {
   $("#addFacetDemiModal").on("hidden", function () {
     if (typeof selectedWidget.hasBeenSelected == "undefined"){
     if (typeof selectedWidget.hasBeenSelected == "undefined"){