Browse Source

HUE-8341 [assist] Create a new document from the doc assist

Roohi 7 years ago
parent
commit
7458341576

+ 6 - 0
desktop/core/src/desktop/static/desktop/js/ko.hue-bindings.js

@@ -7340,4 +7340,10 @@
     };
     };
   })();
   })();
 
 
+  ko.bindingHandlers.dropdown = {
+    init: function (element, valueAccessor) {
+        $(element).dropdown();
+    }
+  };
+
 })();
 })();

+ 81 - 1
desktop/core/src/desktop/templates/assist.mako

@@ -637,13 +637,92 @@ from desktop.views import _ko
       <!-- ko if: !loading() -->
       <!-- ko if: !loading() -->
       <div class="highlightable" data-bind="css: { 'highlight': $parent.highlightTypeFilter() }, component: { name: 'hue-drop-down', params: { fixedPosition: true, value: typeFilter, searchable: true, entries: DOCUMENT_TYPES, linkTitle: '${ _ko('Document type') }' } }" style="display: inline-block"></div>
       <div class="highlightable" data-bind="css: { 'highlight': $parent.highlightTypeFilter() }, component: { name: 'hue-drop-down', params: { fixedPosition: true, value: typeFilter, searchable: true, entries: DOCUMENT_TYPES, linkTitle: '${ _ko('Document type') }' } }" style="display: inline-block"></div>
       <!-- /ko -->
       <!-- /ko -->
+      <span class="dropdown new-document-drop-down">
+
+        <a class="inactive-action dropdown-toggle" data-toggle="dropdown" data-bind="dropdown" href="javascript:void(0);">
+             <i class="pointer fa fa-plus" title="${ _('New document') }"></i>
+        </a>
+        <ul class="dropdown-menu less-padding document-types" style="margin-top:3px; margin-left:-140px; width: 175px;position: absolute;" role="menu">
+            % if 'beeswax' in apps:
+              <li>
+                <a title="${_('Hive Query')}"
+                % if is_embeddable:
+                  data-bind="click: function() { huePubSub.publish('open.editor.new.query', {type: 'hive', 'directoryUuid': $data.getDirectory()}); }" href="javascript:void(0);"
+                % else:
+                  data-bind="click: function() { $('.new-document-drop-down').removeClass('open');}, hueLink: $data.addDirectoryParamToUrl('${ url('notebook:editor') }?type=hive')"
+                % endif
+                >
+                  <!-- ko template: { name: 'app-icon-template', data: { icon: 'hive' } } --><!-- /ko --> ${_('Hive Query')}
+                </a>
+              </li>
+            % endif
+            % if 'impala' in apps:
+              <li>
+                <a title="${_('Impala Query')}" class="dropdown-item"
+                % if is_embeddable:
+                  data-bind="click: function() { huePubSub.publish('open.editor.new.query', {type: 'impala', 'directoryUuid': $data.getDirectory()}); }" href="javascript:void(0);"
+                % else:
+                  data-bind="click: function() { $('.new-document-drop-down').removeClass('open');}, hueLink: $data.addDirectoryParamToUrl('${ url('notebook:editor') }?type=impala')"
+                % endif
+                >
+                  <!-- ko template: { name: 'app-icon-template', data: { icon: 'impala' } } --><!-- /ko --> ${_('Impala Query')}
+                </a>
+            </li>
+            % endif
+            <%
+            from notebook.conf import SHOW_NOTEBOOKS
+            %>
+            % if SHOW_NOTEBOOKS.get():
+              <li>
+                <a title="${_('Notebook')}" data-bind="click: function() { $('.new-document-drop-down').removeClass('open');}, hueLink: $data.addDirectoryParamToUrl('${ url('notebook:index') }')">
+                  <!-- ko template: { name: 'app-icon-template', data: { icon: 'notebook' } } --><!-- /ko --> ${_('Notebook')}
+                </a>
+              </li>
+            % endif
+            % if 'pig' in apps:
+              <li>
+                <a title="${_('Pig Script')}" data-bind="click: function() { $('.new-document-drop-down').removeClass('open');}, hueLink: $data.addDirectoryParamToUrl('${ url('pig:index') }')">
+                  <!-- ko template: { name: 'app-icon-template', data: { icon: 'pig' } } --><!-- /ko --> ${_('Pig Script')}
+                </a>
+              </li>
+            % endif
+            % if 'oozie' in apps:
+              <li>
+                <a title="${_('Oozie Workflow')}" data-bind="click: function() { $('.new-document-drop-down').removeClass('open');}, hueLink: $data.addDirectoryParamToUrl('${ url('oozie:new_workflow') }')">
+                  <!-- ko template: { name: 'app-icon-template', data: { icon: 'oozie-workflow' } } --><!-- /ko --> ${_('Workflow') if is_embeddable else _('Oozie Workflow')}
+                </a>
+              </li>
+              <li>
+                <a title="${_('Oozie Schedule')}" data-bind="click: function() { $('.new-document-drop-down').removeClass('open');}, hueLink: $data.addDirectoryParamToUrl('${ url('oozie:new_coordinator') }')">
+                  <!-- ko template: { name: 'app-icon-template', data: { icon: 'oozie-coordinator' } } --><!-- /ko --> ${_('Schedule') if is_embeddable else _('Oozie Coordinator')}
+                </a>
+              </li>
+              <li>
+                <a title="${_('Oozie Bundle')}" data-bind="click: function() { $('.new-document-drop-down').removeClass('open');}, hueLink: $data.addDirectoryParamToUrl('${ url('oozie:new_bundle') }')">
+                  <!-- ko template: { name: 'app-icon-template', data: { icon: 'oozie-bundle' } } --><!-- /ko --> ${_('Bundle') if is_embeddable else _('Oozie Bundle')}
+                </a>
+              </li>
+            % endif
+            % if 'search' in apps:
+              <li>
+                <a title="${_('Solr Search')}" data-bind="click: function() { $('.new-document-drop-down').removeClass('open');}, hueLink: $data.addDirectoryParamToUrl('${ url('search:new_search') }')">
+                  <!-- ko template: { name: 'app-icon-template', data: { icon: 'dashboard' } } --><!-- /ko --> ${_('Dashboard')}
+                </a>
+              </li>
+            % endif
+            <li class="divider"></li>
+            <li data-bind="css: { 'disabled': $data.isTrash() || $data.isTrashed() || !$data.canModify() }">
+              <a href="javascript:void(0);" data-bind="click: function () { $('.new-document-drop-down').removeClass('open'); huePubSub.publish('show.create.directory.modal', $data); $data.showNewDirectoryModal()}"><svg class="hi"><use xlink:href="#hi-folder"></use><use xlink:href="#hi-plus-addon"></use></svg> ${_('New folder')}</a>
+            </li>
+          </ul>
+      </span>
       <a class="inactive-action" href="javascript:void(0)" data-bind="click: function () { huePubSub.publish('assist.document.refresh'); }"><i class="pointer fa fa-refresh" data-bind="css: { 'fa-spin blue' : loading }" title="${_('Manual refresh')}"></i></a>
       <a class="inactive-action" href="javascript:void(0)" data-bind="click: function () { huePubSub.publish('assist.document.refresh'); }"><i class="pointer fa fa-refresh" data-bind="css: { 'fa-spin blue' : loading }" title="${_('Manual refresh')}"></i></a>
     </div>
     </div>
   </script>
   </script>
 
 
   <script type="text/html" id="assist-documents-inner-panel">
   <script type="text/html" id="assist-documents-inner-panel">
     <!-- ko with: activeEntry -->
     <!-- ko with: activeEntry -->
-    <div class="assist-flex-header assist-breadcrumb">
+    <div class="assist-flex-header assist-breadcrumb" style="overflow: visible">
       <!-- ko ifnot: isRoot -->
       <!-- ko ifnot: isRoot -->
       <a href="javascript: void(0);" data-bind="click: function () { if (loaded()) { parent.makeActive(); } }">
       <a href="javascript: void(0);" data-bind="click: function () { if (loaded()) { parent.makeActive(); } }">
         <i class="fa fa-fw fa-chevron-left"></i>
         <i class="fa fa-fw fa-chevron-left"></i>
@@ -1023,6 +1102,7 @@ from desktop.views import _ko
 
 
 
 
     (function () {
     (function () {
+
       ko.bindingHandlers.assistFileDroppable = {
       ko.bindingHandlers.assistFileDroppable = {
         init: function(element, valueAccessor, allBindings, boundEntry) {
         init: function(element, valueAccessor, allBindings, boundEntry) {
           var dragData;
           var dragData;

+ 1 - 19
desktop/core/src/desktop/templates/document_browser.mako

@@ -194,24 +194,6 @@ from desktop.views import _ko
       <!-- /ko -->
       <!-- /ko -->
     </div>
     </div>
 
 
-    <div id="createDirectoryModal" data-keyboard="true" class="modal hide fade" tabindex="-1">
-      <!-- ko with: activeEntry -->
-      <form class="form-horizontal">
-        <div class="modal-header">
-          <button type="button" class="close" data-dismiss="modal" aria-label="${ _('Close') }"><span aria-hidden="true">&times;</span></button>
-          <h2 class="modal-title">${_('Create Directory')}</h2>
-        </div>
-        <div class="modal-body ">
-          <input id="newDirectoryName" class="input large-as-modal" type="text" placeholder="${ _('Directory name') }" />
-        </div>
-        <div class="modal-footer">
-          <input type="button" class="btn" data-dismiss="modal" data-bind="click: function () { $('#newDirectoryName').val(null) }" value="${ _('Cancel') }">
-          <input type="submit" class="btn btn-primary disable-feedback" value="${ _('Create') }" data-bind="click: function () { if ($('#newDirectoryName').val()) { $data.createDirectory($('#newDirectoryName').val()); $('#createDirectoryModal').modal('hide'); } }"/>
-        </div>
-      </form>
-      <!-- /ko -->
-    </div>
-
     <div id="renameDirectoryModal" data-keyboard="true" class="modal hide fade" tabindex="-1">
     <div id="renameDirectoryModal" data-keyboard="true" class="modal hide fade" tabindex="-1">
       <!-- ko with: activeEntry -->
       <!-- ko with: activeEntry -->
       <form class="form-horizontal">
       <form class="form-horizontal">
@@ -336,7 +318,7 @@ from desktop.views import _ko
                       % endif
                       % endif
                       <li class="divider"></li>
                       <li class="divider"></li>
                       <li data-bind="css: { 'disabled': isTrash() || isTrashed() || !canModify() }">
                       <li data-bind="css: { 'disabled': isTrash() || isTrashed() || !canModify() }">
-                        <a href="javascript:void(0);" data-bind="click: function () { showNewDirectoryModal() }"><svg class="hi"><use xlink:href="#hi-folder"></use><use xlink:href="#hi-plus-addon"></use></svg> ${_('New folder')}</a>
+                        <a href="javascript:void(0);" data-bind="click: function () {  huePubSub.publish('show.create.directory.modal', $data);showNewDirectoryModal() }"><svg class="hi"><use xlink:href="#hi-folder"></use><use xlink:href="#hi-plus-addon"></use></svg> ${_('New folder')}</a>
                       </li>
                       </li>
                     </ul>
                     </ul>
                   </span>
                   </span>

+ 2 - 0
desktop/core/src/desktop/templates/ko_components.mako

@@ -30,6 +30,7 @@
 <%namespace name="koSqlColumnsTable" file="/ko_components/ko_sql_columns_table.mako" />
 <%namespace name="koSqlColumnsTable" file="/ko_components/ko_sql_columns_table.mako" />
 <%namespace name="koDeleteDocModal" file="/ko_components/ko_delete_doc_modal.mako" />
 <%namespace name="koDeleteDocModal" file="/ko_components/ko_delete_doc_modal.mako" />
 <%namespace name="koSentryPrivileges" file="/ko_components/ko_sentry_privileges.mako" />
 <%namespace name="koSentryPrivileges" file="/ko_components/ko_sentry_privileges.mako" />
+<%namespace name="koCreateDirModal" file="/ko_components/ko_create_directory_modal.mako" />
 
 
 <%def name="all()">
 <%def name="all()">
   ${ koAppSwitcher.appSwitcher() }
   ${ koAppSwitcher.appSwitcher() }
@@ -48,4 +49,5 @@
   ${ koSqlColumnsTable.sqlColumnsTable() }
   ${ koSqlColumnsTable.sqlColumnsTable() }
   ${ koDeleteDocModal.deleteDoc() }
   ${ koDeleteDocModal.deleteDoc() }
   ${ koSentryPrivileges.sentryPrivileges() }
   ${ koSentryPrivileges.sentryPrivileges() }
+  ${ koCreateDirModal.createDirectory() }
 </%def>
 </%def>

+ 59 - 0
desktop/core/src/desktop/templates/ko_components/ko_create_directory_modal.mako

@@ -0,0 +1,59 @@
+## 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.views import _ko
+from django.utils.translation import ugettext as _
+%>
+
+<%def name="createDirectory()">
+  <script type="text/html" id="create-directory-template">
+      <!-- ko with: activeEntry -->
+      <form class="form-horizontal">
+        <div class="modal-header">
+          <button type="button" class="close" data-dismiss="modal" aria-label="${ _('Close') }"><span aria-hidden="true">&times;</span></button>
+          <h2 class="modal-title">${_('Create Directory')}</h2>
+        </div>
+        <div class="modal-body ">
+          <input id="newDirectoryName" class="input large-as-modal" type="text" placeholder="${ _('Directory name') }" />
+        </div>
+        <div class="modal-footer">
+          <input type="button" class="btn" data-dismiss="modal" data-bind="click: function () { $('#newDirectoryName').val(null) }" value="${ _('Cancel') }">
+          <input type="submit" class="btn btn-primary disable-feedback" value="${ _('Create') }" data-bind="click: function () { if ($('#newDirectoryName').val()) { $data.createDirectory($('#newDirectoryName').val()); $('#createDirectoryModal').modal('hide'); } }"/>
+        </div>
+      </form>
+      <!-- /ko -->
+</script>
+
+  <script type="text/javascript">
+    (function () {
+      ko.components.register('create-directory', {
+        template: {element: 'create-directory-template'}
+      });
+
+      huePubSub.subscribe('show.create.directory.modal', function (docViewModel) {
+        if ($('#createDirectoryModal').length > 0) {
+          ko.cleanNode($('#createDirectoryModal')[0]);
+          $('#createDirectoryModal').remove();
+        }
+        var $createDirectoryModal = $('<div id="createDirectoryModal" data-bind="component: { name: \'create-directory\', params: $data }" data-keyboard="true" class="modal hide fade" tabindex="-1"/>');
+        $(HUE_CONTAINER).append($createDirectoryModal);
+        ko.applyBindings(docViewModel, $createDirectoryModal[0]);
+      });
+
+    })();
+  </script>
+</%def>