Преглед изворни кода

HUE-4866 [notebook] Execute saved Hive snippet from a notebook snippet

Romain Rigaux пре 9 година
родитељ
комит
9f2fc43

+ 6 - 2
desktop/libs/notebook/src/notebook/connectors/hiveserver2.py

@@ -32,10 +32,11 @@ from desktop.lib.exceptions import StructuredException
 from desktop.lib.exceptions_renderable import PopupException
 from desktop.lib.i18n import force_unicode
 from desktop.lib.rest.http_client import RestException
-from desktop.models import DefaultConfiguration
+from desktop.models import DefaultConfiguration, Document2
 from metadata.optimizer_client import OptimizerApi
 
-from notebook.connectors.base import Api, QueryError, QueryExpired, OperationTimeout, OperationNotSupported
+from notebook.connectors.base import Api, QueryError, QueryExpired, OperationTimeout, OperationNotSupported,\
+  Notebook
 
 
 LOG = logging.getLogger(__name__)
@@ -611,6 +612,9 @@ class HS2Api(Api):
 
     if snippet.get('statementType') == 'file':
       snippet['statement'] = self._get_statement_from_file(snippet)
+    elif snippet.get('statementType') == 'document':
+      notebook = Notebook(Document2.objects.get_by_uuid(user=self.user, uuid=snippet['statementPath'], perm_type='read'))
+      snippet['statement'] = notebook.get_str()
 
     statements = self._get_statements(snippet['statement'])
 

+ 9 - 9
desktop/libs/notebook/src/notebook/templates/editor_components.mako

@@ -1625,7 +1625,7 @@ ${ hueIcons.symbols() }
           <div class="controls">
 
           <div class="select-like">
-          <input placeholder="${ _('Search your documents...') }" type="text" data-bind="autocomplete: {
+          <input class="input-xlarge" placeholder="${ _('Search your documents...') }" type="text" data-bind="autocomplete: {
               source: $root.documentChooser.documentsAutocompleteSource,
               showOnFocus: true,
               blurOnEnter: true,
@@ -1637,20 +1637,20 @@ ${ hueIcons.symbols() }
                  return false;
                },
               select: function (event, ui) { ko.dataFor(event.target).statementPath(ui.item.value); this.value = ui.item.label; return false;},
-              focus: function (event, ui) { this.value = ui.item.label; return false;},
-              change: function (event, ui) { this.value = ko.dataFor(event.target).associatedDocument().name(); return false;},
+              focus: function (event, ui) { this.value = ui.item.label; return false; },
+              change: function (event, ui) { this.value = ko.dataFor(event.target).associatedDocument().name(); return false; },
               itemTemplate: 'doc-search-autocomp-item'
             }, valueUpdate: 'afterkeydown'">
             <span class="inactive-action">
               <i class="fa fa-sort"></i>
             </span>
           </div>
-            <!-- ko if: associatedDocument() -->
-              <div data-bind='text: associatedDocument().description' style="padding: 3px; margin-top: 2px" class="muted"></div>
-              <a data-bind="attr: { associatedDocument().absoluteUrl() }" target="_blank" title="${ _('Open in new tab') }">
-                <i class="fa fa-external-link-square"></i>
-              </a>
-            <!-- /ko -->
+          <!-- ko if: associatedDocument() -->
+            <div data-bind='text: associatedDocument().description' style="padding: 3px; margin-top: 2px" class="muted"></div>
+            <a data-bind="attr: { associatedDocument().absoluteUrl() }" target="_blank" title="${ _('Open in new tab') }">
+              <i class="fa fa-external-link-square"></i>
+            </a>
+          <!-- /ko -->
           </div>
       </div>
       <!-- /ko -->