Эх сурвалжийг харах

HUE-2451 [dashboard] Perform search on enter in the query editor

Johan Ahlen 8 жил өмнө
parent
commit
59a28e2

+ 15 - 4
desktop/core/src/desktop/templates/ko_components/ko_simple_ace_editor.mako

@@ -809,6 +809,15 @@ from desktop.views import _ko
 
         editor.setOptions(aceOptions);
 
+        if (params.onExec) {
+          var bindPrefix = params.singleLine ? 'Enter|Shift-Enter|' : '';
+          editor.commands.addCommand({
+            name: 'enter',
+            bindKey: { win: bindPrefix + 'Ctrl-Enter', mac: bindPrefix + 'Ctrl-Enter|Command-Enter' },
+            exec: params.onExec
+          });
+        }
+
         if (params.singleLine) {
           editor.renderer.screenToTextCoordinates = function(x, y) {
             var pos = this.pixelToScreenCoordinates(x, y);
@@ -818,7 +827,9 @@ from desktop.views import _ko
             );
           };
 
-          editor.commands.bindKey('Enter|Shift-Enter', 'null');
+          if (!params.onExec) {
+            editor.commands.bindKey('Enter|Shift-Enter', 'null');
+          }
 
           var pasteListener = editor.on('paste', function(e) {
             e.text = e.text.replace(/[\r\n]+/g, ' ');
@@ -847,7 +858,7 @@ from desktop.views import _ko
 
           var $placeHolder = $("<div>").text(ko.unwrap(params.placeHolder)).addClass("ace_invisible ace_emptyMessage");
 
-          if (editor.getValue().length == 0) {
+          if (editor.getValue().length === 0) {
             $placeHolder.appendTo(editor.renderer.scroller);
             placeHolderVisible = true;
           }
@@ -900,7 +911,7 @@ from desktop.views import _ko
         }
 
         var parseThrottle = -1;
-        var inputListener = editor.on('input', function () {
+        var valueUpdateListener = editor.on('input', function () {
           self.value(editor.getValue());
           if (self.parsedValue && self.autocompleter && self.autocompleter.parse) {
             window.clearTimeout(parseThrottle);
@@ -917,7 +928,7 @@ from desktop.views import _ko
         });
 
         self.disposeFunctions.push(function () {
-          editor.off('input', inputListener);
+          editor.off('input', valueUpdateListener);
         });
       };
 

+ 2 - 2
desktop/libs/dashboard/src/dashboard/templates/common_search.mako

@@ -106,10 +106,10 @@ from dashboard.conf import USE_GRIDSTER, HAS_REPORT_ENABLED
           <div class="search-bar-query" data-bind="foreach: query.qs">
 
             <!-- ko if: $root.collection.engine() === 'solr' -->
-            <div data-bind="component: { name: 'hue-simple-ace-editor', params: { value: q, placeHolder: '${ _ko('Example: field:value, or press CTRL + space') }', autocomplete: { type: 'solrQuery', support: { collection: $root.collection } }, singleLine: true } }"></div>
+            <div data-bind="component: { name: 'hue-simple-ace-editor', params: { value: q, onExec: $parent.searchBtn, placeHolder: '${ _ko('Example: field:value, or press CTRL + space') }', autocomplete: { type: 'solrQuery', support: { collection: $root.collection } }, singleLine: true } }"></div>
             <!-- /ko -->
             <!-- ko if: $root.collection.engine() !== 'solr' -->
-            <div data-bind="component: { name: 'hue-simple-ace-editor', params: { value: q, placeHolder: '${ _ko('Example: col = value') }', singleLine: true } }"></div>
+            <div data-bind="component: { name: 'hue-simple-ace-editor', params: { value: q, onExec: $parent.searchBtn, placeHolder: '${ _ko('Example: col = value') }', singleLine: true } }"></div>
             <!-- /ko -->
 ##             <input data-bind="clearable: q, valueUpdate:'afterkeydown', typeahead: { target: q, nonBindableSource: queryTypeahead, multipleValues: true, multipleValuesSeparator: ':', extraKeywords: 'AND OR TO', completeSolrRanges: true }, css: {'input-small': $root.query.qs().length > 1, 'flat-left': $index() === 0, 'input-xlarge': $root.collection.supportAnalytics()}" maxlength="4096" type="text" class="search-query">
             <!-- ko if: $index() >= 1 -->