Browse Source

HUE-2679 [search] Added autorefresh to the settings panel

Enrico Berti 10 years ago
parent
commit
6bd901b50d

+ 2 - 0
apps/search/src/search/static/search/js/search.ko.js

@@ -396,6 +396,8 @@ var Collection = function (vm, collection) {
   self.name = ko.mapping.fromJS(collection.name);
   self.label = ko.mapping.fromJS(collection.label);
   self.enabled = ko.mapping.fromJS(collection.enabled);
+  self.autorefresh = ko.mapping.fromJS(collection.autorefresh);
+  self.autorefreshSeconds = ko.mapping.fromJS(collection.autorefreshSeconds || 60);
   self.idField = ko.observable(collection.idField);
   self.template = ko.mapping.fromJS(collection.template);
   self.template.fieldsSelected.subscribe(function () {

+ 29 - 0
apps/search/src/search/templates/search.mako

@@ -1377,6 +1377,10 @@ ${ dashboard.layout_skeleton() }
     <label class="checkbox" style="margin-top: 4px">
       ${ _('Visible to everybody') } <input type="checkbox" data-bind="checked: $root.collection.enabled"/>
     </label>
+
+    <label class="checkbox" style="margin-top: 4px">
+      <input type="checkbox" style="margin-top: 9px" data-bind="checked: $root.collection.autorefresh"/> ${ _('Auto-refresh every') } <input type="text" class="input-mini" style="margin-bottom: 0; margin-left: 6px" data-bind="value: $root.collection.autorefreshSeconds"/> ${ _('seconds') }
+    </label>
   </div>
 </div>
 
@@ -1809,6 +1813,7 @@ $(document).ready(function () {
   viewModel.init(function(data){
     $(".chosen-select").trigger("chosen:updated");
   });
+
   viewModel.isRetrievingResults.subscribe(function(value){
     if (!value){
       resizeFieldsList();
@@ -1825,6 +1830,30 @@ $(document).ready(function () {
     }
   });
 
+  var _refreshTimeout = null;
+
+  viewModel.collection.autorefresh.subscribe(function (value) {
+    if (value) {
+      refresh();
+    }
+    else {
+      window.clearTimeout(_refreshTimeout);
+    }
+  });
+
+  if (viewModel.collection.autorefresh()) {
+    refresh();
+  }
+
+  function refresh() {
+    _refreshTimeout = window.setTimeout(function () {
+      if (viewModel.collection.autorefresh()) {
+        viewModel.search(refresh);
+      }
+    }, ($.isNumeric(viewModel.collection.autorefreshSeconds()) ? viewModel.collection.autorefreshSeconds() * 1 : 60) * 1000)
+  }
+
+
   $("#addFacetDemiModal").on("hidden", function () {
     if (typeof selectedWidget.hasBeenSelected == "undefined"){
       addFacetDemiModalFieldCancel();