소스 검색

HUE-4866 [notebook] Select a document as a snippet

Romain Rigaux 9 년 전
부모
커밋
ba23d40

+ 1 - 0
apps/oozie/src/oozie/templates/editor2/common_workflow.mako

@@ -25,6 +25,7 @@
   from django.utils.translation import ugettext as _
   from django.utils.translation import ugettext as _
   from desktop.views import _ko
   from desktop.views import _ko
 %>
 %>
+
 <%namespace name="utils" file="../utils.inc.mako" />
 <%namespace name="utils" file="../utils.inc.mako" />
 
 
 <%def name="render()">
 <%def name="render()">

+ 2 - 0
desktop/libs/notebook/src/notebook/static/notebook/js/notebook.ko.js

@@ -437,6 +437,7 @@ var EditorViewModel = (function() {
         }
         }
       });
       });
     });
     });
+    self.associatedDocument = ko.observable();
     self.statement_raw = ko.observable(typeof snippet.statement_raw != "undefined" && snippet.statement_raw != null ? snippet.statement_raw : '');
     self.statement_raw = ko.observable(typeof snippet.statement_raw != "undefined" && snippet.statement_raw != null ? snippet.statement_raw : '');
     self.selectedStatement = ko.observable('');
     self.selectedStatement = ko.observable('');
     self.aceSize = ko.observable(typeof snippet.aceSize != "undefined" && snippet.aceSize != null ? snippet.aceSize : 100);
     self.aceSize = ko.observable(typeof snippet.aceSize != "undefined" && snippet.aceSize != null ? snippet.aceSize : 100);
@@ -2062,6 +2063,7 @@ var EditorViewModel = (function() {
     self.successUrl = ko.observable(options.success_url);
     self.successUrl = ko.observable(options.success_url);
     self.isOptimizerEnabled = ko.observable(options.is_optimizer_enabled);
     self.isOptimizerEnabled = ko.observable(options.is_optimizer_enabled);
     self.isNavigatorEnabled = ko.observable(options.is_navigator_enabled);
     self.isNavigatorEnabled = ko.observable(options.is_navigator_enabled);
+    self.documentChooser = new DocumentChooser();
 
 
     self.CoordinatorEditorViewModel = CoordinatorEditorViewModel;
     self.CoordinatorEditorViewModel = CoordinatorEditorViewModel;
     self.RunningCoordinatorModel = RunningCoordinatorModel;
     self.RunningCoordinatorModel = RunningCoordinatorModel;

+ 35 - 4
desktop/libs/notebook/src/notebook/templates/editor_components.mako

@@ -72,7 +72,7 @@ from notebook.conf import ENABLE_QUERY_BUILDER, ENABLE_QUERY_SCHEDULING, ENABLE_
 <script src="${ static('desktop/ext/js/jquery/plugins/jquery.hotkeys.js') }"></script>
 <script src="${ static('desktop/ext/js/jquery/plugins/jquery.hotkeys.js') }"></script>
 <script src="${ static('desktop/ext/js/jquery/plugins/jquery.mousewheel.min.js') }"></script>
 <script src="${ static('desktop/ext/js/jquery/plugins/jquery.mousewheel.min.js') }"></script>
 <script src="${ static('desktop/ext/js/jquery.mCustomScrollbar.concat.min.js') }"></script>
 <script src="${ static('desktop/ext/js/jquery.mCustomScrollbar.concat.min.js') }"></script>
-
+<script src="${ static('desktop/js/document/documentChooser.js') }"></script>
 
 
 % if ENABLE_QUERY_SCHEDULING.get():
 % if ENABLE_QUERY_SCHEDULING.get():
 <script src="${ static('oozie/js/dashboard-utils.js') }" type="text/javascript" charset="utf-8"></script>
 <script src="${ static('oozie/js/dashboard-utils.js') }" type="text/javascript" charset="utf-8"></script>
@@ -1423,6 +1423,15 @@ ${ hueIcons.symbols() }
   </div>
   </div>
 </script>
 </script>
 
 
+<script type="text/html" id="doc-search-autocomp-item">
+  <a>
+    <div>
+      <strong style="font-size: 14px;" data-bind="html: name"></strong>
+      <div style="width: 190px; overflow: hidden; white-space: nowrap; text-overflow:ellipsis; font-size: 12px;" class="muted" data-bind="text: description"></div>
+    </div>
+  </a>
+</script>
+
 <script type="text/html" id="longer-operation">
 <script type="text/html" id="longer-operation">
   <div rel="tooltip" data-placement="bottom" data-bind="tooltip, fadeVisible: showLongOperationWarning" title="${ _('The operation in the server is taking longer than expected') }" class="inline-block">
   <div rel="tooltip" data-placement="bottom" data-bind="tooltip, fadeVisible: showLongOperationWarning" title="${ _('The operation in the server is taking longer than expected') }" class="inline-block">
     <i  class="fa fa-exclamation-triangle warning"></i>
     <i  class="fa fa-exclamation-triangle warning"></i>
@@ -1614,9 +1623,31 @@ ${ hueIcons.symbols() }
         <div class="control-group">
         <div class="control-group">
           <label class="control-label">${_('Query File')}</label>
           <label class="control-label">${_('Query File')}</label>
           <div class="controls">
           <div class="controls">
-            <input type="text" class="input-xxlarge filechooser-input" data-bind="value: statementPath, valueUpdate: 'afterkeydown', filechooser: statementPath" placeholder="${ _('Path to file, e.g. /user/hue/sample.sql, s3a://hue/sample.sql') }"/>
-            <!-- ko if: statementPath() -->
-              <a data-bind="attr: {href: '/filebrowser/view=' + statementPath() }" target="_blank" title="${ _('Open in new tab') }">
+
+          <div class="select-like">
+          <input placeholder="${ _('Search your documents...') }" type="text" data-bind="autocomplete: {
+              source: $root.documentChooser.documentsAutocompleteSource,
+              showOnFocus: true,
+              blurOnEnter: true,
+              type: 'hive',
+              create: function (event, ui) {
+                if (associatedDocument()) {
+                  this.value = ko.dataFor(event.target).associatedDocument().name();
+                 }
+                 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;},
+              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>
                 <i class="fa fa-external-link-square"></i>
               </a>
               </a>
             <!-- /ko -->
             <!-- /ko -->