Browse Source

HUE-8638 [importer] Enable context popover and syntax error highlighting in the importer field editor

Johan Ahlen 7 years ago
parent
commit
b11d426983

+ 7 - 2
desktop/core/src/desktop/static/desktop/js/ko.hue-bindings.js

@@ -4049,6 +4049,7 @@
           sourceType: sourceType,
           namespace: namespace,
           compute: compute,
+          temporaryOnly: options.temporaryOnly,
           cancellable: options.cancellable,
           cachedOnly: options.cachedOnly,
           identifierChain: location.identifierChain || location.colRef.identifierChain,
@@ -4361,7 +4362,9 @@
             };
 
             if (token.parseLocation && token.parseLocation.identifierChain && !token.notFound) {
-              token.parseLocation.resolveCatalogEntry().done(function (entry) {
+              token.parseLocation.resolveCatalogEntry({
+                temporaryOnly: self.snippet.autocompleteSettings.temporaryOnly
+              }).done(function (entry) {
                 huePubSub.publish('context.popover.show', {
                   data: {
                     type: 'catalogEntry',
@@ -4738,6 +4741,7 @@
         sourceType: self.snippet.type(),
         namespace: self.snippet.namespace(),
         compute: self.snippet.compute(),
+        temporaryOnly: self.snippet.autocompleteSettings.temporaryOnly,
         path: $.map(identifierChain, function (identifier) { return identifier.name }),
         silenceErrors: true,
         cachedOnly: true
@@ -4820,6 +4824,7 @@
                 sourceType: self.snippet.type(),
                 namespace: self.snippet.namespace(),
                 compute: self.snippet.compute(),
+                temporaryOnly: self.snippet.autocompleteSettings.temporaryOnly,
                 path: $.map(nextTable.identifierChain, function (identifier) { return identifier.name }),
                 cachedOnly: true,
                 silenceErrors: true
@@ -4986,7 +4991,7 @@
       var lastKnownLocations = {};
 
       var getLocationsSub = huePubSub.subscribe('get.active.editor.locations', function (callback, snippet) {
-        if (self.snippet === snippet || self.snippet.inFocus() || self.snippet.editorMode()) {
+        if (self.snippet === snippet && (self.snippet.inFocus() || self.snippet.editorMode())) {
           callback(lastKnownLocations);
         }
       });

+ 3 - 0
desktop/core/src/desktop/static/desktop/js/sqlUtils.js

@@ -149,6 +149,7 @@ var SqlUtils = (function () {
    * @param {String} options.sourceType
    * @param {ContextNamespace} options.namespace
    * @param {ContextCompute} options.compute
+   * @param {boolean} [options.temporaryOnly] - Default: false
    * @param {Object[]} [options.identifierChain]
    * @param {Object[]} [options.tables]
    * @param {Object} [options.cancellable]
@@ -223,6 +224,7 @@ var SqlUtils = (function () {
         path: SqlUtils.identifierChainToPath(nextTable.identifierChain),
         cachedOnly: options && options.cachedOnly,
         cancellable: options && options.cancellable,
+        temporaryOnly: options && options.temporaryOnly,
         silenceErrors: true
       }).done(function (childEntries) {
         var foundEntry = undefined;
@@ -253,6 +255,7 @@ var SqlUtils = (function () {
         path: [],
         cachedOnly: options && options.cachedOnly,
         cancellable: options && options.cancellable,
+        temporaryOnly: options && options.temporaryOnly,
         silenceErrors: true
       }).done(function (entry) {
         findInTree(entry, SqlUtils.identifierChainToPath(options.identifierChain))

+ 1 - 1
desktop/core/src/desktop/static/desktop/spec/sqlAutocompleter3Spec.js

@@ -418,7 +418,7 @@
           snippet: {
             autocompleteSettings: {
               temporaryOnly: false
-            }
+            },
             type: function () {
               return dialect;
             },

+ 41 - 18
desktop/core/src/desktop/templates/ko_components/ko_simple_ace_editor.mako

@@ -811,26 +811,49 @@ from desktop.views import _ko
 
           var sourceType = params.autocomplete.type.indexOf('Query') !== -1 ? params.autocomplete.type.replace('Query', '') : params.autocomplete.type;
 
+          var snippet = {
+            autocompleteSettings: {
+              temporaryOnly: params.temporaryOnly
+            },
+            type: ko.observable(sourceType),
+            id: ko.observable($element.attr('id')),
+            namespace: params.namespace,
+            compute: params.compute,
+            database: ko.observable(params.database && params.database() ? params.database() : 'default'),
+            availableDatabases: ko.observableArray([params.database && params.database() ? params.database() : 'default']),
+            positionStatement: ko.observable({
+              location: { first_line: 1, last_line: 1, first_column: 0, last_column: editor.getValue().length }
+            }),
+            isSqlDialect: ko.observable(true),
+            aceCursorPosition: ko.observable(),
+            inFocus: ko.observable()
+          };
+
+          if (sourceType === 'hive' || sourceType === 'impala') {
+            WorkerHandler.registerWorkers();
+            var aceLocationHandler = new AceLocationHandler({ editor: editor, editorId: $element.attr('id'), snippet: snippet });
+            self.disposeFunctions.push(function () {
+              aceLocationHandler.dispose();
+            });
+            aceLocationHandler.attachSqlSyntaxWorker();
+          }
+
+          var focusListener = editor.on('focus', function () {
+            snippet.inFocus(true);
+          });
+
+          var blurListener = editor.on('blur', function () {
+            snippet.inFocus(false);
+          });
+
+          self.disposeFunctions.push(function () {
+            editor.off('focus', focusListener);
+            editor.off('blur', blurListener);
+          });
+
           var autocompleteArgs = {
             editor: function() { return editor },
-            snippet: {
-              autocompleteSettings: {
-                temporaryOnly: params.temporaryOnly
-              },
-              type: function () {
-                return sourceType;
-              },
-              namespace: params.namespace,
-              compute: params.compute,
-              database: function () {
-                return params.database && params.database() ? params.database() : 'default';
-              },
-              positionStatement: function () {
-                return {
-                  location: { first_line: 1, last_line: 1, first_column: 0, last_column: editor.getValue().length }
-                }
-              }
-            },
+            snippet: snippet,
             fixedPrefix: params.fixedPrefix,
             fixedPostfix: params.fixedPostfix,
             support: params.autocomplete.support

+ 0 - 71
desktop/libs/notebook/src/notebook/templates/workers_embedded.mako

@@ -1,71 +0,0 @@
-## Licensed to Cloudera, Inc. under one
-## or more contributor license agreements.  See the NOTICE file
-## distributed with this work for additional information
-## regarding copyright ownership.  Cloudera, Inc. licenses this file
-## to you under the Apache License, Version 2.0 (the
-## "License"); you may not use this file except in compliance
-## with the License.  You may obtain a copy of the License at
-##
-##     http://www.apache.org/licenses/LICENSE-2.0
-##
-## Unless required by applicable law or agreed to in writing, software
-## distributed under the License is distributed on an "AS IS" BASIS,
-## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-## See the License for the specific language governing permissions and
-## limitations under the License.
-
-<%!
-  from desktop.models import hue_version
-%>
-
-<html>
-<body></body>
-<script type="text/javascript">
-  (function () {
-    if (window.Worker) {
-      var baseUrl = window.location.href.substring(0, window.location.href.indexOf('/notebook/workers_embedded'));
-      // It can take a while before the worker is active
-      var whenWorkerIsReady = function (worker, message) {
-        if (!worker.isReady) {
-          window.clearTimeout(worker.pingTimeout);
-          worker.postMessage({ ping: true });
-          worker.pingTimeout = window.setTimeout(function () {
-            whenWorkerIsReady(worker, message);
-          }, 500);
-        } else {
-          worker.postMessage(message);
-        }
-      };
-
-      // For syntax checking
-      var aceSqlSyntaxWorker = new Worker(baseUrl + '/desktop/workers/aceSqlSyntaxWorker.js?v=${ hue_version() }');
-      aceSqlSyntaxWorker.onmessage = function (e) {
-        if (e.data.ping) {
-          aceSqlSyntaxWorker.isReady = true;
-        } else {
-          window.top.postMessage({ syntaxWorkerResponse: e.data }, '*');
-        }
-      };
-
-      // For location marking
-      var aceSqlLocationWorker = new Worker(baseUrl + '/desktop/workers/aceSqlLocationWorker.js?v=${ hue_version() }');
-      aceSqlLocationWorker.onmessage = function (e) {
-        if (e.data.ping) {
-          aceSqlLocationWorker.isReady = true;
-        } else {
-          window.top.postMessage({ locationWorkerResponse: e.data }, '*');
-        }
-      };
-
-      window.addEventListener("message", function (event) {
-        if (event.data.locationWorkerRequest) {
-          whenWorkerIsReady(aceSqlLocationWorker, event.data.locationWorkerRequest);
-        }
-        if (event.data.syntaxWorkerRequest) {
-          whenWorkerIsReady(aceSqlSyntaxWorker, event.data.syntaxWorkerRequest);
-        }
-      }, false);
-    }
-  })();
-</script>
-</html>